The Gaudi Framework  master (42b00024)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 >
 requires (!Gaudi::Details::is_gaudi_property_v< TYPE >) Gaudi
 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...
 
 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 77 of file PropertyHolder.h.

Member Typedef Documentation

◆ Properties

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

Definition at line 285 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 88 of file PropertyHolder.h.

◆ RemoteProperties

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

Definition at line 291 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 275 of file PropertyHolder.h.

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

◆ bindPropertiesTo()

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

Definition at line 255 of file PropertyHolder.h.

255  {
256  auto set_prop = [&optsSvc, this]( auto prop ) { optsSvc.bind( this->name(), prop ); };
257  std::for_each( begin( m_properties ), end( m_properties ), set_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() ) );
260  } );
261  }

◆ declareProperty() [1/2]

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 130 of file PropertyHolder.h.

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

◆ declareProperty() [2/2]

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 101 of file PropertyHolder.h.

101  {
102  assertUniqueName( prop.name() );
103  m_properties.push_back( &prop );
104  return prop;
105  }

◆ 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 142 of file PropertyHolder.h.

143  {
144  if ( !rsvc ) return nullptr;
145  const std::string& nam = rname.empty() ? name : rname;
147  m_remoteProperties.emplace_back( RemProperty{ name, rsvc, nam } );
148  return p;
149  }

◆ getProperties()

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

get all properties

See also
IProperty

Definition at line 225 of file PropertyHolder.h.

225 { 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 193 of file PropertyHolder.h.

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

◆ 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 213 of file PropertyHolder.h.

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

◆ 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 204 of file PropertyHolder.h.

204  {
206  if ( !p ) throw std::out_of_range( "Property " + std::string{ name } + " not found." );
207  return *p;
208  }

◆ 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 230 of file PropertyHolder.h.

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

◆ 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 241 of file PropertyHolder.h.

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

◆ 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 265 of file PropertyHolder.h.

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

◆ requires()

template<class BASE >
template<typename TYPE >
PropertyHolder< BASE >::requires ( !Gaudi::Details::is_gaudi_property_v< TYPE >  )
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 110 of file PropertyHolder.h.

112  {
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 );
116  } else {
117  return std::make_unique<Gaudi::Property<TYPE&>>( n, v );
118  }
119  };
120  m_todelete.push_back( make_property( name, value ) );
121  Gaudi::Details::PropertyBase* p = m_todelete.back().get();
122 
123  p->setDocumentation( doc );
124  return &declareProperty( *p );
125  }

◆ setProperty() [1/7]

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/7]

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/7]

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 160 of file PropertyHolder.h.

160  {
162  if ( pp && pp->assign( p ) ) return StatusCode::SUCCESS;
163  return StatusCode::FAILURE;
164  }

◆ setProperty() [4/7]

template<class BASE >
virtual StatusCode IProperty::setProperty

Set the property from a property with a different name.

◆ setProperty() [5/7]

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/7]

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 169 of file PropertyHolder.h.

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

◆ setProperty() [7/7]

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 180 of file PropertyHolder.h.

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

Member Data Documentation

◆ m_properties

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

Collection of all declared properties.

Definition at line 294 of file PropertyHolder.h.

◆ m_remoteProperties

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

Collection of all declared remote properties.

Definition at line 296 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 298 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
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
check_ParticleID.props
props
Definition: check_ParticleID.py:21
GaudiException
Definition: GaudiException.h:32
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:160
MSG::WARNING
@ WARNING
Definition: IMessageSvc.h:25
PropertyHolder
Helper class to implement the IProperty interface.
Definition: PropertyHolder.h:77
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:275
PropertyHolder::m_todelete
std::vector< std::unique_ptr< Gaudi::Details::PropertyBase > > m_todelete
Properties owned by PropertyHolder, to be deleted.
Definition: PropertyHolder.h:298
AvalancheSchedulerErrorTest.msgSvc
msgSvc
Definition: AvalancheSchedulerErrorTest.py:80
PropertyHolder::property
Gaudi::Details::PropertyBase * property(std::string_view name) const
\fixme property and bindPropertiesTo should be protected
Definition: PropertyHolder.h:241
IProperty
Definition: IProperty.h:33
Gaudi::svcLocator
GAUDI_API ISvcLocator * svcLocator()
ISvcLocator::service
virtual SmartIF< IService > & service(const Gaudi::Utils::TypeNameString &typeName, const bool createIf=true)=0
Returns a smart pointer to a service.
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
Gaudi::cxx::for_each
void for_each(ContainerOfSynced &c, Fun &&f)
Definition: SynchronizedValue.h:98
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:180
Gaudi::Utils::iequal
bool iequal(std::string_view v1, std::string_view v2)
Helper for case insensitive string comparison.
Definition: PropertyHolder.h:50
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202
MsgStream
Definition: MsgStream.h:33
cpluginsvc.n
n
Definition: cpluginsvc.py:234
StatusCode::isFailure
bool isFailure() const
Definition: StatusCode.h:130
PropertyHolder::requires
requires(!Gaudi::Details::is_gaudi_property_v< TYPE >) Gaudi
Helper to wrap a regular data member and use it as a regular property.
Definition: PropertyHolder.h:110
PropertyHolder::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Details::PropertyBase &prop)
Declare a property.
Definition: PropertyHolder.h:101
PropertyHolder::m_properties
Properties m_properties
Collection of all declared properties.
Definition: PropertyHolder.h:294
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
ConditionsStallTest.name
name
Definition: ConditionsStallTest.py:77
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
Properties.v
v
Definition: Properties.py:122
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:296
PropertyHolder::hasProperty
bool hasProperty(std::string_view name) const override
Return true if we have a property with the given name.
Definition: PropertyHolder.h:230