The Gaudi Framework  v40r0 (475e45c1)
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 68 of file PropertyHolder.h.

Member Typedef Documentation

◆ Properties

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

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

◆ RemoteProperties

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

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

258  {
259  if ( hasProperty( name ) ) {
260  auto msgSvc = Gaudi::svcLocator()->service<IMessageSvc>( "MessageSvc" );
261  if ( !msgSvc ) std::cerr << "error: cannot get MessageSvc!" << std::endl;
262  MsgStream log( msgSvc, this->name() );
263  log << MSG::WARNING << "duplicated property name '" << name << "', see https://its.cern.ch/jira/browse/GAUDI-1023"
264  << endmsg;
265  }
266  }

◆ bindPropertiesTo()

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

Definition at line 238 of file PropertyHolder.h.

238  {
239  auto set_prop = [&optsSvc, this]( auto prop ) { optsSvc.bind( this->name(), prop ); };
240  std::for_each( begin( m_properties ), end( m_properties ), set_prop );
241  std::for_each( begin( m_remoteProperties ), end( m_remoteProperties ), [&set_prop, this]( auto& rem ) {
242  if ( rem.owner ) set_prop( this->property( rem.remName, rem.owner->getProperties() ) );
243  } );
244  }

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

123  {
124  Gaudi::Details::PropertyBase* p = &prop;
125  p->setName( name );
126 
127  p->setDocumentation( doc );
128  return &declareProperty( *p );
129  }

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

92  {
93  assertUniqueName( prop.name() );
94  m_properties.push_back( &prop );
95  return prop;
96  }

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

134  {
135  if ( !rsvc ) return nullptr;
136  const std::string& nam = rname.empty() ? name : rname;
138  m_remoteProperties.emplace_back( RemProperty{ name, rsvc, nam } );
139  return p;
140  }

◆ getProperties()

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

get all properties

See also
IProperty

Definition at line 210 of file PropertyHolder.h.

210 { 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 181 of file PropertyHolder.h.

181  {
182  try {
183  const Gaudi::Details::PropertyBase* pp = property( p->name() );
184  if ( pp && pp->load( *p ) ) return StatusCode::SUCCESS;
185  } catch ( ... ) {}
186  return StatusCode::FAILURE;
187  }

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

199  {
200  // get the property
202  if ( !p ) return StatusCode::FAILURE;
203  // convert the value into the string
204  v = p->toString();
205  return StatusCode::SUCCESS;
206  }

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

191  {
193  if ( !p ) throw std::out_of_range( "Property " + std::string{ name } + " not found." );
194  return *p;
195  }

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

214  {
215  return any_of( begin( m_properties ), end( m_properties ),
216  [&name]( const Gaudi::Details::PropertyBase* prop ) {
217  return Gaudi::Utils::iequal( prop->name(), name );
218  } ) ||
220  [&name]( const auto& prop ) { return Gaudi::Utils::iequal( prop.name, name ); } );
221  }

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

224  {
225  // local property ?
227  if ( lp ) return lp;
228  // look for remote property
229  for ( const auto& it : m_remoteProperties ) {
230  if ( !Gaudi::Utils::iequal( it.name, name ) ) continue;
231  const IProperty* p = it.owner;
232  if ( !p ) continue;
233  return property( it.remName, p->getProperties() );
234  }
235  return nullptr;
236  }

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

249  {
250  auto it = std::find_if( props.begin(), props.end(), [name]( Gaudi::Details::PropertyBase* p ) {
251  return p && Gaudi::Utils::iequal( p->name(), name );
252  } );
253  return ( it != props.end() ) ? *it : nullptr;
254  }

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

103  {
104  auto make_property = [&]( const std::string& n, TYPE& v ) {
105  if constexpr ( requires { typename TYPE::PropertyType; } ) {
106  return std::make_unique<typename TYPE::PropertyType>( n, v );
107  } else {
108  return std::make_unique<Gaudi::Property<TYPE&>>( n, v );
109  }
110  };
111  m_todelete.push_back( make_property( name, value ) );
112  Gaudi::Details::PropertyBase* p = m_todelete.back().get();
113 
114  p->setDocumentation( doc );
115  return &declareProperty( *p );
116  }

◆ setProperty() [1/7]

template<class BASE >
StatusCode IProperty::setProperty
inline

Set the property from a property.

Definition at line 38 of file IProperty.h.

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

◆ setProperty() [2/7]

template<class BASE >
StatusCode IProperty::setProperty
inline

Special case for string literals.

Definition at line 46 of file IProperty.h.

46 { 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 151 of file PropertyHolder.h.

151  {
153  if ( pp && pp->assign( p ) ) return StatusCode::SUCCESS;
154  return StatusCode::FAILURE;
155  }

◆ 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 48 of file IProperty.h.

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

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

159  {
160  std::string name;
161  std::string value;
162  StatusCode sc = Gaudi::Parsers::parse( name, value, s );
163  if ( sc.isFailure() ) return sc;
164  return setPropertyRepr( name, value );
165  }

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

169  {
170  try {
173  return ( p && p->fromString( r ) ) ? StatusCode::SUCCESS : StatusCode::FAILURE;
174  } catch ( const std::invalid_argument& err ) {
175  throw GaudiException{ "error setting property " + n, this->name(), StatusCode::FAILURE, err };
176  }
177  }

Member Data Documentation

◆ m_properties

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

Collection of all declared properties.

Definition at line 277 of file PropertyHolder.h.

◆ m_remoteProperties

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

Collection of all declared remote properties.

Definition at line 279 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 281 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:34
Gaudi::Details::PropertyBase::name
const std::string name() const
property name
Definition: PropertyBase.h:38
IMessageSvc
Definition: IMessageSvc.h:44
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:29
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:151
MSG::WARNING
@ WARNING
Definition: IMessageSvc.h:22
PropertyHolder
Helper class to implement the IProperty interface.
Definition: PropertyHolder.h:68
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:258
PropertyHolder::m_todelete
std::vector< std::unique_ptr< Gaudi::Details::PropertyBase > > m_todelete
Properties owned by PropertyHolder, to be deleted.
Definition: PropertyHolder.h:281
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:224
IProperty
Definition: IProperty.h:32
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:90
Gaudi::Utils::begin
AttribStringParser::Iterator begin(const AttribStringParser &parser)
Definition: AttribStringParser.h:135
StatusCode
Definition: StatusCode.h:64
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:169
Gaudi::Utils::iequal
bool iequal(std::string_view v1, std::string_view v2)
Helper for case insensitive string comparison.
Definition: PropertyHolder.h:41
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:198
MsgStream
Definition: MsgStream.h:29
cpluginsvc.n
n
Definition: cpluginsvc.py:234
StatusCode::isFailure
bool isFailure() const
Definition: StatusCode.h:129
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:101
PropertyHolder::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Details::PropertyBase &prop)
Declare a property.
Definition: PropertyHolder.h:92
PropertyHolder::m_properties
Properties m_properties
Collection of all declared properties.
Definition: PropertyHolder.h:277
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:99
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:88
IOTest.end
end
Definition: IOTest.py:125
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:100
compareOutputFiles.pp
pp
Definition: compareOutputFiles.py:507
PropertyHolder::m_remoteProperties
RemoteProperties m_remoteProperties
Collection of all declared remote properties.
Definition: PropertyHolder.h:279
PropertyHolder::hasProperty
bool hasProperty(std::string_view name) const override
Return true if we have a property with the given name.
Definition: PropertyHolder.h:214