From: stephan b. <sg...@us...> - 2005-01-06 17:01:33
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16997/include/pclasses Modified Files: Factory.h Log Message: Doc corrections/additions. Index: Factory.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Factory.h,v retrieving revision 1.16 retrieving revision 1.17 diff -u -d -r1.16 -r1.17 --- Factory.h 31 Dec 2004 15:09:52 -0000 1.16 +++ Factory.h 6 Jan 2005 17:01:15 -0000 1.17 @@ -169,9 +169,9 @@ Sample usage: <pre> -Factory<MyClass> & fac = Factory<MyClass>::instance(); -fac.registerFactory( "my_key", P::Hook::FactoryCreateHook>MyClass<::create ); -MyClass *foo = fac.create( "some_key" ); // == NULL +Factory<MyInterface> & fac = Factory<MyInterface>::instance(); +fac.registerFactory( "my_key", P::Hook::FactoryCreateHook<MyInterface,MyClass>::create ); +MyInterface *foo = fac.create( "some_key" ); // == NULL foo = fac.create( "my_key" ); // == a new MyClass object </pre> @@ -182,7 +182,7 @@ other Factory<InterfaceT> instantiations. ContextType is only used as a marker type, and is never instantiated by this class. Used cleverly, it can allow you quite a bit - of freedome in what code has access to which factories. + of freedom in what code has access to which factories. */ template < class InterfaceT, class ContextT = Sharing::FactoryContext, @@ -198,7 +198,7 @@ */ typedef KeyType key_type; - /** Same as ContextType */ + /** Same as ContextT parameterized type. */ typedef ContextT ContextType; /** @@ -285,7 +285,7 @@ return _alias; } key_type exp = (*cit).second; - while( cit != cet ) + while( 1 ) { cit = this->aliases().find( exp ); if( cet == cit ) @@ -306,7 +306,7 @@ /** Tries to instantiate an instance of value_type - using the given key. Returns NULL if no object + using the given key. Returns 0 if no object could be loaded for the given key. Subtypes are free to implement, e.g., DLL lookups. @@ -376,15 +376,35 @@ window. That said, it should never be necessary for clients to use this. - It is safe to call this post-main(), but such calls - may return an empty map! - TODO: use a Hook or Traits type to allow the user to replace this object with his own, so that he can control the scope of the map more fully. + + + At the moment this returns the same object for all + instances of ThisType. Providing a private map from + each instance is under consideration. If we do that + we also will have to change aliasing support to + work the same. + + The reasoning behind using static factory maps is + essentially this: we can only have one definition + of each type. We normally want factories to always + return an instance constructed in the same way. If + we allow multiple factories per type we might + introduce hard-to-track inconsistencies in client + code, where different factories than intended are + accidentally used. OTOH, private factory maps + would open up some interesting possibilities. */ - static FactoryMap & factoryMap() + FactoryMap & factoryMap() { + //return this->m_facs; + return Phoenix<FactoryMap,ContextType>::instance(); + } + const FactoryMap & factoryMap() const + { + //return this->m_facs; return Phoenix<FactoryMap,ContextType>::instance(); } @@ -407,7 +427,8 @@ { return Hook::FactoryInstanceHook<ThisType>::instance(); } - +// private: +// FactoryMap m_facs; }; // class Factory |