本文整理汇总了C++中Serializable类的典型用法代码示例。如果您正苦于以下问题:C++ Serializable类的具体用法?C++ Serializable怎么用?C++ Serializable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Serializable类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1:
void
Sector::write(lisp::Writer& writer)
{
writer.write_string("name", name);
writer.write_float("gravity", gravity);
writer.write_string("music", music);
// write spawnpoints
for(SpawnPoints::iterator i = spawnpoints.begin(); i != spawnpoints.end();
++i) {
SpawnPoint* spawn = *i;
writer.start_list("spawn-points");
writer.write_string("name", spawn->name);
writer.write_float("x", spawn->pos.x);
writer.write_float("y", spawn->pos.y);
writer.end_list("spawn-points");
}
// write objects
for(GameObjects::iterator i = gameobjects.begin();
i != gameobjects.end(); ++i) {
Serializable* serializable = dynamic_cast<Serializable*> (*i);
if(serializable)
serializable->write(writer);
}
}
开发者ID:BackupTheBerlios,项目名称:supertux-svn,代码行数:26,代码来源:sector.cpp
示例2: ASSERT
void
ESEnumerableModifyWnd::SetEnumerableObject(EnumerableObject<Serializable>* pEnumerable){
ASSERT(pEnumerable);
if( !pEnumerable ) return;
ESChildControlList* pList = (ESChildControlList*)GetChildControl(1000);
if( pList ){
Serializable* pObject = pEnumerable->CreateSerializableObject();
ASSERT(pObject);
VariableInfo* pInfo = pObject->GetThisInfo();
MercuryGUI* pGUI = MercuryGUI::GetInstance();
_Size szText(0, 0);
_string sTitle;
int nLoop = 1;
while( pInfo[nLoop].m_sAttributeName.length() > 0 ){
if( !pInfo[nLoop].m_bComplexType ){
sTitle = pInfo[nLoop].m_sDbFieldName;
pGUI->header.m_fontItemText.GetTextSize(&sTitle, szText);
if( szText.cx <= 0 )
szText.cx = 80;
pList->AddColumn(pInfo[nLoop].m_sDbFieldName, pInfo[nLoop].m_sAttributeName, HAlignment::HAlignement_Left, szText.cx + 5, szText.cx + 5);
szText.cx = 0;
}
nLoop ++;
}
VirtualRowSet* pRowSet = Serializable::SerializableObjectToVRowSet(pEnumerable);
m_pListRowSet = pRowSet;
m_pEnumerable = pEnumerable;
pList->SetRowSet(pRowSet, true, true);
delete pObject;
}
}
开发者ID:zqrtalent,项目名称:MercuryUI,代码行数:35,代码来源:ESEnumerableModifyWnd.cpp
示例3: 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
示例4: 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
示例5: setServo
void Pololu::Usc::Usb::SetSpeed::read(std::istream& stream) {
Serializable<unsigned char> servo;
Serializable<unsigned short> value;
setServo(servo.read(stream));
setValue(value.read(stream));
}
开发者ID:kralf,项目名称:libpololu,代码行数:7,代码来源:setspeed.cpp
示例6: readLog
RobotConfiguration* readLog(std::vector<BaseSensorData*>& sensorDatas, Deserializer& des){
RobotConfiguration* conf = 0;
Serializable *o;
int numObjects=0;
while( (! conf && (o=des.readObject())) ){
cerr << o->className() << endl;
numObjects++;
if (! conf) {
conf = dynamic_cast<RobotConfiguration*>(o);
if (conf) {
cerr << "got config" << endl;
if (! conf->isReady()){
cerr << "conf failure" << endl;
return 0;
}
}
continue;
}
}
if (!conf) {
cerr << "unable to read robot configuration, aborting" << endl;
return 0;
}
while( (o=des.readObject()) ){
BaseSensorData* sensorData=dynamic_cast<BaseSensorData*>(o);
if(sensorData)
sensorDatas.push_back(sensorData);
}
return conf;
}
开发者ID:9578577,项目名称:g2o_frontend,代码行数:33,代码来源:robot_configuration.cpp
示例7:
Serializable *Serializable::DeserializeNew (shared_ptr <Stream> stream)
{
string name = Serializable::DeserializeHeader (stream);
Serializable *serializable = SerializerFactory::GetNewSerializable (name);
serializable->Deserialize (stream);
return serializable;
}
开发者ID:4nt1m0n,项目名称:truecrypt,代码行数:8,代码来源:Serializable.cpp
示例8: 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
示例9: 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
示例10: input
bool JsonSerializer::input(Serializable &s)
{
if(s.isInlineSerializable() && !s.isNativeSerializable())
{
String str;
if(!input(str)) return false;
s.fromString(str);
return true;
}
else return s.deserialize(*this);
}
开发者ID:orinocoz,项目名称:Teapotnet,代码行数:11,代码来源:jsonserializer.cpp
示例11: getTestSerializable
void
SerializedInstanceTest::testSerialized(){
toTest->addSerializable( getTestSerializable() );
Serializable *returned = toTest->getSerializable();
CPPUNIT_ASSERT( returned != 0 );
CPPUNIT_ASSERT( returned->getDataType() == getTestSerializable()->getDataType() );
delete returned;
}
开发者ID:CindyYang85,项目名称:pdes,代码行数:11,代码来源:SerializedInstanceTest.cpp
示例12:
void BlinkM::ScriptLine::read(std::istream& stream) {
Serializable<unsigned char> durationTicks;
Serializable<std::string> typeName;
this->durationTicks = durationTicks.read(stream);
typeName.read(stream);
request = Singleton<Protocol>::getInstance().createRequest(
typeName.read(stream));
request->read(stream);
}
开发者ID:kralf,项目名称:libblinkm,代码行数:11,代码来源:scriptline.cpp
示例13: reader
bool RangeProfilePlotManager::deserialize(SessionItemDeserializer& deserializer)
{
XmlReader reader(NULL, false);
DOMElement* pRootElement = deserializer.deserialize(reader, "RangeProfilePlotManager");
if (pRootElement)
{
std::string viewId = A(pRootElement->getAttribute(X("viewId")));
mpView = dynamic_cast<PlotView*>(Service<SessionManager>()->getSessionItem(viewId));
mpPlot = Service<DesktopServices>()->createPlotWidget(getName(), CARTESIAN_PLOT);
VERIFY(mpPlot);
Serializable* pPlotSer = dynamic_cast<Serializable*>(mpPlot); // The imp side is serializable
VERIFY(pPlotSer);
if (!pPlotSer->fromXml(findChildNode(pRootElement, "plot"), reader.VERSION))
{
return false;
}
mpView = mpPlot->getPlot();
VERIFY(mpView);
Serializable* pPlotViewSer = dynamic_cast<Serializable*>(mpView); // The imp side is serializable
VERIFY(pPlotViewSer);
if (!pPlotViewSer->fromXml(findChildNode(pRootElement, "plotView"), reader.VERSION))
{
return false;
}
std::list<PlotObject*> objects;
mpView->getObjects(POINT_SET, objects);
FOR_EACH_DOMNODE(pRootElement, pChild)
{
if (XMLString::equals(pChild->getNodeName(), X("signature")))
{
DOMElement* pChldElmnt = static_cast<DOMElement*>(pChild);
std::string sigId = A(pChldElmnt->getAttribute(X("sigId")));
std::string pointSetName = A(pChldElmnt->getAttribute(X("pointSetName")));
Signature* pSignature = static_cast<Signature*>(Service<SessionManager>()->getSessionItem(sigId));
if (pSignature == NULL)
{
return false;
}
mSigPointSets[pSignature] = pointSetName;
pSignature->attach(SIGNAL_NAME(Subject, Deleted), Slot(this, &RangeProfilePlotManager::signatureDeleted));
pSignature->getDataDescriptor()->attach(SIGNAL_NAME(DataDescriptor, Renamed),
Slot(this, &RangeProfilePlotManager::signatureRenamed));
}
}
deserializer.nextBlock();
return DockWindowShell::deserialize(deserializer);
}
return false;
}
开发者ID:tclarke,项目名称:opticks-extras-Spectral,代码行数:52,代码来源:RangeProfilePlotManager.cpp
示例14: string
boost::shared_ptr<Serializable <PDXRecord> > PDXFileReader<FileEnumeratorType>::read() {
using namespace std;
using namespace boost;
Serializable <PDXRecord>* newRecord;
// open the next file to read.
if (!curFile.is_open()) {
if (this->fIt == this->fEnum.end()) {
// Don't bother, no more files.
return shared_ptr<Serializable <PDXRecord> >();
}
const char* filename = (this->fIt)->file_string().c_str();
curFile.open(filename, ios::in | ios::binary);
if (curFile.fail()) {
this->_error = true;
this->_errorMsg = string(" Failed to open file ") + filename;
return shared_ptr<Serializable <PDXRecord> >();
}
arl_file_hdr_t header;
curFile.read((char*) (&header), sizeof (arl_file_hdr_t));
header.base_date = ntohl(header.base_date);
this->base_time.set(header.base_date, 0);
this->fIt++;
}
//do the reading.
newRecord = new PDXRecord(&(this->base_time));
char record[sizeof (pidx_data_t)];
string dataStr;
curFile.read(record, sizeof (record));
if (curFile.eof()) {
curFile.close();
return this->read();
} else {
newRecord->unserialize(dataStr.insert(0, record, sizeof (record)));
}
return shared_ptr<Serializable <PDXRecord> >(newRecord);
}
开发者ID:,项目名称:,代码行数:51,代码来源:
示例15: read_network_attributes
//
// read_network_attributes
//
void ClientSidePrediction::read_network_attributes(Serializable& object, Deserializer& source)
{
const auto attributes = object.GetNetworkAttributes();
if (!attributes)
return;
unsigned numAttributes = attributes->Size();
for (unsigned i = 0; i < numAttributes && !source.IsEof(); ++i)
{
const auto& attr = attributes->At(i);
object.OnSetAttribute(attr, source.ReadVariant(attr.type_));
}
}
开发者ID:rasteron,项目名称:Urho3D-CSP,代码行数:17,代码来源:ClientSidePrediction.cpp
示例16: deserialize
void Deserializer::deserialize(const std::string& key, Serializable& sObj) {
try {
NodeSwitch ns(*this, key);
sObj.deserialize(*this);
} catch (TxException&) {
}
}
开发者ID:Ojaswi,项目名称:inviwo,代码行数:7,代码来源:deserializer.cpp
示例17: object
void Html::object(const Serializable &s)
{
// TODO
open("span");
mStream->write(escape(s.toString()));
close("span");
}
开发者ID:orinocoz,项目名称:Teapotnet,代码行数:7,代码来源:html.cpp
示例18: write_network_attributes
//
// write_network_attributes
//
void ClientSidePrediction::write_network_attributes(Serializable& object, Serializer& dest)
{
const auto attributes = object.GetNetworkAttributes();
if (!attributes)
return;
auto numAttributes = attributes->Size();
Variant value;
for (unsigned i = 0; i < numAttributes; ++i)
{
const auto& attr = attributes->At(i);
value.Clear();
object.OnGetAttribute(attr, value);
dest.WriteVariantData(value);
}
}
开发者ID:rasteron,项目名称:Urho3D-CSP,代码行数:20,代码来源:ClientSidePrediction.cpp
示例19: writer
bool RangeProfilePlotManager::serialize(SessionItemSerializer& serializer) const
{
XMLWriter writer("RangeProfilePlotManager");
writer.addAttr("viewId", mpView->getId());
#pragma message(__FILE__ "(" STRING(__LINE__) ") : warning : We should be able to save the plot's session id and restore " \
"using that but the PlotWidget is not really part of the session. The following code is a work around and should be changed " \
"when OPTICKS-542 is implemented. (tclarke)")
writer.pushAddPoint(writer.addElement("plot"));
Serializable* pPlotSer = dynamic_cast<Serializable*>(mpPlot); // The imp side is serializable
VERIFY(pPlotSer);
if (!pPlotSer->toXml(&writer))
{
return false;
}
writer.popAddPoint();
writer.pushAddPoint(writer.addElement("plotView"));
Serializable* pPlotViewSer = dynamic_cast<Serializable*>(mpView); // The imp side is serializable
VERIFY(pPlotViewSer);
if (!pPlotViewSer->toXml(&writer))
{
return false;
}
writer.popAddPoint();
for (std::map<Signature*, std::string>::const_iterator sig = mSigPointSets.begin();
sig != mSigPointSets.end(); ++sig)
{
writer.pushAddPoint(writer.addElement("signature"));
writer.addAttr("sigId", sig->first->getId());
writer.addAttr("pointSetName", sig->second);
writer.popAddPoint();
}
if (!serializer.serialize(writer))
{
return false;
}
serializer.endBlock();
return DockWindowShell::serialize(serializer);
}
开发者ID:tclarke,项目名称:opticks-extras-Spectral,代码行数:42,代码来源:RangeProfilePlotManager.cpp
示例20: 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
注:本文中的Serializable类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论