The Gaudi Framework  v30r3 (a5ef0a68)
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 77 of file PropertyHolder.h.

Member Typedef Documentation

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

Definition at line 323 of file PropertyHolder.h.

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

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

Definition at line 325 of file PropertyHolder.h.

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

Definition at line 324 of file PropertyHolder.h.

Constructor & Destructor Documentation

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

prevent copies

Member Function Documentation

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

313  {
314  if ( UNLIKELY( hasProperty( name ) ) ) {
315  auto msgSvc = Gaudi::svcLocator()->service<IMessageSvc>( "MessageSvc" );
316  if ( !msgSvc ) std::cerr << "error: cannot get MessageSvc!" << std::endl;
317  MsgStream log( msgSvc, this->name() );
318  log << MSG::WARNING << "duplicated property name '" << name << "', see https://its.cern.ch/jira/browse/GAUDI-1023"
319  << endmsg;
320  }
321  }
#define UNLIKELY(x)
Definition: Kernel.h:122
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
bool hasProperty(const std::string &name) const override
Return true if we have a property with the given name.
T endl(T...args)
StatusCode service(const Gaudi::Utils::TypeNameString &name, T *&svc, bool createIf=true)
Templated method to access a service by name.
Definition: ISvcLocator.h:79
GAUDI_API ISvcLocator * svcLocator()
The IMessage is the interface implemented by the message service.
Definition: IMessageSvc.h:38
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
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 102 of file PropertyHolder.h.

103  {
104  assertUniqueName( prop.name() );
105  m_properties.push_back( &prop );
106  return prop;
107  }
const std::string name() const
property name
Definition: Property.h:40
Properties m_properties
Collection of all declared properties.
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)...
T push_back(T...args)
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 112 of file PropertyHolder.h.

113  {
114  m_todelete.push_back( std::make_unique<Gaudi::Details::PropertyType<TYPE&>>( name, value ) );
116 
117  p->setDocumentation( doc );
118  return &declareProperty( *p );
119  }
void setDocumentation(std::string value)
set the documentation string
Definition: Property.h:92
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:32
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.
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 124 of file PropertyHolder.h.

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

