The Gaudi Framework  master (37c0b60a)
PropertyHolder< BASE > Class Template Reference

Helper class to implement the IProperty interface. More...

#include </builds/gaudi/Gaudi/GaudiKernel/include/GaudiKernel/PropertyHolder.h>

Inheritance diagram for PropertyHolder< BASE >:
Collaboration diagram for PropertyHolder< BASE >:

Classes

struct  RemProperty
 

Public Types

using PropertyHolderImpl = PropertyHolder< BASE >
 Typedef used to refer to this class from derived classes, as in. More...
 

Public Member Functions

 PropertyHolder ()=default
 
Gaudi::Details::PropertyBasedeclareProperty (Gaudi::Details::PropertyBase &prop)
 Declare a property. More...
 
template<typename TYPE , typename = std::enable_if_t<!Gaudi::Details::is_gaudi_property<TYPE>::value>>
Gaudi::Details::PropertyBasedeclareProperty (const std::string &name, TYPE &value, const std::string &doc="none")
 Helper to wrap a regular data member and use it as a regular property. More...
 
template<class TYPE , class VERIFIER , class HANDLERS >
Gaudi::Details::PropertyBasedeclareProperty (const std::string &name, Gaudi::Property< TYPE, VERIFIER, HANDLERS > &prop, const std::string &doc="none")
 Declare a PropertyBase instance setting name and documentation. More...
 
Gaudi::Details::PropertyBasedeclareRemoteProperty (const std::string &name, IProperty *rsvc, const std::string &rname="")
 Declare a remote property. More...
 
StatusCode setProperty (const std::string &name, const Gaudi::Details::PropertyBase &p) override
 set the property from another property with a different name More...
 
StatusCode setProperty (const std::string &s) override
 set the property from the formatted string More...
 
StatusCode setPropertyRepr (const std::string &n, const std::string &r) override
 set the property from name and value string representation More...
 
StatusCode getProperty (Gaudi::Details::PropertyBase *p) const override
 get the property More...
 
const Gaudi::Details::PropertyBasegetProperty (std::string_view name) const override
 get the property by name More...
 
StatusCode getProperty (std::string_view n, std::string &v) const override
 convert the property to the string More...
 
const std::vector< Gaudi::Details::PropertyBase * > & getProperties () const override
 get all properties More...
 
bool hasProperty (std::string_view name) const override
 Return true if we have a property with the given name. More...
 
Gaudi::Details::PropertyBaseproperty (std::string_view name) const
 \fixme property and bindPropertiesTo should be protected More...
 
void bindPropertiesTo (Gaudi::Interfaces::IOptionsSvc &optsSvc)
 
StatusCode setProperty (const Gaudi::Details::PropertyBase &p)
 Set the property from a property. More...
 
virtual StatusCode setProperty (const std::string &name, const Gaudi::Details::PropertyBase &p)=0
 Set the property from a property with a different name. More...
 
virtual StatusCode setProperty (const std::string &s)=0
 Set the property by string. More...
 
StatusCode setProperty (const std::string &name, const char *v)
 Special case for string literals. More...
 
StatusCode setProperty (const std::string &name, const std::string &v)
 Special case for std::string. More...
 
template<class TYPE , typename = std::enable_if_t<!std::is_base_of_v<Gaudi::Details::PropertyBase, TYPE>>>
StatusCode setProperty (const std::string &name, const TYPE &value)
 set the property form the value More...
 
 PropertyHolder (const PropertyHolder &)=delete
 
PropertyHolderoperator= (const PropertyHolder &)=delete
 

Private Types

typedef std::vector< Gaudi::Details::PropertyBase * > Properties
 
typedef std::vector< RemPropertyRemoteProperties
 

Private Member Functions

Gaudi::Details::PropertyBaseproperty (std::string_view name, const std::vector< Gaudi::Details::PropertyBase * > &props) const
 get the property by name form the proposed list More...
 
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). More...
 

Private Attributes

