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

# CnvFactory.h

Go to the documentation of this file.

    00001 // $Header: /tmp/svngaudi/tmp.jEpFh25751/Gaudi/GaudiKernel/GaudiKernel/CnvFactory.h,v 1.12 2006/12/06 17:18:03 mato Exp $
    00002 #ifndef GAUDIKERNEL_CNVFACTORY_H
    00003 #define GAUDIKERNEL_CNVFACTORY_H
    00004
    00005 #include "Reflex/PluginService.h"
    00006 #include "GaudiKernel/ClassID.h"
    00007 #include "RVersion.h"
    00008
    00009
    00010 // The following is needed to be backward compatible with the old factories of Gaudi. Otherwise the components
    00011 // having the constructor/destructor protected will not be working
    00012
    00013 class IConverter;
    00014 class ISvcLocator;
    00015
    00016 template <typename T> class CnvFactory {
    00017 public:
    00018   static IConverter* create(ISvcLocator *svcloc) {
    00019     return new T(svcloc );
    00020   }
    00021 };
    00022
    00023 namespace {
    00024   template < typename P > class Factory<P, IConverter*(ISvcLocator*)> {
    00025   public:
    00026 #if ROOT_VERSION_CODE < ROOT_VERSION(5,21,6)
    00027     static void* Func( void*, const std::vector<void*>& arg, void*) {
    00028       return CnvFactory<P>::create((ISvcLocator*)(arg[0]));
    00029     }
    00030 #else
    00031     static void Func( void *retaddr, void*, const std::vector<void*>& arg, void*) {
    00032       *(IConverter**) retaddr = CnvFactory<P>::create((ISvcLocator*)(arg[0]));
    00033     }
    00034 #endif
    00035   };
    00036 }
    00037
    00038 // Identified class for converters
    00039
    00040 class ConverterID {
    00041   public:
    00042    ConverterID( long stype, CLID clid ) : m_stype(stype), m_clid(clid) {}
    00043    ~ConverterID() {}
    00044    bool operator ==(const ConverterID& id) const { return m_stype == id.m_stype && m_clid == id.m_clid; }
    00045   private:
    00046    friend std::ostream& operator << ( std::ostream&, const ConverterID&);
    00047    long m_stype;
    00048    CLID m_clid;
    00049 };
    00050
    00051 inline std::ostream& operator << ( std::ostream& s, const ConverterID& id) {
    00052     s << "CNV_" << id.m_stype << "_" << id.m_clid;
    00053     return s;
    00054 }
    00055
    00056 #define DECLARE_GENERIC_CONVERTER(x) /* dummy */
    00057 #define DECLARE_NAMESPACE_GENERIC_CONVERTER(n,x) /* dummy */
    00058 #define DECLARE_CONVERTER(x) /*dummy*/
    00059 #define DECLARE_NAMESPACE_CONVERTER(n,x)   /*dummy */
    00060
    00061 // Macros to declare component factories
    00062 #define DECLARE_CONVERTER_FACTORY(x) \
    00063   PLUGINSVC_FACTORY_WITH_ID(x,ConverterID(x::storageType(),x::classID()),IConverter*(ISvcLocator*))
    00064
    00065 // Macros to declare component factories in a C++ namespace
    00066 #define DECLARE_NAMESPACE_CONVERTER_FACTORY(n,x) \
    00067 using n::x; PLUGINSVC_FACTORY_WITH_ID(x,ConverterID(x::storageType(),x::classID()),IConverter*(ISvcLocator*))
    00068
    00069 #endif // GAUDIKERNEL_CNVFACTORY_H