From: stephan b. <sg...@us...> - 2004-12-26 01:27:11
|
Update of /cvsroot/pclasses/pclasses2/src/s11n In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6895/src/s11n Added Files: test.cpp Log Message: egg: P::s11n works :) --- NEW FILE: test.cpp --- #include "s11n.h" #include "s11n_node.h" #include "s11n_debuggering_macros.h" #include <memory> // auto_ptr #include <cassert> #define NODE_TYPE ::P::s11n::s11n_node #define SERIALIZE(Node,SType,SObj) ::P::s11n::serialize< NODE_TYPE >( Node, SObj ) #define DESERIALIZE(Node,SType) ::P::s11n::deserialize< NODE_TYPE, SType >( Node ) #define TRAITS ::P::s11n::node_traits< NODE_TYPE > struct TheBase { virtual ~TheBase() {} virtual std::string classname() const = 0; virtual bool serialize( NODE_TYPE & dest ) const { TRAITS::class_name( dest, this->classname() ); return true; } virtual bool deserialize( const NODE_TYPE & dest ) { CERR << "Deserializing " << TRAITS::class_name( dest ) << "\n"; return true; } }; struct AType : public TheBase { AType() { CERR << "AType()\n"; } virtual ~AType() { CERR << "~AType()\n"; } virtual std::string classname() const { return "AType"; } }; struct BType : public AType { BType() { CERR << "BType()\n"; } virtual ~BType() { CERR << "~BType()\n"; } virtual std::string classname() const { return "BType"; } }; struct TheBase_s11n { bool operator()( NODE_TYPE & dest, const TheBase & src ) const { return src.serialize( dest ); } bool operator()( const NODE_TYPE & src, TheBase & dest ) const { return dest.deserialize( src ); } }; #define PS11N_TYPE TheBase #define PS11N_TYPE_IS_ABSTRACT #define PS11N_TYPE_NAME "TheBase" #define PS11N_SERIALIZE_FUNCTOR TheBase_s11n #include "reg_serializable_traits.h" #define PS11N_TYPE AType #define PS11N_TYPE_INTERFACE TheBase #define PS11N_TYPE_NAME "AType" #include "reg_serializable_traits.h" #define PS11N_TYPE BType #define PS11N_TYPE_INTERFACE TheBase #define PS11N_TYPE_NAME "BType" #include "reg_serializable_traits.h" /// i wish i could make this a P::App... int main( int argc, char ** argv ) { CERR << "P::s11n tests...\n"; typedef std::auto_ptr<TheBase> BAP; BAP b1 = BAP( new AType ); NODE_TYPE node; assert( SERIALIZE(node,TheBase,b1.get() ) ); CERR << "Serialize Workie!\n"; BAP b2 = BAP( DESERIALIZE(node,TheBase) ); assert( b2.get() && "Deserialize failed :(" ); CERR << "Deser workie!\n"; return 0; } |