Properties m_properties
 Collection of all declared properties. More...
 
RemoteProperties m_remoteProperties
 Collection of all declared remote properties. More...
 
std::vector< std::unique_ptr< Gaudi::Details::PropertyBase > > m_todelete
 Properties owned by PropertyHolder, to be deleted. More...
 

Detailed Description

template<class BASE>
class PropertyHolder< BASE >

Helper class to implement the IProperty interface.

PropertyHolder is used by components base classes (Algorithm, Service, etc.) to provide a default implementation the IProperty interface.

When needing to implement the IProperty interface in a class, it is enough to wrap the base of the class with PropertyHolder, as in

class MyClass : public PropertyHolder<BaseClass> {
// ...
};

where BaseClass should inherit from IProperty and INamedInterface.

Author
Paul Maley
David Quarrie
Marco Clemencic

Definition at line 82 of file PropertyHolder.h.

Member Typedef Documentation

◆ Properties

template<class BASE >
typedef std::vector<Gaudi::Details::PropertyBase*> PropertyHolder< BASE >::Properties
private

Definition at line 282 of file PropertyHolder.h.

◆ PropertyHolderImpl

template<class BASE >
using PropertyHolder< BASE >::PropertyHolderImpl = PropertyHolder<BASE>

Typedef used to refer to this class from derived classes, as in.

class MyClass : public PropertyHolder<BaseClass> {
};

Definition at line 93 of file PropertyHolder.h.

◆ RemoteProperties

template<class BASE >
typedef std::vector<RemProperty> PropertyHolder< BASE >::RemoteProperties
private

Definition at line 288 of file PropertyHolder.h.

Constructor & Destructor Documentation

◆ PropertyHolder() [1/2]

template<class BASE >
PropertyHolder< BASE >::PropertyHolder ( )
default

◆ PropertyHolder() [2/2]

template<class BASE >
PropertyHolder< BASE >::PropertyHolder ( const PropertyHolder< BASE > &  )
delete

prevent copies

Member Function Documentation

◆ assertUniqueName()

template<class BASE >
void PropertyHolder< BASE >::assertUniqueName ( std::string_view  name) const
inlineprivate

Issue a runtime warning if the name is already present in the list of properties (see GAUDI-1023).

Definition at line 272 of file PropertyHolder.h.

272  {
273  if ( hasProperty( name ) ) {
274  auto msgSvc = Gaudi::svcLocator()->service<IMessageSvc>( "MessageSvc" );
275  if ( !msgSvc ) std::cerr << "error: cannot get MessageSvc!" << std::endl;
276  MsgStream log( msgSvc, this->name() );
277  log << MSG::WARNING << "duplicated property name '" << name << "', see https://its.cern.ch/jira/browse/GAUDI-1023"
278  << endmsg;
279  }
280  }

◆ bindPropertiesTo()

template<class BASE >
void PropertyHolder< BASE >::bindPropertiesTo ( Gaudi::Interfaces::IOptionsSvc optsSvc)
inline

Definition at line 252 of file PropertyHolder.h.

252  {
253  auto set_prop = [&optsSvc, this]( auto prop ) { optsSvc.bind( this->name(), prop ); };
254  std::for_each( begin( m_properties ), end( m_properties ), set_prop );
255  std::for_each( begin( m_remoteProperties ), end( m_remoteProperties ), [&set_prop, this]( auto& rem ) {
256  if ( rem.owner ) set_prop( this->property( rem.remName, rem.owner->getProperties() ) );
257  } );
258  }

◆ declareProperty() [1/3]

template<class BASE >
template<class TYPE , class VERIFIER , class HANDLERS >
Gaudi::Details::PropertyBase* PropertyHolder< BASE >::declareProperty ( const std::string name,
Gaudi::Property< TYPE, VERIFIER, HANDLERS > &  prop,
const std::string doc = "none" 
)
inline

Declare a PropertyBase instance setting name and documentation.

Deprecated:
Prefer the signatures using a fully initialized PropertyBase instance.

