1 #ifndef _GAUDI_PLUGIN_SERVICE_DETAILS_V2_H_ 2 #define _GAUDI_PLUGIN_SERVICE_DETAILS_V2_H_ 18 #if __cplusplus >= 201703 21 #include <boost/any.hpp> 25 using boost::any_cast;
26 using boost::bad_any_cast;
42 namespace PluginService
57 template <
typename R,
typename... Args>
58 struct Traits<R( Args... )> {
76 template <
typename ID>
97 enum Level {
Debug = 0, Info = 1, Warning = 2, Error = 3 };
100 inline Level level()
const {
return m_level; }
102 inline void info(
const std::string&
msg ) { report( Info, msg ); }
104 inline void warning(
const std::string&
msg ) { report( Warning, msg ); }
105 inline void error(
const std::string&
msg ) { report( Error, msg ); }
132 inline bool is_set()
const 134 #if __cplusplus >= 201703 135 return factory.has_value();
137 return !factory.empty();
140 Properties::mapped_type getprop(
const Properties::key_type&
name )
const;
147 template <
typename F>
148 F
get(
const KeyType& id )
150 const FactoryInfo& info = Registry::instance().getInfo(
id,
true );
151 #ifdef GAUDI_REFLEX_COMPONENT_ALIASES 152 if ( !info.getprop(
"ReflexName" ).empty() ) {
153 const std::string real_name = info.getprop(
"ClassName" );
154 logger().
warning(
"requesting factory via old name '" +
id +
"' use '" +
155 ( real_name.
empty() ?
"<undefined>" : real_name ) +
"' instead" );
158 return std::any_cast<F>( info.factory );
162 static Registry& instance();
165 FactoryInfo&
add(
const KeyType&
id, FactoryInfo info );
168 const FactoryInfo& getInfo(
const KeyType&
id,
const bool load =
false )
const;
171 Registry& addProperty(
const KeyType&
id,
const KeyType& k,
const std::string& v );
188 Registry(
const Registry& ) =
delete;
201 FactoryMap m_factories;
211 template <
typename,
typename>
212 struct DefaultFactory;
213 template <
typename T,
typename R,
typename... Args>
214 struct DefaultFactory<T, Factory<R( Args... )>> {
215 inline typename Factory<R( Args... )>::ReturnType
operator()( Args...
args )
217 return std::make_unique<T>( std::forward<Args>(
args )... );
235 #define _PS_V2_INTERNAL_FACTORY_MAKE_REGISTER_CNAME_TOKEN( serial ) _register_##serial 236 #define _PS_V2_INTERNAL_FACTORY_MAKE_REGISTER_CNAME( serial ) \ 237 _PS_V2_INTERNAL_FACTORY_MAKE_REGISTER_CNAME_TOKEN( serial ) 238 #define _PS_V2_INTERNAL_FACTORY_REGISTER_CNAME _PS_V2_INTERNAL_FACTORY_MAKE_REGISTER_CNAME( __LINE__ ) 240 #endif //_GAUDI_PLUGIN_SERVICE_DETAILS_H_
#define GAUDI_PLUGIN_SERVICE_V2_INLINE
GAUDIPS_API void setLogger(Logger *logger)
Set the logger instance to use.
void warning(const std::string &msg)
std::string getDSONameFor(void *fptr)
void reportBadAnyCast(const std::type_info &factory_type, const std::string &id)
GAUDIPS_API Logger & logger()
Return the current logger instance.
GAUDIPS_API int Debug()
Backward compatibility with Reflex.
GAUDIPS_API std::string demangle(const std::type_info &id)
Return a canonical name for type_info object (implementation borrowed from GaudiKernel/System).
virtual Out operator()(const vector_of_const_< In > &inputs) const =0
GAUDIPS_API void SetDebug(int debugLevel)
Backward compatibility with Reflex.
Helper functions to set/get the application return code.