The Gaudi Framework  v29r0 (ff2e7097)
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 
18 #include <string>
19 #include <typeinfo>
20 #include <utility>
21 
22 #define DECLARE_FACTORY_WITH_ID( type, id, factory ) _INTERNAL_DECLARE_FACTORY( type, id, factory, __LINE__ )
23 
24 #define DECLARE_FACTORY( type, factory ) \
25  DECLARE_FACTORY_WITH_ID( type, ::Gaudi::PluginService::Details::demangle<type>(), factory )
26 
27 #define DECLARE_FACTORY_WITH_CREATOR_AND_ID( type, typecreator, id, factory ) \
28  _INTERNAL_DECLARE_FACTORY_WITH_CREATOR( type, typecreator, id, factory, __LINE__ )
29 
30 #define DECLARE_FACTORY_WITH_CREATOR( type, typecreator, factory ) \
31  DECLARE_FACTORY_WITH_CREATOR_AND_ID( type, typecreator, ::Gaudi::PluginService::Details::demangle<type>(), factory )
32 
33 #define DECLARE_COMPONENT( type ) DECLARE_FACTORY( type, type::Factory )
34 
35 #define DECLARE_COMPONENT_WITH_ID( type, id ) DECLARE_FACTORY_WITH_ID( type, id, type::Factory )
36 
37 namespace Gaudi
38 {
39  namespace PluginService
40  {
41 
42 #if !defined( __REFLEX__ ) || defined( ATLAS )
43  template <typename R, typename... Args>
45  class Factory
46  {
47  public:
48  typedef R ReturnType;
49  typedef R ( *FuncType )( Args&&... );
50 
51  static ReturnType create( const std::string& id, Args... args )
52  {
53  const FuncType c = Details::getCreator<FuncType>( id );
54  return c ? ( *c )( std::forward<Args>( args )... ) : 0;
55  }
56 
57  template <typename T>
58  static ReturnType create( const T& id, Args... args )
59  {
61  o << id;
62  return create( o.str(), std::forward<Args>( args )... );
63  }
64  };
65 #endif
66 
68  {
69  public:
71  ~Exception() throw() override;
72  const char* what() const throw() override;
73 
74  private:
76  };
77  }
78 }
79 
80 #endif //_GAUDI_PLUGIN_SERVICE_H_
static ReturnType create(const T &id, Args...args)
Definition: PluginService.h:58
static ReturnType create(const std::string &id, Args...args)
Definition: PluginService.h:51
#define GAUDIPS_EXPORT
STL class.
STL class.
Class wrapping the signature for a factory with any number of arguments.
Definition: PluginService.h:45
Helper functions to set/get the application return code.
Definition: __init__.py:1