Definition at line 127 of file PropertyHolder.h.

129  {
130  Gaudi::Details::PropertyBase* p = &prop;
131  p->setName( name );
132 
133  p->setDocumentation( doc );
134  return &declareProperty( *p );
135  }

◆ declareProperty() [2/3]

template<class BASE >
template<typename TYPE , typename = std::enable_if_t<!Gaudi::Details::is_gaudi_property<TYPE>::value>>
Gaudi::Details::PropertyBase* PropertyHolder< BASE >::declareProperty ( const std::string name,
TYPE &  value,
const std::string doc = "none" 
)
inline

Helper to wrap a regular data member and use it as a regular property.

Deprecated:
Prefer the signatures using a a fully initialized PropertyBase instance.

Definition at line 115 of file PropertyHolder.h.

116  {
117  m_todelete.push_back( std::make_unique<Gaudi::Details::PropertyType<TYPE&>>( name, value ) );
119 
120  p->setDocumentation( doc );
121  return &declareProperty( *p );
122  }

◆ declareProperty() [3/3]

template<class BASE >
Gaudi::Details::PropertyBase& PropertyHolder< BASE >::declareProperty ( Gaudi::Details::PropertyBase prop)
inline

Declare a property.

Record a PropertyBase instance to be managed by PropertyHolder.

Definition at line 106 of file PropertyHolder.h.

106  {
107  assertUniqueName( prop.name() );
108  m_properties.push_back( &prop );
109  return prop;
110  }

◆ declareRemoteProperty()

template<class BASE >
Gaudi::Details::PropertyBase* PropertyHolder< BASE >::declareRemoteProperty ( const std::string name,
IProperty rsvc,
const std::string rname = "" 
)
inline

Declare a remote property.

Bind name to the property rname of rsvc.

Definition at line 139 of file PropertyHolder.h.

140  {
141  if ( !rsvc ) return nullptr;
142  const std::string& nam = rname.empty() ? name : rname;
144  m_remoteProperties.emplace_back( RemProperty{ name, rsvc, nam } );
145  return p;
146  }

◆ getProperties()

template<class BASE >
const std::vector<Gaudi::Details::PropertyBase*>& PropertyHolder< BASE >::getProperties ( ) const
inlineoverride

get all properties

See also
IProperty

Definition at line 222 of file PropertyHolder.h.

222 { return m_properties; }

◆ getProperty() [1/3]

template<class BASE >
StatusCode PropertyHolder< BASE >::getProperty ( Gaudi::Details::PropertyBase p) const
inlineoverride

get the property

See also
IProperty

Definition at line 190 of file PropertyHolder.h.

190  {
191  try {
192  const Gaudi::Details::PropertyBase* pp = property( p->name() );
193  if ( pp && pp->load( *p ) ) return StatusCode::SUCCESS;
194  } catch ( ... ) {}
195  return StatusCode::FAILURE;
196  }

◆ getProperty() [2/3]

template<class BASE >
StatusCode PropertyHolder< BASE >::getProperty ( std::string_view  n,
std::string v 
) const
inlineoverride

convert the property to the string

See also
IProperty

Definition at line 210 of file PropertyHolder.h.

210  {
211  // get the property
213  if ( !p ) return StatusCode::FAILURE;
214  // convert the value into the string
215  v = p->toString();
216  return StatusCode::SUCCESS;
217  }

◆ getProperty() [3/3]

template<class BASE >
const Gaudi::Details::PropertyBase& PropertyHolder< BASE >::getProperty ( std::string_view  name) const
inlineoverride

get the property by name

See also
IProperty

Definition at line 201 of file PropertyHolder.h.

201  {
203  if ( !p ) throw std::out_of_range( "Property " + std::string{ name } + " not found." );
204  return *p;
205  }

◆ hasProperty()

template<class BASE >
bool PropertyHolder< BASE >::hasProperty ( std::string_view  name) const
inlineoverride

