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


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

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


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

示例1: serializer

void Database::Statement::write(const Serializable &s)
{
	if(mOutputLevel == 0 || s.isInlineSerializable()) s.serialize(*this);
	else {
		String tmp;
		JsonSerializer serializer(&tmp);
		s.serialize(serializer);
		write(tmp);
	}
}
开发者ID:paullouisageneau,项目名称:Teapotnet,代码行数:10,代码来源:database.cpp

示例2: test

void test()
{
	Deserializer::d()["TestSerializable"] = TestSerializable::returnNew;

	TestSerializable testSerializable("important stuff");

	ptree serial = testSerializable.serialize();

	stringstream ss;
	write_xml(ss, serial);
	cout << "TestSerializable.serialize() to string:" << endl << ss.str() << endl;

	Serializable * deserializedUncast = newDeserialize(serial);
	//Serializable * deserializedUncast = Deserializer::d()["TestSerializable"]();

	ptree serial2 = deserializedUncast->serialize();

	stringstream ss2;
	write_xml(ss2, serial2);
	cout << "deserializedUncast->serialize() *post-returned* to string:" << endl << ss2.str() << endl;

	TestSerializable * deserialized = dynamic_cast<TestSerializable *>(deserializedUncast);
	
	cout << "deserialized->data: " << deserialized->data << endl;
}
开发者ID:pwag42,项目名称:moba_source,代码行数:25,代码来源:test.cpp

示例3: newDeserialize

Serializable * newDeserialize(ptree serial)
{
#if VERBOSE
	cout << "registered types:" << endl;
	for(map<string, Serializable * (*)()>::iterator iterator = Deserializer::d().begin(); iterator != Deserializer::d().end(); iterator++) {
		cout << iterator->first << endl;
	}
#endif

	string type = serial.get<std::string>("type");

	map<string, Serializable * (*)()>::iterator it = Deserializer::d().find(type);

	if(it != Deserializer::d().end())
	{
		Serializable * toReturn = Deserializer::d()[type]();
		toReturn->deserialize(serial);
		
	#if VERBOSE
		stringstream ss2;
		write_xml(ss2, toReturn->serialize());
		cout << "newDeserialize()->serialize() *pre-returned* to string:" << endl << ss2.str() << endl;
	#endif

		return toReturn;
	}
	else
	{
		cout<<"ERROR! No compatible deserialization function for " << type; //In case someone forgets to add a deserializer
		throw 319;
	}
}
开发者ID:pwag42,项目名称:moba_source,代码行数:32,代码来源:serializable.cpp

示例4: save

bool OutXmlSerializer::save(Stream& stream)
{
	XmlDocument doc;

	XmlDeclaration* decl = zenic_new XmlDeclaration;
	decl->setValue("xml");
	decl->setAttribute("version","1.0");
	decl->setAttribute("encoding","ISO-8859-1");
	doc.addChild(decl);

	XmlComment* comment = new XmlComment;
	comment->setValue(" Cell XML Object Graph ");
	doc.addChild(comment);

	// add initial objects

	for (uint i = 0, n = count(); i < n; ++i)
	{
		Serializable* initial = (*this)[i];
		uint j,m;
		for (j = 0, m = m_objects.count(); j < m; ++j)
		{
			if (m_objects[j] == initial)
				break;
		}

		if (j == m_objects.count())
			m_objects.pushBack(initial);
	}

	// build xml tree

	XmlElement* root = new XmlElement;
	root->setValue("zenic");

	for (uint i = 0; i < m_objects.count(); ++i)
	{
		Serializable* object = m_objects[i];
		ZENIC_ASSERT(object);

		m_current = 0;
		m_currentIndex = i;
		object->serialize(*this);

		ZENIC_ASSERT(m_current);
		root->addChild(m_current);
	}

	doc.addChild(root);

	// write tree to stream
	if (!doc.save(stream))
		return false;

	return true;
}
开发者ID:jsvennevid,项目名称:tbl-4edges,代码行数:56,代码来源:OutXmlSerializer.cpp

示例5: writeObject

bool Serializer::writeObject(Serializable& instance) {
  ObjectData* data=new ObjectData();
  instance.serialize(*data,*this);

  processDataForWrite(data,*this);

  if (!_datastream) {
    string str=_dataFileName;
    replaceEnvTags(str,_envMap);
    create_directories(path(str).parent_path());
    _datastream=new ofstream(str.c_str());
  }
  if (*_datastream) {
    _objectWriter->writeObject(*_datastream,instance.className(),*data);
    //TODO Change writer to get status flag
    return true;
  }
  return false;

}
开发者ID:9578577,项目名称:g2o_frontend,代码行数:20,代码来源:serializer.cpp

示例6: serialize

void Serializer::serialize(const std::string& key, const Serializable& sObj) {
    auto newNode = util::make_unique<TxElement>(key);
    rootElement_->LinkEndChild(newNode.get());
    NodeSwitch nodeSwitch(*this, newNode.get());
    sObj.serialize(*this);
}
开发者ID:Ojaswi,项目名称:inviwo,代码行数:6,代码来源:serializer.cpp


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