本文整理汇总了C++中variant类的典型用法代码示例。如果您正苦于以下问题:C++ variant类的具体用法?C++ variant怎么用?C++ variant使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了variant类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: set_value
void scrollbar_widget::set_value(const std::string& key, const variant& v)
{
if(key == "on_scroll") {
ffl_handler_ = get_environment()->create_formula(v["on_scroll"]);
} else if(key == "up_arrow") {
up_arrow_ = widget_factory::create(v, get_environment());
} else if(key == "down_arrow") {
down_arrow_ = widget_factory::create(v, get_environment());
} else if(key == "handle") {
handle_ = widget_factory::create(v, get_environment());
} else if(key == "handle_bottom") {
handle_bot_ = widget_factory::create(v, get_environment());
} else if(key == "handle_top") {
handle_top_ = widget_factory::create(v, get_environment());
} else if(key == "background") {
background_ = widget_factory::create(v, get_environment());
} else if(key == "range") {
std::vector<int> range = v.as_list_int();
ASSERT_EQ(range.size(), 2);
set_range(range[0], range[1]);
} else if(key == "position") {
window_pos_ = v.as_int();
clip_window_position();
}
widget::set_value(key, v);
}
开发者ID:kimsama,项目名称:frogatto,代码行数:27,代码来源:scrollbar_widget.cpp
示例2: is_valid
void variant::swap(variant& other)
{
if (this == &other)
return;
const bool is_this_valid = is_valid();
const bool is_other_valid = other.is_valid();
if (!is_this_valid && !is_other_valid)
return;
if (is_this_valid && is_other_valid)
{
detail::variant_data tmp_data;
detail::variant_policy_func tmp_policy_func = other.m_policy;
other.m_policy(detail::variant_policy_operation::SWAP, other.m_data, tmp_data);
m_policy(detail::variant_policy_operation::SWAP, m_data, other.m_data);
other.m_policy = m_policy;
tmp_policy_func(detail::variant_policy_operation::SWAP, tmp_data, m_data);
m_policy = tmp_policy_func;
}
else
{
detail::variant_data& full_data = is_this_valid ? m_data : other.m_data;
detail::variant_data& empty_data = is_this_valid ? other.m_data : m_data;
detail::variant_policy_func full_policy_func = is_this_valid ? m_policy : other.m_policy;
full_policy_func(detail::variant_policy_operation::SWAP, full_data, empty_data);
std::swap(m_policy, other.m_policy);
}
}
开发者ID:Victorique-GOSICK,项目名称:rttr,代码行数:34,代码来源:variant.cpp
示例3: set_value
void dropdown_widget::set_value(const std::string& key, const variant& v)
{
if(key == "on_change") {
on_change_ = boost::bind(&dropdown_widget::change_delegate, this, _1);
change_handler_ = get_environment()->create_formula(v);
} else if(key == "on_select") {
on_select_ = boost::bind(&dropdown_widget::select_delegate, this, _1, _2);
select_handler_ = get_environment()->create_formula(v);
} else if(key == "item_list") {
list_ = v.as_list_string();
current_selection_ = 0;
} else if(key == "selection") {
current_selection_ = v.as_int();
} else if(key == "type") {
std::string s = v.as_string();
if(s == "combo" || s == "combobox") {
type_ = DROPDOWN_COMBOBOX;
} else if(s == "list" || s == "listbox") {
type_ = DROPDOWN_LIST;
} else {
ASSERT_LOG(false, "Unreognised type: " << s);
}
}
widget::set_value(key, v);
}
开发者ID:gradonly,项目名称:frogatto,代码行数:25,代码来源:dropdown_widget.cpp
示例4: type_error
variant variant::operator/(const variant& v) const
{
if(type_ == TYPE_DECIMAL || v.type_ == TYPE_DECIMAL) {
int denominator = v.as_decimal();
if(denominator == 0) {
throw type_error((formatter() << "divide by zero error").str());
}
long long long_int = as_decimal();
long_int *= 10000;
long_int /= denominator;
if( long_int%10 >= 5) {
long_int /= 10;
++long_int;
} else
long_int/=10;
return variant( static_cast<int>(long_int) , variant::DECIMAL_VARIANT);
}
const int numerator = as_int();
const int denominator = v.as_int();
if(denominator == 0) {
throw type_error((formatter() << "divide by zero error").str());;
}
return variant(numerator/denominator);
}
开发者ID:RushilPatel,项目名称:BattleForWesnoth,代码行数:33,代码来源:variant.cpp
示例5: from_variant
int from_variant(variant node)
{
if(node.is_string()) {
return from_string(node.as_string());
}
return node.as_int(-1);
}
开发者ID:gradonly,项目名称:frogatto,代码行数:7,代码来源:difficulty.cpp
示例6: set
void BlendMode::set(const variant& node)
{
if(node.is_string()) {
const std::string& blend = node.as_string();
if(blend == "add") {
set(BlendModeConstants::BM_ONE, BlendModeConstants::BM_ONE);
} else if(blend == "alpha_blend") {
set(BlendModeConstants::BM_SRC_ALPHA, BlendModeConstants::BM_ONE_MINUS_SRC_ALPHA);
} else if(blend == "colour_blend" || blend == "color_blend") {
set(BlendModeConstants::BM_SRC_COLOR, BlendModeConstants::BM_ONE_MINUS_SRC_COLOR);
} else if(blend == "modulate") {
set(BlendModeConstants::BM_DST_COLOR, BlendModeConstants::BM_ZERO);
} else if(blend == "src_colour one" || blend == "src_color one") {
set(BlendModeConstants::BM_SRC_COLOR, BlendModeConstants::BM_ONE);
} else if(blend == "src_colour zero" || blend == "src_color zero") {
set(BlendModeConstants::BM_SRC_COLOR, BlendModeConstants::BM_ZERO);
} else if(blend == "src_colour dest_colour" || blend == "src_color dest_color") {
set(BlendModeConstants::BM_SRC_COLOR, BlendModeConstants::BM_DST_COLOR);
} else if(blend == "dest_colour one" || blend == "dest_color one") {
set(BlendModeConstants::BM_DST_COLOR, BlendModeConstants::BM_ONE);
} else if(blend == "dest_colour src_colour" || blend == "dest_color src_color") {
set(BlendModeConstants::BM_DST_COLOR, BlendModeConstants::BM_SRC_COLOR);
} else {
ASSERT_LOG(false, "BlendMode: Unrecognised scene_blend mode " << blend);
}
} else if(node.is_list() && node.num_elements() >= 2) {
ASSERT_LOG(node[0].is_string() && node[1].is_string(),
"BlendMode: Blend mode must be specified by a list of two strings.");
set(parse_blend_string(node[0].as_string()), parse_blend_string(node[1].as_string()));
} else {
ASSERT_LOG(false, "BlendMode: Setting blend requires either a string or a list of greater than two elements." << node.to_debug_string());
}
}
开发者ID:sweetkristas,项目名称:Castles,代码行数:33,代码来源:Blend.cpp
示例7: create_model_map
std::string Visitor::visit(variant & object) {
create_model_map();
Derived *base = (Derived *)*object;
std::string classname;
if (!object) {
printf("visit was empty!\n");
return "";
}
if (ClassMap::is_recognized_classname(object.type().name())) {
classname = base->classname();
} else {
if (object.isString() ||
object.isType<bool>())
classname = "quoted";
else if (object.isType<std::vector<variant> >())
classname = "array";
else
classname = "literal";
}
method_dict_map_t method_dict_map = method_dictionary();
if (method_dict_map[classname]) {
return (this->*method_dict_map[classname])(object);
}
else {
printf("Visitor::visit failed to find method: %s(%s)\n", classname.c_str(), object.type().name());
return "";
}
}
开发者ID:netarc,项目名称:c-arel,代码行数:32,代码来源:visitor.cpp
示例8:
world::world(const variant& node)
: view_distance_(node["view_distance"].as_int(default_view_distance)),
seed_(node["seed"].as_int(0))
{
ASSERT_LOG(node.has_key("shader"), "Must have 'shader' attribute");
ASSERT_LOG(node["shader"].is_string(), "'shader' attribute must be a string");
shader_ = gles2::shader_program::get_global(node["shader"].as_string())->shader();
if(node.has_key("lighting")) {
lighting_.reset(new graphics::lighting(shader_, node["lighting"]));
}
if(node.has_key("objects")) {
for(int n = 0; n != node["objects"].num_elements(); ++n) {
add_object(new user_voxel_object(node["objects"][n]));
}
}
if(node.has_key("skybox")) {
skybox_.reset(new graphics::skybox(node["skybox"]));
}
if(node.has_key("chunks")) {
logic_.reset(new logical_world(node));
build_fixed(node["chunks"]);
} else {
build_infinite();
}
}
开发者ID:AsKorysti,项目名称:anura,代码行数:29,代码来源:isoworld.cpp
示例9: checked_
checkbox::checkbox(const variant& v, game_logic::formula_callable* e)
: checked_(false), button(v,e)
{
hpadding_ = v["hpad"].as_int(12);
if(v.has_key("padding")) {
ASSERT_LOG(v["padding"].num_elements() == 2, "Incorrect number of padding elements specifed." << v["padding"].num_elements());
hpadding_ = v["padding"][0].as_int();
}
checked_ = v["checked"].as_bool(false);
variant label_var = v["label"];
label_ = (label_var.is_map() || label_var.is_callable()) ? "" : label_var.as_string_default("Checkbox");
label_widget_ = (label_var.is_map() || label_var.is_callable())
? widget_factory::create(label_var, e)
: widget_ptr(new graphical_font_label(label_, "door_label", 2));
ASSERT_LOG(get_environment() != 0, "You must specify a callable environment");
click_handler_ = get_environment()->create_formula(v["on_click"]);
onclick_ = boost::bind(&checkbox::click, this, _1);
set_click_handler(boost::bind(&checkbox::on_click, this));
set_label(create_checkbox_widget(label_widget_,
checked_,
button_resolution(),
hpadding_));
if(v.has_key("width") || v.has_key("height")) {
set_dim(v["width"].as_int(width()), v["height"].as_int(height()));
}
}
开发者ID:apr-apr-apr,项目名称:anura,代码行数:28,代码来源:checkbox.cpp
示例10: manhattan_distance
template<> decimal manhattan_distance(const variant& p1, const variant& p2) {
const std::vector<decimal>& v1 = p1.as_list_decimal();
const std::vector<decimal>& v2 = p2.as_list_decimal();
decimal x1 = v1[0] - v2[0];
decimal x2 = v1[1] - v2[1];
return (x1 < 0 ? -x1 : x1) + (x2 < 0 ? -x2 : x2);
}
开发者ID:kimsama,项目名称:frogatto,代码行数:7,代码来源:pathfinding.cpp
示例11: variant
variant variant::operator*(const variant& v) const
{
if(type_ == TYPE_DECIMAL || v.type_ == TYPE_DECIMAL) {
return variant(as_decimal() * v.as_decimal());
}
if(type_ == TYPE_LIST) {
int ncopies = v.as_int();
if(ncopies < 0) {
ncopies *= -1;
}
const std::vector<variant>& items = list_->elements;
std::vector<variant> res;
res.reserve(items.size()*ncopies);
for(int n = 0; n != ncopies; ++n) {
for(int m = 0; m != items.size(); ++m) {
res.push_back(items[m]);
}
}
return variant(&res);
}
return variant(as_int() * v.as_int());
}
开发者ID:paulkarayan,项目名称:frogatto,代码行数:25,代码来源:variant.cpp
示例12: as_decimal
bool variant::operator==(const variant& v) const
{
if(type_ != v.type_) {
if(type_ == TYPE_DECIMAL || v.type_ == TYPE_DECIMAL) {
return as_decimal() == v.as_decimal();
}
return false;
}
switch(type_) {
case TYPE_NULL: {
return v.is_null();
}
case TYPE_STRING: {
return string_->str == v.string_->str;
}
case TYPE_INT: {
return int_value_ == v.int_value_;
}
case TYPE_DECIMAL: {
return decimal_value_ == v.decimal_value_;
}
case TYPE_LIST: {
if(num_elements() != v.num_elements()) {
return false;
}
for(size_t n = 0; n != num_elements(); ++n) {
if((*this)[n] != v[n]) {
return false;
}
}
return true;
}
case TYPE_MAP: {
return map_->elements == v.map_->elements;
}
case TYPE_CALLABLE_LOADING: {
return false;
}
case TYPE_CALLABLE: {
return callable_->equals(v.callable_);
}
case TYPE_FUNCTION: {
return fn_ == v.fn_;
}
}
assert(false);
return false;
}
开发者ID:paulkarayan,项目名称:frogatto,代码行数:60,代码来源:variant.cpp
示例13: f
std::string formula_ai::evaluate(const std::string& formula_str)
{
try{
game_logic::formula f(formula_str, &function_table_);
game_logic::map_formula_callable callable(this);
callable.add_ref();
//formula_debugger fdb;
const variant v = f.evaluate(callable,NULL);
if (ai_ptr_) {
variant var = execute_variant(v, *ai_ptr_, true );
if ( !var.is_empty() ) {
return "Made move: " + var.to_debug_string();
}
}
return v.to_debug_string();
}
catch(formula_error& e) {
e.line = 0;
handle_exception(e);
throw;
}
}
开发者ID:dr4gon94,项目名称:wesnoth,代码行数:28,代码来源:ai.cpp
示例14: parse_dir
std::vector<CastlePart> parse_dir(const variant& node)
{
std::vector<CastlePart> res;
const std::vector<std::string> keys = { "bl", "br", "l", "r", "tl", "tr" };
ASSERT_LOG(node.is_map(), "must be a map type.");
for(auto key : keys) {
ASSERT_LOG(node.has_key(key), "Must have attribute '" << key << "' in definition.");
const variant& dir = node[key];
ASSERT_LOG(dir.has_key("rect"), "Attribute '" << key << "' must have 'rect' definition.");
CastlePart cp;
cp.r_ = rect(dir["rect"]);
if(dir.has_key("border")) {
ASSERT_LOG(dir["border"].num_elements() == 4, "'border' attribute must be list of 4 integers.");
for(int n = 0; n != 4; ++n) {
cp.border_[n] = dir["border"][n].as_int32();
}
} else {
for(int n = 0; n != 4; ++n) {
cp.border_[n] = 0;
}
}
if(dir.has_key("offset")) {
cp.offs_ = point(dir["offset"]);
} else {
cp.offs_.x = cp.offs_.y = 0;
}
res.emplace_back(cp);
}
return res;
}
开发者ID:sweetkristas,项目名称:Castles,代码行数:30,代码来源:main.cpp
示例15: variant
variant variant::operator-(const variant& v) const
{
if(type_ == TYPE_DECIMAL || v.type_ == TYPE_DECIMAL) {
return variant( as_decimal() - v.as_decimal() , DECIMAL_VARIANT);
}
return variant(as_int() - v.as_int());
}
开发者ID:RushilPatel,项目名称:BattleForWesnoth,代码行数:8,代码来源:variant.cpp
示例16: load_castle_definitions
void load_castle_definitions(const variant& castle_def)
{
ASSERT_LOG(castle_def.is_map(), "Castle definitions must be a map.");
for(const auto& def : castle_def.as_map()) {
const std::string name = def.first.as_string();
get_castle_def()[name] = std::make_shared<CastleDef>(name, def.second);
}
}
开发者ID:sweetkristas,项目名称:Castles,代码行数:8,代码来源:main.cpp
示例17: foreach
void formula_variable_storage::read(variant node)
{
if(node.is_null()) {
return;
}
foreach(const variant_pair& val, node.as_map()) {
add(val.first.as_string(), val.second);
}
}
开发者ID:DDR0,项目名称:Cube_Trains,代码行数:10,代码来源:formula_variable_storage.cpp
示例18: lookup_contact
oWalletContactEntry WalletDb::lookup_contact( const variant& data )const
{ try {
FC_ASSERT( is_open() ,"Wallet not open!");
FC_ASSERT( !data.is_null() );
const auto iter = contacts.find( data.as_string() );
if( iter != contacts.end() ) return iter->second;
return oWalletContactEntry();
} FC_CAPTURE_AND_RETHROW( (data) ) }
开发者ID:ElleryHao,项目名称:Goopal,代码行数:10,代码来源:WalletDb.cpp
示例19: lookup_contact
owallet_contact_record wallet_db::lookup_contact( const variant& data )const
{ try {
FC_ASSERT( is_open() );
FC_ASSERT( !data.is_null() );
const auto iter = contacts.find( data.as_string() );
if( iter != contacts.end() ) return iter->second;
return owallet_contact_record();
} FC_CAPTURE_AND_RETHROW( (data) ) }
开发者ID:FlappycoinDEV,项目名称:bitshares,代码行数:10,代码来源:wallet_db.cpp
示例20: id_
frame::frame(variant node)
: id_(node["id"].as_string()),
image_(node["image"].as_string()),
variant_id_(id_),
enter_event_id_(get_object_event_id("enter_" + id_ + "_anim")),
end_event_id_(get_object_event_id("end_" + id_ + "_anim")),
leave_event_id_(get_object_event_id("leave_" + id_ + "_anim")),
process_event_id_(get_object_event_id("process_" + id_)),
texture_(node.has_key("fbo") ? node["fbo"].convert_to<texture_object>()->texture() : graphics::texture::get(image_, node["image_formula"].as_string_default())),
solid_(solid_info::create(node)),
collide_rect_(node.has_key("collide") ? rect(node["collide"]) :
rect(node["collide_x"].as_int(),
node["collide_y"].as_int(),
node["collide_w"].as_int(),
node["collide_h"].as_int())),
hit_rect_(node.has_key("hit") ? rect(node["hit"]) :
rect(node["hit_x"].as_int(),
node["hit_y"].as_int(),
node["hit_w"].as_int(),
node["hit_h"].as_int())),
platform_rect_(node.has_key("platform") ? rect(node["platform"]) :
rect(node["platform_x"].as_int(),
node["platform_y"].as_int(),
node["platform_w"].as_int(), 1)),
img_rect_(node.has_key("rect") ? rect(node["rect"]) :
rect(node["x"].as_int(),
node["y"].as_int(),
node["w"].as_int(),
node["h"].as_int())),
feet_x_(node["feet_x"].as_int()),
feet_y_(node["feet_y"].as_int()),
accel_x_(node["accel_x"].as_int(INT_MIN)),
accel_y_(node["accel_y"].as_int(INT_MIN)),
velocity_x_(node["velocity_x"].as_int(INT_MIN)),
velocity_y_(node["velocity_y"].as_int(INT_MIN)),
nframes_(node["frames"].as_int(1)),
nframes_per_row_(node["frames_per_row"].as_int(-1)),
frame_time_(node["duration"].as_int(-1)),
reverse_frame_(node["reverse"].as_bool()),
play_backwards_(node["play_backwards"].as_bool()),
scale_(node["scale"].as_int(2)),
pad_(node["pad"].as_int()),
rotate_(node["rotate"].as_int()),
blur_(node["blur"].as_int()),
rotate_on_slope_(node["rotate_on_slope"].as_bool()),
damage_(node["damage"].as_int()),
sounds_(util::split(node["sound"].as_string_default())),
no_remove_alpha_borders_(node["no_remove_alpha_borders"].as_bool(false)),
collision_areas_inside_frame_(true),
current_palette_(-1)
{
std::vector<std::string> hit_frames = util::split(node["hit_frames"].as_string_default());
foreach(const std::string& f, hit_frames) {
hit_frames_.push_back(boost::lexical_cast<int>(f));
}
开发者ID:kimsama,项目名称:frogatto,代码行数:55,代码来源:frame.cpp
注:本文中的variant类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论