00001
00002 #ifndef GAUDI_KERNEL_TOOLFACTORY_H
00003 #define GAUDI_KERNEL_TOOLFACTORY_H
00004
00005 #include "Reflex/PluginService.h"
00006 #include "RVersion.h"
00007
00008
00009
00010
00011 class IAlgTool;
00012 class IInterface;
00013
00014 template <typename T> class ToolFactory {
00015 public:
00016 static IAlgTool* create(const std::string& type, const std::string& name, IInterface *parent) {
00017 return new T(type, name, parent );
00018 }
00019 };
00020
00021 namespace {
00022 template < typename P > class Factory<P, IAlgTool*(std::string, std::string, const IInterface*)> {
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 ToolFactory<P>::create(*(std::string*)(arg[0]), *(std::string*)(arg[1]), (IInterface*)(arg[2]));
00027 }
00028 #else
00029 static void Func( void *retaddr, void*, const std::vector<void*>& arg, void*) {
00030 *(IAlgTool**) retaddr = ToolFactory<P>::create(*(std::string*)(arg[0]), *(std::string*)(arg[1]), (IInterface*)(arg[2]));
00031 }
00032 #endif
00033 };
00034 }
00035
00036
00037 #define DECLARE_ALGTOOL(x)
00038 #define DECLARE_NAMESPACE_ALGTOOL(n,x)
00039 #define DECLARE_TOOL(x)
00040 #define DECLARE_NAMESPACE_TOOL(n,x)
00041
00042
00043 #define DECLARE_TOOL_FACTORY(x) PLUGINSVC_FACTORY(x,IAlgTool*(std::string, std::string, const IInterface*))
00044 #define DECLARE_NAMESPACE_TOOL_FACTORY(n,x) using n::x; PLUGINSVC_FACTORY(x,IAlgTool*(std::string, std::string, const IInterface*))
00045
00046 #endif // GAUDI_KERNEL_TOOLFACTORY_H