1 #ifndef _GAUDI_PLUGIN_SERVICE_V2_H_ 2 #define _GAUDI_PLUGIN_SERVICE_V2_H_ 21 #include <type_traits> 28 namespace PluginService
38 template <
typename R,
typename... Args>
39 struct Factory<R( Args... )> {
40 using Traits = Details::Traits<R( Args... )>;
50 return Details::Registry::instance().get<
FactoryType>( Details::stringify_id(
id ) )(
51 std::forward<Args>(
args )... );
52 }
catch ( std::bad_any_cast& ) {
88 template <
typename T,
typename F =
typename T::Factory>
100 using Details::Registry;
102 if ( props.find(
"ClassName" ) ==
end( props ) ) props.emplace(
"ClassName", Details::demangle<T>() );
119 #define _PS_V2_DECLARE_COMPONENT( type ) \ 122 ::Gaudi::PluginService::v2::DeclareFactory<type> _PS_V2_INTERNAL_FACTORY_REGISTER_CNAME{}; \ 125 #define _PS_V2_DECLARE_COMPONENT_WITH_ID( type, id ) \ 128 ::Gaudi::PluginService::v2::DeclareFactory<type> _PS_V2_INTERNAL_FACTORY_REGISTER_CNAME{ \ 129 ::Gaudi::PluginService::v2::Details::stringify_id( id )}; \ 132 #define _PS_V2_DECLARE_FACTORY( type, factory ) \ 135 ::Gaudi::PluginService::v2::DeclareFactory<type, factory> _PS_V2_INTERNAL_FACTORY_REGISTER_CNAME{}; \ 138 #define _PS_V2_DECLARE_FACTORY_WITH_ID( type, id, factory ) \ 141 ::Gaudi::PluginService::v2::DeclareFactory<type, factory> _PS_V2_INTERNAL_FACTORY_REGISTER_CNAME{ \ 142 ::Gaudi::PluginService::v2::Details::stringify_id( id )}; \ 145 #if GAUDI_PLUGIN_SERVICE_USE_V2 146 #define DECLARE_COMPONENT( type ) _PS_V2_DECLARE_COMPONENT( type ) 147 #define DECLARE_COMPONENT_WITH_ID( type, id ) _PS_V2_DECLARE_COMPONENT_WITH_ID( type, id ) 148 #define DECLARE_FACTORY( type, factory ) _PS_V2_DECLARE_FACTORY( type, factory ) 149 #define DECLARE_FACTORY_WITH_ID( type, id, factory ) _PS_V2_DECLARE_FACTORY_WITH_ID( type, id, factory ) 152 #endif //_GAUDI_PLUGIN_SERVICE_H_
#define GAUDI_PLUGIN_SERVICE_V2_INLINE
DeclareFactory(Details::Registry::Properties props)
Details::Traits< R(Args...)> Traits
std::vector< Gaudi::Details::PropertyBase * > Properties
Helper to declare the factory implementation for a user defined type T.
DeclareFactory(typename F::FactoryType f=DefaultFactory{}, Details::Registry::Properties props={})
static ReturnType create(const T &id, Args...args)
Function to call to create an instance of type identified by id and that uses this factory signature...
std::string getDSONameFor(void *fptr)
void reportBadAnyCast(const std::type_info &factory_type, const std::string &id)
typename Traits::FactoryType FactoryType
Details::DefaultFactory< T, F > DefaultFactory
typename Traits::ReturnType ReturnType
DeclareFactory(const std::string &id, typename F::FactoryType f=DefaultFactory{}, Details::Registry::Properties props={})
static std::string libraryName()
Helper to record the name of the library that declare the factory.
Helper functions to set/get the application return code.