Return true if we have a property with the given name.

See also
IProperty

Definition at line 227 of file PropertyHolder.h.

227  {
228  return any_of( begin( m_properties ), end( m_properties ),
229  [&name]( const Gaudi::Details::PropertyBase* prop ) {
230  return Gaudi::Utils::iequal( prop->name(), name );
231  } ) ||
233  [&name]( const auto& prop ) { return Gaudi::Utils::iequal( prop.name, name ); } );
234  }

◆ operator=()

template<class BASE >
PropertyHolder& PropertyHolder< BASE >::operator= ( const PropertyHolder< BASE > &  )
delete

◆ property() [1/2]

template<class BASE >
Gaudi::Details::PropertyBase* PropertyHolder< BASE >::property ( std::string_view  name) const
inline

\fixme property and bindPropertiesTo should be protected

Definition at line 238 of file PropertyHolder.h.

238  {
239  // local property ?
241  if ( lp ) return lp;
242  // look for remote property
243  for ( const auto& it : m_remoteProperties ) {
244  if ( !Gaudi::Utils::iequal( it.name, name ) ) continue;
245  const IProperty* p = it.owner;
246  if ( !p ) continue;
247  return property( it.remName, p->getProperties() );
248  }
249  return nullptr; // RETURN
250  }

◆ property() [2/2]

template<class BASE >
Gaudi::Details::PropertyBase* PropertyHolder< BASE >::property ( std::string_view  name,
const std::vector< Gaudi::Details::PropertyBase * > &  props 
) const
inlineprivate

get the property by name form the proposed list

Definition at line 262 of file PropertyHolder.h.

263  {
264  auto it = std::find_if( props.begin(), props.end(), [name]( Gaudi::Details::PropertyBase* p ) {
265  return p && Gaudi::Utils::iequal( p->name(), name );
266  } );
267  return ( it != props.end() ) ? *it : nullptr; // RETURN
268  }

◆ setProperty() [1/8]

template<class BASE >
StatusCode IProperty::setProperty
inline

Set the property from a property.

Definition at line 39 of file IProperty.h.

39 { return setProperty( p.name(), p ); }

◆ setProperty() [2/8]

template<class BASE >
StatusCode IProperty::setProperty
inline

Special case for string literals.

Definition at line 47 of file IProperty.h.

47 { return setProperty( name, std::string{ v } ); }

◆ setProperty() [3/8]

template<class BASE >
StatusCode PropertyHolder< BASE >::setProperty ( const std::string name,
const Gaudi::Details::PropertyBase p 
)
inlineoverride

set the property from another property with a different name

See also
IProperty

Definition at line 157 of file PropertyHolder.h.

157  {
159  if ( pp && pp->assign( p ) ) return StatusCode::SUCCESS;
160  return StatusCode::FAILURE;
161  }

◆ setProperty() [4/8]

template<class BASE >
virtual StatusCode IProperty::setProperty

Set the property from a property with a different name.

◆ setProperty() [5/8]

template<class BASE >
StatusCode IProperty::setProperty
inline

Special case for std::string.

Definition at line 49 of file IProperty.h.

49  {
50  if ( !hasProperty( name ) ) return StatusCode::FAILURE;
51  return setPropertyRepr( name, v );
52  }

◆ setProperty() [6/8]

template<class BASE >
template<class TYPE , typename = std::enable_if_t<!std::is_base_of_v<Gaudi::Details::PropertyBase, TYPE>>>
StatusCode IProperty::setProperty ( class TYPE  ,
typename  = std::enable_if_t<!std::is_base_of_v<Gaudi::Details::PropertyBase, TYPE>> 
)
inline

set the property form the value

std::vector<double> data = ... ;
setProperty( "Data" , data ) ;
setProperty( "Cuts" , cuts ) ;
setProperty( "Dictionary" , dict ) ;

Note: the interface IProperty allows setting of the properties either directly from other properties or from strings only

This is very convenient in resetting of the default properties in the derived classes.

