From: stephan b. <sg...@us...> - 2004-12-25 01:57:20
|
Update of /cvsroot/pclasses/pclasses2/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4987/test Modified Files: CType.cpp FactoryTest.cpp FactoryTest.h Log Message: Accomodated changes in Factory. Index: FactoryTest.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/test/FactoryTest.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- FactoryTest.cpp 24 Dec 2004 23:26:40 -0000 1.5 +++ FactoryTest.cpp 25 Dec 2004 01:57:09 -0000 1.6 @@ -21,38 +21,51 @@ TheBase * a = 0; -#define CLOAD(CN) a = P::NamedTypeFactory<TheBase>::instance().create( CN ); \ - CERR << CN << " classload()ed? == " << a << "\n"; \ +#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; - /************************* -Can't test until linking the libpclasses_xxx works. - *************************/ - typedef P::Plugin::PluginManager<TheBase> PM; + 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; - PM & pm = PM::instance(); -#define PLOAD(CN) a = pm.create( CN ); \ - CERR << CN << " plugin-create()ed? == " << a << "\n"; \ + 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) CLOAD(CN); PLOAD(CN); +#define LOAD(CN) NTLOAD(CN); CLOAD(CN); +#if 0 try { - ::P::System::SharedLib * sh = pm.addPlugin( "CType" ); - CERR << "CType lib = " << sh << "\n"; - // throw P::Exception( "Foo!", P_SOURCEINFO ); + std::string sofile = pm.findPlugin( "CType" ); + CERR << "sofile="<<sofile<<"\n"; + if( sofile.empty() ) + { + throw P::Exception( "Plugin not found!", P_SOURCEINFO ); + } + ::P::System::SharedLib * sh = 0; + sh = pm.addPlugin( sofile ); + // sh = ::P::Plugin::addPlugin<TheBase>( "CType" ); + CERR << "plugged in lib: " << sh << "\n"; + CERR << "Symbol lookup test: " << (*sh)["new_CType"] << "\n"; + //throw P::Exception( "Foo!", P_SOURCEINFO ); } catch( const ::P::Exception & ex ) { - CERR << "Exception:\n"<<ex.where()<<"\n"<<ex.what()<<"\n"; + CERR << "Exception:\n"<<ex.what()<<"\n"<<ex.where()<<"\n"; } +#endif + LOAD("DefaultDocumentType"); LOAD("CType"); - LOAD("XtraType"); LOAD("TheBase"); LOAD("AType"); LOAD("BType"); Index: FactoryTest.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/test/FactoryTest.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- FactoryTest.h 24 Dec 2004 23:25:55 -0000 1.1 +++ FactoryTest.h 25 Dec 2004 01:57:09 -0000 1.2 @@ -20,6 +20,45 @@ 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"; } + +}; + + + +#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() + { + CERR << "BType()\n"; + } + virtual ~BType() + { + CERR << "~BType()\n"; + } + 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> #endif // ptest_FACTORYTEST_HPP_INCLUDED Index: CType.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/test/CType.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- CType.cpp 24 Dec 2004 23:25:55 -0000 1.1 +++ CType.cpp 25 Dec 2004 01:57:09 -0000 1.2 @@ -1,44 +1,6 @@ #include "FactoryTest.h" -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"; } -}; - - -#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> struct CType : public BType { @@ -54,15 +16,17 @@ }; -TheBase * new_CType() -{ - return new CType; +extern "C" { + TheBase * new_CType() + { + return new CType; + } } void CType_bogo_init() { CERR << "CType_bogo_init()\n"; - ::P::NamedTypeFactory<TheBase>::instance().registerFactory( "XtraType", new_CType ); + ::P::NamedTypeFactory<TheBase>::instance().registerFactory( "DefaultDocumentType", new_CType ); } int CType_bogo_init_placeholder = ( CType_bogo_init(), 0 ); |