2009-04-24 07:13:10 +00:00
|
|
|
/*! @file
|
|
|
|
|
|
|
|
@id $Id: inherit_serialization.cxx 25 2009-04-23 15:10:21Z $
|
|
|
|
*/
|
|
|
|
// 1 2 3 4 5 6 7 8
|
|
|
|
// 45678901234567890123456789012345678901234567890123456789012345678901234567890
|
|
|
|
|
|
|
|
#include <xml-cxx/xml.hxx>
|
|
|
|
#include <iostream>
|
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
class A: public xml::Serialize {
|
|
|
|
public:
|
|
|
|
int a;
|
|
|
|
std::string txt;
|
|
|
|
protected:
|
|
|
|
void initXmlMembers() {
|
|
|
|
className("a")
|
|
|
|
.persist(a, "a")
|
|
|
|
.persist(txt, "txt");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class B: public xml::Serialize {
|
|
|
|
public:
|
|
|
|
int i;
|
|
|
|
std::string txt;
|
|
|
|
A a;
|
|
|
|
protected:
|
|
|
|
void initXmlMembers() {
|
|
|
|
className("b")
|
|
|
|
.persist(i, "i")
|
|
|
|
.persist(txt, "txt")
|
2009-04-27 10:48:27 +00:00
|
|
|
.persist(a, "a");
|
2009-04-24 07:13:10 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
int main(int, char**) {
|
|
|
|
{ // Serialization as a member
|
|
|
|
std::stringstream ss("<b>\n"
|
|
|
|
"\t<i>1234</i>\n"
|
|
|
|
"\t<txt>Dies ist Class B</txt>\n"
|
|
|
|
"\t<a>\n"
|
|
|
|
"\t\t<a>5678</a>\n"
|
|
|
|
"\t\t<txt>Dies ist Class A</txt>\n"
|
|
|
|
"\t</a>"
|
|
|
|
"</b>");
|
|
|
|
B b;
|
|
|
|
b.loadXml(ss);
|
|
|
|
if (b.i==1234) b.i=4321;
|
|
|
|
if (b.a.a==5678) b.a.a=8765;
|
|
|
|
std::cout<<"Text B: "<<b.txt<<std::endl;
|
|
|
|
std::cout<<"Text A: "<<b.a.txt<<std::endl;
|
|
|
|
b.saveXml(std::cout)<<std::endl;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|