Parameters
namename of the property
valuevalue of the property
See also
Gaudi::Utils::setProperty
Author
Vanya BELYAEV ibely.nosp@m.aev@.nosp@m.physi.nosp@m.cs.s.nosp@m.yr.ed.nosp@m.u
Date
2007-05-13

Definition at line 82 of file IProperty.h.

82  {
84  if ( !hasProperty( name ) ) return StatusCode::FAILURE;
85  return setPropertyRepr( name, toString( value ) );
86  }

◆ setProperty() [7/8]

template<class BASE >
StatusCode PropertyHolder< BASE >::setProperty ( const std::string s)
inlineoverride

set the property from the formatted string

See also
IProperty

Definition at line 166 of file PropertyHolder.h.

166  {
168  std::string value;
169  StatusCode sc = Gaudi::Parsers::parse( name, value, s );
170  if ( sc.isFailure() ) return sc;
171  return setPropertyRepr( name, value );
172  }

◆ setProperty() [8/8]

template<class BASE >
virtual StatusCode IProperty::setProperty

Set the property by string.

◆ setPropertyRepr()

template<class BASE >
StatusCode PropertyHolder< BASE >::setPropertyRepr ( const std::string n,
const std::string r 
)
inlineoverride

set the property from name and value string representation

See also
IProperty

@fixme SUCCESS is not required to be checked for compatibility with Gaudi::Utils::setProperty

Definition at line 177 of file PropertyHolder.h.

177  {
178  try {
181  return ( p && p->fromString( r ) ) ? StatusCode::SUCCESS : StatusCode::FAILURE;
182  } catch ( const std::invalid_argument& err ) {
183  throw GaudiException{ "error setting property " + n, this->name(), StatusCode::FAILURE, err };
184  }
185  }

Member Data Documentation

◆ m_properties

template<class BASE >
Properties PropertyHolder< BASE >::m_properties
private

Collection of all declared properties.

Definition at line 291 of file PropertyHolder.h.

◆ m_remoteProperties

template<class BASE >
RemoteProperties PropertyHolder< BASE >::m_remoteProperties
private

Collection of all declared remote properties.

Definition at line 293 of file PropertyHolder.h.

◆ m_todelete

template<class BASE >
std::vector<std::unique_ptr<Gaudi::Details::PropertyBase> > PropertyHolder< BASE >::m_todelete
private

Properties owned by PropertyHolder, to be deleted.

Definition at line 295 of file PropertyHolder.h.


