Go to the documentation of this file.00001
00002 #ifndef GAUDIKERNEL_ALGFACTORY_H
00003 #define GAUDIKERNEL_ALGFACTORY_H
00004
00005 #include "GaudiKernel/Kernel.h"
00006 #include "Reflex/PluginService.h"
00007 #include "RVersion.h"
00008
00009
00010
00011
00012 class IAlgorithm;
00013 class ISvcLocator;
00014
00015 template <typename T> class AlgFactory {
00016 public:
00017 static IAlgorithm* create(const std::string& name, ISvcLocator *svcloc) {
00018 return new T(name, svcloc );
00019 }
00020 };
00021
00022 namespace {
00023 template < typename P > class Factory<P, IAlgorithm*(std::string, ISvcLocator*)> {
00024 public:
00025 #if ROOT_VERSION_CODE < ROOT_VERSION(5,21,6)
00026 static void* Func( void*, const std::vector<void*>& arg, void*) {
00027 return AlgFactory<P>::create(*(std::string*)(arg[0]), (ISvcLocator*)(arg[1]));
00028 }
00029 #else
00030 static void Func( void *retaddr, void*, const std::vector<void*>& arg, void*) {
00031 *(IAlgorithm**) retaddr = AlgFactory<P>::create(*(std::string*)(arg[0]), (ISvcLocator*)(arg[1]));
00032 }
00033 #endif
00034 };
00035 }
00036
00037
00038 #define DECLARE_ALGORITHM_FACTORY(x) PLUGINSVC_FACTORY(x,IAlgorithm*(std::string, ISvcLocator*))
00039 #define DECLARE_NAMED_ALGORITHM_FACTORY(x,n) PLUGINSVC_FACTORY_WITH_ID(x,std::string(#n), IAlgorithm*(std::string, ISvcLocator*))
00040
00041 #define DECLARE_NAMESPACE_ALGORITHM_FACTORY(n,x) using n::x; PLUGINSVC_FACTORY(x,IAlgorithm*(std::string, ISvcLocator*))
00042 #define DECLARE_ALGORITHM(x)
00043 #define DECLARE_NAMESPACE_ALGORITHM(n,x)
00044
00045 #endif // GAUDIKERNEL_ALGFACTORY_H