The Gaudi Framework  master (37c0b60a)
PluginServiceV1.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 2013-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 #ifndef _GAUDI_PLUGIN_SERVICE_V1_H_
12 #define _GAUDI_PLUGIN_SERVICE_V1_H_
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  namespace PluginService {
54  template <typename R, typename... Args>
55  class Factory {
56  public:
57  typedef R ReturnType;
58  typedef R ( *FuncType )( Args&&... );
59 
60  static ReturnType create( const std::string& id, Args... args ) {
61  const FuncType c = Details::getCreator<FuncType>( id );
62  return c ? ( *c )( std::forward<Args>( args )... ) : 0;
63  }
64 
65  template <typename T>
66  static ReturnType create( const T& id, Args... args ) {
68  o << id;
69  return create( o.str(), std::forward<Args>( args )... );
70  }
71  };
72 
74  public:
76  ~Exception() throw() override;
77  const char* what() const throw() override;
78 
79  private:
81  };
82  }
83  } // namespace PluginService
84 } // namespace Gaudi
85 
86 #endif //_GAUDI_PLUGIN_SERVICE_H_
PluginServiceDetailsV1.h
std::string
STL class.
Gaudi::PluginService::v1::Factory::create
static ReturnType create(const std::string &id, Args... args)
Definition: PluginServiceV1.h:60
std::exception
STL class.
GaudiPartProp.tests.v1
v1
Definition: tests.py:39
GaudiMP.FdsRegistry.msg
msg
Definition: FdsRegistry.py:19
gaudirun.c
c
Definition: gaudirun.py:525
GaudiPartProp.tests.id
id
Definition: tests.py:111
Gaudi::PluginService::v1::Factory
Class wrapping the signature for a factory with any number of arguments.
Definition: PluginServiceV1.h:55
GAUDIPS_EXPORT
#define GAUDIPS_EXPORT
Definition: PluginServiceCommon.h:31
Gaudi::PluginService::v1::Factory::ReturnType
R ReturnType
Definition: PluginServiceV1.h:57
Gaudi::PluginService::v1::Exception
Definition: PluginServiceV1.h:73
Gaudi
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
Definition: __init__.py:1
GAUDI_PLUGIN_SERVICE_V1_INLINE
#define GAUDI_PLUGIN_SERVICE_V1_INLINE
Definition: PluginServiceCommon.h:18
std::ostringstream
STL class.
gaudirun.args
args
Definition: gaudirun.py:336
Gaudi::PluginService::v1::Exception::m_msg
std::string m_msg
Definition: PluginServiceV1.h:80
Gaudi::PluginService::v1::Factory::FuncType
R(* FuncType)(Args &&...)
Definition: PluginServiceV1.h:58
std::ostringstream::str
T str(T... args)
Gaudi::PluginService::v1::Factory::create
static ReturnType create(const T &id, Args... args)
Definition: PluginServiceV1.h:66