All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
PluginService.h
Go to the documentation of this file.
1 #ifndef _GAUDI_PLUGIN_SERVICE_H_
2 #define _GAUDI_PLUGIN_SERVICE_H_
3 /*****************************************************************************\
4 * (c) Copyright 2013 CERN *
5 * *
6 * This software is distributed under the terms of the GNU General Public *
7 * Licence version 3 (GPL Version 3), copied verbatim in the file "LICENCE". *
8 * *
9 * In applying this licence, CERN does not waive the privileges and immunities *
10 * granted to it by virtue of its status as an Intergovernmental Organization *
11 * or submit itself to any jurisdiction. *
12 \*****************************************************************************/
13 
16 
17 #include <string>
18 #include <typeinfo>
20 
21 #define DECLARE_FACTORY_WITH_ID(type, id, factory) \
22  _INTERNAL_DECLARE_FACTORY(type, id, factory, __LINE__)
23 
24 #define DECLARE_FACTORY(type, factory) \
25  DECLARE_FACTORY_WITH_ID(type, \
26  ::Gaudi::PluginService::Details::demangle<type>(), factory)
27 
28 #define DECLARE_FACTORY_WITH_CREATOR_AND_ID(type, typecreator, id, factory) \
29  _INTERNAL_DECLARE_FACTORY_WITH_CREATOR(type, typecreator, id, factory, __LINE__)
30 
31 #define DECLARE_FACTORY_WITH_CREATOR(type, typecreator, factory) \
32  DECLARE_FACTORY_WITH_CREATOR_AND_ID(type, typecreator, \
33  ::Gaudi::PluginService::Details::demangle<type>(), factory)
34 
35 #define DECLARE_COMPONENT(type) \
36  DECLARE_FACTORY(type, type::Factory)
37 
38 #define DECLARE_COMPONENT_WITH_ID(type, id) \
39  DECLARE_FACTORY_WITH_ID(type, id, type::Factory)
40 
41 namespace Gaudi { namespace PluginService {
42 
44  template <typename R>
45  class Factory0 {
46  public:
47  typedef R ReturnType;
48  typedef R (*FuncType)();
49 
50  static ReturnType create(const std::string& id) {
51  const FuncType c = Details::getCreator<FuncType>(id);
52  return c ? (*c)() : 0;
53  }
54 
55  template <typename T>
56  static ReturnType create(const T& id) {
57  std::ostringstream o; o << id;
58  return create(o.str());
59  }
60  };
61 
63  template <typename R, typename A1>
64  class Factory1 {
65  public:
66  typedef R ReturnType;
67  typedef A1 Arg1Type;
68  typedef R (*FuncType)(Arg1Type);
69 
70  static ReturnType create(const std::string& id,
71  Arg1Type a1) {
72  const FuncType c = Details::getCreator<FuncType>(id);
73  return c ? (*c)(a1) : 0;
74  }
75 
76  template <typename T>
77  static ReturnType create(const T& id,
78  Arg1Type a1) {
79  std::ostringstream o; o << id;
80  return create(o.str(), a1);
81  }
82  };
83 
85  template <typename R, typename A1, typename A2>
86  class Factory2 {
87  public:
88  typedef R ReturnType;
89  typedef A1 Arg1Type;
90  typedef A2 Arg2Type;
91  typedef R (*FuncType)(Arg1Type, Arg2Type);
92 
93  static ReturnType create(const std::string& id,
94  Arg1Type a1,
95  Arg2Type a2) {
96  const FuncType c = Details::getCreator<FuncType>(id);
97  return c ? (*c)(a1, a2) : 0;
98  }
99 
100  template <typename T>
101  static ReturnType create(const T& id,
102  Arg1Type a1,
103  Arg2Type a2) {
104  std::ostringstream o; o << id;
105  return create(o.str(), a1, a2);
106  }
107  };
108 
110  template <typename R, typename A1, typename A2, typename A3>
111  class Factory3 {
112  public:
113  typedef R ReturnType;
114  typedef A1 Arg1Type;
115  typedef A2 Arg2Type;
116  typedef A3 Arg3Type;
118 
119  static ReturnType create(const std::string& id,
120  Arg1Type a1,
121  Arg2Type a2,
122  Arg3Type a3) {
123  const FuncType c = Details::getCreator<FuncType>(id);
124  return c ? (*c)(a1, a2, a3) : 0;
125  }
126 
127  template <typename T>
128  static ReturnType create(const T& id,
129  Arg1Type a1,
130  Arg2Type a2,
131  Arg3Type a3) {
132  std::ostringstream o; o << id;
133  return create(o.str(), a1, a2, a3);
134  }
135  };
136 
137  class GAUDIPS_EXPORT Exception: public std::exception {
138  public:
139  Exception(const std::string& msg);
140  virtual ~Exception() throw();
141  virtual const char* what() const throw();
142  private:
143  std::string m_msg;
144  };
145 }}
146 
147 #endif //_GAUDI_PLUGIN_SERVICE_H_
R(* FuncType)(Arg1Type, Arg2Type, Arg3Type)
Class wrapping the signature for a factory without arguments.
Definition: PluginService.h:45
static ReturnType create(const T &id, Arg1Type a1)
Definition: PluginService.h:77
tuple c
Definition: gaudirun.py:341
#define GAUDIPS_EXPORT
R(* FuncType)(Arg1Type, Arg2Type)
Definition: PluginService.h:91
static ReturnType create(const std::string &id, Arg1Type a1)
Definition: PluginService.h:70
Class wrapping the signature for a factory with 3 arguments.
static ReturnType create(const std::string &id, Arg1Type a1, Arg2Type a2)
Definition: PluginService.h:93
static ReturnType create(const T &id, Arg1Type a1, Arg2Type a2, Arg3Type a3)
Class wrapping the signature for a factory with 2 arguments.
Definition: PluginService.h:86
static ReturnType create(const T &id, Arg1Type a1, Arg2Type a2)
static ReturnType create(const std::string &id, Arg1Type a1, Arg2Type a2, Arg3Type a3)
static ReturnType create(const std::string &id)
Definition: PluginService.h:50
This is a number of static methods for bootstrapping the Gaudi framework.
Definition: Bootstrap.h:15
Class wrapping the signature for a factory with 1 argument.
Definition: PluginService.h:64
static ReturnType create(const T &id)
Definition: PluginService.h:56