本文整理汇总了C++中variant::is_null方法的典型用法代码示例。如果您正苦于以下问题:C++ variant::is_null方法的具体用法?C++ variant::is_null怎么用?C++ variant::is_null使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类variant
的用法示例。
在下文中一共展示了variant::is_null方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: 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) ) }
示例3: read
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);
}
}
示例4: 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) ) }
示例5: 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);
}
}
示例6: remove_contact
oWalletContactEntry WalletDb::remove_contact( const variant& data )
{ try {
FC_ASSERT( is_open() ,"Wallet not open!");
FC_ASSERT( !data.is_null() );
oWalletContactEntry entry = lookup_contact( data );
if( entry.valid() )
{
label_to_account_or_contact.erase( entry->label );
contacts.erase( data.as_string() );
remove_item( entry->wallet_entry_index );
}
return entry;
} FC_CAPTURE_AND_RETHROW( (data) ) }
示例7: remove_contact
owallet_contact_record wallet_db::remove_contact( const variant& data )
{ try {
FC_ASSERT( is_open() );
FC_ASSERT( !data.is_null() );
owallet_contact_record record = lookup_contact( data );
if( record.valid() )
{
label_to_account_or_contact.erase( record->label );
contacts.erase( data.as_string() );
remove_item( record->wallet_record_index );
}
return record;
} FC_CAPTURE_AND_RETHROW( (data) ) }
示例8: 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;
}
}
示例9: set_value
void label::set_value(const std::string& key, const variant& v)
{
if(key == "text") {
if(v.is_null()) {
set_text("");
} else {
set_text(v.as_string());
}
} else if(key == "color") {
set_color(graphics::color(v).as_sdl_color());
} else if(key == "size") {
set_font_size(v.as_int());
} else if(key == "font") {
set_font(v.as_string());
}
widget::set_value(key, v);
}
示例10: load_preferences
void load_preferences()
{
std::string path;
if(preferences_path_.empty()) {
#if defined( _WINDOWS )
preferences_path_ = winPrefs.GetPreferencePath();
save_file_path_ = winPrefs.GetSaveFilePath();
auto_save_file_path_ = winPrefs.GetAutoSaveFilePath();
path = preferences_path_;
#else
path = PREFERENCES_PATH;
#endif // defined( _WINDOWS )
} else {
path = preferences_path_;
}
expand_path(path);
if(!sys::file_exists(path + "preferences.cfg")) {
return;
}
variant node;
try {
node = json::parse_from_file(path + "preferences.cfg");
} catch(json::parse_error&) {
return;
}
unique_user_id = node["user_id"].as_int(0);
use_joystick_ = node["joystick"].as_bool(use_joystick_);
variant show_control_rects = node["show_iphone_controls"];
if(show_control_rects.is_null() == false) {
show_iphone_controls_ = show_control_rects.as_bool(show_iphone_controls_);
}
no_sound_ = node["no_sound"].as_bool(no_sound_);
no_music_ = node["no_music"].as_bool(no_music_);
reverse_ab_ = node["reverse_ab"].as_bool(reverse_ab_);
sound::set_music_volume(node["music_volume"].as_int(1000)/1000.0);
sound::set_sound_volume(node["sound_volume"].as_int(1000)/1000.0);
const variant registry_node = node["registry"];
if(registry_node.is_null() == false) {
game_registry::instance().set_contents(registry_node);
}
if(node["code_editor"].is_map()) {
external_code_editor_ = node["code_editor"];
}
#if !TARGET_OS_IPHONE && !TARGET_IPHONE_SIMULATOR
controls::set_sdlkey(controls::CONTROL_UP, static_cast<SDLKey>(node["key_up"].as_int(SDLK_UP)));
controls::set_sdlkey(controls::CONTROL_DOWN, static_cast<SDLKey>(node["key_down"].as_int(SDLK_DOWN)));
controls::set_sdlkey(controls::CONTROL_LEFT, static_cast<SDLKey>(node["key_left"].as_int(SDLK_LEFT)));
controls::set_sdlkey(controls::CONTROL_RIGHT, static_cast<SDLKey>(node["key_right"].as_int(SDLK_RIGHT)));
controls::set_sdlkey(controls::CONTROL_ATTACK, static_cast<SDLKey>(node["key_attack"].as_int(SDLK_d)));
controls::set_sdlkey(controls::CONTROL_JUMP, static_cast<SDLKey>(node["key_jump"].as_int(SDLK_a)));
controls::set_sdlkey(controls::CONTROL_TONGUE, static_cast<SDLKey>(node["key_tongue"].as_int(SDLK_s)));
#endif
}