139  {
140  if ( !rsvc ) return nullptr;
141  const std::string& nam = rname.empty() ? name : rname;
143  m_remoteProperties.emplace_back( name, std::make_pair( rsvc, nam ) );
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:32
virtual const std::vector< Gaudi::Details::PropertyBase * > & getProperties() const =0
Get list of properties.
T emplace_back(T...args)
template<class BASE>
const std::vector<Gaudi::Details::PropertyBase*>& PropertyHolder< BASE >::getProperties ( ) const
inlineoverride

get all properties

See also
IProperty

Definition at line 270 of file PropertyHolder.h.

270 { return m_properties; }
Properties m_properties
Collection of all declared properties.
template<class BASE>
StatusCode PropertyHolder< BASE >::getProperty ( Gaudi::Details::PropertyBase p) const
inlineoverride

get the property

See also
IProperty

Definition at line 234 of file PropertyHolder.h.

235  {
236  try {
237  const Gaudi::Details::PropertyBase* pp = property( p->name() );
238  if ( pp && pp->load( *p ) ) return StatusCode::SUCCESS;
239  } catch ( ... ) {
240  }
241  return StatusCode::FAILURE;
242  }
constexpr static const auto FAILURE
Definition: StatusCode.h:88
Gaudi::Details::PropertyBase * property(const std::string &name) const
virtual bool load(PropertyBase &dest) const =0
export the property value to the destination
const std::string name() const
property name
Definition: Property.h:40
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: Property.h:32
constexpr static const auto SUCCESS
Definition: StatusCode.h:87
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 247 of file PropertyHolder.h.

248  {
249  const Gaudi::Details::PropertyBase* p = property( name );
250  if ( !p ) throw std::out_of_range( "Property " + name + " not found." );
251  return *p;
252  }
Gaudi::Details::PropertyBase * property(const std::string &name) const
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: Property.h:32
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 257 of file PropertyHolder.h.

258  {
259  // get the property
260  const Gaudi::Details::PropertyBase* p = property( n );
261  if ( !p ) return StatusCode::FAILURE;
262  // convert the value into the string
263  v = p->toString();
264  return StatusCode::SUCCESS;
265  }
constexpr static const auto FAILURE
Definition: StatusCode.h:88
Gaudi::Details::PropertyBase * property(const std::string &name) const
virtual std::string toString() const =0
value -> string
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: Property.h:32
constexpr static const auto SUCCESS
Definition: StatusCode.h:87
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 275 of file PropertyHolder.h.

276  {
277  return any_of( begin( m_properties ), end( m_properties ), [&name]( const Gaudi::Details::PropertyBase* prop ) {
278  return Gaudi::Utils::iequal( prop->name(), name );
279  } );
280  }
const std::string name() const
property name
Definition: Property.h:40
Properties m_properties
Collection of all declared 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:32
T any_of(T...args)
AttribStringParser::Iterator begin(const AttribStringParser &parser)
template<class BASE>
PropertyHolder& PropertyHolder< BASE >::operator= ( const PropertyHolder< BASE > &  )
delete
template<class BASE>
Gaudi::Details::PropertyBase* PropertyHolder< BASE >::property ( const std::string name) const
inlineprotected

Definition at line 284 of file PropertyHolder.h.

285  {
286  // local property ?
288  if ( lp ) return lp;
289  // look for remote property
290  for ( const auto& it : m_remoteProperties ) {
291  if ( !Gaudi::Utils::iequal( it.first, name ) ) continue;
292  const IProperty* p = it.second.first;
293  if ( !p ) continue;
294  return property( it.second.second, p->getProperties() );
295  }
296  return nullptr; // RETURN
297  }
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:32
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:20
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 301 of file PropertyHolder.h.

303  {
304  auto it = std::find_if( props.begin(), props.end(), [&name]( Gaudi::Details::PropertyBase* p ) {
305  return p && Gaudi::Utils::iequal( p->name(), name );
306  } );
307  return ( it != props.end() ) ? *it : nullptr; // RETURN
308  }
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:32
T find_if(T...args)
T begin(T...args)
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.

156  {
158  try {
159  if ( pp && pp->assign( p ) ) return StatusCode::SUCCESS;
160  } catch ( ... ) {
161  }
162  return StatusCode::FAILURE;
163  }
constexpr static const auto FAILURE
Definition: StatusCode.h:88
Gaudi::Details::PropertyBase * property(const std::string &name) const
virtual bool assign(const PropertyBase &source)=0
import the property value form the source
const std::string name() const
property name
Definition: Property.h:40
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: Property.h:32
constexpr static const auto SUCCESS
Definition: StatusCode.h:87
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 168 of file PropertyHolder.h.

169  {
171  std::string value;
172  StatusCode sc = Gaudi::Parsers::parse( name, value, s );
173  if ( sc.isFailure() ) return sc;
174  return setProperty( name, value );
175  }
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.
bool isFailure() const
Definition: StatusCode.h:139
STL class.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:51
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 180 of file PropertyHolder.h.

181  {
183  return ( p && p->fromString( v ) ) ? StatusCode::SUCCESS : StatusCode::FAILURE;
184  }
constexpr static const auto FAILURE
Definition: StatusCode.h:88
Gaudi::Details::PropertyBase * property(const std::string &name) const
virtual StatusCode fromString(const std::string &value)=0
string -> value
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: Property.h:32
constexpr static const auto SUCCESS
Definition: StatusCode.h:87
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 226 of file PropertyHolder.h.

227  {
228  return Gaudi::Utils::setProperty( this, name, value );
229  }
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:1243

Member Data Documentation

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

Collection of all declared properties.

Definition at line 328 of file PropertyHolder.h.

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

Collection of all declared remote properties.

Definition at line 330 of file PropertyHolder.h.

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


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