本文整理汇总了C++中variant::as_int方法的典型用法代码示例。如果您正苦于以下问题:C++ variant::as_int方法的具体用法?C++ variant::as_int怎么用?C++ variant::as_int使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类variant
的用法示例。
在下文中一共展示了variant::as_int方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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());
}
示例2: set_value
void arrow_primitive::set_value(const std::string& key, const variant& value)
{
if(key == "points") {
set_points(value);
} else if(key == "color") {
color_ = graphics::color(value);
} else if(key == "granularity") {
granularity_ = value.as_decimal().as_float();
} else if(key == "arrow_head_length") {
arrow_head_length_ = value.as_int();
} else if(key == "arrow_head_width") {
arrow_head_width_ = value.as_decimal().as_float();
} else if(key == "fade_in_length") {
fade_in_length_ = value.as_int();
} else if(key == "width_base") {
width_base_ = value.as_decimal().as_float();
} else if(key == "width_head") {
width_head_ = value.as_decimal().as_float();
} else {
ASSERT_LOG(false, "ILLEGAL KEY IN ARROW: " << key);
}
varray_.clear();
carray_.clear();
}
示例3: set_value
void set_value(const std::string& key, const variant& value) {
if(key == "generation_rate") {
generation_rate_millis_ = value.as_int();
} else if (key == "pos_x") {
pos_x_ = value.as_int()*1024;
} else if (key == "pos_x_rand") {
pos_x_rand_ = value.as_int()*1024;
} else if (key == "pos_y") {
pos_y_ = value.as_int()*1024;
} else if (key == "pos_y_rand") {
pos_y_rand_ = value.as_int()*1024;
}
}
示例4: from_variant
int from_variant(variant node)
{
if(node.is_string()) {
return from_string(node.as_string());
}
return node.as_int(-1);
}
示例5: 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);
}
示例6: set_value
void dialog_label::set_value(const std::string& key, const variant& v)
{
if(key == "progress") {
set_progress(v.as_int());
}
label::set_value(key, v);
}
示例7: 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);
}
示例8: 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);
}
示例9: set_value
void bar_widget::set_value(const std::string& key, const variant& value)
{
if(key == "segments") {
segments_ = value.as_int();
ASSERT_GE(segments_, 0);
init();
} else if(key == "segment_length") {
segment_length_ = value.as_int();
ASSERT_GT(segment_length_, 0);
init();
} else if(key == "tick_width") {
tick_width_ = value.as_int();
ASSERT_GT(tick_width_, 0);
init();
} else if(key == "scale") {
scale_ = value.as_decimal().as_float();
ASSERT_GT(scale_, 0.0f);
init();
} else if(key == "drain_rate") {
drain_rate_ = value.as_decimal().as_float();
ASSERT_GE(drain_rate_, 0.0);
} else if(key == "drained") {
int drain = value.as_int();
if(drain == drained_segments_) {
return;
}
int animation_start_position = segments_-drained_segments_;
animation_current_position_ = 0;
drained_segments_after_anim_ = drain;
if(drained_segments_after_anim_ < 0) {
drained_segments_after_anim_ = 0;
}
if(drained_segments_after_anim_ > segments_) {
drained_segments_after_anim_ = segments_;
}
int animation_end_position = segments_-drained_segments_after_anim_;
animation_end_point_unscaled_ = animation_end_position - animation_start_position;
animating_ = true;
init();
} else if(key == "max_width") {
bar_max_width_ = value.as_int();
init();
} else if(key == "animation_position") {
animation_current_position_ = value.as_decimal().as_float();
}
widget::set_value(key, value);
}
示例10: 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());
}
示例11: set_player_value_by_slot
void playable_custom_object::set_player_value_by_slot(int slot, const variant& value)
{
switch(slot) {
case CUSTOM_OBJECT_PLAYER_DIFFICULTY:
difficulty_ = value.as_int();
break;
case CUSTOM_OBJECT_PLAYER_CAN_INTERACT:
can_interact_ = value.as_int();
break;
case CUSTOM_OBJECT_PLAYER_UNDERWATER_CONTROLS:
underwater_controls_ = value.as_bool();
break;
case CUSTOM_OBJECT_PLAYER_VERTICAL_LOOK:
vertical_look_ = value.as_int();
break;
case CUSTOM_OBJECT_PLAYER_CONTROL_LOCK:
if(value.is_null()) {
control_lock_.reset();
} else if(value.is_list()) {
unsigned char state = 0;
for(int n = 0; n != value.num_elements(); ++n) {
ASSERT_LOG(value[n].is_string(), "MEMBER OF control_lock LIST NOT A STRING");
const std::string& str = value[n].as_string();
int control_key = -1;
for(int m = 0; m != sizeof(ctrl)/sizeof(*ctrl); ++m) {
if(ctrl[m] == str) {
control_key = m;
break;
}
}
ASSERT_LOG(control_key != -1, "ILLEGAL STRING SET FOR control_lock: '" << str << "' LEGAL KEYS ARE ctrl_(up|down|left|right|attack|jump)");
state |= 1 << control_key;
}
//destroy the old one before creating a new control_lock,
//since control_lock objects must be constructed and destroyed
//in FIFO order.
control_lock_.reset();
control_lock_.reset(new controls::local_controls_lock(state));
} else {
ASSERT_LOG(false, "BAD VALUE WHEN SETTING control_lock KEY. A LIST OR NULL IS REQUIRED: " << value.to_debug_string());
}
break;
}
}
示例12: set_value
void radial_distortion::set_value(const std::string& key, const variant& value)
{
if(key == "radius") {
radius_ = value.as_int()/1000.0;
std::cerr << "set radius: " << radius_ << "\n";
set_area(rect(x_ - radius_, y_ - radius_, radius_*2, radius_*2));
}
}
示例13: luaW_pushfaivariant
void luaW_pushfaivariant(lua_State* L, variant val) {
if(val.is_int()) {
lua_pushinteger(L, val.as_int());
} else if(val.is_decimal()) {
lua_pushnumber(L, val.as_decimal() / 1000.0);
} else if(val.is_string()) {
const std::string result_string = val.as_string();
lua_pushlstring(L, result_string.c_str(), result_string.size());
} else if(val.is_list()) {
lua_newtable(L);
for(const variant& v : val.as_list()) {
lua_pushinteger(L, lua_rawlen(L, -1) + 1);
luaW_pushfaivariant(L, v);
lua_settable(L, -3);
}
} else if(val.is_map()) {
typedef std::map<variant,variant>::value_type kv_type;
lua_newtable(L);
for(const kv_type& v : val.as_map()) {
luaW_pushfaivariant(L, v.first);
luaW_pushfaivariant(L, v.second);
lua_settable(L, -3);
}
} else if(val.is_callable()) {
// First try a few special cases
if(unit_callable* u_ref = val.try_convert<unit_callable>()) {
const unit& u = u_ref->get_unit();
unit_map::iterator un_it = resources::gameboard->units().find(u.get_location());
if(&*un_it == &u) {
luaW_pushunit(L, u.underlying_id());
} else {
luaW_pushunit(L, u.side(), u.underlying_id());
}
} else if(location_callable* loc_ref = val.try_convert<location_callable>()) {
luaW_pushlocation(L, loc_ref->loc());
} else {
// If those fail, convert generically to a map
const formula_callable* obj = val.as_callable();
std::vector<formula_input> inputs;
obj->get_inputs(&inputs);
lua_newtable(L);
for(const formula_input& attr : inputs) {
if(attr.access == FORMULA_WRITE_ONLY) {
continue;
}
lua_pushstring(L, attr.name.c_str());
luaW_pushfaivariant(L, obj->query_value(attr.name));
lua_settable(L, -3);
}
}
} else if(val.is_null()) {
lua_pushnil(L);
}
}
示例14: set_value
void graphical_font_label::set_value(const std::string& key, const variant& v)
{
if(key == "text") {
set_text(v.as_string());
} else if(key == "font") {
font_ = graphical_font::get(v.as_string());
ASSERT_LOG(font_.get(), "UNKNOWN FONT: " << v.as_string());
reset_text_dimensions();
} else if(key == "size") {
size_ = v.as_int();
reset_text_dimensions();
}
//widget::set_value(key);
}
示例15: type_error
variant variant::operator/(const variant& v) const
{
if(type_ == TYPE_DECIMAL || v.type_ == TYPE_DECIMAL) {
if(v.as_decimal().value() == 0) {
throw type_error((formatter() << "divide by zero error").str());
}
return variant(as_decimal() / v.as_decimal());
}
const int numerator = as_int();
const int denominator = v.as_int();
if(denominator == 0) {
throw type_error(formatter() << "divide by zero error");
}
return variant(numerator/denominator);
}