From: <sg...@us...> - 2003-09-28 01:35:52
|
Update of /cvsroot/libfunutil/libfunutil/tests/s11n In directory sc8-pr-cvs1:/tmp/cvs-serv3118/tests/s11n Modified Files: FooClass.cpp FooClass.h Makefile test.s11n.cpp Log Message: refinements/improvments to the classloader. Added DLLLoader_boostrap "callback" support, to run boostrapping code when opening an DLL. This allows a way around using S11N_INSTANTIATOR, and a way to dynamically add factories to the classloader from DLLs. Index: FooClass.cpp =================================================================== RCS file: /cvsroot/libfunutil/libfunutil/tests/s11n/FooClass.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- FooClass.cpp 27 Sep 2003 22:36:54 -0000 1.1 +++ FooClass.cpp 28 Sep 2003 01:35:30 -0000 1.2 @@ -1,17 +1,32 @@ + #include <s11n/s11n-macros.h> // COUT/CERR +#include <s11n/s11n_globals.h> // register_serializable_type() // #include <s11n/s11n_globals.h> // trim_string() // #include <s11n/PointerList.h> // #include <s11n/PropertiesProvider.h> -// #include <s11n/ClassLoader.h> -// #include <s11n/Instantiator.h> - +#include <s11n/ClassLoader.h> +#include <s11n/Instantiator.h> +#include <s11n/DLLLoader.h> #include "FooClass.h" + +S11N_INSTANTIATOR(foo,FooClass); + using namespace s11n; using namespace std; -S11N_INSTANTIATOR(FooClass); +extern "C" { + void DLLLoader_bootstrap() + { + typedef s11n::Factory<s11n::Serializable,foo::FooClass> Fac; + COUT << "DLLLoader_bootstrap()" << endl; + s11n::register_serializable_type<foo::FooClass>("WonderBra"); + s11n::register_serializable_type<foo::FooClass>("foo:FooClass"); + } +} + +namespace foo { std::string name; FooClass::FooClass() : Serializable("FooClass") { @@ -32,8 +47,10 @@ bool FooClass::deserialize( const S11nNode & ser ) { + if ( !this->Serializable::deserialize( ser ) ) return false; this->name = ser.get( "name", "<unnamed>" ); return true; } +}; // namespace foo Index: FooClass.h =================================================================== RCS file: /cvsroot/libfunutil/libfunutil/tests/s11n/FooClass.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- FooClass.h 27 Sep 2003 22:36:54 -0000 1.1 +++ FooClass.h 28 Sep 2003 01:35:30 -0000 1.2 @@ -4,6 +4,7 @@ #include <s11n/S11n.h> #include <s11n/S11nIO.h> +namespace foo { struct FooClass:public s11n::Serializable { std::string name; @@ -13,5 +14,5 @@ virtual bool deserialize( const s11n::S11nNode & ser ); }; - +}; // namespace foo #endif // FOO_H_INCLUDED Index: Makefile =================================================================== RCS file: /cvsroot/libfunutil/libfunutil/tests/s11n/Makefile,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- Makefile 27 Sep 2003 22:36:54 -0000 1.1 +++ Makefile 28 Sep 2003 01:35:30 -0000 1.2 @@ -12,21 +12,22 @@ ifeq (1,$(configure_have_zlib)) BIN_PROGRAMS_LDADD += -lz $(L_S11N) -ldl -export-dynamic endif -sertest_bin_OBJECTS = test.s11n.o BarClass.o +sertest_bin_OBJECTS = test.s11n.o sertest_bin_LDADD += $(LQT) $(top_srcdir)/lib/funUtil/libfunUtil.a dlopen_bin_OBJECTS = dlopen.o -SHARED_LIBS = FooClass BarClass +SHARED_LIBS = FooClass BarClass BigSO SHARED_LIBS_LDADD = $(L_S11N) FooClass_so_OBJECTS = FooClass.o -FooClass_so_VERSION = 0.9.9 BarClass_so_OBJECTS = BarClass.o +BigSO_so_OBJECTS = BarClass.o FooClass.o include $(toc_makesdir)/cpp_dynamic_libs.make include $(toc_makesdir)/cpp_bins.make CLEAN_FILES += $(wildcard *.o) + all: libs-shared $(BIN_PROGRAMS) Index: test.s11n.cpp =================================================================== RCS file: /cvsroot/libfunutil/libfunutil/tests/s11n/test.s11n.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- test.s11n.cpp 27 Sep 2003 22:36:54 -0000 1.1 +++ test.s11n.cpp 28 Sep 2003 01:35:30 -0000 1.2 @@ -33,8 +33,6 @@ // #include "BarClass.h" - - namespace fake { struct FakeRoot:public Serializable @@ -45,15 +43,9 @@ typedef PointerList < s11n::Serializable > FakeVec; //typedef std::vector<BarClass *> FakeVec; FakeVec m_vec; - FakeRoot( ) + FakeRoot( ) : Serializable( "fake::FakeRoot" ) { - //LOUT << "FakeRoot()" << endl; - this->implClass( "fake::FakeRoot" ); m_vec.autoDelete( true ); -// m_vec.push_back( new BarClass( ) ); -// m_vec.push_back( new BarClass( ) ); -// m_vec.push_back( new BarClass( ) ); -// ( *m_vec.begin( ) )->name = "google"; }; virtual ~ FakeRoot( ) { @@ -61,8 +53,7 @@ virtual bool serialize( S11nNode & node ) const { - if ( !this->Serializable::serialize( node ) ) - return false; + if ( !this->Serializable::serialize( node ) ) return false; node.set( "foo", m_foo ); node.set( "bar", m_bar ); node.serializeChildren( "foo_child", m_vec ); @@ -74,8 +65,7 @@ //m_vec.deleteAll(); m_foo = ser.get( "foo", "<not set>" ); m_bar = ser.get( "bar", "<not set>" ); - //ser.childrenCast( "foo_childs", m_vec ); - m_vec.deleteAll( ); + m_vec.deleteAll(); ser.deserializeChildren( "foo_child", m_vec ); COUT << "deser: foo_child count: " << m_vec.size( ) << std::endl; COUT << "deser: m_foo=["<<m_foo<<"]"<<std::endl; @@ -88,31 +78,6 @@ }; // namespace fake -// #include "FooClass.h" -void -register_initial_node_classes( ) -{ - typedef Instantiator < Serializable > SerFactory; - typedef ClassLoader < Serializable > SerLoader; - -// s11n::register_serializable_type<FooClass>( "FooClass" ); - - SerLoader::registerFactory( "fake::FakeRoot", Factory < Serializable, fake::FakeRoot >::newInstance ); - -// typedef Factory < Serializable, BarClass > BarInst; -// SerLoader::registerFactory( "woo::hoo::BarClass", BarInst::newInstance ); -// SerLoader::registerFactory( "bar::BarClass", BarInst::newInstance ); -// SerLoader::registerFactory( "BarClass", BarInst::newInstance ); - //SerLoader::registerFactory( "FooClass", BarInst::newInstance ); - -// #define CLREG(clN) SerLoader::registerFactory( # clN, SerFactory::newInstance ); -// CLREG(GEVHex); -// CLREG(fun::HexMap); -// CLREG(fun::HexNumberStyle); -// CLREG(fun::MapAreaTerrainFeature); - -} - // void // testtree( ) @@ -139,6 +104,29 @@ // delete( cleanbar ); // } + +extern "C" { + /** + Called by DLLLoader the first time it tries to load a + class from the global space. + */ + void DLLLoader_bootstrap() + { + COUT << "DLLLoader_bootstrap()" << endl; + s11n::register_serializable_type<fake::FakeRoot>( "fake::FakeRoot" ); + +#define CLREG(clN) COUT << "Warning: faking class type for " << # clN << std::endl; \ +s11n::register_serializable_type<s11n::Serializable>( # clN ); + + CLREG(GEVHex); + CLREG(fun::HexMap); + CLREG(fun::HexNumberStyle); + CLREG(fun::MapAreaTerrainFeature); + + } +} + + int main( int argc, char **argv ) { @@ -161,8 +149,7 @@ COUT << "You must specify an input file with -f or --file." << endl; return 1; } - - register_initial_node_classes( ); + //register_initial_node_classes( ); std::ostream * os = &std::cout; string ofilename = args.getString( "-o", "" ).data( ); |