本文整理汇总了C++中variant::as_map方法的典型用法代码示例。如果您正苦于以下问题:C++ variant::as_map方法的具体用法?C++ variant::as_map怎么用?C++ variant::as_map使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类variant
的用法示例。
在下文中一共展示了variant::as_map方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: variant_map_merge
// Given two variants, which are maps merge the properties from v2 into v1 that
// don't already exist in v1.
void variant_map_merge(variant& v1, const variant& v2)
{
std::map<variant, variant>::const_iterator v2it = v2.as_map().begin();
std::map<variant, variant>::const_iterator v2end = v2.as_map().end();
while(v2it != v2end) {
std::map<variant, variant>::const_iterator v1it = v1.as_map().find(v2it->first);
if(v1it == v1.as_map().end()) {
v1.add_attr(v2it->first, v2it->second);
}
v2it++;
}
}
示例2: 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);
}
}
示例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: 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);
}
}
示例5: load_hex_tiles
void load_hex_tiles(variant node)
{
if(!get_tile_type_map().empty()) {
get_tile_type_map().clear();
}
for(auto p : node.as_map()) {
std::string key_str = p.first.as_string();
get_tile_type_map()[key_str] = tile_type_ptr(new tile_type(key_str, p.second));
}
// get list of all tiles have non-empty "editor_info" blocks.
if(!get_hex_editor_tiles().empty()) {
get_hex_editor_tiles().clear();
}
load_editor_tiles();
if(!get_editor_hex_tile_map().empty()) {
get_editor_hex_tile_map().clear();
}
load_hex_editor_tiles();
}