From: stephan b. <sg...@us...> - 2004-12-23 14:13:58
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16132 Modified Files: Factory.h Log Message: removed the internalInstantiate() altogether - the extra indirection brought nothing Index: Factory.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Factory.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- Factory.h 23 Dec 2004 13:49:54 -0000 1.2 +++ Factory.h 23 Dec 2004 14:13:35 -0000 1.3 @@ -238,16 +238,22 @@ typedef std::map < key_type, factory_type > FactoryMap; - /** - returns instance().internalInstantiate( key ). + /** + Tries to instantiate an instance of value_type + using the given key. Returns NULL if no class could + be loaded for the given key. - The caller takes responsibility for the returned pointer. + Subtypes are free to implement, e.g., DLL lookups. */ - static result_type instantiate( const key_type & key ) + virtual result_type instantiate( const key_type & key ) { - - return instance().internalInstantiate( key ); - } + typename FactoryMap::const_iterator it = factoryMap().find( key ); + if ( it != factoryMap().end() ) // found a factory? + { + return ( it->second ) (); // run our factory. + } + return 0; + } /** @@ -255,7 +261,7 @@ */ result_type operator()( const key_type & key ) { - return this->internalInstantiate( key ); + return this->internal( key ); } @@ -311,26 +317,6 @@ return Hook::FactoryInstanceHook<ThisType>::instance(); } - - protected: - /** - Tries to instantiate an instance of value_type - using the given key. Returns NULL if no class could - be loaded for the given key. - - This is the virtual equivalent to the static instantiate(). - - Subtypes are free to implement, e.g., DLL lookups. - */ - virtual result_type internalInstantiate( const key_type & key ) - { - typename FactoryMap::const_iterator it = factoryMap().find( key ); - if ( it != factoryMap().end() ) // found a factory? - { - return ( it->second ) (); // run our factory. - } - return 0; - } }; // class Factory @@ -341,7 +327,7 @@ implementation, as non-string-keyed factories are rare in practice (but sometimes very useful). */ -template <typename InterfaceT> + template <typename InterfaceT> struct NamedTypeFactory : public Factory< InterfaceT, std::string, Sharing::FactoryContext > { virtual ~NamedTypeFactory(){} @@ -350,9 +336,15 @@ /** The CL namespace encapsulates P's classloader-related API. - All of the functions in this API use the obbject NamedTypeFactory<InterfaceT>::instance() - for factory-related operations. Thus, using the various Hook classes you can force these - functions to use your factory. + All of the functions in this API use the obbject + NamedTypeFactory<InterfaceT>::instance() for + factory-related operations. Thus, using the various Hook + classes you can force these functions to use your factory. + + i don't like this namespace. Maybe move these functions + into Factory itself??? They're simply proxying that type, + after all. + */ namespace CL { |