parent
37fd5e8695
commit
17dc91d35e
6 changed files with 133 additions and 35 deletions
@ -0,0 +1,59 @@ |
||||
/*! @file
|
||||
|
||||
@id $Id: inherit_serialization.cxx 25 2009-04-23 15:10:21Z $ |
||||
*/ |
||||
// 1 2 3 4 5 6 7 8
|
||||
// 45678901234567890123456789012345678901234567890123456789012345678901234567890
|
||||
|
||||
// g++ -I../../src ../../src/xml.cxx contain_serialization.cxx
|
||||
|
||||
#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") |
||||
.persist(a); |
||||
} |
||||
}; |
||||
|
||||
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; |
||||
} |
Loading…
Reference in new issue