Update of /cvsroot/libfunutil/libfunutil/lib/s11n In directory sc8-pr-cvs1:/tmp/cvs-serv24817/lib/s11n Modified Files: S11n.h Serializable.cpp Serializable.h node_builder.cpp node_builder.h s11n_node.h serializable_adapter.h Log Message: a few minor changes/fixes from the main tree. Index: S11n.h =================================================================== RCS file: /cvsroot/libfunutil/libfunutil/lib/s11n/S11n.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- S11n.h 14 Oct 2003 03:38:14 -0000 1.3 +++ S11n.h 14 Oct 2003 20:42:30 -0000 1.4 @@ -4,9 +4,10 @@ #ifndef S11N_H_INCLUDED #define S11N_H_INCLUDED 1 -#include <s11n/s11n_node.h> -#include <s11n/Serializable.h> -#include <s11n/serializable_adapter.h> +// please don't use this header - it's being phased out. +// #include <s11n/s11n_node.h> +// #include <s11n/Serializable.h> +// #include <s11n/serializable_adapter.h> /** The s11n serialization (s11n) framework is an object serialization framework modelled heavily off work by Rusty Ballinger Index: Serializable.cpp =================================================================== RCS file: /cvsroot/libfunutil/libfunutil/lib/s11n/Serializable.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- Serializable.cpp 14 Oct 2003 03:07:15 -0000 1.1 +++ Serializable.cpp 14 Oct 2003 20:42:30 -0000 1.2 @@ -1,8 +1,10 @@ -#include "Serializable.h" #include <s11n/s11n-macros.h> // CERR #include <s11n/s11n_node.h> -#include <s11n/serializable_adapter.h> +// #include <s11n/serializable_adapter.h> +#include "Serializable.h" + +#include <s11n/s11n_node.h> // make the library aware of Serializable as a serializable type: Index: Serializable.h =================================================================== RCS file: /cvsroot/libfunutil/libfunutil/lib/s11n/Serializable.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- Serializable.h 14 Oct 2003 03:07:15 -0000 1.1 +++ Serializable.h 14 Oct 2003 20:42:30 -0000 1.2 @@ -7,10 +7,8 @@ #define SERIALIZABLE_H_INCLUDED #include <string> -#include <s11n/s11n_node.h> - namespace s11n { - + class s11n_node; // forward decl /** Serializable plays several roles: @@ -100,7 +98,7 @@ #include <s11n/serializable_adapter.h> -SERIALIZABLE_ADAPTER(s11n::Serializable,s7e,d9e); // this is the only sane place to put this, i think? - +SERIALIZABLE_ADAPTER(s11n::Serializable,s7e,d9e); // this is the +// only sane place to put this, i think? #endif // SERIALIZABLE_H_INCLUDED Index: node_builder.cpp =================================================================== RCS file: /cvsroot/libfunutil/libfunutil/lib/s11n/node_builder.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- node_builder.cpp 14 Oct 2003 03:07:15 -0000 1.1 +++ node_builder.cpp 14 Oct 2003 20:42:30 -0000 1.2 @@ -8,8 +8,12 @@ #include <s11n/s11n-macros.h> // CERR macro #include <toolbox/PointerList.h> #include <toolbox/ClassLoader.h> -#include <s11n/S11n.h> + +#include <s11n/serializable_adapter.h> +#include <s11n/Serializable.h> #include <s11n/node_builder.h> + +#include <s11n/s11n_node.h> #define LEXER_LOUD 0 Index: node_builder.h =================================================================== RCS file: /cvsroot/libfunutil/libfunutil/lib/s11n/node_builder.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- node_builder.h 14 Oct 2003 03:07:15 -0000 1.1 +++ node_builder.h 14 Oct 2003 20:42:30 -0000 1.2 @@ -10,13 +10,11 @@ #include <cassert> #include <toolbox/PointerList.h> -#include <toolbox/ClassLoader.h> -#include <s11n/s11n_node.h> namespace s11n { - + class s11n_node; // forward decl /** node_builder is a helper class for building trees from Index: s11n_node.h =================================================================== RCS file: /cvsroot/libfunutil/libfunutil/lib/s11n/s11n_node.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- s11n_node.h 14 Oct 2003 03:07:15 -0000 1.1 +++ s11n_node.h 14 Oct 2003 20:42:30 -0000 1.2 @@ -250,7 +250,7 @@ return tgt; } - if ( ! serializable_adapter<SerializableType>::proxy_deserialize( *tgt, *this ) ) + if ( ! serializable_adapter<SerializableType>::deserialize( *tgt, *this ) ) { NODEDEBUG << "tgt->deserialize() failed. Deleting tgt. impl_class="<< classname << ", nodename=" << this->name() << std::endl; delete( tgt ); @@ -276,7 +276,7 @@ // std::string classname = Adapter::impl_class(); // node->impl_class( Adapter::impl_class() ); NODEDEBUG << "serialize(" << nodename << " , " <<std::hex << &ser << ") typeid=["<<typeid(ser).name()<<"] impl_class="<<node->impl_class() << std::endl; - if ( !Adapter::proxy_serialize( ser, *node ) ) + if ( !Adapter::serialize( ser, *node ) ) { NODEDEBUG << "serialize(" << nodename << " , " <<std::hex << &ser << ") failed!" << std::endl; delete( node ); @@ -302,7 +302,7 @@ bool serialize( const SerializableType & ser ) { typedef serializable_adapter<SerializableType> Adapter; - return Adapter::proxy_serialize( ser, *this ); + return Adapter::serialize( ser, *this ); } @@ -516,7 +516,7 @@ ch = ( *it ); node = new s11n_node(); node->name( nodename ); - if ( ! Adapter::proxy_serialize( *ch, *node ) ) + if ( ! Adapter::serialize( *ch, *node ) ) { delete( node ); worked = false; @@ -546,7 +546,7 @@ bool deserialize( SerializableType & tgt ) const { NODEDEBUG << "bool deserialize<T>()" << std::endl; - return serializable_adapter<SerializableType>::proxy_deserialize( tgt, *this ); + return serializable_adapter<SerializableType>::deserialize( tgt, *this ); } /** Index: serializable_adapter.h =================================================================== RCS file: /cvsroot/libfunutil/libfunutil/lib/s11n/serializable_adapter.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- serializable_adapter.h 14 Oct 2003 03:07:15 -0000 1.1 +++ serializable_adapter.h 14 Oct 2003 20:42:30 -0000 1.2 @@ -10,8 +10,8 @@ #include <toolbox/ClassLoader.h> #include <toolbox/class_name.h> - -// funny how this code can compile without any other s11n code, via +// #include <s11n/s11n_node.h> +// funny how this class can compile without any other s11n code, via // the magic of templates. @@ -22,58 +22,8 @@ class s11n_node; } -namespace { // anonymous ns, important for linking reasons - - template <typename T, typename X> struct serializable_adapter; // forward decl - /** - This class exists solely for experimental classloading reasons! - */ - struct base_serializable_adapter - { - base_serializable_adapter(){} - virtual ~base_serializable_adapter(){} - - virtual const char * impl_class() const { return "base_serializable_adapter::impl_class() needs to be overridden by a specialization"; }; - -// template <class serializable_type,class node_type> -// bool serialize( const serializable_type & ser, node_type & node ) -// { -// return false; -// } -// template <class serializable_type,class node_type> -// bool deserialize( serializable_type & ser, const node_type & node ) -// { -// return false; -// } - - template <class serializable_type,class node_type> - static bool proxy_serialize( const serializable_type & ser, node_type & node ) - { - return toolbox::context_singleton< - serializable_adapter<serializable_type,node_type> , - serializable_type - >::instance().serialize( ser, node ); - } - - template <class serializable_type,class node_type> - static bool proxy_deserialize( serializable_type & ser, const node_type & node ) - { - return toolbox::context_singleton< - serializable_adapter<serializable_type,node_type> , - serializable_type - >::instance().deserialize( ser, node ); - } - - template <class serializable_type,class node_type> - static const char * proxy_impl_class() - { - return toolbox::context_singleton< - serializable_adapter<serializable_type,node_type> , - serializable_type - >::instance().impl_class( ser, node ); - } +namespace { - }; /** This class acts as a proxy between concrete @@ -114,7 +64,7 @@ setting an s11n_node's impl_class() during serialization. */ template <class SerializableType,class NodeType = s11n::s11n_node> - class serializable_adapter : public base_serializable_adapter + class serializable_adapter { public: typedef serializable_adapter<SerializableType,NodeType> ThisType; @@ -122,9 +72,6 @@ typedef SerializableType serializable_type; typedef SerializableType impl_type; - serializable_adapter(){} - virtual ~serializable_adapter(){}; - #define NOT_SPECIALIZED(func) CERR << ":? got non-specialized "<<# func<<"()! You must specialize serializable_adaptor<T> for type "<<typeid(ser).name()<< std::endl; assert(0); /** Returns the class name for x. @@ -134,33 +81,38 @@ template signature, but this is the only way i've found to ensure the class name. */ - virtual const char * impl_class() const + static std::string class_name() { - NOT_SPECIALIZED(impl_class); + NOT_SPECIALIZED(class_name); return typeid(ser).name(); + /* aaarrgggg!! why does this always return the serializable_type classname in specializations??? + classloader_registerer<serializable_type,impl_type>::class_name(); */ } - bool serialize( const serializable_type & ser, node_type & node ) + static bool serialize( const serializable_type & ser, node_type & node ) { NOT_SPECIALIZED(serialize); - node.impl_class( impl_class() ); + node.impl_class( class_name() ); return ser.serialize( node ); } - bool deserialize( serializable_type & ser, const node_type & node ) + static bool deserialize( serializable_type & ser, const node_type & node ) { NOT_SPECIALIZED(deserialize); return ser.serialize( node ); } + protected: + serializable_adapter(){} + ~serializable_adapter(){}; // unimpl. + private: static std::string m_implclass; }; // basic_serializable_adaptor /** Quasi-bogus specialization to accomodate usage of, e.g., - container::value_type as a SerializableType parameter in - container-related de/ser methods. + container::value_type as a SerializableType parameter. */ template <class SerializableType,class NodeType> class serializable_adapter<SerializableType *,NodeType> : public serializable_adapter <SerializableType,NodeType>{}; @@ -186,24 +138,23 @@ */ #define SERIALIZABLE_ADAPTER(SerInterface,SerializE,DeserializE) \ CLASSLOADER_REGISTER(SerInterface,SerInterface); \ - CLASSLOADER_REGISTER(base_serializable_adapter,serializable_adapter<SerInterface>); \ CLASS_NAME(SerInterface); \ namespace { \ typedef s11n::s11n_node node_type;\ - template <> struct serializable_adapter<SerInterface,node_type> : public base_serializable_adapter { \ + template <> struct serializable_adapter<SerInterface,node_type> { \ typedef SerInterface serializable_type; \ typedef SerInterface impl_type; \ typedef serializable_adapter<SerInterface,node_type> this_t; \ explicit serializable_adapter(){}; \ ~serializable_adapter(){}; \ - virtual const char * impl_class() const \ + static std::string class_name() \ { return # SerInterface; }\ - bool serialize( const serializable_type & ser, node_type &node ) \ + static bool serialize( const serializable_type & ser, node_type &node ) \ { \ - node.impl_class( impl_class() ); \ + node.impl_class( class_name() ); \ return ser.SerializE( node ); \ } \ - bool deserialize( serializable_type & ser, const node_type & node ) \ + static bool deserialize( serializable_type & ser, const node_type & node ) \ { return ser.DeserializE( node ); } \ }; \ } @@ -246,7 +197,6 @@ #define SERIALIZABLE_REGISTER(SerInterface,SerImpl) \ CLASS_NAME(SerImpl); \ - CLASSLOADER_REGISTER(base_serializable_adapter,serializable_adapter<SerImpl>); \ CLASSLOADER_REGISTER(SerInterface,SerImpl); \ CLASSLOADER_REGISTER(SerImpl,SerImpl); \ namespace { \ @@ -258,15 +208,15 @@ typedef serializable_adapter<impl_type,node_type> this_t; \ explicit serializable_adapter(){}; \ ~serializable_adapter(){}; \ - virtual const char * impl_class() const \ + static std::string class_name() \ { return # SerImpl; }\ - bool serialize( const serializable_type & ser, node_type &node ) \ + static bool serialize( const serializable_type & ser, node_type &node ) \ { \ bool b = parent_t::serialize( ser, node ); \ - node.impl_class( impl_class() ); \ + node.impl_class( class_name() ); \ return b; \ } \ - bool deserialize( serializable_type & ser, const node_type & node ) \ + static bool deserialize( serializable_type & ser, const node_type & node ) \ { return parent_t::deserialize( ser, node ); } \ }; \ template<> struct serializable_adapter<SerImpl *,node_type> : public serializable_adapter<SerImpl,node_type> {};\ |