11 #ifndef _GAUDI_PLUGIN_SERVICE_V2_H_
12 #define _GAUDI_PLUGIN_SERVICE_V2_H_
23 #include <string_view>
24 #include <type_traits>
28 #if __cplusplus > 201703L && __has_include( <source_location> ) && !defined (__CLING__)
29 # include <source_location>
31 using std::source_location;
34 #elif __cplusplus >= 201402L && !defined( __clang__ ) && __GNUC__ >= 8
35 # include <experimental/source_location>
37 using std::experimental::source_location;
46 const char* __func = __builtin_FUNCTION(),
int __line = __builtin_LINE(),
47 int __col = 0 ) noexcept {
59 constexpr uint_least32_t
line() const noexcept {
return _M_line; }
60 constexpr uint_least32_t
column() const noexcept {
return _M_col; }
76 namespace PluginService {
86 template <
typename R,
typename... Args>
87 struct Factory<R( Args... )> {
88 using Traits = Details::Traits<R( Args... )>;
97 return Details::Registry::instance().get<
FactoryType>( Details::stringify_id(
id ) )(
98 std::forward<Args>(
args )... );
99 }
catch ( std::bad_any_cast& ) {
135 template <
typename T,
typename F =
typename T::Factory>
144 Details::Registry::Properties
props = {},
146 using Details::Registry;
148 if (
props.find(
"ClassName" ) ==
end(
props ) )
props.emplace(
"ClassName", Details::demangle<T>() );
150 std::string_view fn = src_loc.file_name();
151 auto pos = fn.rfind(
'/' );
152 if ( pos != std::string_view::npos ) { fn.remove_prefix( pos + 1 ); }
154 s << fn <<
':' << src_loc.line();
155 props[
"declaration_location"] =
s.str();
170 #define _PS_V2_DECLARE_COMPONENT( type ) \
172 ::Gaudi::PluginService::v2::DeclareFactory<type> _PS_V2_INTERNAL_FACTORY_REGISTER_CNAME{}; \
175 #define _PS_V2_DECLARE_COMPONENT_WITH_ID( type, id ) \
177 ::Gaudi::PluginService::v2::DeclareFactory<type> _PS_V2_INTERNAL_FACTORY_REGISTER_CNAME{ \
178 ::Gaudi::PluginService::v2::Details::stringify_id( id ) }; \
181 #define _PS_V2_DECLARE_FACTORY( type, factory ) \
183 ::Gaudi::PluginService::v2::DeclareFactory<type, factory> _PS_V2_INTERNAL_FACTORY_REGISTER_CNAME{}; \
186 #define _PS_V2_DECLARE_FACTORY_WITH_ID( type, id, factory ) \
188 ::Gaudi::PluginService::v2::DeclareFactory<type, factory> _PS_V2_INTERNAL_FACTORY_REGISTER_CNAME{ \
189 ::Gaudi::PluginService::v2::Details::stringify_id( id ) }; \
192 #define _PS_V2_DECLARE_COMPONENT_PROPERTY( id, name, value ) \
194 struct _PS_V2_INTERNAL_SET_PROPERTY { \
195 _PS_V2_INTERNAL_SET_PROPERTY() { \
196 ::Gaudi::PluginService::v2::Details::Registry::instance().addProperty( #id, name, value ); \
198 } _ps_v2_internal_set_property; \
201 #if GAUDI_PLUGIN_SERVICE_USE_V2
202 # define DECLARE_COMPONENT( type ) _PS_V2_DECLARE_COMPONENT( type )
203 # define DECLARE_COMPONENT_WITH_ID( type, id ) _PS_V2_DECLARE_COMPONENT_WITH_ID( type, id )
204 # define DECLARE_FACTORY( type, factory ) _PS_V2_DECLARE_FACTORY( type, factory )
205 # define DECLARE_FACTORY_WITH_ID( type, id, factory ) _PS_V2_DECLARE_FACTORY_WITH_ID( type, id, factory )
206 # define DECLARE_COMPONENT_PROPERTY( id, name, value ) _PS_V2_DECLARE_COMPONENT_PROPERTY( id, name, value )
209 #endif //_GAUDI_PLUGIN_SERVICE_H_