From: stephan b. <st...@s1...> - 2004-12-28 23:19:30
|
Yo, Before i go to bed i wanted to introduce you to a new part of the SIO API: S11nNode now contains the same de/serialize() members as the SIO namespace. It does not have the load/save() (file/stream-based) variants because those require knowledge of the SerializerInterface, and S11nNode inherently doesn't know that. Anyway, here's a short demo: CERR << "Time...\n"; Time thetime( 12, 13, 14 ); Date thedate( 2005, 1, 30 ); DateTime dt( thedate, thetime ); // save using SIO interface: save( thetime, std::cout ); save( thedate, std::cout ); save( dt, std::cout ); CERR << "Using S11nNode-specific API...\n"; S11nNode tmnode; assert( tmnode.serialize( dt ) ); assert( save( tmnode, std::cout ) ); DateTime * pdt = tmnode.deserialize<DateTime>(); assert( pdt ); CERR << "deserialized (DateTime*) == " << *pdt<<"\n"; delete pdt; DateTime vdt; assert( tmnode.deserialize( vdt ) ); CERR << "deserialized DateTime == " << vdt<<"\n"; Output... s11nTest.cpp:460 : Time... <!DOCTYPE s11n::io::expat_serializer> <S11nNode class="P::Time"> <hour>12</hour> <min>13</min> <sec>14</sec> <usec>0</usec> </S11nNode> <!DOCTYPE s11n::io::expat_serializer> <S11nNode class="P::Date"> <day>30</day> <month>1</month> <year>2005</year> </S11nNode> <!DOCTYPE s11n::io::expat_serializer> <S11nNode class="P::DateTime"> <time class="P::Time"> <hour>12</hour> <min>13</min> <sec>14</sec> <usec>0</usec> </time> <date class="P::Date"> <day>30</day> <month>1</month> <year>2005</year> </date> </S11nNode> s11nTest.cpp:471 : Using S11nNode-specific API... <!DOCTYPE s11n::io::expat_serializer> <S11nNode class="P::DateTime"> <time class="P::Time"> <hour>12</hour> <min>13</min> <sec>14</sec> <usec>0</usec> </time> <date class="P::Date"> <day>30</day> <month>1</month> <year>2005</year> </date> </S11nNode> s11nTest.cpp:478 : deserialized (DateTime*) == 2005-01-30 12:13:14 s11nTest.cpp:482 : deserialized DateTime == 2005-01-30 12:13:14 -- ----- st...@s1... http://s11n.net "...pleasure is a grace and is not obedient to the commands of the will." -- Alan W. Watts |