|
From: stephan b. <sg...@us...> - 2004-12-24 19:17:05
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31557/include/pclasses Modified Files: Factory.h Log Message: Some API renaming, for consistency with other API parts (Plugin). Index: Factory.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Factory.h,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- Factory.h 24 Dec 2004 13:10:54 -0000 1.6 +++ Factory.h 24 Dec 2004 19:16:54 -0000 1.7 @@ -165,8 +165,8 @@ <pre> Factory<MyClass> & fac = Factory<MyClass>::instance(); fac.registerFactory( "my_key", P::Hook::FactoryCreateHook>MyClass<::create ); -MyClass *foo = fac.instantiate( "some_key" ); // == NULL -foo = fac.instantiate( "my_key" ); // == a new MyClass object +MyClass *foo = fac.create( "some_key" ); // == NULL +foo = fac.create( "my_key" ); // == a new MyClass object </pre> Note that all instantiators of the same type use the same @@ -235,7 +235,7 @@ Subtypes are free to implement, e.g., DLL lookups. */ - virtual result_type instantiate( const key_type & key ) + virtual result_type create( const key_type & key ) { typename FactoryMap::const_iterator it = factoryMap().find( key ); if ( it != factoryMap().end() ) // found a factory? @@ -247,7 +247,24 @@ /** - Returns this->instantiate(key). + Deletes obj. Subclasses are free to do custom + accounting, garbage collection, or whatever, by + overriding this. + + Note that it is not practical to expect all clients + to call this in order to destroy their objects, so + the utility of this function is highly arguable. + + Subclasses are free to dictate a must-destroy() + policy if they wish. + */ + virtual void destroy( result_type obj ) + { + delete obj; + } + + /** + Returns this->create(key). */ result_type operator()( const key_type & key ) { @@ -281,7 +298,7 @@ */ static FactoryMap & factoryMap() { - return Phoenix<FactoryMap,ThisType>::instance(); + return Phoenix<FactoryMap,context_type>::instance(); } /** @@ -290,7 +307,7 @@ is sometimes necessary post-main(), when the internal map gets hosed before clients are done using it. */ - bool isRegistered( const key_type & key ) const + bool provides( const key_type & key ) const { return factoryMap().end() != factoryMap().find( key ); } @@ -374,12 +391,12 @@ } /** - Returns the same as NamedTypeFactory<InterfaceT>::instance().instantiate( classname ). + Returns the same as NamedTypeFactory<InterfaceT>::instance().create( classname ). */ template <typename InterfaceT> InterfaceT * classload( const std::string & classname ) { - return NamedTypeFactory<InterfaceT>::instance().instantiate( classname ); + return NamedTypeFactory<InterfaceT>::instance().create( classname ); } } // namespace CL |