From: stephan b. <st...@s1...> - 2004-12-23 20:13:22
|
Yo, Consider the following 3 classes: AType ==> extended by ==> BType ==> x by ==> CType Here's the current P2 code to get at them via Factory: First, register them: P::CL::registerBase<AType>( "AType" ); P::CL::registerSubtype<AType,BType>( "BType" ); P::CL::registerSubtype<AType,CType>( "CType" ); Here we use the default factories, but we can also swap those out with our own via at least 3 different techniques. In standard usage the default factories serve very well. There will also be a technique to allow DLLs to *register themselves* with their factory(ies), meaning P won't have to do any more symbol lookups in DLLs to load classes. Part 2, load them: #define LOAD(CN) a = P::CL::classload<AType>( CN ); \ CERR << CN << " loaded? == " << a << "\n"; \ if( a ) CERR << "classname="<<a->classname()<<"\n"; \ delete( a ); a = 0; LOAD("AType"); LOAD("BType"); LOAD("CType"); LOAD("NoType"); Output: stephan@owl:~/cvs/pclasses2/test> ./FactoryTest FactoryTest.cpp:59 : Factory tests... FactoryTest.cpp:20 : AType() FactoryTest.cpp:75 : AType loaded? == 0x804e3d0 FactoryTest.cpp:75 : classname=AType FactoryTest.cpp:24 : ~AType() FactoryTest.cpp:20 : AType() FactoryTest.cpp:35 : BType() FactoryTest.cpp:76 : BType loaded? == 0x804e3d0 FactoryTest.cpp:76 : classname=BType FactoryTest.cpp:39 : ~BType() FactoryTest.cpp:24 : ~AType() FactoryTest.cpp:20 : AType() FactoryTest.cpp:35 : BType() FactoryTest.cpp:48 : CType() FactoryTest.cpp:77 : CType loaded? == 0x804e3d0 FactoryTest.cpp:77 : classname=CType FactoryTest.cpp:52 : ~CType() FactoryTest.cpp:39 : ~BType() FactoryTest.cpp:24 : ~AType() FactoryTest.cpp:78 : NoType loaded? == 0 The reasons their addresses repeat is because we delete the object between each call - that is not a bug. -- ----- st...@s1... http://s11n.net "...pleasure is a grace and is not obedient to the commands of the will." -- Alan W. Watts |