00001
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
00011
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
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)
00057 #define DECLARE_NAMESPACE_GENERIC_CONVERTER(n,x)
00058 #define DECLARE_CONVERTER(x)
00059 #define DECLARE_NAMESPACE_CONVERTER(n,x)
00060
00061
00062 #define DECLARE_CONVERTER_FACTORY(x) \
00063 PLUGINSVC_FACTORY_WITH_ID(x,ConverterID(x::storageType(),x::classID()),IConverter*(ISvcLocator*))
00064
00065
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