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


C++ Serializable::get_metadata方法代码示例

本文整理汇总了C++中Serializable::get_metadata方法的典型用法代码示例。如果您正苦于以下问题:C++ Serializable::get_metadata方法的具体用法?C++ Serializable::get_metadata怎么用?C++ Serializable::get_metadata使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Serializable的用法示例。


在下文中一共展示了Serializable::get_metadata方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: full_serialization

void SerializerStream::full_serialization(const Serializable &obj, bool include_typehashes){
	auto node = obj.get_object_node();
#ifdef LOG
	std::clog << "Traversing reference graph...\n";
#endif
	std::set<std::uint32_t> used_types;
	objectid_t root_object = 0;
	{
		std::vector<decltype(node)> stack, temp_stack;
		this->id_map[0] = 0;

		auto id = this->save_object(node.get_address());
		assert(id);
		root_object = id;
		this->node_map[id] = node;
		used_types.insert(node.get_typeid());
		stack.push_back(node);

		while (stack.size()){
			auto top = stack.back();
			stack.pop_back();
			if (!top.get_address())
				continue;
			top.get_children(temp_stack);
			for (auto &i : temp_stack){
				id = this->save_object(i.get_address());
				if (!id)
					continue;
				this->node_map[id] = i;
				used_types.insert(i.get_typeid());
				stack.push_back(i);
			}
			temp_stack.clear();
		}
	}
	if (include_typehashes){
#ifdef LOG
		std::clog <<
			"Travesal found " << this->node_map.size() << " objects.\n"
			"Serializing type hashes...\n";
#endif
		auto list = obj.get_metadata()->get_known_types();
		std::map<decltype(list[0].first), decltype(list[0].second) *> typemap;
		for (auto &i : list)
			typemap[i.first] = &i.second;
		this->serialize((std::uint32_t)used_types.size());
		for (auto &t : used_types){
			this->serialize(t);
			this->serialize_array(typemap[t]->digest);
		}
	}
#ifdef LOG
	std::clog << "Remapping object IDs...\n";
#endif

	{
		std::map<std::uint32_t, std::vector<objectid_t>> remap;
		for (auto &n : this->node_map)
			remap[n.second.get_typeid()].push_back(n.first);
		
		this->next_object_id = 1;
		decltype(this->node_map) temp;
		bool root_set = false;
		this->id_map.clear();
		this->id_map[0] = 0;
		for (auto &r : remap){
			for (auto i : r.second){
				auto &node = this->node_map[i];
				if (!node.get_address())
					continue;
				auto oid = this->save_object(node.get_address());
				if (!root_set && i == root_object){
					root_object = oid;
					root_set = true;
				}
				temp[oid] = node;
			}
		}
		this->node_map = temp;
	}

#ifdef LOG
	std::clog << "Serializing node map...\n";
#endif

	{
		std::vector<std::pair<std::uint32_t, objectid_t>> type_map;
		for (auto &n : this->node_map){
			auto type = n.second.get_typeid();
			if (!type)
				throw InternalErrorException();
			if (!type_map.size() || type != type_map.back().first){
				type_map.push_back(std::make_pair(type, n.first));
				continue;
			}
			type_map.back().second = std::max(type_map.back().second, n.first);
		}
		this->serialize((wire_size_t)type_map.size());
		for (auto &i : type_map){
			this->serialize(i.first);
//.........这里部分代码省略.........
开发者ID:Helios-vmg,项目名称:cppserialization,代码行数:101,代码来源:SerializerStream.cpp


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