The Gaudi Framework  v33r0 (d5ea422b)
PropertyHolder< BASE > Class Template Reference

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

#include <GaudiKernel/PropertyHolder.h>

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

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 Gaudi::Details::PropertyBase &p) override
 set the property form another property More...
 
StatusCode setProperty (const std::string &s) override
 set the property from the formatted string More...
 
StatusCode setProperty (const std::string &n, const std::string &v) override
 set the property from name and the value More...
 
template<class TYPE >
StatusCode setProperty (const std::string &name, const TYPE &value)
 set the property form the value More...
 
StatusCode getProperty (Gaudi::Details::PropertyBase *p) const override
 get the property More...
 
const Gaudi::Details::PropertyBasegetProperty (const std::string &name) const override
 get the property by name More...
 
StatusCode getProperty (const std::string &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 (const std::string &name) const override
 Return true if we have a property with the given name. More...
 
 PropertyHolder (const PropertyHolder &)=delete
 
PropertyHolderoperator= (const PropertyHolder &)=delete
 

Protected Member Functions

Gaudi::Details::PropertyBaseproperty (const std::string &name) const
 

Private Types

typedef std::vector< Gaudi::Details::PropertyBase * > Properties
 
typedef std::pair< std::string, std::pair< IProperty *, std::string > > RemProperty
 
typedef std::vector< RemPropertyRemoteProperties
 

Private Member Functions

Gaudi::Details::PropertyBaseproperty (const std::string &name, const std::vector< Gaudi::Details::PropertyBase * > &props) const
 get the property by name form the proposed list More...
 
void assertUniqueName (const std::string &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 81 of file PropertyHolder.h.

Member Typedef Documentation

◆ Properties

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

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

◆ RemoteProperties

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

Definition at line 312 of file PropertyHolder.h.

◆ RemProperty

template<class BASE>
typedef std::pair<std::string, std::pair<IProperty*, std::string> > PropertyHolder< BASE >::RemProperty
private

Definition at line 311 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 ( const std::string name) const
inlineprivate

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

Definition at line 300 of file PropertyHolder.h.

300  {
301  if ( UNLIKELY( hasProperty( name ) ) ) {
302  auto msgSvc = Gaudi::svcLocator()->service<IMessageSvc>( "MessageSvc" );
303  if ( !msgSvc ) std::cerr << "error: cannot get MessageSvc!" << std::endl;
304  MsgStream log( msgSvc, this->name() );
305  log << MSG::WARNING << "duplicated property name '" << name << "', see https://its.cern.ch/jira/browse/GAUDI-1023"
306  << endmsg;
307  }
308  }
#define UNLIKELY(x)
Definition: Kernel.h:106
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:34
T endl(T... args)
bool hasProperty(const std::string &name) const override
Return true if we have a property with the given name.
StatusCode service(const Gaudi::Utils::TypeNameString &name, T *&svc, bool createIf=true)
Templated method to access a service by name.
Definition: ISvcLocator.h:86
GAUDI_API ISvcLocator * svcLocator()
The IMessage is the interface implemented by the message service.
Definition: IMessageSvc.h:47
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202

◆ declareProperty() [1/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 105 of file PropertyHolder.h.

105  {
106  assertUniqueName( prop.name() );
107  m_properties.push_back( &prop );
108  return prop;
109  }
Properties m_properties
Collection of all declared properties.
const std::string name() const
property name
Definition: Property.h:46
T push_back(T... args)
void assertUniqueName(const std::string &name) const
Issue a runtime warning if the name is already present in the list of properties (see GAUDI-1023).

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

115  {
116  m_todelete.push_back( std::make_unique<Gaudi::Details::PropertyType<TYPE&>>( name, value ) );
118 
119  p->setDocumentation( doc );
120  return &declareProperty( *p );
121  }
void setDocumentation(std::string value)
set the documentation string
Definition: Property.h:98
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Details::PropertyBase &prop)
Declare a property.
T push_back(T... args)
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: Property.h:42
T get(T... args)
T back(T... args)
std::vector< std::unique_ptr< Gaudi::Details::PropertyBase > > m_todelete
Properties owned by PropertyHolder, to be deleted.

◆ declareProperty() [3/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 126 of file PropertyHolder.h.

128  {
129  Gaudi::Details::PropertyBase* p = &prop;
130  p->setName( name );
131 
132  p->setDocumentation( doc );
133  return &declareProperty( *p );
134  }
void setDocumentation(std::string value)
set the documentation string
Definition: Property.h:98
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Details::PropertyBase &prop)
Declare a property.
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: Property.h:42
void setName(std::string value)
set the new value for the property name
Definition: Property.h: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 138 of file PropertyHolder.h.

139  {
140  if ( !rsvc ) return nullptr;
141  const std::string& nam = rname.empty() ? name : rname;
144  return p;
145  }
T empty(T... args)
Gaudi::Details::PropertyBase * property(const std::string &name) const
STL class.
RemoteProperties m_remoteProperties
Collection of all declared remote properties.
T make_pair(T... args)
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: Property.h:42
virtual const std::vector< Gaudi::Details::PropertyBase * > & getProperties() const =0
Get list of properties.
T emplace_back(T... args)

◆ getProperties()

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

get all properties

See also
IProperty

Definition at line 261 of file PropertyHolder.h.

261 { return m_properties; }
Properties m_properties
Collection of all declared 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 229 of file PropertyHolder.h.

229  {
230  try {
231  const Gaudi::Details::PropertyBase* pp = property( p->name() );
232  if ( pp && pp->load( *p ) ) return StatusCode::SUCCESS;
233  } catch ( ... ) {}
234  return StatusCode::FAILURE;
235  }
Gaudi::Details::PropertyBase * property(const std::string &name) const
constexpr static const auto SUCCESS
Definition: StatusCode.h:96
const std::string name() const
property name
Definition: Property.h:46
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: Property.h:42
constexpr static const auto FAILURE
Definition: StatusCode.h:97

◆ getProperty() [2/3]

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

get the property by name

See also
IProperty

Definition at line 240 of file PropertyHolder.h.

240  {
242  if ( !p ) throw std::out_of_range( "Property " + name + " not found." );
243  return *p;
244  }
Gaudi::Details::PropertyBase * property(const std::string &name) const
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: Property.h:42

◆ getProperty() [3/3]

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

convert the property to the string

See also
IProperty

Definition at line 249 of file PropertyHolder.h.

249  {
250  // get the property
252  if ( !p ) return StatusCode::FAILURE;
253  // convert the value into the string
254  v = p->toString();
255  return StatusCode::SUCCESS;
256  }
Gaudi::Details::PropertyBase * property(const std::string &name) const
constexpr static const auto SUCCESS
Definition: StatusCode.h:96
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: Property.h:42
constexpr static const auto FAILURE
Definition: StatusCode.h:97
virtual std::string toString() const =0
value -> string

◆ hasProperty()

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

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

See also
IProperty

Definition at line 266 of file PropertyHolder.h.

266  {
267  return any_of( begin( m_properties ), end( m_properties ), [&name]( const Gaudi::Details::PropertyBase* prop ) {
268  return Gaudi::Utils::iequal( prop->name(), name );
269  } );
270  }
Properties m_properties
Collection of all declared properties.
const std::string name() const
property name
Definition: Property.h:46
bool iequal(const std::string &v1, const std::string &v2)
Helper for case insensitive string comparison.
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: Property.h:42
def end
Definition: IOTest.py:123
T any_of(T... args)
AttribStringParser::Iterator begin(const AttribStringParser &parser)

◆ operator=()

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

◆ property() [1/2]

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

Definition at line 274 of file PropertyHolder.h.

274  {
275  // local property ?
277  if ( lp ) return lp;
278  // look for remote property
279  for ( const auto& it : m_remoteProperties ) {
280  if ( !Gaudi::Utils::iequal( it.first, name ) ) continue;
281  const IProperty* p = it.second.first;
282  if ( !p ) continue;
283  return property( it.second.second, p->getProperties() );
284  }
285  return nullptr; // RETURN
286  }
Gaudi::Details::PropertyBase * property(const std::string &name) const
Properties m_properties
Collection of all declared properties.
RemoteProperties m_remoteProperties
Collection of all declared remote properties.
bool iequal(const std::string &v1, const std::string &v2)
Helper for case insensitive string comparison.
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: Property.h:42
virtual const std::vector< Gaudi::Details::PropertyBase * > & getProperties() const =0
Get list of properties.
The IProperty is the basic interface for all components which have properties that can be set or get.
Definition: IProperty.h:30

◆ property() [2/2]

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

get the property by name form the proposed list

Definition at line 290 of file PropertyHolder.h.

291  {
292  auto it = std::find_if( props.begin(), props.end(), [&name]( Gaudi::Details::PropertyBase* p ) {
293  return p && Gaudi::Utils::iequal( p->name(), name );
294  } );
295  return ( it != props.end() ) ? *it : nullptr; // RETURN
296  }
T end(T... args)
bool iequal(const std::string &v1, const std::string &v2)
Helper for case insensitive string comparison.
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: Property.h:42
T find_if(T... args)
T begin(T... args)

◆ setProperty() [1/4]

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

set the property form another property

See also
IProperty

Definition at line 155 of file PropertyHolder.h.

155  {
157  try {
158  if ( pp && pp->assign( p ) ) return StatusCode::SUCCESS;
159  } catch ( ... ) {}
160  return StatusCode::FAILURE;
161  }
Gaudi::Details::PropertyBase * property(const std::string &name) const
constexpr static const auto SUCCESS
Definition: StatusCode.h:96
const std::string name() const
property name
Definition: Property.h:46
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: Property.h:42
constexpr static const auto FAILURE
Definition: StatusCode.h:97

◆ setProperty() [2/4]

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 setProperty( name, value );
172  }
StatusCode setProperty(const Gaudi::Details::PropertyBase &p) override
set the property form another property
StatusCode parse(GaudiUtils::HashMap< K, V > &result, const std::string &input)
Basic parser for the types of HashMap used in DODBasicMapper.
STL class.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:61
string s
Definition: gaudirun.py:328
bool isFailure() const
Definition: StatusCode.h:141

◆ setProperty() [3/4]

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

set the property from name and the value

See also
IProperty

Definition at line 177 of file PropertyHolder.h.

177  {
179  return ( p && p->fromString( v ) ) ? StatusCode::SUCCESS : StatusCode::FAILURE;
180  }
Gaudi::Details::PropertyBase * property(const std::string &name) const
constexpr static const auto SUCCESS
Definition: StatusCode.h:96
virtual StatusCode fromString(const std::string &value)=0
string -> value
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: Property.h:42
constexpr static const auto FAILURE
Definition: StatusCode.h:97

◆ setProperty() [4/4]

template<class BASE>
template<class TYPE >
StatusCode PropertyHolder< BASE >::setProperty ( const std::string name,
const TYPE &  value 
)
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. E.g. without this method one needs to convert everything into strings to use IProperty::setProperty

setProperty ( "OutputLevel" , "1" ) ;
setProperty ( "Enable" , "True" ) ;
setProperty ( "ErrorMax" , "10" ) ;

For simple cases it is more or less ok, but for complicated properties it is just ugly..

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

222  {
223  return Gaudi::Utils::setProperty( this, name, value );
224  }
StatusCode setProperty(IProperty *component, const std::string &name, const TYPE &value, const std::string &doc)
simple function to set the property of the given object from the value
Definition: Property.h:1207

Member Data Documentation

◆ m_properties

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

Collection of all declared properties.

Definition at line 315 of file PropertyHolder.h.

◆ m_remoteProperties

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

Collection of all declared remote properties.

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


The documentation for this class was generated from the following file: