serialization nearly ready for containment
This commit is contained in:
		
							
								
								
									
										59
									
								
								doc/examples/contain_serialization.cxx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										59
									
								
								doc/examples/contain_serialization.cxx
									
									
									
									
									
										Normal file
									
								
							| @@ -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; | ||||
| } | ||||
| @@ -11,7 +11,7 @@ | ||||
| #include <iostream> | ||||
| #include <sstream> | ||||
|  | ||||
| class B: public xml::Serialize { | ||||
| class A: public xml::Serialize { | ||||
|   public: | ||||
|     int a; | ||||
|     std::string txt; | ||||
| @@ -23,7 +23,7 @@ class B: public xml::Serialize { | ||||
|     } | ||||
| }; | ||||
|  | ||||
| class B: public xml::Serialize { | ||||
| class B: public A { | ||||
|   public: | ||||
|     int a; | ||||
|     std::string txt; | ||||
|   | ||||
| @@ -4,11 +4,13 @@ | ||||
| ## 45678901234567890123456789012345678901234567890123456789012345678901234567890 | ||||
|  | ||||
| AM_CXXFLAGS += -I ${top_srcdir}/src | ||||
| AM_LDFLAGS = -L${top_builddir}/src | ||||
| AM_LDFLAGS = -L${top_builddir}/src -lxml-cxx | ||||
|  | ||||
| noinst_PROGRAMS = address | ||||
| noinst_PROGRAMS = address node_macros serialization contain_serialization | ||||
|  | ||||
| address_SOURCES = address.cxx | ||||
| address_LDADD = -lxml-cxx | ||||
| node_macros_SOURCES = node_macros.cxx | ||||
| serialization_SOURCES = serialization.cxx | ||||
| contain_serialization_SOURCES = contain_serialization.cxx | ||||
|  | ||||
| MAINTAINERCLEANFILES = makefile.in | ||||
|   | ||||
		Reference in New Issue
	
	Block a user