The Gaudi Framework  v30r3 (a5ef0a68)
PluginServiceV1.h
Go to the documentation of this file.
1 #ifndef _GAUDI_PLUGIN_SERVICE_V1_H_
2 #define _GAUDI_PLUGIN_SERVICE_V1_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 
18 #include <string>
19 #include <typeinfo>
20 #include <utility>
21 
22 #define _PS_V1_DECLARE_FACTORY_WITH_ID( type, id, factory ) \
23  _PS_V1_INTERNAL_DECLARE_FACTORY( type, id, factory, __LINE__ )
24 
25 #define _PS_V1_DECLARE_FACTORY( type, factory ) \
26  _PS_V1_DECLARE_FACTORY_WITH_ID( type, ::Gaudi::PluginService::v1::Details::demangle<type>(), factory )
27 
28 #define _PS_V1_DECLARE_FACTORY_WITH_CREATOR_AND_ID( type, typecreator, id, factory ) \
29  _PS_V1_INTERNAL_DECLARE_FACTORY_WITH_CREATOR( type, typecreator, id, factory, __LINE__ )
30 
31 #define _PS_V1_DECLARE_FACTORY_WITH_CREATOR( type, typecreator, factory ) \
32  _PS_V1_DECLARE_FACTORY_WITH_CREATOR_AND_ID( type, typecreator, \
33  ::Gaudi::PluginService::v1::Details::demangle<type>(), factory )
34 
35 #define _PS_V1_DECLARE_COMPONENT( type ) _PS_V1_DECLARE_FACTORY( type, type::Factory )
36 
37 #define _PS_V1_DECLARE_COMPONENT_WITH_ID( type, id ) _PS_V1_DECLARE_FACTORY_WITH_ID( type, id, type::Factory )
38 
39 #if !GAUDI_PLUGIN_SERVICE_USE_V2
40 #define DECLARE_FACTORY_WITH_ID( type, id, factory ) _PS_V1_DECLARE_FACTORY_WITH_ID( type, id, factory )
41 #define DECLARE_FACTORY( type, factory ) _PS_V1_DECLARE_FACTORY( type, factory )
42 #define DECLARE_FACTORY_WITH_CREATOR_AND_ID( type, typecreator, id, factory ) \
43  _PS_V1_DECLARE_FACTORY_WITH_CREATOR_AND_ID( type, typecreator, id, factory )
44 #define DECLARE_FACTORY_WITH_CREATOR( type, typecreator, factory ) \
45  _PS_V1_DECLARE_FACTORY_WITH_CREATOR( type, typecreator, factory )
46 #define DECLARE_COMPONENT( type ) _PS_V1_DECLARE_COMPONENT( type )
47 #define DECLARE_COMPONENT_WITH_ID( type, id ) _PS_V1_DECLARE_COMPONENT_WITH_ID( type, id )
48 #endif
49 
50 namespace Gaudi
51 {
52  namespace PluginService
53  {
55  {
57  template <typename R, typename... Args>
58  class Factory
59  {
60  public:
61  typedef R ReturnType;
62  typedef R ( *FuncType )( Args&&... );
63 
64  static ReturnType create( const std::string& id, Args... args )
65  {
66  const FuncType c = Details::getCreator<FuncType>( id );
67  return c ? ( *c )( std::forward<Args>( args )... ) : 0;
68  }
69 
70  template <typename T>
71  static ReturnType create( const T& id, Args... args )
72  {
74  o << id;
75  return create( o.str(), std::forward<Args>( args )... );
76  }
77  };
78 
80  {
81  public:
83  ~Exception() throw() override;
84  const char* what() const throw() override;
85 
86  private:
88  };
89  }
90  }
91 }
92 
93 #endif //_GAUDI_PLUGIN_SERVICE_H_
static ReturnType create(const T &id, Args...args)
#define GAUDI_PLUGIN_SERVICE_V1_INLINE
STL class.
Class wrapping the signature for a factory with any number of arguments.
STL class.
#define GAUDIPS_EXPORT
static ReturnType create(const std::string &id, Args...args)
Helper functions to set/get the application return code.
Definition: __init__.py:1