Go to the documentation of this file.
11 #ifndef GAUDIKERNEL_PROPERTYHOLDER_H
12 #define GAUDIKERNEL_PROPERTYHOLDER_H
44 template <
typename TYPE,
typename VERIFIER,
typename HANDLERS>
45 constexpr
bool is_gaudi_property_v<Gaudi::Property<TYPE, VERIFIER, HANDLERS>> =
true;
50 inline bool iequal( std::string_view
v1, std::string_view
v2 ) {
78 static_assert( std::is_base_of_v<IProperty, BASE> && std::is_base_of_v<INamedInterface, BASE>,
79 "PropertyHolder template argument must inherit from IProperty and INamedInterface" );
102 assertUniqueName( prop.
name() );
103 m_properties.push_back( &prop );
109 template <
typename TYPE>
110 requires( !Gaudi::Details::is_gaudi_property_v<TYPE> )
112 const std::string& doc =
"none" ) {
113 auto make_property = [&](
const std::string&
n, TYPE&
v ) {
114 if constexpr (
requires {
typename TYPE::PropertyType; } ) {
115 return std::make_unique<typename TYPE::PropertyType>(
n,
v );
117 return std::make_unique<Gaudi::Property<TYPE&>>(
n,
v );
120 m_todelete.push_back( make_property(
name, value ) );
124 return &declareProperty( *p );
129 template <
class TYPE,
class VERIFIER,
class HANDLERS>
132 const std::string& doc =
"none" ) {
137 return &declareProperty( *p );
143 const std::string& rname =
"" ) {
144 if ( !rsvc )
return nullptr;
145 const std::string& nam = rname.empty() ?
name : rname;
147 m_remoteProperties.emplace_back( RemProperty{
name, rsvc, nam } );
174 return setPropertyRepr(
name, value );
185 }
catch (
const std::invalid_argument& err ) {
206 if ( !p )
throw std::out_of_range(
"Property " + std::string{
name } +
" not found." );
225 const std::vector<Gaudi::Details::PropertyBase*>&
getProperties()
const override {
return m_properties; }
231 return any_of(
begin( m_properties ),
end( m_properties ),
235 any_of(
begin( m_remoteProperties ),
end( m_remoteProperties ),
246 for (
const auto& it : m_remoteProperties ) {
256 auto set_prop = [&optsSvc,
this](
auto prop ) { optsSvc.
bind( this->
name(), prop ); };
258 std::for_each(
begin( m_remoteProperties ),
end( m_remoteProperties ), [&set_prop,
this](
auto& rem ) {
259 if ( rem.owner ) set_prop( this->property( rem.remName, rem.owner->getProperties() ) );
266 const std::vector<Gaudi::Details::PropertyBase*>&
props )
const {
268 return p && Gaudi::Utils::iequal( p->name(), name );
270 return ( it !=
props.end() ) ? *it :
nullptr;
278 if ( !
msgSvc ) std::cerr <<
"error: cannot get MessageSvc!" << std::endl;
280 log <<
MSG::WARNING <<
"duplicated property name '" <<
name <<
"', see https://its.cern.ch/jira/browse/GAUDI-1023"
285 typedef std::vector<Gaudi::Details::PropertyBase*>
Properties;
298 std::vector<std::unique_ptr<Gaudi::Details::PropertyBase>>
m_todelete;
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
const std::string name() const
property name
void toupper(std::string &s)
Gaudi::Details::PropertyBase * declareProperty(const std::string &name, Gaudi::Property< TYPE, VERIFIER, HANDLERS > &prop, const std::string &doc="none")
Declare a PropertyBase instance setting name and documentation.
StatusCode parse(GaudiUtils::HashMap< K, V > &result, std::string_view input)
Basic parser for the types of HashMap used in DODBasicMapper.
StatusCode setProperty(const std::string &name, const Gaudi::Details::PropertyBase &p) override
set the property from another property with a different name
StatusCode getProperty(Gaudi::Details::PropertyBase *p) const override
get the property
Helper class to implement the IProperty interface.
virtual StatusCode fromString(const std::string &value)=0
string -> value
void assertUniqueName(std::string_view name) const
Issue a runtime warning if the name is already present in the list of properties (see GAUDI-1023).
std::vector< std::unique_ptr< Gaudi::Details::PropertyBase > > m_todelete
Properties owned by PropertyHolder, to be deleted.
Gaudi::Details::PropertyBase * declareRemoteProperty(const std::string &name, IProperty *rsvc, const std::string &rname="")
Declare a remote property.
void bindPropertiesTo(Gaudi::Interfaces::IOptionsSvc &optsSvc)
Gaudi::Details::PropertyBase * property(std::string_view name) const
\fixme property and bindPropertiesTo should be protected
const std::vector< Gaudi::Details::PropertyBase * > & getProperties() const override
get all properties
Gaudi::Details::PropertyBase * property(std::string_view name, const std::vector< Gaudi::Details::PropertyBase * > &props) const
get the property by name form the proposed list
GAUDI_API ISvcLocator * svcLocator()
virtual SmartIF< IService > & service(const Gaudi::Utils::TypeNameString &typeName, const bool createIf=true)=0
Returns a smart pointer to a service.
virtual void bind(const std::string &prefix, Gaudi::Details::PropertyBase *property)=0
Register a Gaudi::Property instance to the option service.
void setDocumentation(std::string value)
set the documentation string
AttribStringParser::Iterator begin(const AttribStringParser &parser)
void for_each(ContainerOfSynced &c, Fun &&f)
StatusCode setProperty(const std::string &s) override
set the property from the formatted string
StatusCode setPropertyRepr(const std::string &n, const std::string &r) override
set the property from name and value string representation
bool iequal(std::string_view v1, std::string_view v2)
Helper for case insensitive string comparison.
AttribStringParser::Iterator end(const AttribStringParser &)
PropertyHolder(const PropertyHolder &)=delete
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
requires(!Gaudi::Details::is_gaudi_property_v< TYPE >) Gaudi
Helper to wrap a regular data member and use it as a regular property.
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Details::PropertyBase &prop)
Declare a property.
Properties m_properties
Collection of all declared properties.
constexpr static const auto SUCCESS
virtual const std::vector< Gaudi::Details::PropertyBase * > & getProperties() const =0
Get list of properties.
const Gaudi::Details::PropertyBase & getProperty(std::string_view name) const override
get the property by name
virtual std::string toString() const =0
value -> string
std::vector< Gaudi::Details::PropertyBase * > Properties
void setName(std::string value)
set the new value for the property name
std::vector< RemProperty > RemoteProperties
StatusCode getProperty(std::string_view n, std::string &v) const override
convert the property to the string
constexpr static const auto FAILURE
Interface for a component that manages application configuration options.
constexpr bool is_gaudi_property_v
Implementation of property with value of concrete type.
PropertyHolder & operator=(const PropertyHolder &)=delete
GAUDI_API bool hasProperty(const IProperty *p, std::string_view name)
simple function which check the existence of the property with the given name.
RemoteProperties m_remoteProperties
Collection of all declared remote properties.
bool hasProperty(std::string_view name) const override
Return true if we have a property with the given name.
StatusCode setProperty(const Gaudi::Details::PropertyBase &p)
Set the property from a property.