| # Gaudi Framework, version v21r8 |

Home |  | Generated: 17 Mar 2010

# SvcFactory.h

Go to the documentation of this file.

    00001 // $Header: /tmp/svngaudi/tmp.jEpFh25751/Gaudi/GaudiKernel/GaudiKernel/SvcFactory.h,v 1.11 2008/10/09 21:00:37 marcocle Exp $
    00002 #ifndef KERNEL_SVCFACTORY_H
    00003 #define KERNEL_SVCFACTORY_H
    00004
    00005 #include "Reflex/PluginService.h"
    00006 #include "RVersion.h"
    00007
    00008 // The following is needed to be backward compatible with the old factories of Gaudi. Otherwise the components
    00009 // having the constructor/destructor protected will not be working
    00010
    00011 class IService;
    00012 class ISvcLocator;
    00013
    00014 template <typename T> class SvcFactory {
    00015 public:
    00016   static IService* create(const std::string& name, ISvcLocator *svcloc) {
    00017     return new T(name, svcloc );
    00018   }
    00019 };
    00020
    00021 namespace {
    00022   template < typename P > class Factory<P, IService*(std::string, ISvcLocator*)> {
    00023   public:
    00024 #if ROOT_VERSION_CODE < ROOT_VERSION(5,21,6)
    00025     static void* Func( void*, const std::vector<void*>& arg, void*) {
    00026       return SvcFactory<P>::create(*(std::string*)(arg[0]), (ISvcLocator*)(arg[1]));
    00027     }
    00028 #else
    00029     static void Func( void *retaddr, void*, const std::vector<void*>& arg, void*) {
    00030       *(IService**) retaddr = SvcFactory<P>::create(*(std::string*)(arg[0]), (ISvcLocator*)(arg[1]));
    00031     }
    00032 #endif
    00033   };
    00034 }
    00035
    00036 // Macros to declare component factories
    00037
    00038 #define DECLARE_SERVICE_FACTORY(x)              PLUGINSVC_FACTORY(x,IService*(std::string, ISvcLocator*))
    00039 #define DECLARE_NAMED_SERVICE_FACTORY(x,n)      PLUGINSVC_FACTORY_WITH_ID(x,std::string(#n), IService*(std::string, ISvcLocator*))
    00040 #define DECLARE_NAMESPACE_SERVICE_FACTORY(n,x)  using n::x; PLUGINSVC_FACTORY(x,IService*(std::string, ISvcLocator*))
    00041 #define DECLARE_SERVICE(x)  /*dummy*/
    00042 #define DECLARE_NAMESPACE_SERVICE(n,x) /*dummy*/
    00043
    00044
    00045 #endif // GAUDIKERNEL_SVCFACTORY_H