![]() |
|
|
Generated: 18 Jul 2008 |
00001 // $Header: /local/reps/Gaudi/GaudiKernel/GaudiKernel/AlgFactory.h,v 1.9 2007/01/23 09:13:06 mato Exp $ 00002 #ifndef GAUDIKERNEL_ALGFACTORY_H 00003 #define GAUDIKERNEL_ALGFACTORY_H 00004 00005 #include "Reflex/PluginService.h" 00006 00007 // The following is needed to be backward compatible with the old factories of Gaudi. Otherwise the components 00008 // having the constructor/destructor protected will not be working 00009 00010 class IAlgorithm; 00011 class ISvcLocator; 00012 00013 template <typename T> class AlgFactory { 00014 public: static IAlgorithm* create(const std::string& name, ISvcLocator *svcloc) { 00015 return new T(name, svcloc ); 00016 } 00017 }; 00018 00019 namespace { 00020 template < typename P > class Factory<P, IAlgorithm*(std::string, ISvcLocator*)> { 00021 public: static void* Func( void*, const std::vector<void*>& arg, void*) { 00022 return AlgFactory<P>::create(*(std::string*)(arg[0]), (ISvcLocator*)(arg[1])); 00023 } 00024 }; 00025 } 00026 //---Specialization needed to overcome a problem with Reflex..... 00027 #ifndef TYPEDISTILLER_STRING_SPECIALIZATION 00028 #define TYPEDISTILLER_STRING_SPECIALIZATION 00029 namespace ROOT { 00030 namespace Reflex { 00031 template<> class TypeDistiller<std::string> { 00032 public: 00033 static Type Get() { 00034 return TypeBuilder("std::basic_string<char>"); 00035 } 00036 }; 00037 } 00038 } 00039 #endif 00040 00041 // Macros to declare component factories 00042 #define DECLARE_ALGORITHM_FACTORY(x) PLUGINSVC_FACTORY(x,IAlgorithm*(std::string, ISvcLocator*)) 00043 #define DECLARE_NAMESPACE_ALGORITHM_FACTORY(n,x) using n::x; PLUGINSVC_FACTORY(x,IAlgorithm*(std::string, ISvcLocator*)) 00044 #define DECLARE_ALGORITHM(x) /*dummy*/ 00045 #define DECLARE_NAMESPACE_ALGORITHM(n,x) /*dummy*/ 00046 00047 #endif // GAUDIKERNEL_ALGFACTORY_H