The Gaudi Framework  master (594c33fa)
Gaudi::PluginService::v2::DeclareFactory< T, F > Struct Template Reference

Helper to declare the factory implementation for a user defined type T. More...

#include </builds/gaudi/Gaudi/GaudiPluginService/include/Gaudi/PluginServiceV2.h>

Public Types

using DefaultFactory = Details::DefaultFactory< T, F >
 

Public Member Functions

 DeclareFactory (typename F::FactoryType f=DefaultFactory{}, Details::Registry::Properties props={}, source_location src_loc=source_location::current())
 
 DeclareFactory (const std::string &id, typename F::FactoryType f=DefaultFactory{}, Details::Registry::Properties props={}, [[maybe_unused]] source_location src_loc=source_location::current())
 
 DeclareFactory (Details::Registry::Properties props, source_location src_loc=source_location::current())
 

Static Private Member Functions

static std::string libraryName ()
 Helper to record the name of the library that declare the factory. More...
 

Detailed Description

template<typename T, typename F = typename T::Factory>
struct Gaudi::PluginService::v2::DeclareFactory< T, F >

Helper to declare the factory implementation for a user defined type T.

The basic use is:

namespace {
Gaudi::PluginService::DeclareFactory<MyComponent> __some_random_name;
}

which is the equivalent of DECLARE_COMPONENT( MyComponent ).

It's possible to specify a custom factory type (instead of the default type alias MyComponent::Factory):

namespace {
using namespace Gaudi::PluginService;
DeclareFactory<MyComponent, Factory<MyBase*( int, int )>> __some_random_name;
}

We can pass arguments to the constructor to use a custom factory function, or a special id, or properties:

namespace {
using namespace Gaudi::PluginService;
DeclareFactory<MyComponent> __some_random_name( "special-id",
[]() -> MyComponent::Factory::ReturnType {
return std::make_unique<MyComponent>( "special-id" );
},
{{"MyProperty", "special"}} );
}

Definition at line 136 of file PluginServiceV2.h.

Member Typedef Documentation

◆ DefaultFactory

template<typename T , typename F = typename T::Factory>
using Gaudi::PluginService::v2::DeclareFactory< T, F >::DefaultFactory = Details::DefaultFactory<T, F>

Definition at line 137 of file PluginServiceV2.h.

Constructor & Destructor Documentation

◆ DeclareFactory() [1/3]

template<typename T , typename F = typename T::Factory>
Gaudi::PluginService::v2::DeclareFactory< T, F >::DeclareFactory ( typename F::FactoryType  f = DefaultFactory{},
Details::Registry::Properties  props = {},
source_location  src_loc = source_location::current() 
)
inline

Definition at line 139 of file PluginServiceV2.h.

139  {}, Details::Registry::Properties props = {},
140  source_location src_loc = source_location::current() )
141  : DeclareFactory( Details::demangle<T>(), std::move( f ), std::move( props ), src_loc ) {}

◆ DeclareFactory() [2/3]

template<typename T , typename F = typename T::Factory>
Gaudi::PluginService::v2::DeclareFactory< T, F >::DeclareFactory ( const std::string id,
typename F::FactoryType  f = DefaultFactory{},
Details::Registry::Properties  props = {},
[[maybe_unused] ] source_location  src_loc = source_location::current() 
)
inline

Definition at line 143 of file PluginServiceV2.h.

143  {},
144  Details::Registry::Properties props = {},
145  [[maybe_unused]] source_location src_loc = source_location::current() ) {
146  using Details::Registry;
147 
148  if ( props.find( "ClassName" ) == end( props ) ) props.emplace( "ClassName", Details::demangle<T>() );
149  // keep only the file name
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();
156  Registry::instance().add( id, { libraryName(), std::move( f ), std::move( props ) } );
157  }

◆ DeclareFactory() [3/3]

template<typename T , typename F = typename T::Factory>
Gaudi::PluginService::v2::DeclareFactory< T, F >::DeclareFactory ( Details::Registry::Properties  props,
source_location  src_loc = source_location::current() 
)
inline

Definition at line 159 of file PluginServiceV2.h.

160  : DeclareFactory( DefaultFactory{}, std::move( props ), src_loc ) {}

Member Function Documentation

◆ libraryName()

template<typename T , typename F = typename T::Factory>
static std::string Gaudi::PluginService::v2::DeclareFactory< T, F >::libraryName ( )
inlinestaticprivate

Helper to record the name of the library that declare the factory.

Definition at line 164 of file PluginServiceV2.h.

164 { return Details::getDSONameFor( reinterpret_cast<void*>( libraryName ) ); }

The documentation for this struct was generated from the following file:
std::move
T move(T... args)
gaudirun.s
string s
Definition: gaudirun.py:346
Gaudi::PluginService::v2::DeclareFactory::libraryName
static std::string libraryName()
Helper to record the name of the library that declare the factory.
Definition: PluginServiceV2.h:164
check_ParticleID.props
props
Definition: check_ParticleID.py:21
std::stringstream
STL class.
Gaudi::PluginService
See Gaudi::PluginService.
Definition: PluginServiceDetailsV1.h:28
Gaudi::PluginService::v2::Details::getDSONameFor
std::string getDSONameFor(void *fptr)
Definition: PluginServiceV2.cpp:348
Gaudi::PluginService::v2::DeclareFactory::DeclareFactory
DeclareFactory(typename F::FactoryType f=DefaultFactory{}, Details::Registry::Properties props={}, source_location src_loc=source_location::current())
Definition: PluginServiceV2.h:139
Gaudi::PluginService::Details::source_location::current
static constexpr source_location current(const char *__file=__builtin_FILE(), const char *__func=__builtin_FUNCTION(), int __line=__builtin_LINE(), int __col=0) noexcept
Definition: PluginServiceV2.h:45
Gaudi::PluginService::v2::DeclareFactory::DefaultFactory
Details::DefaultFactory< T, F > DefaultFactory
Definition: PluginServiceV2.h:137
IOTest.end
end
Definition: IOTest.py:125