| # Gaudi Framework, version v21r8 |

Home |  | Generated: 17 Mar 2010

# ToolFactory.h

Go to the documentation of this file.

    00001 // $Header: /tmp/svngaudi/tmp.jEpFh25751/Gaudi/GaudiKernel/GaudiKernel/ToolFactory.h,v 1.9 2007/01/23 09:13:07 mato Exp $
    00002 #ifndef GAUDI_KERNEL_TOOLFACTORY_H
    00003 #define GAUDI_KERNEL_TOOLFACTORY_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 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 // Macros to declare components
    00037 #define DECLARE_ALGTOOL(x)             /*dummy*/
    00038 #define DECLARE_NAMESPACE_ALGTOOL(n,x) /*dummy*/
    00039 #define DECLARE_TOOL(x)                /*dummy*/
    00040 #define DECLARE_NAMESPACE_TOOL(n,x)    /*dummy*/
    00041
    00042 // Macros to declare component factories
    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