| # Gaudi Framework, version v20r4
Generated: 8 Jan 2009

# PoolDbCnvFactory.h

Go to the documentation of this file.

    00001 // $Id: PoolDbCnvFactory.h,v 1.3 2006/11/22 18:10:43 hmd Exp $
    00002 //====================================================================
    00003 //      IPoolDbCnvFactory and PoolDbCnvFactory definition
    00004 //--------------------------------------------------------------------
    00005 //
    00006 //      Author     : M.Frank
    00007 //====================================================================
    00008 #ifndef POOLDB_POOLDBCNVFACTORY_H
    00009 #define POOLDB_POOLDBCNVFACTORY_H 1
    00010 #include "GaudiKernel/ICnvFactory.h"
    00011 #include "GaudiKernel/FactoryTable.h"
    00012 #include "GaudiKernel/System.h"
    00013 #include "StorageSvc/DbType.h"
    00014
    00015 // Interface ID ( interface id, major version, minor version)
    00016 static const InterfaceID IID_IPoolDbCnvFactory("IPoolDbCnvFactory", 2 , 0);
    00017
    00026 class IPoolDbCnvFactory : virtual public IInterface   {
    00027 public:
    00029   static const InterfaceID& interfaceID() { return IID_IPoolDbCnvFactory; }
    00038   virtual IConverter* instantiate(long typ,
    00039                                   const CLID& clid,
    00040                                   ISvcLocator *svcloc )  const = 0;
    00041 };
    00042
    00051 template <class ConcreteConverter, int i>
    00052 class PoolDbCnvFactory : virtual public ICnvFactory,
    00053                          virtual public IPoolDbCnvFactory
    00054 {
    00056   mutable std::string m_typeName;
    00057 public:
    00059   typedef ConcreteConverter converter_t;
    00060
    00062   PoolDbCnvFactory()  {
    00063     m_typeName = "";
    00064     FactoryTable::instance()->addFactory( this );
    00065   }
    00067   virtual ~PoolDbCnvFactory()  {  }
    00069   virtual const std::string& typeName()  const    {
    00070     // The name MUST be set here, not in the constructor.
    00071     // At construction time it is not yet clear if we run from
    00072     // an executable or a DLL.
    00073     if ( m_typeName == "" )  {
    00074       if ( System::moduleType() == System::SHAREDLIB )  {
    00075         m_typeName  = System::moduleName();
    00076         m_typeName += ":";
    00077       }
    00078       // Get the class name using the RTTI.
    00079       m_typeName += System::typeinfoName( typeid(ConcreteConverter) );
    00080     }
    00081     return m_typeName;
    00082   }
    00084   virtual const CLID& objType()  const;
    00086   virtual const long repSvcType()   const
    00087   {    return pool::POOL_StorageType.type();  }
    00088   virtual unsigned long addRef()  const     {     return 1;           }
    00089   virtual unsigned long release()   const   {     return 1;           }
    00090   virtual const std::string& ident() const  {     return typeName();  }
    00091   // IInterface implementation
    00092   virtual unsigned long addRef()            {     return 1;           }
    00093   virtual unsigned long release()           {     return 1;           }
    00094
    00096   virtual StatusCode queryInterface(const InterfaceID& riid, void** ppISvc)   {
    00097           if ( IID_IPoolDbCnvFactory == riid )   {
    00098       *ppISvc = (IPoolDbCnvFactory *) this;
    00099     }
    00100           else if( IID_ICnvFactory == riid )    {
    00101         *ppISvc = (ICnvFactory*) this;
    00102     }
    00103           else if ( IID_IFactory == riid )     {
    00104           *ppISvc = (IFactory *) this;
    00105     }
    00106     else if ( IID_IInterface == riid )    {
    00107         *ppISvc = (IInterface *) this;
    00108     }
    00109           else    {
    00110                   return StatusCode::FAILURE;
    00111     }
    00112     addRef();
    00113           return StatusCode::SUCCESS;
    00114   }
    00115
    00124   virtual IConverter* instantiate(long typ,
    00125                                   const CLID& /* clid */,
    00126                                   ISvcLocator *svcloc)  const
    00127   {    return new ConcreteConverter(typ, svcloc);  }
    00128
    00130   virtual IConverter* instantiate( ISvcLocator* /* svcloc */ )  const
    00131   {    return 0;  }
    00132
    00134   virtual IInterface* instantiate( IInterface* /* parent */ ) const
    00135   {    return 0;  }
    00136
    00137 };
    00138 #endif    // POOLDB_POOLDBCNVFACTORY_H