当前位置: 首页>>代码示例>>C++>>正文


C++ variant::as_map方法代码示例

本文整理汇总了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++;
	}
}
开发者ID:AsKorysti,项目名称:anura,代码行数:14,代码来源:animation_creator.cpp

示例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);
	}
}
开发者ID:sweetkristas,项目名称:Castles,代码行数:8,代码来源:main.cpp

示例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);
	}
}
开发者ID:DDR0,项目名称:Cube_Trains,代码行数:10,代码来源:formula_variable_storage.cpp

示例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);
	}
}
开发者ID:Wedge009,项目名称:wesnoth,代码行数:54,代码来源:lua_formula_bridge.cpp

示例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();
}
开发者ID:AsKorysti,项目名称:anura,代码行数:21,代码来源:hex_object.cpp


注:本文中的variant::as_map方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。