|
From: stephan b. <sg...@us...> - 2004-12-24 12:44:18
|
Update of /cvsroot/pclasses/pclasses2/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21438/test Modified Files: FactoryTest.cpp Log Message: mass commit: toc-related fixes/changes Index: FactoryTest.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/test/FactoryTest.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- FactoryTest.cpp 23 Dec 2004 20:12:14 -0000 1.1 +++ FactoryTest.cpp 24 Dec 2004 12:44:03 -0000 1.2 @@ -9,11 +9,19 @@ #include <pclasses/Factory.h> + #ifndef CERR #define CERR std::cerr << __FILE__ << ":" << std::dec << __LINE__ << " : " #endif -struct AType +struct TheBase +{ + + virtual ~TheBase() {} + virtual std::string classname() const = 0; +}; + +struct AType : public TheBase { AType() { @@ -24,7 +32,7 @@ CERR << "~AType()\n"; } - virtual std::string classname() { return "AType"; } + virtual std::string classname() const { return "AType"; } }; @@ -38,7 +46,7 @@ { CERR << "~BType()\n"; } - virtual std::string classname() { return "BType"; } + virtual std::string classname() const { return "BType"; } }; struct CType : public BType @@ -51,27 +59,39 @@ { CERR << "~CType()\n"; } - virtual std::string classname() { return "CType"; } + virtual std::string classname() const { return "CType"; } }; -int main( int argc, char ** argv ) -{ - CERR << "Factory tests...\n"; - typedef P::Factory<AType> FT; +#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> - P::CL::registerBase<AType>( "AType" ); - P::CL::registerSubtype<AType,BType>( "BType" ); - P::CL::registerSubtype<AType,CType>( "CType" ); +#define PFACREG_TYPE BType +#define PFACREG_TYPE_INTERFACE TheBase +#define PFACREG_TYPE_NAME "BType" +#include <pclasses/FactoryReg.h> +#define PFACREG_TYPE CType +#define PFACREG_TYPE_INTERFACE TheBase +#define PFACREG_TYPE_NAME "CType" +#include <pclasses/FactoryReg.h> - AType * a = 0; -#define LOAD(CN) a = P::CL::classload<AType>( CN ); \ +int main( int argc, char ** argv ) +{ + CERR << "Factory tests...\n"; + + TheBase * a = 0; + +#define LOAD(CN) a = P::CL::classload<TheBase>( CN ); \ CERR << CN << " loaded? == " << a << "\n"; \ if( a ) CERR << "classname="<<a->classname()<<"\n"; \ delete( a ); a = 0; + LOAD("TheBase"); LOAD("AType"); LOAD("BType"); LOAD("CType"); |