22#if __has_include( <source_location> ) && !defined (__CLING__)
23# include <source_location>
24namespace Gaudi::PluginService::Details {
25 using std::source_location;
28#elif !defined( __clang__ ) && __GNUC__ >= 8
29# include <experimental/source_location>
30namespace Gaudi::PluginService::Details {
31 using std::experimental::source_location;
34namespace Gaudi::PluginService::Details {
36 struct source_location {
39 static constexpr source_location current(
const char* __file = __builtin_FILE(),
40 const char* __func = __builtin_FUNCTION(),
int __line = __builtin_LINE(),
41 int __col = 0 ) noexcept {
42 source_location __loc;
43 __loc._M_file = __file;
44 __loc._M_func = __func;
45 __loc._M_line = __line;
50 constexpr source_location() noexcept : _M_file(
"unknown" ), _M_func( _M_file ), _M_line( 0 ), _M_col( 0 ) {}
53 constexpr uint_least32_t
line() const noexcept {
return _M_line; }
54 constexpr uint_least32_t column() const noexcept {
return _M_col; }
55 constexpr const char* file_name() const noexcept {
return _M_file; }
56 constexpr const char* function_name() const noexcept {
return _M_func; }
61 uint_least32_t _M_line;
62 uint_least32_t _M_col;
72 using Gaudi::PluginService::Details::source_location;
80 template <
typename R,
typename... Args>
81 struct Factory<R( Args... )> {
82 using Traits = Details::Traits<R( Args... )>;
83 using ReturnType =
typename Traits::ReturnType;
84 using FactoryType =
typename Traits::FactoryType;
85 using ReturnValueType = R;
89 static ReturnType create(
const T&
id, Args... args ) {
91 return Details::Registry::instance().get<FactoryType>( Details::stringify_id(
id ) )(
92 std::forward<Args>( args )... );
93 }
catch ( std::bad_any_cast& ) {
94 Details::reportBadAnyCast(
typeid( FactoryType ), Details::stringify_id(
id ) );
129 template <
typename T,
typename F =
typename T::Factory>
130 struct DeclareFactory {
131 using DefaultFactory = Details::DefaultFactory<T, F>;
133 DeclareFactory(
typename F::FactoryType f = DefaultFactory{}, Details::Registry::Properties
props = {},
134 source_location src_loc = source_location::current() )
137 DeclareFactory(
const std::string&
id,
typename F::FactoryType f = DefaultFactory{},
138 Details::Registry::Properties
props = {},
139 [[maybe_unused]] source_location src_loc = source_location::current() ) {
140 using Details::Registry;
142 if (
props.find(
"ClassName" ) ==
end( props ) )
props.emplace(
"ClassName", Details::demangle<T>() );
144 std::string_view fn = src_loc.file_name();
145 auto pos = fn.rfind(
'/' );
146 if ( pos != std::string_view::npos ) { fn.remove_prefix( pos + 1 ); }
148 s << fn <<
':' << src_loc.line();
149 props[
"declaration_location"] =
s.str();
150 Registry::instance().add(
id, { libraryName(), std::move( f ), std::move( props ) } );
153 DeclareFactory( Details::Registry::Properties props, source_location src_loc = source_location::current() )
154 : DeclareFactory( DefaultFactory{},
std::move(
props ), src_loc ) {}
158 static std::string libraryName() {
return Details::getDSONameFor(
reinterpret_cast<void*
>( libraryName ) ); }
164#define _PS_V2_DECLARE_COMPONENT( type ) \
166 ::Gaudi::PluginService::v2::DeclareFactory<type> _PS_V2_INTERNAL_FACTORY_REGISTER_CNAME{}; \
169#define _PS_V2_DECLARE_COMPONENT_WITH_ID( type, id ) \
171 ::Gaudi::PluginService::v2::DeclareFactory<type> _PS_V2_INTERNAL_FACTORY_REGISTER_CNAME{ \
172 ::Gaudi::PluginService::v2::Details::stringify_id( id ) }; \
175#define _PS_V2_DECLARE_FACTORY( type, factory ) \
177 ::Gaudi::PluginService::v2::DeclareFactory<type, factory> _PS_V2_INTERNAL_FACTORY_REGISTER_CNAME{}; \
180#define _PS_V2_DECLARE_FACTORY_WITH_ID( type, id, factory ) \
182 ::Gaudi::PluginService::v2::DeclareFactory<type, factory> _PS_V2_INTERNAL_FACTORY_REGISTER_CNAME{ \
183 ::Gaudi::PluginService::v2::Details::stringify_id( id ) }; \
186#define _PS_V2_DECLARE_COMPONENT_PROPERTY( id, name, value ) \
188 struct _PS_V2_INTERNAL_SET_PROPERTY { \
189 _PS_V2_INTERNAL_SET_PROPERTY() { \
190 ::Gaudi::PluginService::v2::Details::Registry::instance().addProperty( #id, name, value ); \
192 } _ps_v2_internal_set_property; \
195#if GAUDI_PLUGIN_SERVICE_USE_V2
196# define DECLARE_COMPONENT( type ) _PS_V2_DECLARE_COMPONENT( type )
197# define DECLARE_COMPONENT_WITH_ID( type, id ) _PS_V2_DECLARE_COMPONENT_WITH_ID( type, id )
198# define DECLARE_FACTORY( type, factory ) _PS_V2_DECLARE_FACTORY( type, factory )
199# define DECLARE_FACTORY_WITH_ID( type, id, factory ) _PS_V2_DECLARE_FACTORY_WITH_ID( type, id, factory )
200# define DECLARE_COMPONENT_PROPERTY( id, name, value ) _PS_V2_DECLARE_COMPONENT_PROPERTY( id, name, value )
#define GAUDI_PLUGIN_SERVICE_V2_INLINE
GAUDIPS_API std::string demangle(const std::type_info &id)
Return a canonical name for type_info object (implementation borrowed from GaudiKernel/System).
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...