You can subscribe to this list here.
2004 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(622) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2005 |
Jan
(303) |
Feb
(64) |
Mar
(5) |
Apr
(63) |
May
(82) |
Jun
(53) |
Jul
(50) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: stephan b. <sg...@us...> - 2004-12-26 06:02:02
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/Plugin In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17821/include/pclasses/Plugin Modified Files: Plugin.h Log Message: Added factory aliasing support. Allows mapping multiple names to one factory. Index: Plugin.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Plugin/Plugin.h,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- Plugin.h 25 Dec 2004 20:50:20 -0000 1.11 +++ Plugin.h 26 Dec 2004 06:01:52 -0000 1.12 @@ -79,17 +79,21 @@ The caller owns the returned object, which may be 0. */ virtual - ResultType create( const std::string & feature ) + ResultType create( const std::string & _feature ) { + std::string feature = this->expandAliases( _feature ); + //CERR << "create("<<_feature<<" ["<<feature<<"])\n"; InterfaceType * ret = ParentType::create( feature ); if( ret ) return ret; std::string dll = this->findPlugin( feature ); if( dll.empty() ) { + //CERR << "No dll found for feature '"<<feature<<"'!\n"; return 0; } try { + //CERR << "Adding plugin '"<<dll<<"'!\n"; this->addPlugin( dll ); ret = ParentType::create( feature ); } @@ -290,14 +294,24 @@ return pluginManager<T>().findPlugin( name ); } + /** + Convenience function returning + pluginManager<T>().searchPath(). + */ + template <typename T> + ::P::System::PathFinder & searchPath() + { + return pluginManager<T>().searchPath(); + } + } // namespace Plugin -#ifndef PCLASSES_DEFAULT_FACTORY_KNOWS_SHAREDLIBS -# define PCLASSES_DEFAULT_FACTORY_KNOWS_SHAREDLIBS 1 +#ifndef PCLASSES_ENABLE_PLUGINS_FACTORY_HOOK +# define PCLASSES_ENABLE_PLUGINS_FACTORY_HOOK 0 #endif -#if PCLASSES_DEFAULT_FACTORY_KNOWS_SHAREDLIBS +#if PCLASSES_ENABLE_PLUGINS_FACTORY_HOOK namespace Hook { /** @@ -318,7 +332,7 @@ */ void operator()( FactoryType & ) throw() { - CERR << "Initializing a PluginManager instance() we hacked in via FactoryInstanceHook!\n"; + // CERR << "Initializing a PluginManager instance() we hacked in via FactoryInstanceHook!\n"; } /** @@ -334,7 +348,7 @@ }; } // ns Hook -#endif // PCLASSES_DEFAULT_FACTORY_KNOWS_SHAREDLIBS +#endif // PCLASSES_ENABLE_PLUGINS_FACTORY_HOOK } // namespace P |
From: stephan b. <sg...@us...> - 2004-12-26 06:02:00
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17821/include/pclasses Modified Files: Factory.h Log Message: Added factory aliasing support. Allows mapping multiple names to one factory. Index: Factory.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Factory.h,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- Factory.h 25 Dec 2004 19:56:39 -0000 1.11 +++ Factory.h 26 Dec 2004 06:01:52 -0000 1.12 @@ -198,6 +198,7 @@ typedef InterfaceT * ResultType; + /** A typedef for the KeyType used by this class. */ @@ -206,6 +207,68 @@ /** Same as ContextType */ typedef ContextT ContextType; + typedef std::map<key_type,key_type> AliasMap; + + /** + Returns the map of classname aliases. + */ + AliasMap & aliases() + { + return m_alias; + } + + /** + Returns the map of classname aliases. + */ + const AliasMap & aliases() const + { + return m_alias; + } + + /** + Aliases 'alias' as an equivalent of 'isthesameas'. + + This can be used to register multiple named via a + single factory. + */ + void alias( const key_type & alias, const key_type & isthesameas ) + { + this->aliases()[alias] = isthesameas; + } + + /** + Expands the given alias recursively. If a recursive alias is detected, + the last expansion is returned - i.e., the same as _alias. + */ + key_type expandAliases( const key_type & _alias ) const + { + //CERR << "expandAlias("<<_alias<<")\n"; + typename AliasMap::const_iterator cit = this->aliases().find( _alias ), + cet = this->aliases().end(); + if( cet == cit ) + { + //CERR << "No alias found for "<<_alias<<"\n"; + return _alias; + } + key_type exp = (*cit).second; + while( cit != cet ) + { + cit = this->aliases().find( exp ); + if( cet == cit ) + { + // CERR << "Returning '"<<_alias<<"' unaliased: " << exp<<"\n"; + return exp; + } + exp = (*cit).second; + if( exp == _alias ) + { // circular aliasing + // CERR << "Warning: circular alias '"<<_alias<<"'."; + return exp; + } + } + return exp; + } + /** Convenience typedef. */ @@ -238,8 +301,9 @@ Subtypes are free to implement, e.g., DLL lookups. */ - virtual ResultType create( const key_type & key ) + virtual ResultType create( const key_type & _key ) { + key_type key = this->expandAliases( _key ); typename FactoryMap::const_iterator it = factoryMap().find( key ); if ( it != factoryMap().end() ) // found a factory? { @@ -286,7 +350,7 @@ */ virtual void registerFactory( const key_type & key, FactoryFuncType fp ) { - // CERR << "registerFactory("<<key<<",facfunc)\n"; + //CERR << "registerFactory("<<key<<",facfunc)\n"; factoryMap().insert( FactoryMap::value_type( key, fp ) ); } @@ -329,6 +393,9 @@ return Hook::FactoryInstanceHook<ThisType>::instance(); } + + private: + AliasMap m_alias; }; // class Factory @@ -338,6 +405,9 @@ expected that this will be the most-used factory implementation, as non-string-keyed factories are rare in practice (but sometimes very useful). + + A note to doxygen users: for some reason the parent class + isn't showing up via doxygen. :/ See Factory<InterfaceT>. */ template <typename InterfaceT> struct NamedTypeFactory : public Factory< InterfaceT, Sharing::FactoryContext, std::string > |
From: stephan b. <sg...@us...> - 2004-12-26 06:01:05
|
Update of /cvsroot/pclasses/pclasses2/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17684/test Modified Files: CType.cpp FactoryTest.cpp FactoryTest.h Makefile.toc s11nTest.cpp Log Message: mass commit: playing with Factory's new aliasing support. Index: s11nTest.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/test/s11nTest.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- s11nTest.cpp 26 Dec 2004 05:02:59 -0000 1.2 +++ s11nTest.cpp 26 Dec 2004 06:00:55 -0000 1.3 @@ -1,8 +1,8 @@ +#include <pclasses/s11n/s11n_debuggering_macros.h> #include <pclasses/s11n/s11n.h> #include <pclasses/s11n/s11n_node.h> #include <pclasses/s11n/io/s11n_io.h> -#include <pclasses/s11n/s11n_debuggering_macros.h> #include <pclasses/s11n/list.h> #include <pclasses/s11n/map.h> #include <pclasses/s11n/pods_streamable.h> @@ -12,79 +12,12 @@ #include <list> #include <map> -#include "FactoryTest.h" +#include "FactoryTest.h" // must come after s11n.h - the FactoryTest.h for why #define SERIALIZE(Node,SType,SObj) ::P::s11n::serialize< NODE_TYPE >( Node, SObj ) #define DESERIALIZE(Node,SType) ::P::s11n::deserialize< NODE_TYPE, SType >( Node ) typedef ::P::s11n::io::data_node_serializer<NODE_TYPE> SerializerBase; -#define FACTORYTEST_NO_REGISTER - -// struct TheBase -// { - -// virtual ~TheBase() {} -// virtual std::string classname() const = 0; - -// }; - -// 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 <pclasses/s11n/reg_serializable_traits.h> - -#define PS11N_TYPE AType -#define PS11N_TYPE_INTERFACE TheBase -#define PS11N_TYPE_NAME "AType" -#include <pclasses/s11n/reg_serializable_traits.h> - -#define PS11N_TYPE BType -#define PS11N_TYPE_INTERFACE TheBase -#define PS11N_TYPE_NAME "BType" -#include <pclasses/s11n/reg_serializable_traits.h> bool test_load( const std::string & fn ) { Index: FactoryTest.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/test/FactoryTest.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- FactoryTest.cpp 26 Dec 2004 05:02:59 -0000 1.7 +++ FactoryTest.cpp 26 Dec 2004 06:00:55 -0000 1.8 @@ -13,7 +13,6 @@ #include <pclasses/Plugin/Plugin.h> - int main( int argc, char ** argv ) { CERR << "Factory tests...\n"; @@ -21,26 +20,31 @@ TheBase * a = 0; + typedef P::NamedTypeFactory<TheBase> NTF; + typedef P::Plugin::PluginManager<TheBase> PM; + + PM & pm = PM::instance(); + std::string dllname = "SumDumDLL"; + pm.alias( dllname, "CType" ); + #define CLOAD(CN) a = P::CL::classload<TheBase>( CN ); \ CERR << CN << " classload("<<CN<<")ed? == " << a << "\n"; \ if( a ) CERR << "classname="<<a->classname()<<"\n"; \ delete( a ); a = 0; - typedef P::NamedTypeFactory<TheBase> NTF; #define NTLOAD(CN) a = NTF::instance().create( CN ); \ CERR << CN << " NamedTypeFactory::create("<<CN<<")ed? == " << a << "\n"; \ if( a ) CERR << "classname="<<a->classname()<<"\n"; \ delete( a ); a = 0; - typedef P::Plugin::PluginManager<TheBase> PM; #define PLOAD(CN) a = PM::instance().create( CN ); \ CERR << CN << " PluginManager::create("<<CN<<")ed? == " << a << "\n"; \ if( a ) CERR << "classname="<<a->classname()<<"\n"; \ delete( a ); a = 0; -#define LOAD(CN) NTLOAD(CN); CLOAD(CN); +#define LOAD(CN) PLOAD(CN); CLOAD(CN); #if 0 try @@ -64,7 +68,7 @@ } #endif - LOAD("CType"); // should load ./CType.so + LOAD(dllname); // should load ./CType.so LOAD("DefaultDocumentType"); // should return a (C*) LOAD("TheBase"); LOAD("AType"); Index: Makefile.toc =================================================================== RCS file: /cvsroot/pclasses/pclasses2/test/Makefile.toc,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- Makefile.toc 26 Dec 2004 05:02:59 -0000 1.7 +++ Makefile.toc 26 Dec 2004 06:00:55 -0000 1.8 @@ -32,16 +32,11 @@ ifeq (1,$(build_bins)) BIN_PROGRAMS = FactoryTest PtrTest s11nTest BIN_PROGRAMS_LDADD = $(LIBP_TESTS_LDADD) -# Can't do these until i get the linker flags imported via toc: -# PtrTest - FactoryTest_bin_OBJECTS = FactoryTest.o - FactoryTest_bin_LDADD = $(LIBPSYSTEM_CLIENT_LDADD) -# $(LIBPSYSTEM_CLIENT_LDADD) + FactoryTest_bin_OBJECTS = FactoryTest.o registrations.o + FactoryTest_bin_LDADD = $(LIBPSYSTEM_CLIENT_LDADD) $(LIBPS11N_CLIENT_LDADD) PtrTest_bin_OBJECTS = PtrTest.o PtrTest_bin_LDADD = $(LIBPSYSTEM_CLIENT_LDADD) - - s11nTest_bin_OBJECTS = s11nTest.o $(LIBPS11N_CLIENT_LDADD) $(LIBPSYSTEM_CLIENT_LDADD) - + s11nTest_bin_OBJECTS = s11nTest.o registrations.o $(LIBPS11N_CLIENT_LDADD) $(LIBPSYSTEM_CLIENT_LDADD) include $(TOC_MAKESDIR)/BIN_PROGRAMS.make endif Index: FactoryTest.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/test/FactoryTest.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- FactoryTest.h 26 Dec 2004 05:02:59 -0000 1.3 +++ FactoryTest.h 26 Dec 2004 06:00:55 -0000 1.4 @@ -10,6 +10,11 @@ #endif #include <pclasses/Factory.h> + +#ifndef USE_S11N +# define USE_S11N 0 +#endif + #include <pclasses/s11n/s11n.h> #define NODE_TYPE ::P::s11n::s11n_node @@ -21,6 +26,7 @@ virtual ~TheBase() {} virtual std::string classname() const = 0; + virtual bool serialize( NODE_TYPE & dest ) const { NODETR::class_name( dest, this->classname() ); @@ -35,6 +41,26 @@ }; + +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 <pclasses/s11n/reg_serializable_traits.h> + struct AType : public TheBase { AType() @@ -65,19 +91,19 @@ }; -#ifndef PCLASSES_S11N_INCLUDED -// avoid duplicate registrations... -# define PFACREG_TYPE AType -# define PFACREG_TYPE_INTERFACE TheBase -// #define PFACREG_TYPE_IS_ABSTRACT // define to install a null factory for AType -# define PFACREG_TYPE_NAME "AType" -# include <pclasses/FactoryReg.h> +// #ifndef PCLASSES_S11N_INCLUDED +// // avoid duplicate registrations... +// # define PFACREG_TYPE AType +// # define PFACREG_TYPE_INTERFACE TheBase +// // #define PFACREG_TYPE_IS_ABSTRACT // define to install a null factory for AType +// # define PFACREG_TYPE_NAME "AType" +// # include <pclasses/FactoryReg.h> -# define PFACREG_TYPE BType -# define PFACREG_TYPE_INTERFACE TheBase -# define PFACREG_TYPE_NAME "BType" -# include <pclasses/FactoryReg.h> -#endif // PCLASSES_S11N_INCLUDED +// # define PFACREG_TYPE BType +// # define PFACREG_TYPE_INTERFACE TheBase +// # define PFACREG_TYPE_NAME "BType" +// # include <pclasses/FactoryReg.h> +// #endif // PCLASSES_S11N_INCLUDED #endif // ptest_FACTORYTEST_HPP_INCLUDED Index: CType.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/test/CType.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- CType.cpp 25 Dec 2004 01:57:09 -0000 1.2 +++ CType.cpp 26 Dec 2004 06:00:55 -0000 1.3 @@ -1,6 +1,6 @@ #include "FactoryTest.h" - +#include <pclasses/s11n/s11n.h> struct CType : public BType { @@ -31,8 +31,12 @@ int CType_bogo_init_placeholder = ( CType_bogo_init(), 0 ); -#define PFACREG_TYPE CType -#define PFACREG_TYPE_INTERFACE TheBase -#define PFACREG_TYPE_NAME "CType" -#include <pclasses/FactoryReg.h> +// #define PFACREG_TYPE CType +// #define PFACREG_TYPE_INTERFACE TheBase +// #define PFACREG_TYPE_NAME "CType" +// #include <pclasses/FactoryReg.h> +#define PS11N_TYPE CType +#define PS11N_TYPE_INTERFACE TheBase +#define PS11N_TYPE_NAME "CType" +#include <pclasses/s11n/reg_serializable_traits.h> |
From: stephan b. <sg...@us...> - 2004-12-26 06:00:36
|
Update of /cvsroot/pclasses/pclasses2/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17598/test Added Files: registrations.cpp Log Message: egg --- NEW FILE: registrations.cpp --- #include "FactoryTest.h" #include <pclasses/s11n/s11n.h> #define PS11N_TYPE AType #define PS11N_TYPE_INTERFACE TheBase #define PS11N_TYPE_NAME "AType" #include <pclasses/s11n/reg_serializable_traits.h> #define PS11N_TYPE BType #define PS11N_TYPE_INTERFACE TheBase #define PS11N_TYPE_NAME "BType" #include <pclasses/s11n/reg_serializable_traits.h> |
From: stephan b. <sg...@us...> - 2004-12-26 05:03:23
|
Update of /cvsroot/pclasses/pclasses2/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7975/test Modified Files: FactoryTest.cpp FactoryTest.h Makefile.toc s11nTest.cpp Log Message: mass commit: sharing code between FactoryTest and s11nTest. Index: s11nTest.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/test/s11nTest.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- s11nTest.cpp 26 Dec 2004 02:25:30 -0000 1.1 +++ s11nTest.cpp 26 Dec 2004 05:02:59 -0000 1.2 @@ -1,6 +1,7 @@ #include <pclasses/s11n/s11n.h> #include <pclasses/s11n/s11n_node.h> +#include <pclasses/s11n/io/s11n_io.h> #include <pclasses/s11n/s11n_debuggering_macros.h> #include <pclasses/s11n/list.h> #include <pclasses/s11n/map.h> @@ -11,55 +12,49 @@ #include <list> #include <map> -#define NODE_TYPE ::P::s11n::s11n_node +#include "FactoryTest.h" + #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 -{ +typedef ::P::s11n::io::data_node_serializer<NODE_TYPE> SerializerBase; - 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; - } +#define FACTORYTEST_NO_REGISTER -}; +// struct TheBase +// { -struct AType : public TheBase -{ - AType() - { - CERR << "AType()\n"; - } - virtual ~AType() - { - CERR << "~AType()\n"; - } +// virtual ~TheBase() {} +// virtual std::string classname() const = 0; - virtual std::string classname() const { return "AType"; } +// }; -}; +// struct AType : public TheBase +// { +// AType() +// { +// CERR << "AType()\n"; +// } +// virtual ~AType() +// { +// CERR << "~AType()\n"; +// } -struct BType : public AType -{ - BType() - { - CERR << "BType()\n"; - } - virtual ~BType() - { - CERR << "~BType()\n"; - } - virtual std::string classname() const { return "BType"; } -}; +// 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 @@ -91,23 +86,51 @@ #define PS11N_TYPE_NAME "BType" #include <pclasses/s11n/reg_serializable_traits.h> +bool test_load( const std::string & fn ) +{ + typedef std::auto_ptr<NODE_TYPE> NAP; + NAP n = NAP( P::s11n::io::load_node<NODE_TYPE>( fn ) ); + assert( n.get() && "Failed loading node from file :(" ); + if( n.get() ) + { + typedef std::auto_ptr<SerializerBase> SAP; + std::string serclass = "expat"; + SAP ser = SAP( ::P::Plugin::pluginManager<SerializerBase>().create( serclass ) ); + assert( ser.get() && "Could not load serializer :(" ); + return ser->serialize( *(n.get()), std::cout ); + } + return false; +} /// 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 BType ); + + if( 2 == argc ) + { + return test_load( argv[1] ) ? 0 : 1; + } + + typedef std::auto_ptr<TheBase> TAP; + TAP b1 = TAP( new BType ); NODE_TYPE node; assert( SERIALIZE(node,TheBase,b1.get() ) ); CERR << "Serialize Workie!\n"; - BAP b2 = BAP( DESERIALIZE(node,TheBase) ); + NODETR::class_name( node, "CType" ); // should force load of CType.so on next line... + TAP b2 = TAP( DESERIALIZE(node,TheBase) ); assert( b2.get() && "Deserialize failed :(" ); - CERR << "Deser workie!\n"; + CERR << "Deser workie: " << b2->classname()<<"\n"; + typedef std::auto_ptr<SerializerBase> SAP; + std::string serclass = "expat"; + SAP ser = SAP( ::P::Plugin::pluginManager<SerializerBase>().create( serclass ) ); + assert( ser.get() && "Could not load serializer :(" ); + CERR << "Loaded serializer '"<<serclass<<"'. :)\n"; + - TRAITS::clear(node); + NODETR::clear(node); using ::P::Util::LexT; typedef std::list<LexT> ListT; @@ -128,12 +151,14 @@ CERR << "Containers...\n"; assert( ::P::s11n::serialize(node,list) ); + assert( ser->serialize( node, std::cout ) ); list.clear(); worked = ::P::s11n::deserialize( node, list ); assert( worked && "deser list failed :(" ); node.clear(); assert( ::P::s11n::serialize(node,map) ); + assert( ser->serialize( node, std::cout ) ); map.clear(); worked = ::P::s11n::deserialize( node, map ); assert( worked && "deser map failed :(" ); Index: FactoryTest.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/test/FactoryTest.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- FactoryTest.cpp 25 Dec 2004 01:57:09 -0000 1.6 +++ FactoryTest.cpp 26 Dec 2004 05:02:59 -0000 1.7 @@ -64,8 +64,8 @@ } #endif - LOAD("DefaultDocumentType"); - LOAD("CType"); + LOAD("CType"); // should load ./CType.so + LOAD("DefaultDocumentType"); // should return a (C*) LOAD("TheBase"); LOAD("AType"); LOAD("BType"); Index: Makefile.toc =================================================================== RCS file: /cvsroot/pclasses/pclasses2/test/Makefile.toc,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- Makefile.toc 26 Dec 2004 02:25:49 -0000 1.6 +++ Makefile.toc 26 Dec 2004 05:02:59 -0000 1.7 @@ -40,7 +40,7 @@ PtrTest_bin_OBJECTS = PtrTest.o PtrTest_bin_LDADD = $(LIBPSYSTEM_CLIENT_LDADD) - s11nTest_bin_OBJECTS = s11nTest.o $(LIBPS11N_CLIENT_LDADD) + s11nTest_bin_OBJECTS = s11nTest.o $(LIBPS11N_CLIENT_LDADD) $(LIBPSYSTEM_CLIENT_LDADD) include $(TOC_MAKESDIR)/BIN_PROGRAMS.make endif Index: FactoryTest.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/test/FactoryTest.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- FactoryTest.h 25 Dec 2004 01:57:09 -0000 1.2 +++ FactoryTest.h 26 Dec 2004 05:02:59 -0000 1.3 @@ -10,14 +10,29 @@ #endif #include <pclasses/Factory.h> +#include <pclasses/s11n/s11n.h> - +#define NODE_TYPE ::P::s11n::s11n_node +#define NODETR ::P::s11n::node_traits< NODE_TYPE > struct TheBase { virtual ~TheBase() {} virtual std::string classname() const = 0; + + virtual bool serialize( NODE_TYPE & dest ) const + { + NODETR::class_name( dest, this->classname() ); + CERR << "Serializing " << NODETR::class_name( dest ) << "...\n"; + return true; + } + virtual bool deserialize( const NODE_TYPE & dest ) + { + CERR << "Deserializing " << NODETR::class_name( dest ) << "...\n"; + return true; + } + }; struct AType : public TheBase @@ -36,13 +51,6 @@ }; - -#define PFACREG_TYPE AType -#define PFACREG_TYPE_INTERFACE TheBase -// #define PFACREG_TYPE_IS_ABSTRACT // define to install a null factory for AType -#define PFACREG_TYPE_NAME "AType" -#include <pclasses/FactoryReg.h> - struct BType : public AType { BType() @@ -55,10 +63,21 @@ } virtual std::string classname() const { return "BType"; } }; -#define PFACREG_TYPE BType -#define PFACREG_TYPE_INTERFACE TheBase -#define PFACREG_TYPE_NAME "BType" -#include <pclasses/FactoryReg.h> + + +#ifndef PCLASSES_S11N_INCLUDED +// avoid duplicate registrations... +# define PFACREG_TYPE AType +# define PFACREG_TYPE_INTERFACE TheBase +// #define PFACREG_TYPE_IS_ABSTRACT // define to install a null factory for AType +# define PFACREG_TYPE_NAME "AType" +# include <pclasses/FactoryReg.h> + +# define PFACREG_TYPE BType +# define PFACREG_TYPE_INTERFACE TheBase +# define PFACREG_TYPE_NAME "BType" +# include <pclasses/FactoryReg.h> +#endif // PCLASSES_S11N_INCLUDED #endif // ptest_FACTORYTEST_HPP_INCLUDED |
From: stephan b. <sg...@us...> - 2004-12-26 04:45:07
|
Update of /cvsroot/pclasses/pclasses2/src/s11n/io In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5194/src/s11n/io Modified Files: Makefile.toc Log Message: added s11n_io.h Index: Makefile.toc =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/s11n/io/Makefile.toc,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- Makefile.toc 26 Dec 2004 04:04:32 -0000 1.1 +++ Makefile.toc 26 Dec 2004 04:44:58 -0000 1.2 @@ -8,6 +8,7 @@ data_node_format.h \ data_node_io.h \ reg_serializer.h \ + s11n_io.h \ serializers.h DIST_FILES += $(HEADERS) |
From: stephan b. <sg...@us...> - 2004-12-26 04:44:00
|
Update of /cvsroot/pclasses/pclasses2/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5035/src Modified Files: Makefile.toc Log Message: Moved s11n after System, for deps reasons. Index: Makefile.toc =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/Makefile.toc,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- Makefile.toc 26 Dec 2004 01:58:05 -0000 1.9 +++ Makefile.toc 26 Dec 2004 04:43:51 -0000 1.10 @@ -2,7 +2,7 @@ include toc.make -SUBDIRS = Unicode s11n IO System Util Net +SUBDIRS = Unicode System s11n IO Util Net # Plugins SOURCES = Alloc.cpp \ |
From: stephan b. <sg...@us...> - 2004-12-26 04:42:27
|
Update of /cvsroot/pclasses/pclasses2/src/s11n/io In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4718/src/s11n/io Added Files: s11n_io.h Log Message: egg --- NEW FILE: s11n_io.h --- #ifndef p_s11n_io_HPP_INCLUDED #define p_s11n_io_HPP_INCLUDED 1 //////////////////////////////////////////////////////////////////////// // s11n_io.h // Intended to be the only header clients of P::s11n::io need to // include. //////////////////////////////////////////////////////////////////////// #include "data_node_io.h" #include "data_node_format.h" #include "serializers.h" namespace P { namespace s11n { namespace io { }}} // namespace P::s11n::io #endif // p_s11n_io_HPP_INCLUDED |
From: stephan b. <sg...@us...> - 2004-12-26 04:11:11
|
Update of /cvsroot/pclasses/pclasses2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31914 Modified Files: toc.pclasses2.make.at Log Message: Added another huge kludge to fool Make... Index: toc.pclasses2.make.at =================================================================== RCS file: /cvsroot/pclasses/pclasses2/toc.pclasses2.make.at,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- toc.pclasses2.make.at 25 Dec 2004 00:12:53 -0000 1.5 +++ toc.pclasses2.make.at 26 Dec 2004 04:10:57 -0000 1.6 @@ -33,10 +33,11 @@ LIBP_TESTS_LDADD = -rdynamic $(P_BACKLINK_LDADD) -L$(top_srcdir)/lib $(LIBPCORE_CLIENT_LDADD) ######################################################################## -# Huge kludge to shut up make: +# HUGE KLUDGE to shut up 'no rule to make target -lfoo' errors from make: -l$(LIBPCORE_BASENAME): -l$(LIBPNET_BASENAME): -l$(LIBPIO_BASENAME): -l$(LIBPUNICODE_BASENAME): -l$(LIBPSYSTEM_BASENAME): -l$(LIBPUTIL_BASENAME): +-l$(LIBPS11N_BASENAME): |
From: stephan b. <sg...@us...> - 2004-12-26 04:10:37
|
Update of /cvsroot/pclasses/pclasses2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31787 Modified Files: configure.pclasses2 Log Message: added expat-related defines for condition build, plus linker args. Index: configure.pclasses2 =================================================================== RCS file: /cvsroot/pclasses/pclasses2/configure.pclasses2,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -r1.12 -r1.13 --- configure.pclasses2 26 Dec 2004 02:25:05 -0000 1.12 +++ configure.pclasses2 26 Dec 2004 04:10:27 -0000 1.13 @@ -43,6 +43,11 @@ fi toc_test libs11n; toc_export PCLASSES_HAVE_S11N=${HAVE_LIBS11N} toc_test libexpat +if test x1 = "x${HAVE_LIBEXPAT}"; then + toc_export PCLASSES_HAVE_LIBEXPAT=1 + toc_export LIBEXPAT_CLIENT_LDADD="-lexpat" + expat_ldadd="-lexpat" +fi ######################################################################## # pthreads kludge... @@ -191,7 +196,7 @@ toc_export LIBPUTIL_CFLAGS="${THREADS_CFLAGS}" toc_export LIBPS11N_BASENAME=pclasses_s11n -toc_export LIBPS11N_LDADD="" +toc_export LIBPS11N_LDADD="${expat_ldadd}" toc_export LIBPS11N_CLIENT_LDADD="-l${LIBPS11N_BASENAME}" toc_export LIBPS11N_CFLAGS="" |
Update of /cvsroot/pclasses/pclasses2/src/s11n In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31467/src/s11n Modified Files: Makefile.toc classload.h reg_list_specializations.h reg_map_specializations.h reg_serializable_traits.h traits.h valarray.h Log Message: mass commit: more P-port changes. Index: reg_map_specializations.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/s11n/reg_map_specializations.h,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- reg_map_specializations.h 26 Dec 2004 01:54:34 -0000 1.4 +++ reg_map_specializations.h 26 Dec 2004 04:09:28 -0000 1.5 @@ -49,7 +49,7 @@ typedef PS11N_MAP_TYPE<KeyT,ValT> serializable_type; typedef PS11N_MAP_TYPE_PROXY serialize_functor; typedef serialize_functor deserialize_functor; - typedef ::P::s11n::cl::object_factory<serializable_type> factory_type; + typedef ::P::s11n::cl::factory_create_functor<serializable_type> factory_type; static const bool cl_reg_placeholder = (::classname<serializable_type>(),true) ; }; Index: classload.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/s11n/classload.h,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- classload.h 26 Dec 2004 01:43:29 -0000 1.4 +++ classload.h 26 Dec 2004 04:09:28 -0000 1.5 @@ -2,7 +2,7 @@ #define p_s11n_cl_S11N_CLASSLOAD_HPP_INCLUDED 1 #include <pclasses/Factory.h> // default classloader/factory implementation. - +#include <pclasses/Plugin/Plugin.h> namespace P { namespace s11n { @@ -13,12 +13,8 @@ Note that the registration functions in this namespace register with the cllite framework. Clients wishing to use - their own factories must: - - - register with their appropriate classloader. - - - specialize the object_factory class template so that it - forwards calls to their classloader. + their own factories must register with their appropriate + classloader. This layer is used for classloading anything which s11n @@ -36,16 +32,11 @@ namespace cl { /** - A default object factory implementation for use - with the s11n::cl::classload()-related functions. - - Clients may specialize this to return objects from - their own factories. By default it uses the cllite - framework and thus can load any type registered with - cllite's InterfaceType classloader. + A functor which passes on calls to + P::PluginManager<InterfaceType>. */ template <typename InterfaceType> - struct object_factory + struct factory_create_functor { /** Same as InterfaceType. */ typedef InterfaceType base_type; @@ -60,7 +51,7 @@ { try { - return ::P::Factory<InterfaceType, ::P::Sharing::FactoryContext, std::string >::instance().create( classname ); + return ::P::Plugin::pluginManager<InterfaceType>().create( classname ); } catch(...) { @@ -72,26 +63,16 @@ /** Returns InterfaceT's classloader. - See cllite::classloader() for important info. - - Before mucking with this object, please be aware of - the cllite relationship between it and the default - object_factory<InterfaceT> implementation (e.g., by looking - at the s11n::cl source code). - - Using this classloader for types which have - customized, non-cllite-based object_factory<InterfaceT> - specializations is essentially useless. */ template <typename InterfaceT> - ::P::Factory<InterfaceT> & + ::P::Plugin::PluginManager<InterfaceT> & classloader() { - return ::P::Factory<InterfaceT>::instance(); + return ::P::Plugin::pluginManager<InterfaceT>(); } /** - Returns object_factory<InterfaceType>()( key ). + Returns classloader<InterfaceType>().create( key ). Note that calling this function is NOT the same as @@ -102,7 +83,7 @@ template <typename InterfaceType> InterfaceType * classload( const std::string key ) { - return object_factory<InterfaceType>()( key ); + return classloader<InterfaceType>().create( key ); } /** Index: valarray.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/s11n/valarray.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- valarray.h 26 Dec 2004 00:55:20 -0000 1.2 +++ valarray.h 26 Dec 2004 04:09:28 -0000 1.3 @@ -134,7 +134,7 @@ typedef std::valarray<ValueType> serializable_type; typedef ::P::s11n::va::valarray_serializable_proxy serialize_functor; typedef serialize_functor deserialize_functor; - typedef ::P::s11n::cl::object_factory<serializable_type> factory_type; + typedef ::P::s11n::cl::factory_create_functor<serializable_type> factory_type; }; Index: traits.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/s11n/traits.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- traits.h 26 Dec 2004 01:43:29 -0000 1.3 +++ traits.h 26 Dec 2004 04:09:28 -0000 1.4 @@ -349,7 +349,7 @@ registered via the s11n::cl::classload() family of functions. */ - typedef ::P::s11n::cl::object_factory<serializable_type> factory_type; + typedef ::P::s11n::cl::factory_create_functor<serializable_type> factory_type; /** Functor type implementing serialize code. Index: reg_list_specializations.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/s11n/reg_list_specializations.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- reg_list_specializations.h 26 Dec 2004 01:26:15 -0000 1.3 +++ reg_list_specializations.h 26 Dec 2004 04:09:28 -0000 1.4 @@ -65,7 +65,7 @@ typedef PS11N_LIST_TYPE<ValT> serializable_type; typedef PS11N_LIST_TYPE_PROXY serialize_functor; typedef serialize_functor deserialize_functor; - typedef ::P::s11n::cl::object_factory<serializable_type> factory_type; + typedef ::P::s11n::cl::factory_create_functor<serializable_type> factory_type; static const bool cl_reg_placeholder = (::classname<serializable_type>(),true) ; }; Index: Makefile.toc =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/s11n/Makefile.toc,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- Makefile.toc 26 Dec 2004 02:28:13 -0000 1.4 +++ Makefile.toc 26 Dec 2004 04:09:28 -0000 1.5 @@ -2,10 +2,13 @@ include toc.make +SUBDIRS = io + SOURCES = \ data_node.cpp \ s11n.cpp \ - s11n_node.cpp + s11n_node.cpp \ + string_util.cpp HEADERS = $(wildcard *.h) @@ -14,6 +17,7 @@ data_node \ s11n \ s11n_node \ + string_util \ ) objects: $(OBJECTS) @@ -27,8 +31,20 @@ SYMLINK_HEADERS_DEST = $(top_srcdir)/include/pclasses/s11n include $(TOC_MAKESDIR)/SYMLINK_HEADERS.make +SUBDIR_OBJECTS = io/data_node_io.o +ifeq (1,$(PCLASSES_HAVE_LIBEXPAT)) + SUBDIR_OBJECTS += io/expat/expat_serializer.o +endif + + +# odd: always causes the .o to be rebuilt: +# io/data_node_io.o: subdir-io +# io/expat/expat_serializer.o: subdir-io + + SHARED_LIBS = libpclasses_s11n -libpclasses_s11n_so_OBJECTS = $(OBJECTS) +libpclasses_s11n_so_LDADD = $(LIBEXPAT_CLIENT_LDADD) +libpclasses_s11n_so_OBJECTS = $(OBJECTS) $(SUBDIR_OBJECTS) libpclasses_s11n_so_VERSION = $(PACKAGE_VERSION) include $(TOC_MAKESDIR)/SHARED_LIBS.make @@ -36,7 +52,7 @@ test_bin_OBJECTS = test.o libpclasses_s11n.so include $(TOC_MAKESDIR)/BIN_PROGRAMS.make -all: symlink-headers SHARED_LIBS +all: symlink-headers subdirs SHARED_LIBS # BIN_PROGRAMS Index: reg_serializable_traits.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/s11n/reg_serializable_traits.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- reg_serializable_traits.h 26 Dec 2004 01:26:15 -0000 1.3 +++ reg_serializable_traits.h 26 Dec 2004 04:09:28 -0000 1.4 @@ -24,7 +24,7 @@ // // PS11N_FACTORY_TYPE: functor which is responsible for instantiating // objects of type PS11N_TYPE. Default behaviour is to use -// s11n::cl::object_factory< PS11N_TYPE_INTERFACE >. +// s11n::cl::factory_create_functor< PS11N_TYPE_INTERFACE >. // // THINGS TO KNOW: // @@ -109,7 +109,7 @@ #ifndef PS11N_FACTORY_TYPE // then register a factory of our own... # define PS11N_REG_CLLITE 1 -# define PS11N_FACTORY_TYPE ::P::s11n::cl::object_factory< PS11N_TYPE_INTERFACE > +# define PS11N_FACTORY_TYPE ::P::s11n::cl::factory_create_functor< PS11N_TYPE_INTERFACE > #else # define PS11N_REG_CLLITE 0 #endif // PS11N_FACTORY_TYPE |
From: stephan b. <sg...@us...> - 2004-12-26 04:04:43
|
Update of /cvsroot/pclasses/pclasses2/src/s11n/io/expat In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30469/src/s11n/io/expat Added Files: expat_serializer.cpp expat_serializer.h in.expat Makefile.toc Log Message: egg: initial port of s11n::io layer, the parts which don't need FlexLexer and friends. It compiles and links, but is untested after factory-related changes. --- NEW FILE: expat_serializer.cpp --- #include <pclasses/Phoenix.h> #include <pclasses/s11n/data_node.h> #include <pclasses/s11n/s11n_node.h> #include <pclasses/s11n/io/serializers.h> #include "expat_serializer.h" namespace P { namespace s11n { namespace io { /** Internal-use initializer for setting up the expat Serializer translation map. */ struct expat_serializer_translations_initializer { template <typename MapType> void operator()( MapType & map ) { map["&"] = "&"; map["\""] = """; map["'"] = "'"; map[">"] = ">"; map["<"] = "<"; } }; entity_translation_map & expat_serializer_translations() { typedef ::P::Phoenix< entity_translation_map, sharing::expat_sharing_context, expat_serializer_translations_initializer > TheMap; return TheMap::instance(); } } }} // namespace P::s11n::io namespace { void expat_serializer_registration_init() { #define SERINST(NodeT) \ ::P::s11n::io::register_serializer< ::P::s11n::io::expat_serializer< NodeT > >( "P::s11n::io::expat_serializer", "expat" ); SERINST(::P::s11n::data_node); SERINST(::P::s11n::s11n_node); #undef SERINST } int expat_reg_placeholder = ( expat_serializer_registration_init(), 1 ); } // anonymous namespace --- NEW FILE: Makefile.toc --- #!/usr/bin/make -f include toc.make HEADERS = expat_serializer.h SOURCES = expat_serializer.cpp DIST_FILES += $(SOURCES) $(HEADERS) ######################################################################## ifneq (1,$(PCLASSES_HAVE_LIBEXPAT)) $(warning expat_serializer build disabled because PCLASSES_HAVE_LIBEXPAT is not set to 1.) all: ######################################################################## else ######################################################################## INSTALL_PACKAGE_HEADERS += $(HEADERS) INSTALL_PACKAGE_HEADERS_DEST = $(INSTALL_PACKAGE_HEADERS_BASE)/s11n/io SYMLINK_HEADERS = $(INSTALL_PACKAGE_HEADERS) SYMLINK_HEADERS_DEST = $(top_srcdir)/include/pclasses/s11n/io include $(TOC_MAKESDIR)/SYMLINK_HEADERS.make OBJECTS = expat_serializer.o CLEAN_FILES += $(OBJECTS) all: $(OBJECTS) ######################################################################## endif # ^^^^ end PCLASSES_HAVE_LIBEXPAT block ######################################################################## --- NEW FILE: in.expat --- <!DOCTYPE s11n::io::expat_serializer> <somenode class="NoClass"> <a>()\b</a> <foo>bar</foo> <empty /> <long>this is a long property</long> <dino class="DinoClass" /> <fred class="FredClass"> <key>value</key> </fred> <wilma class="WilmaClass"> <the>lovely wife</the> </wilma> <betty class="BettyClass"> <value>the apple of Barney's eye</value> </betty> <deep class="Foo"> <deeper class="Foo"> <how_deep>really deep!</how_deep> <and_deeper class="Ouch"> </and_deeper> </deeper> </deep> </somenode> --- NEW FILE: expat_serializer.h --- #ifndef s11n_EXPAT_SERIALIZER_HPP_INCLUDED #define s11n_EXPAT_SERIALIZER_HPP_INCLUDED 1 #include <pclasses/s11n/str.h> // translate() #include <pclasses/s11n/s11n_debuggering_macros.h> // COUT/CERR #include <pclasses/s11n/io/data_node_format.h> #include <pclasses/s11n/traits.h> // node_traits #include <expat.h> #define MAGIC_COOKIE_EXPAT_XML "<!DOCTYPE P::s11n::io::expat_serializer>" #include <stdexcept> #include <sstream> #define EXPATDEBUG if(0) CERR #define EXPAT_CLASS_ATTRIBUTE "class" namespace P { namespace s11n { namespace io { namespace sharing { /** Sharing context used by expat_serializer. */ struct expat_sharing_context {}; } /** convenience typedef */ typedef std::map<std::string,std::string> entity_translation_map; /** The entity translations map used by expat_serializer. */ entity_translation_map & expat_serializer_translations(); /** expat_serializer is an XML-based Serializer, using libexpat to read it's data. */ template <typename NodeType> class expat_serializer : public data_node_serializer<NodeType> { public: typedef NodeType node_type; typedef expat_serializer<node_type> this_type; // convenience typedef expat_serializer() : m_depth(0) { this->magic_cookie( MAGIC_COOKIE_EXPAT_XML ); } virtual ~expat_serializer() {} /** Writes src out to dest. */ virtual bool serialize( const node_type & src, std::ostream & dest ) { typedef ::P::s11n::node_traits<node_type> NT; // INDENT() is a helper macro for some serializers. #define INDENT(LEVEL,ECHO) indent = ""; for( size_t i = 0; i < depth + LEVEL; i++ ) { indent += '\t'; if(ECHO) buff << '\t'; } std::ostringstream buff; // we buffer so we can handle self-closing nodes size_t depth = this->m_depth++; if ( 0 == depth ) { buff << this->magic_cookie() << '\n'; } std::string nname = NT::name(src); std::string impl = NT::class_name(src); str::translate( impl, expat_serializer_translations(), false ); std::string indent; buff << "<" << nname << " "<<EXPAT_CLASS_ATTRIBUTE<<"=\""<< impl <<"\""; bool closed = false; typename NT::const_iterator cit = NT::begin(src), cet = NT::end(src); std::string propval; std::string key; if( cet != cit ) { // got properties? closed = true; buff << ">\n"; INDENT(1,0); for ( ; cet != cit; ++cit ) { key = ( *cit ).first; propval = ( *cit ).second; buff << indent << "<" << key; if( propval.empty() ) { buff << "/>"; } else { buff << ">"; propval = str::translate( propval, expat_serializer_translations(), false ); buff << propval; buff << "</" << key << ">"; } buff << "\n"; } } typename NT::child_const_iterator chit = NT::children(src).begin(), chet = NT::children(src).end(); if( chet != chit ) { // got kids? if( !closed ) { // close node opener buff << ">\n"; closed = true; } INDENT(1,0); std::for_each( chit, chet, node_child_simple_formatter<this_type>( *this, buff, indent, "" ) ); } if( closed ) { INDENT(0,1); buff << "</" << nname << ">"; } else // self-close node { buff << "/>"; } dest << buff.str() << "\n"; if( 0 == depth ) { dest.flush(); // if we don't do this then the client is possibly forced to flush() the stream :/ } --this->m_depth; return true; #undef INDENT } static void XMLCALL start_node( void *, const char * name, const char ** attr ) { m_cbuf = ""; if( attr[0] ) { // object node std::string clname = "WTF?"; const std::string classnameattr = std::string(EXPAT_CLASS_ATTRIBUTE); for( int i = 0; attr[i]; i += 2 ) { if( attr[i] == classnameattr ) { clname = attr[i+1]; break; } } EXPATDEBUG << "Opening object node["<<clname<<","<<name<<"]\n"; m_builder.open_node( clname, name ); } else // property node { m_name = name; EXPATDEBUG << "Opening property node["<<m_name<<"]\n"; } } /** expat end-node callback. */ static void XMLCALL end_node( void *, const char * ) { if( ! m_name.empty() ) // property node { EXPATDEBUG << "Closing property node["<<m_name<<"="<<m_cbuf<<"]\n"; m_builder.add_property( m_name, m_cbuf ); } else { // object_node EXPATDEBUG << "Closing object node.\n"; m_builder.close_node(); } m_name = ""; m_cbuf = ""; } /** expat char-data callback. */ static void XMLCALL char_handler( void *, const char * txt, int len ) { if( m_name.empty() ) return; // we're not in a property. const char *c; for( int i = 0; i < len; i++ ) { c = txt++; m_cbuf += *c; } EXPATDEBUG << "char_handler(...,"<<len<<"): m_cbuf=[" << m_cbuf << "]\n"; } /** Uses expat to try to parse a tree of nodes from the given stream. */ node_type * expat_parse_stream( std::istream & is ) { XML_Parser p = XML_ParserCreate(NULL); if (! p) { EXPATDEBUG << "Couldn't allocate memory for parser\n"; return 0; } XML_SetElementHandler(p, start_node, end_node); XML_SetCharacterDataHandler( p, char_handler ); m_builder.reset(); m_name = ""; m_cbuf = ""; bool done = false; size_t len = 0; std::string buff; try { while( true ) { if( std::getline( is, buff ).eof() ) done = true; len = buff.size(); if( 0 < len ) if (XML_Parse(p, buff.c_str(), len, done) == XML_STATUS_ERROR) { std::ostringstream err; err << "Parse error at line " << XML_GetCurrentLineNumber(p) << ": " << XML_ErrorString(XML_GetErrorCode(p)) << ": buffer=["<<buff<<"]"; // EXPATDEBUG << err.str() << "\n"; throw std::runtime_error( err.str() ); } if( done ) break; } } catch( std::runtime_error & ex ) { CERR << "EXCEPTION while XML_Parsing input: " << ex.what() << "!\n"; m_builder.auto_delete( true ); m_builder.reset(); } XML_ParserFree( p ); m_builder.auto_delete( false ); return m_builder.root_node(); } /** Overridden to parse src using this object's grammar rules. */ virtual node_type * deserialize( std::istream & src ) { return this->expat_parse_stream( src ); } private: size_t m_depth; static data_node_tree_builder<node_type> m_builder; static std::string m_name; // current node's name static std::string m_cbuf; // cdata buffer }; template <typename NodeT> data_node_tree_builder<NodeT> expat_serializer<NodeT>::m_builder; template <typename NodeT> std::string expat_serializer<NodeT>::m_name; template <typename NodeT> std::string expat_serializer<NodeT>::m_cbuf; } // namespace io }} // namespace P::s11n #undef EXPATDEBUG #undef EXPAT_CLASS_ATTRIBUTE #endif // s11n_EXPAT_SERIALIZER_HPP_INCLUDED |
From: stephan b. <sg...@us...> - 2004-12-26 04:04:42
|
Update of /cvsroot/pclasses/pclasses2/src/s11n/io In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30469/src/s11n/io Added Files: data_node_format.h data_node_io.cpp data_node_io.h Makefile.toc reg_serializer.h serializers.h Log Message: egg: initial port of s11n::io layer, the parts which don't need FlexLexer and friends. It compiles and links, but is untested after factory-related changes. --- NEW FILE: data_node_io.cpp --- #include <memory> // auto_ptr #include <iostream> #include <fstream> #include <pclasses/s11n/io/data_node_io.h> namespace P { namespace s11n { namespace io { std::string get_magic_cookie( const std::string & src, bool AsFile ) { if( src.empty() ) return src; std::string ret; typedef std::auto_ptr<std::istream> AP; AP is; if( AsFile ) { is = AP( new std::ifstream( src.c_str() ) ); } else { is = AP( new std::istringstream(src) ); } // AP is = AP( zfstream::get_istream( src, AsFile ) ); // ^^^^ @fixme: removed because P doesn't have this support (yet) if( ! is.get() ) return ret; return ( std::getline( *is, ret ).eof() ? "" : ret ); } std::string get_magic_cookie( std::istream & is ) { std::string ret; if( std::getline( is, ret ).eof() ) return ""; return ret; } } // namespace io }} // namespace P::s11n --- NEW FILE: Makefile.toc --- #!/usr/bin/make -f include toc.make SUBDIRS = expat HEADERS = \ data_node_format.h \ data_node_io.h \ reg_serializer.h \ serializers.h DIST_FILES += $(HEADERS) INSTALL_PACKAGE_HEADERS += $(HEADERS) INSTALL_PACKAGE_HEADERS_DEST = $(INSTALL_PACKAGE_HEADERS_BASE)/s11n/io SYMLINK_HEADERS = $(INSTALL_PACKAGE_HEADERS) SYMLINK_HEADERS_DEST = $(top_srcdir)/include/pclasses/s11n/io include $(TOC_MAKESDIR)/SYMLINK_HEADERS.make SOURCES = data_node_io.cpp DIST_FILES += $(SOURCES) OBJECTS = data_node_io.o CLEAN_FILES += $(OBJECTS) all: SYMLINK_HEADERS subdirs $(OBJECTS) --- NEW FILE: reg_serializer.h --- //////////////////////////////////////////////////////////////////////// // "supermacro" code for doing some registration stuff for Serializers. // // See s11n::io::register_serializer<>() for a function which does the // same thing as this supermacro (it's easier to use and doesn't // add as much back-end overhead). // // License: Public Domain // Author: st...@s1... //////////////////////////////////////////////////////////////////////// // NOTE: this file does not use a conventional BLAH_H_INCLUDED guard. // Yes, that's on purpose. //////////////////////////////////////////////////////////////////////// // The s11n header files are expected to have been included by the // time this file is ever included. // // usage: // define: // SERIALIZER_TYPE serializer_class // SERIALIZER_BASE base_of_serializer (or SERIALIZER_TYPE) // SERIALIZER_MAGIC_COOKIE optional "#!/magic/cookie/string" // SERIALIZER_ALIAS optional "alias_string" for classloading // // #include <this_file> // // After each include all of these macros are unset so that they may // be immediately re-used for another registration. // // The cookie is required if s11n is to be able to load // your files transparently. An alias is convenient for s11nconvert // and such, but not required. //////////////////////////////////////////////////////////////////////// #include <stdlib.h> // abort() #define DEBUG_REG 0 #if DEBUG_REG # include <pclasses/s11n/s11n_debuggering_macros.h> #endif #ifndef SERIALIZER_TYPE # error "SERIALIZER_TYPE is not set. Set it to the type you want to proxy before including this file!" #endif #ifndef SERIALIZER_NAME # error "SERIALIZER_NAME must be set to the string form of SERIALIZER_TYPE" #endif #ifndef SERIALIZER_BASE # error "SERIALIZER_BASE must be the base-most type of SERIALIZER_TYPE (may be the same)." #endif #include <pclasses/s11n/classload.h> namespace { // anonymous namespace is important for complex linking reasons. //////////////////////////////////////////////////////////////////////// // A utility to keep us from having to hard-code or macro-ize the class // name (macroing won't work with commas in the class names, anyway). template <> struct class_name< SERIALIZER_TYPE > { static const char * name() { return SERIALIZER_NAME; } }; #ifndef p_SERIALIZER_REG_CONTEXT_DEFINED #define p_SERIALIZER_REG_CONTEXT_DEFINED 1 /////////////////////////////////////////////////////////////// // we must not include this more than once per compilation unit /////////////////////////////////////////////////////////////// // A unique (per SERIALIZER_BASE/per compilation unit) space to assign // a bogus value for classloader registration purposes (see // the classloader docs for a full description of how this // works). template <typename Context> struct serializer_reg_context { typedef Context context; static bool placeholder; static void reg() { CERR << "ACHTUNG: << " << ::classname< serializer_reg_context<context> >() << " is not specialized, which means that registration hasn't been done.\n" << "For instructions see: " << __FILE__ << "\n"; abort(); } }; template <typename Context> bool serializer_reg_context<Context>::placeholder = false; #endif // !s11n_SERIALIZER_REG_CONTEXT_DEFINED //////////////////////////////////////////////////////////////////////////////// template <> struct serializer_reg_context< SERIALIZER_TYPE > { typedef SERIALIZER_TYPE context; static bool placeholder; static void reg() { std::string cname = ::classname< context >(); #if DEBUG_REG CERR << "\nRegistering Serializer: " << SERIALIZER_NAME << "\n" << "classname() says: " << cname << "\n" # ifdef SERIALIZER_MAGIC_COOKIE << "cookie="<< SERIALIZER_MAGIC_COOKIE << "\n" # endif # ifdef SERIALIZER_ALIAS << "alias="<< SERIALIZER_ALIAS << "\n" # endif ; // CERR #endif // DEBUG_REG #ifdef SERIALIZER_ABSTRACT ::P::s11n::cl::classloader_register_abstract< SERIALIZER_BASE >( cname ); # undef SERIALIZER_ABSTRACT #else ::P::s11n::cl::classloader_register< SERIALIZER_BASE, SERIALIZER_TYPE >( cname ); ::P::s11n::cl::classloader_register< SERIALIZER_TYPE, SERIALIZER_TYPE >( cname ); #endif #ifdef SERIALIZER_MAGIC_COOKIE // @fixme: P factory can't alias yet: // cllite::alias< SERIALIZER_BASE >( SERIALIZER_MAGIC_COOKIE, cname ); // cllite::alias< SERIALIZER_TYPE >( SERIALIZER_MAGIC_COOKIE, cname ); # undef SERIALIZER_MAGIC_COOKIE #endif #ifdef SERIALIZER_ALIAS // @fixme: P factory can't alias yet: // cllite::alias< SERIALIZER_BASE >( SERIALIZER_ALIAS, cname ); // cllite::alias< SERIALIZER_TYPE >( SERIALIZER_ALIAS, cname ); # undef SERIALIZER_ALIAS #endif } }; bool serializer_reg_context< SERIALIZER_TYPE >::placeholder = ( serializer_reg_context< SERIALIZER_TYPE >::reg() , true ); } // anon namespace //////////////////////////////////////////////////////////////////////////////// // end proxy code for [SERIALIZER] //////////////////////////////////////////////////////////////////////////////// #undef SERIALIZER_TYPE #undef SERIALIZER_NAME #undef DEBUG_REG --- NEW FILE: data_node_format.h --- #ifndef p_DATA_NODE_FORMAT_H_INCLUDED #define p_DATA_NODE_FORMAT_H_INCLUDED //////////////////////////////////////////////////////////////////////////////// // data_node_format.h // Contains some helpers related to parsing/formating data_node-style objects. // // License: Public Domain // Author: st...@s1... //////////////////////////////////////////////////////////////////////////////// #include <string> #include <list> #include <map> #include <stdexcept> // #include <typeinfo> // #include <s11n.net/zfstream/zfstream.h> // get_i/ostream() // #include <s11n.net/tostring/to_string.h> // to/from_string() // #include <s11n.net/stringutil/string_util.h> // translate_entities() #include <pclasses/s11n/s11n_debuggering_macros.h> // COUT/CERR #include <pclasses/s11n/classload.h> // classload() #include <pclasses/s11n/data_node_functor.h> // some utility functors #include <pclasses/s11n/data_node_serialize.h> // data_node_serializer<> and friends #include <pclasses/s11n/traits.h> #include <pclasses/s11n/io/data_node_io.h> // default serializer interfaces //////////////////////////////////////////////////////////////////////////////// // NO DEPS ON data_node.h ALLOWED! //////////////////////////////////////////////////////////////////////////////// namespace P { namespace s11n { namespace io { /** A typedef representing a map of tokens used for "entity translations" by s11n parsers/serializers. */ typedef std::map<std::string,std::string> entity_translation_map; /** tree_builder exists mainly so some lex-based code can get access to a non-templated type (so we don't have to hard-code the parsers to a node_type). It provides only the interface needed by the current lex-based parsers, not some ultimately reusable interface. It is not functionally useful by itself - it must be subclassed and all of it's virtual methods must be implemented. */ class tree_builder { public: tree_builder() : m_autodel(true) {} virtual ~tree_builder() {} /** Starts a new node with the the given class name and node name. Return value indicates success or failure. */ virtual bool open_node( const std::string & classname, const std::string & nodename ) = 0; /** Closes the current node. Return value indicates success or failure. */ virtual bool close_node() = 0; /** Sets property key to val for the current node. Return value indicates success or failure. */ virtual bool add_property( const std::string & key, const std::string & val ) = 0; /** Returns the depth level of the parser, where the root node is 1. */ virtual size_t node_depth() const = 0; /** Changes the implementation class name of the current node. */ virtual bool change_node_class( const std::string & newclassname ) = 0; /** If auto_delete() is on (the default) then this object should delete it's children when it is destroyed, otherwise it will not. It is up to subclasses to honor this, as this base type does no handling of children. */ void auto_delete( bool b ) { this->m_autodel = b; } /** This is the getter for auto_delete( bool ). */ bool auto_delete() const { return this->m_autodel; } private: bool m_autodel; }; /** data_node_tree_builder is a helper class for building trees from deserialized data, designed particularly for use with lex/callback-based tree builders. It owns all objects which build up it's tree. If you want them you must manually remove them from the container. You normally do not want them, however - they're mostly throwaway nodes on their way to becoming fully deserialized objects. This class only provides methods for building a tree, not for traversing it. Once you have built a tree, traverse it starting at the root_node(). Based on usage conventions this type supports only a single root node. */ template <typename NodeType> class data_node_tree_builder : public tree_builder { public: typedef NodeType node_type; typedef std::list< node_type * > child_list_type; /** Creates a default builder. */ data_node_tree_builder() : m_node_count(0), m_node(0),m_root(0) { } /** Deletes this object's children if auto_delete() returns true. */ virtual ~data_node_tree_builder() { if( this->auto_delete() && this->m_root ) { //CERR << "data_node_tree_builder<> cleaning up root node.\n"; delete( this->m_root ); } else { //CERR << "data_node_tree_builder<> was relieved of child duty (or had no child).\n"; } } /** Opens a new node, making that the current node. classname will be used for the node's impl_class() (see docs for node_type::impl_class()). name will be the object's name, which is important for de/serializing the node (see node_type::name()). It returns false on error, else true. The default implementation has no error conditions, and therefor always returns true. Node that classnames and node names need not be unique (nor make up unique combinations). Any number of nodes may have the same name or classname. */ bool open_node( const std::string & classname, const std::string & nodename ) { ++m_node_count; this->m_node = ( this->m_nodestack.empty() ? 0 : this->m_nodestack.back() ); typedef ::P::s11n::node_traits<node_type> NTR; node_type * newnode = new node_type(); if ( m_node ) { // if we're in a node, add new node as a child to that one: NTR::children( *m_node ).push_back( newnode ); } this->m_node = newnode; NTR::name( *m_node, nodename ); NTR::class_name( *m_node, classname ); this->m_nodestack.push_back( m_node ); bool ret = true; if ( 1 == this->m_nodestack.size() ) { if( m_root ) { CERR << "open_node("<<classname<<","<<nodename<<") WARNING: deleting extra root node!\n"; delete( m_node ); ret = false; } else { m_root = m_node; } } return ret; } /** Closes the most-recently-opened node, effectively popping the previous node off of the node stack (it is not destroyed). It is an error to call this more often than calling open_node(). It returns false on error (e.g., called with no opened node). */ virtual bool close_node() { if ( !m_node || m_nodestack.empty() ) { CERR << "close_node() error: called with an empty node stack!" << std::endl; return false; } m_nodestack.pop_back(); if ( m_nodestack.empty() ) { m_node = NULL; } else { m_node = m_nodestack.back(); } return true; } /** Adds the given key/value pair to the current node and returns true. If no node is currently opened it returns false. */ virtual bool add_property( const std::string & key, const std::string & val ) { if( ! this->m_node ) return false; typedef ::P::s11n::node_traits<node_type> NTR; NTR::set( *m_node, key, val ); return true; } /** Returns the total number of nodes opened via open_node(). */ size_t node_count() const { return m_node_count; } /** Returns the current depth of opened nodes. A return value of 1 means the current node is the root node, for example, and 0 means that no node has yet been opened. */ size_t node_depth() const { return m_nodestack.size(); } /** Returns the most recent root node parsed out of the input object. Use auto_delete() to determine ownership of the returned pointer. */ node_type * root_node() const { return m_root; } /** Returns the current node. Use auto_delete() to determine ownership of the returned pointer. */ node_type * current_node() const { return m_node; } /** Changes class name of current node, if one is set. Returns false only if no node is currently opened, else it returns true. */ virtual bool change_node_class( const std::string & newclassname ) { if( ! this->m_node ) return false; typedef ::P::s11n::node_traits<node_type> NTR; NTR::class_name( *(this->m_node), newclassname ); return true; } /** Deletes this object's root_node() if auto_delete() is true. */ void reset() { if( this->auto_delete() && this->m_root ) delete this->m_root; this->m_root = 0; } private: size_t m_node_count; node_type * m_node; node_type * m_root; typedef std::deque < node_type * > node_stack; node_stack m_nodestack; }; /** A helper functor to loop over serializable children of a node from within a Serializer implementation. Designed for use with std::for_each(). SerializerT must be compatible with <code>data_node_serializer<></code>. */ template <typename SerializerT> struct node_child_simple_formatter { typedef SerializerT serializer_type; // typedef typename SerializerT::node_type node_type; /** Preconditions: - Ser must be valid references. - Both ser and os must outlive this object. More correctly, this object's operator() must not be called after either ser or os are destroyed. */ node_child_simple_formatter( serializer_type & ser, std::ostream & os, const std::string & prefix = "", const std::string & suffix = "\n" ) : m_ser(ser), m_os(&os), m_pre(prefix), m_suf(suffix) { } /** Serializes src into this object's target container, using this object's serializer. */ template <typename NodeType> bool operator()( const NodeType * src ) const { if( ! src ) return false; if( ! this->m_pre.empty() ) *(this->m_os) << this->m_pre; bool b = this->m_ser.serialize( *src, *(this->m_os) ); if( ! this->m_suf.empty() ) *(this->m_os) << this->m_suf; return b; } private: serializer_type & m_ser; std::ostream * m_os; std::string m_pre; std::string m_suf; }; } // namespace io }} // namespace P::s11n #endif // p_DATA_NODE_FORMAT_H_INCLUDED --- NEW FILE: serializers.h --- #ifndef p_SERIALIZERS_HPP_INCLUDED #define p_SERIALIZERS_HPP_INCLUDED 1 //////////////////////////////////////////////////////////////////////////////// // serializers.h: Some utility code for working with // s11n::io Serializer types. // // License: Public Domain // Author: st...@s1... //////////////////////////////////////////////////////////////////////////////// #include <pclasses/Factory.h> #include <pclasses/Plugin/Plugin.h> #include <pclasses/Phoenix.h> #include <pclasses/s11n/io/data_node_io.h> #include <pclasses/s11n/s11n_debuggering_macros.h> namespace P { namespace s11n { namespace io { template <typename NodeType> class serializer_plugin_manager : public ::P::Plugin::PluginManager< data_node_serializer< NodeType > > { public: serializer_plugin_manager(){} virtual ~serializer_plugin_manager(){} }; } // P::s11n::io } // P::s11n namespace Hook { /** This hook will cause calls to Factory::instance() to return a serializer_plugin_manager instance in disguise. */ template < typename NodeT > struct FactoryInstanceHook< ::P::Factory< ::P::s11n::io::data_node_serializer<NodeT>, ::P::Sharing::FactoryContext, std::string > > { typedef ::P::Factory< ::P::s11n::io::data_node_serializer<NodeT>, ::P::Sharing::FactoryContext, std::string > FactoryType; typedef ::P::s11n::io::serializer_plugin_manager< NodeT > RealFactoryType; typedef FactoryInstanceHook<FactoryType> ThisType; /** Initializes the passed-in factory. i.e., it does nothing. It's here for demonstration purposes. */ void operator()( FactoryType & ) throw() { CERR << "Initializing a PluginManager instance() we hacked in via FactoryInstanceHook!\n"; } /** The default implementation returns a shared Factory object. THIS type's operator() will be called on the factory immediately after creating the factory. */ static FactoryType & instance() { typedef ::P::Phoenix<RealFactoryType, ::P::Sharing::FactoryContext, ThisType > PHX; return PHX::instance(); } }; } // P::Hook namespace s11n { namespace io { /** Populates target list with the names of registered Serializers. ListT must support push_back( std::string ). If onlyShortNames is true (the default) then only "simple" names are put into target, not the "full" names of the classes. This is to make the data more useful in the context of client applications as, e.g., a list of choices for users. Note that only serializers extending from s11n::io::data_node_serializer<NodeT> are returned. If onlyShortNames is true then only names which contain only alphanumeric or underscore characters are returned. This is used for filtering out all names except Serializer aliases, excluding the full class names and any magic cookie aliases. */ template <typename NodeT, typename ListT> void serializer_list( ListT & target, bool onlyShortNames = true ) { CERR << "FIXME: serializer_list() not yet fixed to work with P::Factory.\n"; return; // typedef ::P::s11n::io::data_node_serializer<NodeT> BaseSerT; // typedef ::cl::class_loader< BaseSerT > SerCL; // typedef typename SerCL::alias_map AMap; // #define SERCL ::P::s11n::cl::classloader< BaseSerT >() // typename AMap::const_iterator cit = SERCL.aliases().begin(), // cet = SERCL.aliases().end(); // #undef SERCL // std::string alias; // static const std::string nonspecial = // "_0123456789abcdefghijklmnopqrstuvwqxyzABCDEFGHIJKLMNOPQRSTUVWQXYZ"; // for( ; cet != cit; ++cit ) // { // alias = (*cit).first; // if( onlyShortNames ) // { // filter out all but "simple" names: // if( std::string::npos != // alias.find_first_not_of( nonspecial ) // ) // { // continue; // } // } // target.push_back( alias ); // } } /** Registers a Serializer type with the s11n::io layer. It must: - be templatized on a DataNodeType - subclass s11n::io::data_node_serializer<DataNodeType> - provide a node_type typedef which is the same as DataNodeType i.e., the conventions of all of the Serializers included with libs11n. Registering makes the type available to the data_node_serializer classloader. Arguments: - classname = SerializerT's stringified class name. - alias = a "friendly" name for the SerializerT. SerializeT's magic_cookie() function is called to alias the cookie as an alias for classname. Thus, a SerializerT object is (briefly) instantiated. Node that this functions essentially performs the same operations as the reg_serializer.h supermacro, and the two should be equivalent (though this seems easier to use). */ template <typename SerializerT> void register_serializer( const std::string & classname, const std::string & alias ) { typedef SerializerT ST; typedef typename ST::node_type NT; typedef data_node_serializer<NT> BaseST; // typedef data_node_serializer<NodeT> * BaseSerializerType; // CERR << "FIXME: register_serializer() not yet fixed to work with P::Factory.\n"; // return; #define PM pluginManager< BaseST >() #define FACCREATE ::P::Hook::FactoryCreateHook<BaseST,ST>::create using namespace ::P::Plugin; static bool inited = false; if( ! inited && (inited=true) ) { PM.searchPath().addExtension( "_serializer.so" ); PM.searchPath().addExtension( "_serializer.dll" ); // cllite::class_path().add_extension( "_serializer.so" ); // cllite::class_path().add_extension( "_serializer.dll" ); } CERR << "register_serializer(" << classname << ","<<alias<<")\n"; PM.registerFactory( classname, FACCREATE ); PM.registerFactory( alias, FACCREATE ); PM.registerFactory( ST().magic_cookie(), FACCREATE ); #undef PM #undef FACCREATE // ::P::s11n::cl::classloader_register< BaseST, ST >( classname ); // ::P::s11n::cl::classloader< BaseST >().alias( alias, classname ); // ::P::s11n::cl::classloader< BaseST >().alias( ST().magic_cookie(), classname ); } /** Returns a Serializer object, which must have been registered with s11n::cl::classloader< s11n::io::data_node_serializer<NodeT> >(). The caller owns the returned pointer, which may be 0. */ template <typename NodeT> s11n::io::data_node_serializer<NodeT> * create_serializer( const std::string & classname ) { // typedef serializer_plugin_manager<NodeT> SPM; try { CERR << "create_serializer("<<classname<<") trying plugin manager...\n"; // return SPM::instance().create( classname ); return ::P::s11n::cl::classloader< SPM >().create( classname ); } catch(const ::P::Exception & e) { CERR << "Exception while loading serializer '"<<classname<<"': " << e.what() << "\n"; } return 0; // typedef s11n::io::data_node_serializer<NodeT> BaseSerT; // BaseSerT * s = 0; // if( ( s = s11n::cl::classload< BaseSerT >( classname ) ) ) // { // return s; // } // static const char * addon = "_serializer"; // if( (std::string::npos == classname.find(addon)) ) // try harder! // { // std::string harder = classname + addon; // //CERR << "Trying harder for " << classname << " --> " << harder << "!\n"; // s = create_serializer<NodeT>( harder ); // } // //CERR << "Harder try= " << std::hex << s << "\n"; // return s; } }} // namespace P::s11n::io } // namespace P::s11n #endif // p_SERIALIZERS_HPP_INCLUDED --- NEW FILE: data_node_io.h --- #ifndef p_DATA_NODE_IO_H_INCLUDED #define p_DATA_NODE_IO_H_INCLUDED //////////////////////////////////////////////////////////////////////// // data_node_io.h // some i/o interfaces & helpers for s11n // License: Public Domain // Author: st...@s1... //////////////////////////////////////////////////////////////////////// #include <string> #include <sstream> #include <list> #include <map> #include <deque> #include <iostream> #include <fstream> #include <memory>// auto_ptr #include <cassert> #include <typeinfo> #include <pclasses/Phoenix.h> // phoenix class #include <pclasses/Plugin/Plugin.h> #include <pclasses/System/SharedLib.h> // openSharedLib() #include <pclasses/s11n/s11n_debuggering_macros.h> // COUT/CERR #include <pclasses/s11n/classload.h> // classloader() #include <pclasses/s11n/data_node_serialize.h> // unfortunately dep #include <pclasses/s11n/traits.h> // s11n_traits & node_traits //////////////////////////////////////////////////////////////////////////////// // NO DEPS ON data_node.h ALLOWED! //////////////////////////////////////////////////////////////////////////////// namespace P { namespace s11n { namespace io { /** Convenience function for grabbing the first line of a file. If AsFile == true then returns the first line of the file, else returns up to the first newline of src. */ std::string get_magic_cookie( const std::string & src, bool AsFile = true ); /** Convenience function for grabbing the first line of a stream. Returns the first line of the given stream, or an empty string on error. */ std::string get_magic_cookie( std::istream & is ); /** data_node_serializer provides an interface for saving/loading a given abstract data node type to/from streams. It is designed for containers which comply with s11n's Data Node interface and conventions. Conventions: Must provide: typedef NodeT node_type Two de/serialize functions, following the stream-based interface shown here (filename-based variants are optional, but convenient for clients). */ template <typename NodeT> class data_node_serializer { public: /** The underlying data type used to store serialized data. */ typedef NodeT node_type; data_node_serializer() { this->magic_cookie( "WARNING: magic_cookie() not set!" ); // ^^^ subclasses must do this. this->metadata().name( "serializer_metadata" ); }; virtual ~data_node_serializer(){}; /** A convenience typedef, mainly for subclasses. */ typedef std::map<std::string,std::string> translation_map; /** Returns a map intended for use with stringutil::translate_entities(). The default implementation returns an empty map. Subclasses should override this to return a translation map, if they need one. The default map is empty. Be aware that this may very well be called post-main(), so subclasses should take that into account and provide post-main()-safe maps! (Tip: see phoenix::phoenix.) */ virtual const translation_map & entity_translations() const { typedef ::P::Phoenix<translation_map,data_node_serializer<node_type> > TMap; return TMap::instance(); } /** Must be implemented to format node_type to the given ostream. It should return true on success, false on error. The default implementation always returns false. Note that this function does not use s11n::serialize() in any way, and is only coincidentally related to it. */ virtual bool serialize( const node_type & /*src*/, std::ostream & /*dest*/ ) { return false; } /** Overloaded to save dest to the given filename. The default implementation treats destfile as a file name and passes the call on to serialize(node_type,ostream). Returns true on success, false on error. This function is virtual so that Serializers which do not deal with i/ostreams (e.g., those which use a database connection) can override it to interpret destfile as, e.g., a database-related string (e.g., connection, db object name, or whatever). */ virtual bool serialize( const node_type & src, const std::string & destfile ) { std::ofstream os( destfile.c_str() ); // @fixme: zfstream support was removed for P! if( os.good() ) return false; bool b = this->serialize( src, os ); return b; } /** Must be implemented to parse a node_type from the given istream. It should return true on success, false on error. The default implementation always returns 0 and does nothing. Note that this function does not use s11n::deserialize() in any way, and is only coincidentally related to it. */ virtual node_type * deserialize( std::istream & ) { return 0; } /** Overloaded to load dest from the given filename. It supports zlib/bz2lib decompression for files if your s11n lib supports them. This is virtual for the same reason as serialize(string). */ virtual node_type * deserialize( const std::string & src ) { // typedef std::auto_ptr<std::istream> AP; // AP is = AP( zfstream::get_istream( src ) ); // if( ! is.get() ) return 0; // @fixme: ^^^ zfstream removed for P std::ifstream is(src.c_str()); if( ! is.good() ) return 0; return this->deserialize( is ); } /** Gets this object's magic cookie. Cookies are registered with <code>class_loader< data_node_serializer<NodeType> ></code> types to map files to file input parsers. */ std::string magic_cookie() const { return this->m_cookie; } protected: /** Sets the magic cookie for this type. */ void magic_cookie( const std::string & c ) { this->m_cookie = c; } /** metadata is an experimental feature allowing serializers to store arbitrary serializer-specific information in their data steams. */ node_type & metadata() { return this->m_meta; } /** A const overload of metadata(). */ const node_type & metadata() const { return this->m_meta;} private: std::string m_cookie; node_type m_meta; }; // data_node_serializer<> /** Tries to load a NodeType object from the given node. It uses the cookie from the input stream and classload<SerializerBaseType>() to find a matching Serializer. 0 is returned on error, else a new pointer, which the caller owns. Achtung: the first line of input from the input stream is consumed by this function (to find the cookie), and the cookie is not passed on to the handler! The only reliable way around this [that i know of] is to buffer the whole input as a string, and i don't wanna do that (it's bad for massive data files). ACHTUNG: Only usable for loading ROOT nodes. Special feature: If the first line of the stream is "#s11n::io::load_serializer" then the next token on that line is expected to be a Serializer class name. This function will try to classload that object. If successful it will use that type to deserialize the input string. If unsuccessful it will read the next line for a cookie and try to use that Serializer. If that fails, it will return 0. */ template <typename NodeType> NodeType * load_node_classload_serializer( std::istream & is ) { typedef data_node_serializer<NodeType> ST; std::string cookie; // = get_magic_cookie( is ); // CERR << "cookie="<<cookie<<std::endl; if( ! std::getline( is, cookie ) ) { CERR << "Odd: got a null cookie from the istream.\n"; return 0; // happens post-main() on valid streams sometimes!?!?! } typedef std::auto_ptr<ST> AP; AP ser; static const std::string opencmd = "#s11n::io::serializer"; std::string::size_type at = cookie.find( opencmd ); while( 0 == at ) { std::string dll = cookie.substr( opencmd.size()+1 ); //CERR << "Trying to load Serializer from cookie: " << dll << "\n"; ser = AP( ::P::s11n::cl::classload<ST>( dll ) ); if( ser.get() ) { // if we load that Serializer, use it on the rest of the data... break; } std::string where; try { where = ::P::Plugin::findPlugin<ST>( dll ); if( ! where.empty() ) { ::P::System::openSharedLib( where ); } } catch( const ::P::Exception & ex ) { CERR << "Error opening DLL: " << dll << ": " << ex.what()<<"\n"; } if( where.empty() ) { CERR <<opencmd << " Serializer class ["<<dll<<"] could not be found. Continuing and hoping for the best...\n"; } return load_node_classload_serializer<NodeType>( is ); } if( ! ser.get() ) { ser = AP( ::P::s11n::cl::classload<ST>( cookie ) ); } if( ! (ser.get()) ) { CERR << "Did not find serializer for cookie ["<<cookie<<"]."<<std::endl; return NULL; } // CERR << "Dispatching to node loader for cookie ["<<cookie<<"]\n"; return ser->deserialize( is ); } /** Returns a node pointer, parsed from the given stream, using <code>s11n::io::data_node_serializer<NodeType></code> as the base type for looking up a stream handler. ACHTUNG: Only usable for loading ROOT nodes. */ template <typename NodeType> NodeType * load_node( std::istream & is ) { return load_node_classload_serializer< NodeType >( is ); } /** Overloaded form of load_node( istream ), provided for convenience. If AsFile is true, input is treated as a file, otherwise it is treated as a string containing input to parse. ACHTUNG: Only usable for loading ROOT nodes. Maintenance note: AsFile==false may be extremely inefficient, as src may get copied one additional time. */ template <typename NodeType> NodeType * load_node( const std::string & src, bool AsFile = true ) { typedef std::auto_ptr<std::istream> AP; AP is; if( AsFile ) { is = AP( new std::ifstream( src.c_str() ) ); } else { is = AP( new std::istringstream(src) ); } // AP is = AP( zfstream::get_istream( src, AsFile ) ); // ^^^^ @fixme: zfstream removed because P doesn't have this support (yet) if( ! is.get() ) return 0; return load_node<NodeType>( *is ); } /** Tries to load a SerializableT from the given stream. On success returns a new object, else 0. The caller owns the returned pointer. ACHTUNG: Only usable for loading ROOT nodes. */ template <typename NodeT,typename SerializableT> SerializableT * load_serializable( std::istream & src ) { typedef std::auto_ptr<NodeT> AP; AP node = AP( load_node<NodeT>( src ) ); if( ! node.get() ) { CERR << "load_serializable<>(istream) Could not load a root node from the input.\n"; return 0; } return s11n::deserialize<NodeT,SerializableT>( *node ); } /** An overloaded form which takes an input string. If AsFile is true the string is treated as a file name, otherwise it is processed as an input stream. ACHTUNG: Only usable for loading ROOT nodes. */ template <typename NodeT,typename SerializableT> SerializableT * load_serializable( const std::string & src, bool AsFile = true ) { typedef std::auto_ptr<std::istream> AP; if( AsFile ) { is = AP( new std::ifstream( src.c_str() ) ); } else { is = AP( new std::istringstream(src) ); } // AP is = AP( zfstream::get_istream( src, AsFile ) ); // @fixme: ^^^ zfstream removed for P. if( ! is.get() ) { CERR << "load_serializable<>(string) Could not open stream!.\n"; return 0; } return load_serializable<NodeT,SerializableT>( is ); } /** Saves src to the given ostream using the given Serializer type. ONLY use this for saving root nodes! */ template <typename SerializerT> bool save_node( const typename SerializerT::node_type & src, std::ostream & dest ) { return SerializerT().serialize( src, dest ); } /** Saves src, a Serializable type, to the given ostream using a SerializerT serializer. SerializerT must be compatible with s11n::io::data_node_serializer<> conventions and must provide a <code>typedef XXX node_type</code>, where XXX is a data type conforming to s11n::data_node conventions. Returns true on success, false on error. ONLY use this for saving root nodes! */ template <typename SerializerT,typename SerializableT> bool save_serializable( const SerializableT & src, std::ostream & dest ) { typedef typename SerializerT::node_type node_type; node_type node( "serializable" ); if( ! ::P::s11n::serialize<node_type,SerializableT>( node, src ) ) return false; return SerializerT().serialize( node, dest ); } /** An overloaded form which takes a filename. ONLY use this for saving root nodes! */ template <typename SerializerT,typename SerializableT> bool save_serializable( const SerializableT & src, const std::string & filename ) { // typedef std::auto_ptr<std::ostream> AP; // AP os = AP( zfstream::get_ostream( filename ) ); // if( ! os.get() ) return false; // @fixme: ^^^ zfstream removed for P std::ofstream os( filename.c_str() ); if( ! os.good() ) return false; return save_serializable<SerializerT,SerializableT>( src, os ); } } // namespace io }} // namespace P::s11n #endif // p_DATA_NODE_IO_H_INCLUDED |
From: stephan b. <sg...@us...> - 2004-12-26 04:03:30
|
Update of /cvsroot/pclasses/pclasses2/src/s11n/io/expat In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30302/src/s11n/io/expat Log Message: Directory /cvsroot/pclasses/pclasses2/src/s11n/io/expat added to the repository |
From: stephan b. <sg...@us...> - 2004-12-26 04:00:03
|
Update of /cvsroot/pclasses/pclasses2/src/s11n/io In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29734/src/s11n/io Log Message: Directory /cvsroot/pclasses/pclasses2/src/s11n/io added to the repository |
From: stephan b. <sg...@us...> - 2004-12-26 02:28:23
|
Update of /cvsroot/pclasses/pclasses2/src/s11n In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15726/src/s11n Modified Files: Makefile.toc Log Message: Removed auto-build of test bin. Copied test to (top)/test/s11nTest.cpp. Index: Makefile.toc =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/s11n/Makefile.toc,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- Makefile.toc 26 Dec 2004 01:26:15 -0000 1.3 +++ Makefile.toc 26 Dec 2004 02:28:13 -0000 1.4 @@ -7,26 +7,7 @@ s11n.cpp \ s11n_node.cpp -HEADERS = \ - abstract_creator.h \ - classload.h \ - data_node.h \ - data_node_algo.h \ - data_node_functor.h \ - data_node_serialize.h \ - list.h \ - map.h \ - pods_streamable.h \ - reg_list_specializations.h \ - reg_map_specializations.h \ - reg_serializable_traits.h \ - s11n_debuggering_macros.h \ - s11n_node.h \ - s11n.h \ - str.h \ - string_util.h \ - traits.h \ - valarray.h +HEADERS = $(wildcard *.h) OBJECTS = $(addsuffix .o,\ @@ -55,6 +36,7 @@ test_bin_OBJECTS = test.o libpclasses_s11n.so include $(TOC_MAKESDIR)/BIN_PROGRAMS.make -all: symlink-headers SHARED_LIBS BIN_PROGRAMS +all: symlink-headers SHARED_LIBS +# BIN_PROGRAMS |
From: stephan b. <sg...@us...> - 2004-12-26 02:27:47
|
Update of /cvsroot/pclasses/pclasses2/src/s11n In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15586/src/s11n Modified Files: data_node.h Log Message: a tiny optimistic-compiler optimization. Index: data_node.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/s11n/data_node.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- data_node.h 26 Dec 2004 02:09:26 -0000 1.3 +++ data_node.h 26 Dec 2004 02:27:23 -0000 1.4 @@ -341,8 +341,7 @@ */ template < typename T > void set( const std::string & key, const T & val ) { - ::P::Util::LexT lex(val); - this->set_string( key, lex ); + this->set_string( key, ::P::Util::LexT(val) ); } /** |
From: stephan b. <sg...@us...> - 2004-12-26 02:26:02
|
Update of /cvsroot/pclasses/pclasses2/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15337/test Modified Files: Makefile.toc Log Message: added s11nTest Index: Makefile.toc =================================================================== RCS file: /cvsroot/pclasses/pclasses2/test/Makefile.toc,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- Makefile.toc 25 Dec 2004 00:13:31 -0000 1.5 +++ Makefile.toc 26 Dec 2004 02:25:49 -0000 1.6 @@ -30,7 +30,7 @@ build_bins = 1 ifeq (1,$(build_bins)) - BIN_PROGRAMS = FactoryTest PtrTest + BIN_PROGRAMS = FactoryTest PtrTest s11nTest BIN_PROGRAMS_LDADD = $(LIBP_TESTS_LDADD) # Can't do these until i get the linker flags imported via toc: # PtrTest @@ -39,10 +39,10 @@ # $(LIBPSYSTEM_CLIENT_LDADD) PtrTest_bin_OBJECTS = PtrTest.o PtrTest_bin_LDADD = $(LIBPSYSTEM_CLIENT_LDADD) -# $(top_srcdir)/src/System/PathFinder.o $(wildcard $(top_srcdir)/src/System/SharedLib*.o) + + s11nTest_bin_OBJECTS = s11nTest.o $(LIBPS11N_CLIENT_LDADD) + include $(TOC_MAKESDIR)/BIN_PROGRAMS.make -# INSTALL_BINS += $(BIN_PROGRAMS) - # Run target BIN_PROGRAMS to build these. endif SHARED_LIBS = CType |
From: stephan b. <sg...@us...> - 2004-12-26 02:25:49
|
Update of /cvsroot/pclasses/pclasses2/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15296/test Added Files: s11nTest.cpp Log Message: egg --- NEW FILE: s11nTest.cpp --- #include <pclasses/s11n/s11n.h> #include <pclasses/s11n/s11n_node.h> #include <pclasses/s11n/s11n_debuggering_macros.h> #include <pclasses/s11n/list.h> #include <pclasses/s11n/map.h> #include <pclasses/s11n/pods_streamable.h> #include <pclasses/Util/LexT.h> #include <memory> // auto_ptr #include <cassert> #include <list> #include <map> #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 <pclasses/s11n/reg_serializable_traits.h> #define PS11N_TYPE AType #define PS11N_TYPE_INTERFACE TheBase #define PS11N_TYPE_NAME "AType" #include <pclasses/s11n/reg_serializable_traits.h> #define PS11N_TYPE BType #define PS11N_TYPE_INTERFACE TheBase #define PS11N_TYPE_NAME "BType" #include <pclasses/s11n/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 BType ); 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"; TRAITS::clear(node); using ::P::Util::LexT; typedef std::list<LexT> ListT; typedef std::map<int,LexT> MapT; ListT list; MapT map; LexT tmpval; for( int i = 0; i < 10; i++ ) { tmpval = std::string("this is item #") + LexT(i).str(); CERR << "Adding ["<<tmpval<<"]\n"; list.push_back( tmpval ); map[i] = tmpval; } CERR << "list/map sizes == " << list.size() << " , " << map.size()<<"\n"; bool worked; CERR << "Containers...\n"; assert( ::P::s11n::serialize(node,list) ); list.clear(); worked = ::P::s11n::deserialize( node, list ); assert( worked && "deser list failed :(" ); node.clear(); assert( ::P::s11n::serialize(node,map) ); map.clear(); worked = ::P::s11n::deserialize( node, map ); assert( worked && "deser map failed :(" ); CERR << "Deserialized:\n"; CERR << "deser list.size() == " << list.size()<<"\n"; CERR << "map.size() == " << map.size()<<"\n"; // now prove it... ListT::const_iterator lit = list.begin(); size_t at = 0; while( lit != list.end() ) { CERR << "list["<<at++<<"] = " << (*(lit++))<<"\n"; } MapT::const_iterator mit = map.begin(); while( mit != map.end() ) { CERR << "map["<<(*mit).first<<"] = "<<(*mit).second<<"\n"; ++mit; } return 0; } |
From: stephan b. <sg...@us...> - 2004-12-26 02:25:16
|
Update of /cvsroot/pclasses/pclasses2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15171 Modified Files: configure.pclasses2 Log Message: Added libpclasses_s11n handling. Index: configure.pclasses2 =================================================================== RCS file: /cvsroot/pclasses/pclasses2/configure.pclasses2,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- configure.pclasses2 25 Dec 2004 21:32:06 -0000 1.11 +++ configure.pclasses2 26 Dec 2004 02:25:05 -0000 1.12 @@ -190,6 +190,10 @@ toc_export LIBPUTIL_CLIENT_LDADD="-l${LIBPUTIL_BASENAME}" toc_export LIBPUTIL_CFLAGS="${THREADS_CFLAGS}" +toc_export LIBPS11N_BASENAME=pclasses_s11n +toc_export LIBPS11N_LDADD="" +toc_export LIBPS11N_CLIENT_LDADD="-l${LIBPS11N_BASENAME}" +toc_export LIBPS11N_CFLAGS="" ######################################################################## # Enable mysql driver... |
From: stephan b. <sg...@us...> - 2004-12-26 02:25:15
|
Update of /cvsroot/pclasses/pclasses2/lib In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15171/lib Modified Files: Makefile.toc Log Message: Added libpclasses_s11n handling. Index: Makefile.toc =================================================================== RCS file: /cvsroot/pclasses/pclasses2/lib/Makefile.toc,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- Makefile.toc 24 Dec 2004 23:07:10 -0000 1.1 +++ Makefile.toc 26 Dec 2004 02:25:01 -0000 1.2 @@ -10,12 +10,13 @@ ############# P Module libs: pliblist = $(addprefix $(plibp), \ - libpclasses_core \ - System/libpclasses_system \ - Net/libpclasses_net \ - IO/libpclasses_io \ - Unicode/libpclasses_unicode \ - Util/libpclasses_util \ + lib$(LIBPCORE_BASENAME) \ + System/lib$(LIBPSYSTEM_BASENAME) \ + Net/lib$(LIBPNET_BASENAME) \ + IO/lib$(LIBPIO_BASENAME) \ + Unicode/lib$(LIBPUNICODE_BASENAME) \ + Util/lib$(LIBPUTIL_BASENAME) \ + s11n/lib$(LIBPS11N_BASENAME) \ ) pliblist := $(addsuffix .so*,$(pliblist)) |
From: stephan b. <sg...@us...> - 2004-12-26 02:09:35
|
Update of /cvsroot/pclasses/pclasses2/src/s11n In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12626/src/s11n Modified Files: data_node.h Log Message: Fixed a bug brought on by removal of to_string() dep. Index: data_node.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/s11n/data_node.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- data_node.h 26 Dec 2004 00:55:20 -0000 1.2 +++ data_node.h 26 Dec 2004 02:09:26 -0000 1.3 @@ -342,7 +342,7 @@ template < typename T > void set( const std::string & key, const T & val ) { ::P::Util::LexT lex(val); - this->set_string( key, val ); + this->set_string( key, lex ); } /** |
From: stephan b. <sg...@us...> - 2004-12-26 02:07:13
|
Update of /cvsroot/pclasses/pclasses2/src/s11n In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12146/src/s11n Modified Files: test.cpp Log Message: Now actually demonstrates that the deser'd data was what it serialized. Index: test.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/s11n/test.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- test.cpp 26 Dec 2004 01:54:34 -0000 1.3 +++ test.cpp 26 Dec 2004 02:06:57 -0000 1.4 @@ -97,7 +97,7 @@ { CERR << "P::s11n tests...\n"; typedef std::auto_ptr<TheBase> BAP; - BAP b1 = BAP( new AType ); + BAP b1 = BAP( new BType ); NODE_TYPE node; assert( SERIALIZE(node,TheBase,b1.get() ) ); CERR << "Serialize Workie!\n"; @@ -127,19 +127,36 @@ bool worked; CERR << "Containers...\n"; - assert( SERIALIZE(node,ListT,list) ); + assert( ::P::s11n::serialize(node,list) ); list.clear(); worked = ::P::s11n::deserialize( node, list ); assert( worked && "deser list failed :(" ); - CERR << "deser list.size() == " << list.size()<<"\n"; node.clear(); - assert( SERIALIZE(node,MapT,map) ); + assert( ::P::s11n::serialize(node,map) ); map.clear(); worked = ::P::s11n::deserialize( node, map ); assert( worked && "deser map failed :(" ); + + CERR << "Deserialized:\n"; + + CERR << "deser list.size() == " << list.size()<<"\n"; CERR << "map.size() == " << map.size()<<"\n"; + // now prove it... + + ListT::const_iterator lit = list.begin(); + size_t at = 0; + while( lit != list.end() ) + { + CERR << "list["<<at++<<"] = " << (*(lit++))<<"\n"; + } + MapT::const_iterator mit = map.begin(); + while( mit != map.end() ) + { + CERR << "map["<<(*mit).first<<"] = "<<(*mit).second<<"\n"; + ++mit; + } return 0; } |
From: stephan b. <sg...@us...> - 2004-12-26 01:58:21
|
Update of /cvsroot/pclasses/pclasses2/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10534/src Modified Files: Makefile.toc Log Message: Re-ordered the subdirs. Index: Makefile.toc =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/Makefile.toc,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- Makefile.toc 26 Dec 2004 00:37:32 -0000 1.8 +++ Makefile.toc 26 Dec 2004 01:58:05 -0000 1.9 @@ -2,7 +2,7 @@ include toc.make -SUBDIRS = Unicode IO System Util Net s11n +SUBDIRS = Unicode s11n IO System Util Net # Plugins SOURCES = Alloc.cpp \ |
From: stephan b. <sg...@us...> - 2004-12-26 01:54:43
|
Update of /cvsroot/pclasses/pclasses2/src/s11n In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10013/src/s11n Modified Files: reg_map_specializations.h test.cpp Log Message: map de/ser is working. Index: reg_map_specializations.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/s11n/reg_map_specializations.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- reg_map_specializations.h 26 Dec 2004 01:26:15 -0000 1.3 +++ reg_map_specializations.h 26 Dec 2004 01:54:34 -0000 1.4 @@ -36,6 +36,7 @@ } // anon namespace +namespace P { namespace s11n { @@ -54,7 +55,7 @@ -} // namespace s11n +} } // namespace P::s11n #undef PS11N_MAP_TYPE_PROXY #undef PS11N_MAP_TYPE_NAME Index: test.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/s11n/test.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- test.cpp 26 Dec 2004 01:43:29 -0000 1.2 +++ test.cpp 26 Dec 2004 01:54:34 -0000 1.3 @@ -3,11 +3,13 @@ #include <pclasses/s11n/s11n_node.h> #include <pclasses/s11n/s11n_debuggering_macros.h> #include <pclasses/s11n/list.h> +#include <pclasses/s11n/map.h> #include <pclasses/s11n/pods_streamable.h> #include <pclasses/Util/LexT.h> #include <memory> // auto_ptr #include <cassert> #include <list> +#include <map> #define NODE_TYPE ::P::s11n::s11n_node #define SERIALIZE(Node,SType,SObj) ::P::s11n::serialize< NODE_TYPE >( Node, SObj ) @@ -109,17 +111,35 @@ using ::P::Util::LexT; typedef std::list<LexT> ListT; + typedef std::map<int,LexT> MapT; ListT list; + MapT map; + LexT tmpval; for( int i = 0; i < 10; i++ ) { - list.push_back( LexT( std::string("this is item #") + LexT(i).str() ) ); + tmpval = std::string("this is item #") + LexT(i).str(); + CERR << "Adding ["<<tmpval<<"]\n"; + list.push_back( tmpval ); + map[i] = tmpval; } - assert( SERIALIZE(node,ListT,list) ); + CERR << "list/map sizes == " << list.size() << " , " << map.size()<<"\n"; + + bool worked; + CERR << "Containers...\n"; + + assert( SERIALIZE(node,ListT,list) ); list.clear(); + worked = ::P::s11n::deserialize( node, list ); + assert( worked && "deser list failed :(" ); + CERR << "deser list.size() == " << list.size()<<"\n"; + + node.clear(); + assert( SERIALIZE(node,MapT,map) ); + map.clear(); + worked = ::P::s11n::deserialize( node, map ); + assert( worked && "deser map failed :(" ); + CERR << "map.size() == " << map.size()<<"\n"; - bool worked = ::P::s11n::deserialize( node, list ); - assert( worked && "deser list failed :(" ); - CERR << "list.size() == " << list.size()<<"\n"; return 0; } |