From: stephan b. <sg...@us...> - 2004-12-25 01:45:27
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3260/include/pclasses Modified Files: Factory.h FactoryReg.h Log Message: Swapped the 2nd and 3rd template args, because usage suggests that the ContextType is used more often than the KeyType. Index: Factory.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Factory.h,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- Factory.h 24 Dec 2004 19:16:54 -0000 1.7 +++ Factory.h 25 Dec 2004 01:45:14 -0000 1.8 @@ -9,14 +9,12 @@ #include <functional> #include <pclasses/Phoenix.h> // i don't like this dep, but i also don't like + // what happens in some cases when i don't use + // phoenix. :/ #include <pclasses/SharingContext.h> -// what happens in some cases when i don't use -// phoenix. :/ namespace P { - - /** The Hook namespace holds classes intended to be used to allow client-side code to hook in to the framework's @@ -40,8 +38,10 @@ </pre> Clients may freely specialize this type to hook their - factories in to P, and the above requirement may not be - imposed by client-side specializations. + factories in to P, and the above 'new' requirement need + not be imposed by client-side specializations. For example, + specializations are used to provide no-op factories for + abstract types, where 'new T' cannot work. */ template < class T, class SubT > @@ -80,7 +80,7 @@ /** Same as create(). */ - result_type operator()() const + result_type operator()() { return create(); } @@ -155,7 +155,8 @@ Both InterfaceT and KeyType must be Default Constructable, and InterfaceT must be constructable on the heap - (e.g., via new InterfaceT()). + (e.g., via new InterfaceT()). Thus InterfaceT must not be + pointer-qualified. The default ipmlementation holds no per-instance state, thus it can be copied quickly. @@ -177,8 +178,8 @@ and is never instantiated by this class. */ template < class InterfaceT, - class KeyType = std::string, - class ContextType = Sharing::FactoryContext + class ContextType = Sharing::FactoryContext, + class KeyType = std::string > class Factory { @@ -206,7 +207,7 @@ /** Convenience typedef. */ - typedef Factory< InterfaceT, KeyType, ContextType > ThisType; + typedef Factory< InterfaceT, ContextType, KeyType > ThisType; Factory() {} @@ -283,6 +284,7 @@ */ void registerFactory( const key_type & key, factory_type fp ) { + // CERR << "registerFactory("<<key<<",facfunc)\n"; factoryMap().insert( FactoryMap::value_type( key, fp ) ); } @@ -314,14 +316,11 @@ /** Returns a shared reference to a Factory. - - Client code may plug in a new default instance() by - specializing Hook::FactoryInstanceHook< FactoryT >. See - that type for details. + */ static Factory & instance() { - return Hook::FactoryInstanceHook<ThisType>::instance(); + return Hook::FactoryInstanceHook<ThisType>::instance(); } @@ -335,7 +334,7 @@ practice (but sometimes very useful). */ template <typename InterfaceT> - struct NamedTypeFactory : public Factory< InterfaceT, std::string, Sharing::FactoryContext > + struct NamedTypeFactory : public Factory< InterfaceT, Sharing::FactoryContext, std::string > { virtual ~NamedTypeFactory(){} }; Index: FactoryReg.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/FactoryReg.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- FactoryReg.h 24 Dec 2004 21:17:35 -0000 1.2 +++ FactoryReg.h 25 Dec 2004 01:45:14 -0000 1.3 @@ -79,7 +79,7 @@ # endif // !p_FACTORY_REG_CONTEXT_DEFINED # define FACTORY_FUNCTION_ ::P::Hook::FactoryCreateHook< PFACREG_TYPE_INTERFACE , PFACREG_TYPE >::create -# define FACTORY_INSTANCE_ ::P::Factory< PFACREG_TYPE_INTERFACE, std::string, PFACREG_CONTEXT >::instance() +# define FACTORY_INSTANCE_ ::P::Factory< PFACREG_TYPE_INTERFACE, PFACREG_CONTEXT, std::string >::instance() //////////////////////////////////////////////////////////////////////// // Register a factory with the classloader: bool pfactory_reg_context< PFACREG_TYPE >::placeholder= ( |