The documentation for this class was generated from the following file:
Gaudi::Details::PropertyBase
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: PropertyBase.h:35
Gaudi::Details::PropertyBase::name
const std::string name() const
property name
Definition: PropertyBase.h:39
std::for_each
T for_each(T... args)
std::string
STL class.
IMessageSvc
Definition: IMessageSvc.h:47
Gaudi.Configuration.log
log
Definition: Configuration.py:28
Gaudi::Parsers::parse
StatusCode parse(GaudiUtils::HashMap< K, V > &result, std::string_view input)
Basic parser for the types of HashMap used in DODBasicMapper.
Definition: DODBasicMapper.cpp:21
gaudirun.s
string s
Definition: gaudirun.py:346
std::vector< double >
std::find_if
T find_if(T... args)
check_ParticleID.props
props
Definition: check_ParticleID.py:21
GaudiException
Definition: GaudiException.h:31
PropertyHolder::setProperty
StatusCode setProperty(const std::string &name, const Gaudi::Details::PropertyBase &p) override
set the property from another property with a different name
Definition: PropertyHolder.h:157
std::unique_ptr::get
T get(T... args)
MSG::WARNING
@ WARNING
Definition: IMessageSvc.h:25
std::vector::back
T back(T... args)
std::any_of
T any_of(T... args)
PropertyHolder
Helper class to implement the IProperty interface.
Definition: PropertyHolder.h:82
Gaudi::Details::PropertyBase::fromString
virtual StatusCode fromString(const std::string &value)=0
string -> value
PropertyHolder::assertUniqueName
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).
Definition: PropertyHolder.h:272
PropertyHolder::m_todelete
std::vector< std::unique_ptr< Gaudi::Details::PropertyBase > > m_todelete
Properties owned by PropertyHolder, to be deleted.
Definition: PropertyHolder.h:295
AvalancheSchedulerErrorTest.msgSvc
msgSvc
Definition: AvalancheSchedulerErrorTest.py:80
Gaudi::Details::PropertyType
Gaudi::cpp17::detected_or_t< Gaudi::Property< T >, PropertyType_t, T > PropertyType
Definition: PropertyHolder.h:51
PropertyHolder::property
Gaudi::Details::PropertyBase * property(std::string_view name) const
\fixme property and bindPropertiesTo should be protected
Definition: PropertyHolder.h:238
std::vector::push_back
T push_back(T... args)
IProperty
Definition: IProperty.h:33
Gaudi::svcLocator
GAUDI_API ISvcLocator * svcLocator()
Gaudi::Interfaces::IOptionsSvc::bind
virtual void bind(const std::string &prefix, Gaudi::Details::PropertyBase *property)=0
Register a Gaudi::Property instance to the option service.
Gaudi::Details::PropertyBase::setDocumentation
void setDocumentation(std::string value)
set the documentation string
Definition: PropertyBase.h:91
Gaudi::Utils::begin
AttribStringParser::Iterator begin(const AttribStringParser &parser)
Definition: AttribStringParser.h:136
StatusCode
Definition: StatusCode.h:65
std::cerr
PropertyHolder::setPropertyRepr
StatusCode setPropertyRepr(const std::string &n, const std::string &r) override
set the property from name and value string representation
Definition: PropertyHolder.h:177
ISvcLocator::service
StatusCode service(const Gaudi::Utils::TypeNameString &name, T *&svc, bool createIf=true)
Templated method to access a service by name.
Definition: ISvcLocator.h:98
Gaudi::Utils::iequal
bool iequal(std::string_view v1, std::string_view v2)
Helper for case insensitive string comparison.
Definition: PropertyHolder.h:55
std::invalid_argument
STL class.
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202
std::map< std::string, double >
MsgStream
Definition: MsgStream.h:33
cpluginsvc.n
n
Definition: cpluginsvc.py:234
StatusCode::isFailure
bool isFailure() const
Definition: StatusCode.h:129
Gaudi::Utils::toString
std::string toString(const TYPE &obj)
the generic implementation of the type conversion to the string
Definition: ToStream.h:353
std::vector::emplace_back
T emplace_back(T... args)
PropertyHolder::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Details::PropertyBase &prop)
Declare a property.
Definition: PropertyHolder.h:106
PropertyHolder::m_properties
Properties m_properties
Collection of all declared properties.
Definition: PropertyHolder.h:291
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
ConditionsStallTest.name
name
Definition: ConditionsStallTest.py:77
std::endl
T endl(T... args)
IProperty::getProperties
virtual const std::vector< Gaudi::Details::PropertyBase * > & getProperties() const =0
Get list of properties.
Gaudi::Details::PropertyBase::toString
virtual std::string toString() const =0
value -> string
std::string::empty
T empty(T... args)
Properties.v
v
Definition: Properties.py:122
std::out_of_range
STL class.
Gaudi::Details::PropertyBase::setName
void setName(std::string value)
set the new value for the property name
Definition: PropertyBase.h:89
IOTest.end
end
Definition: IOTest.py:125
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:101
compareOutputFiles.pp
pp
Definition: compareOutputFiles.py:507
PropertyHolder::m_remoteProperties
RemoteProperties m_remoteProperties
Collection of all declared remote properties.
Definition: PropertyHolder.h:293
PropertyHolder::hasProperty
bool hasProperty(std::string_view name) const override
Return true if we have a property with the given name.
Definition: PropertyHolder.h:227