PropertyMgr Class Reference

Property manager helper class. More...

#include <GaudiKernel/PropertyMgr.h>

Inheritance diagram for PropertyMgr:
Collaboration diagram for PropertyMgr:

Public Member Functions

 PropertyMgr (IInterface *iface=nullptr)
 constructor from the interface More...
 
 PropertyMgr (const PropertyMgr &)=delete
 
PropertyMgroperator= (const PropertyMgr &)=delete
 
 ~PropertyMgr () override=default
 virtual destructor More...
 
template<class TYPE >
PropertydeclareProperty (const std::string &name, TYPE &value, const std::string &doc="none")
 Declare a property (templated) More...
 
template<class TYPE >
PropertydeclareProperty (const std::string &name, SimpleProperty< TYPE > &prop, const std::string &doc="none")
 Declare a property (specialization) More...
 
template<class TYPE >
PropertydeclareProperty (const std::string &name, SimplePropertyRef< TYPE > &prop, const std::string &doc="none")
 Declare a property (specialization) More...
 
template<class TYPE >
PropertydeclareProperty (const std::string &name, ToolHandle< TYPE > &ref, const std::string &doc="none")
 Declare a property (specialization) More...
 
template<class TYPE >
PropertydeclareProperty (const std::string &name, ServiceHandle< TYPE > &ref, const std::string &doc="none")
 Declare a property (specialization) More...
 
template<class TYPE >
PropertydeclareProperty (const std::string &name, ToolHandleArray< TYPE > &ref, const std::string &doc="none")
 Declare a property (specialization) More...
 
template<class TYPE >
PropertydeclareProperty (const std::string &name, ServiceHandleArray< TYPE > &ref, const std::string &doc="none")
 Declare a property (specialization) More...
 
template<class TYPE >
PropertydeclareProperty (const std::string &name, DataObjectHandle< TYPE > &ref, const std::string &doc="none")
 Declare a property (specialization) More...
 
PropertydeclareRemoteProperty (const std::string &name, IProperty *rsvc, const std::string &rname="")
 Declare a remote property. More...
 
StatusCode setProperty (const Property &p) override
 set the property form another property More...
 
StatusCode setProperty (const std::string &s) override
 set the property from the property formatted string More...
 
StatusCode setProperty (const std::string &n, const std::string &v) override
 set the property from name and the value More...
 
StatusCode getProperty (Property *p) const override
 get the property More...
 
const PropertygetProperty (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< Property * > & 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...
 
StatusCode queryInterface (const InterfaceID &iid, void **pinterface) override
 
- Public Member Functions inherited from implements< IProperty >
void * i_cast (const InterfaceID &tid) const override
 Implementation of IInterface::i_cast. More...
 
StatusCode queryInterface (const InterfaceID &ti, void **pp) override
 Implementation of IInterface::queryInterface. More...
 
std::vector< std::stringgetInterfaceNames () const override
 Implementation of IInterface::getInterfaceNames. More...
 
 implements ()=default
 Default constructor. More...
 
 implements (const implements &)
 Copy constructor (zero the reference count) More...
 
implementsoperator= (const implements &)
 Assignment operator (do not touch the reference count). More...
 
 ~implements () override=default
 Virtual destructor. More...
 
unsigned long addRef () override
 Reference Interface instance. More...
 
unsigned long release () override
 Release Interface instance. More...
 
unsigned long refCount () const override
 Current reference count. More...
 
- Public Member Functions inherited from extend_interfaces< Interfaces...>
 ~extend_interfaces () override=default
 Virtual destructor. More...
 

Protected Member Functions

Propertyproperty (const std::string &name) const
 

Private Types

typedef std::vector< Property * > Properties
 
typedef std::pair< std::string, std::pair< IProperty *, std::string > > RemProperty
 
typedef std::vector< RemPropertyRemoteProperties
 

Private Member Functions

Propertyproperty (const std::string &name, const std::vector< Property * > &props) const
 get the property by name form the proposed list More...
 
void assertUniqueName (const std::string &name) const
 Throw an exception 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< Property > > m_todelete
 Properties to be deleted. More...
 
IInterfacem_pOuter
 Interface hub reference (ApplicationMgr) More...
 

Additional Inherited Members

- Public Types inherited from implements< IProperty >
using base_class = implements< Interfaces...>
 Typedef to this class. More...
 
using extend_interfaces_base = extend_interfaces< Interfaces...>
 Typedef to the base of this class. More...
 
using iids = typename extend_interfaces_base::ext_iids
 
- Public Types inherited from extend_interfaces< Interfaces...>
using ext_iids = typename Gaudi::interface_list_cat< typename Interfaces::ext_iids...>::type
 take union of the ext_iids of all Interfaces... More...
 
- Protected Attributes inherited from implements< IProperty >
std::atomic_ulong m_refCount
 Reference counter. More...
 

Detailed Description

Property manager helper class.

This class is used by algorithms and services for helping to manage its own set of properties. It implements the IProperty interface.

Author
Paul Maley
David Quarrie

Definition at line 37 of file PropertyMgr.h.

Member Typedef Documentation

Definition at line 166 of file PropertyMgr.h.

Definition at line 169 of file PropertyMgr.h.

Constructor & Destructor Documentation

PropertyMgr::PropertyMgr ( IInterface iface = nullptr)

constructor from the interface

Definition at line 52 of file PropertyMgr.cpp.

53  : m_pOuter ( iface )
54 {
55  addRef(); // initial reference count set to 1
56 }
IInterface * m_pOuter
Interface hub reference (ApplicationMgr)
Definition: PropertyMgr.h:178
unsigned long addRef() override
Reference Interface instance.
Definition: implements.h:44
PropertyMgr::PropertyMgr ( const PropertyMgr )
delete
PropertyMgr::~PropertyMgr ( )
overridedefault

virtual destructor

Member Function Documentation

void PropertyMgr::assertUniqueName ( const std::string name) const
private

Throw an exception if the name is already present in the list of properties (see GAUDI-1023).

Definition at line 207 of file PropertyMgr.cpp.

207  {
208  if (UNLIKELY(hasProperty(name))) {
209  auto owner = SmartIF<INamedInterface>( m_pOuter );
210  auto msgSvc = Gaudi::svcLocator()->service<IMessageSvc>("MessageSvc");
211  if (!msgSvc) { std::cerr<< "error: cannot get MessageSvc!" << std::endl; }
212  MsgStream log(msgSvc, owner ? owner->name() : "PropertyMgr" );
213  log << MSG::WARNING
214  << "duplicated property name '" << name
215  << "', see https://its.cern.ch/jira/browse/GAUDI-1023"<< endmsg;
216  }
217 }
#define UNLIKELY(x)
Definition: Kernel.h:126
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
IInterface * m_pOuter
Interface hub reference (ApplicationMgr)
Definition: PropertyMgr.h:178
T endl(T...args)
virtual const std::string & name() const =0
Retrieve the name of the instance.
StatusCode service(const Gaudi::Utils::TypeNameString &name, T *&svc, bool createIf=true)
Templated method to access a service by name.
Definition: ISvcLocator.h:78
GAUDI_API ISvcLocator * svcLocator()
The IMessage is the interface implemented by the message service.
Definition: IMessageSvc.h:57
bool hasProperty(const std::string &name) const override
Return true if we have a property with the given name.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
template<class TYPE >
Property * PropertyMgr::declareProperty ( const std::string name,
TYPE &  value,
const std::string doc = "none" 
)
inline

Declare a property (templated)

Definition at line 186 of file PropertyMgr.h.

189 {
190  assertUniqueName(name);
192  Property* p = m_todelete.back().get();
193  //
194  p->setDocumentation( doc );
195  m_properties .push_back( p ) ;
196  //
197  return p ;
198 }
SimplePropertyRef templated class.
Definition: HistoProperty.h:14
void setDocumentation(std::string documentation)
set the documentation string
Definition: Property.h:94
T push_back(T...args)
Properties m_properties
Collection of all declared properties.
Definition: PropertyMgr.h:172
T get(T...args)
Property base class allowing Property* collections to be "homogeneous".
Definition: Property.h:38
T back(T...args)
void assertUniqueName(const std::string &name) const
Throw an exception if the name is already present in the list of properties (see GAUDI-1023).
std::vector< std::unique_ptr< Property > > m_todelete
Properties to be deleted.
Definition: PropertyMgr.h:176
T emplace_back(T...args)
template<class TYPE >
Property * PropertyMgr::declareProperty ( const std::string name,
SimpleProperty< TYPE > &  prop,
const std::string doc = "none" 
)
inline

Declare a property (specialization)

Declare a property (templated)

Definition at line 205 of file PropertyMgr.h.

208 {
209  assertUniqueName(name);
210  Property* p = &prop ;
211  //
212  p -> setName ( name ) ;
213  p -> setDocumentation ( doc ) ;
214  m_properties.push_back ( p ) ;
215  //
216  return p ;
217 }
T push_back(T...args)
Properties m_properties
Collection of all declared properties.
Definition: PropertyMgr.h:172
Property base class allowing Property* collections to be "homogeneous".
Definition: Property.h:38
void assertUniqueName(const std::string &name) const
Throw an exception if the name is already present in the list of properties (see GAUDI-1023).
template<class TYPE >
Property * PropertyMgr::declareProperty ( const std::string name,
SimplePropertyRef< TYPE > &  prop,
const std::string doc = "none" 
)
inline

Declare a property (specialization)

Declare a property (templated)

Definition at line 224 of file PropertyMgr.h.

227 {
228  assertUniqueName(name);
229  Property* p = &prop ;
230  //
231  p -> setName ( name ) ;
232  p -> setDocumentation ( doc ) ;
233  m_properties.push_back ( p ) ;
234  //
235  return p ;
236 }
T push_back(T...args)
Properties m_properties
Collection of all declared properties.
Definition: PropertyMgr.h:172
Property base class allowing Property* collections to be "homogeneous".
Definition: Property.h:38
void assertUniqueName(const std::string &name) const
Throw an exception if the name is already present in the list of properties (see GAUDI-1023).
template<class TYPE >
Property * PropertyMgr::declareProperty ( const std::string name,
ToolHandle< TYPE > &  ref,
const std::string doc = "none" 
)
inline

Declare a property (specialization)

Definition at line 243 of file PropertyMgr.h.

246 {
247  assertUniqueName(name);
248  m_todelete . emplace_back ( new GaudiHandleProperty( name, ref ) );
249  Property* p = m_todelete.back().get();
250  //
251  p -> setDocumentation ( doc ) ;
252  m_properties . push_back ( p ) ;
253  //
254  return p ;
255 }
Properties m_properties
Collection of all declared properties.
Definition: PropertyMgr.h:172
T get(T...args)
Property base class allowing Property* collections to be "homogeneous".
Definition: Property.h:38
T back(T...args)
void assertUniqueName(const std::string &name) const
Throw an exception if the name is already present in the list of properties (see GAUDI-1023).
std::vector< std::unique_ptr< Property > > m_todelete
Properties to be deleted.
Definition: PropertyMgr.h:176
template<class TYPE >
Property * PropertyMgr::declareProperty ( const std::string name,
ServiceHandle< TYPE > &  ref,
const std::string doc = "none" 
)
inline

Declare a property (specialization)

Definition at line 260 of file PropertyMgr.h.

263 {
264  assertUniqueName(name);
265  m_todelete . emplace_back (new GaudiHandleProperty( name, ref ));
266  Property* p = m_todelete.back().get();
267  //
268  p -> setDocumentation ( doc ) ;
269  m_properties . push_back ( p ) ;
270  //
271  return p ;
272 }
Properties m_properties
Collection of all declared properties.
Definition: PropertyMgr.h:172
T get(T...args)
Property base class allowing Property* collections to be "homogeneous".
Definition: Property.h:38
T back(T...args)
void assertUniqueName(const std::string &name) const
Throw an exception if the name is already present in the list of properties (see GAUDI-1023).
std::vector< std::unique_ptr< Property > > m_todelete
Properties to be deleted.
Definition: PropertyMgr.h:176
template<class TYPE >
Property * PropertyMgr::declareProperty ( const std::string name,
ToolHandleArray< TYPE > &  ref,
const std::string doc = "none" 
)
inline

Declare a property (specialization)

Definition at line 277 of file PropertyMgr.h.

280 {
281  assertUniqueName(name);
282  m_todelete . emplace_back ( new GaudiHandleArrayProperty( name, ref ) );
283  Property* p = m_todelete.back().get();
284  //
285  p -> setDocumentation ( doc ) ;
286  m_properties . push_back ( p ) ;
287  //
288  return p ;
289 }
Properties m_properties
Collection of all declared properties.
Definition: PropertyMgr.h:172
T get(T...args)
Property base class allowing Property* collections to be "homogeneous".
Definition: Property.h:38
T back(T...args)
void assertUniqueName(const std::string &name) const
Throw an exception if the name is already present in the list of properties (see GAUDI-1023).
std::vector< std::unique_ptr< Property > > m_todelete
Properties to be deleted.
Definition: PropertyMgr.h:176
template<class TYPE >
Property * PropertyMgr::declareProperty ( const std::string name,
ServiceHandleArray< TYPE > &  ref,
const std::string doc = "none" 
)
inline

Declare a property (specialization)

Definition at line 294 of file PropertyMgr.h.

297 {
298  assertUniqueName(name);
299  m_todelete . emplace_back ( new GaudiHandleArrayProperty( name, ref ) );
300  Property* p = m_todelete.back().get();
301  //
302  p -> setDocumentation ( doc ) ;
303  m_properties . push_back ( p ) ;
304  //
305  return p ;
306 }
Properties m_properties
Collection of all declared properties.
Definition: PropertyMgr.h:172
T get(T...args)
Property base class allowing Property* collections to be "homogeneous".
Definition: Property.h:38
T back(T...args)
void assertUniqueName(const std::string &name) const
Throw an exception if the name is already present in the list of properties (see GAUDI-1023).
std::vector< std::unique_ptr< Property > > m_todelete
Properties to be deleted.
Definition: PropertyMgr.h:176
template<class TYPE >
Property * PropertyMgr::declareProperty ( const std::string name,
DataObjectHandle< TYPE > &  ref,
const std::string doc = "none" 
)
inline

Declare a property (specialization)

Definition at line 312 of file PropertyMgr.h.

315 {
316  assertUniqueName(name);
317  Property* p = new DataObjectHandleProperty( name, ref );
318  //
319  p -> setDocumentation ( doc ) ;
320  m_properties . push_back ( p ) ;
321  //
322  return p ;
323 }
DataObjectHandleProperty.h GaudiKernel/DataObjectHandleProperty.h.
Properties m_properties
Collection of all declared properties.
Definition: PropertyMgr.h:172
Property base class allowing Property* collections to be "homogeneous".
Definition: Property.h:38
void assertUniqueName(const std::string &name) const
Throw an exception if the name is already present in the list of properties (see GAUDI-1023).
Property * PropertyMgr::declareRemoteProperty ( const std::string name,
IProperty rsvc,
const std::string rname = "" 
)

Declare a remote property.

Definition at line 61 of file PropertyMgr.cpp.

64 {
65  if ( !rsvc ) { return nullptr ; }
66  const std::string& nam = rname.empty() ? name : rname ;
67  Property* p = property ( nam , rsvc->getProperties() ) ;
68  m_remoteProperties.emplace_back ( name , std::make_pair( rsvc , nam ) ) ;
69  return p ;
70 }
T empty(T...args)
virtual const std::vector< Property * > & getProperties() const =0
Get list of properties.
STL class.
RemoteProperties m_remoteProperties
Collection of all declared remote properties.
Definition: PropertyMgr.h:174
T make_pair(T...args)
Property base class allowing Property* collections to be "homogeneous".
Definition: Property.h:38
Property * property(const std::string &name) const
Definition: PropertyMgr.cpp:85
T emplace_back(T...args)
const std::vector< Property * > & PropertyMgr::getProperties ( ) const
override

get all properties

See also
IProperty

Definition at line 186 of file PropertyMgr.cpp.

186 { return m_properties; }
Properties m_properties
Collection of all declared properties.
Definition: PropertyMgr.h:172
StatusCode PropertyMgr::getProperty ( Property p) const
override

get the property

See also
IProperty

Definition at line 144 of file PropertyMgr.cpp.

145 {
146  try
147  {
148  const Property* pp = property( p->name() ) ;
149  if ( pp && pp->load(*p) ) return StatusCode::SUCCESS; // RETURN
150  }
151  catch ( ... ) { }
152  return StatusCode::FAILURE ; // RETURN
153 }
const std::string & name() const
property name
Definition: Property.h:45
virtual bool load(Property &dest) const =0
export the property value to the destination
Property base class allowing Property* collections to be "homogeneous".
Definition: Property.h:38
Property * property(const std::string &name) const
Definition: PropertyMgr.cpp:85
const Property & PropertyMgr::getProperty ( const std::string name) const
override

get the property by name

See also
IProperty

Definition at line 159 of file PropertyMgr.cpp.

160 {
161  const Property* p = property( name ) ;
162  if ( !p ) throw std::out_of_range( "Property "+name+" not found." ); // Not found
163  return *p ; // RETURN
164 }
Property base class allowing Property* collections to be "homogeneous".
Definition: Property.h:38
Property * property(const std::string &name) const
Definition: PropertyMgr.cpp:85
StatusCode PropertyMgr::getProperty ( const std::string n,
std::string v 
) const
override

convert the property to the string

See also
IProperty

Definition at line 171 of file PropertyMgr.cpp.

173 {
174  // get the property
175  const Property* p = property( n ) ;
176  if ( !p ) { return StatusCode::FAILURE ; }
177  // convert the value into the string
178  v = p->toString() ;
179  //
180  return StatusCode::SUCCESS ;
181 }
virtual std::string toString() const =0
value -> string
Property base class allowing Property* collections to be "homogeneous".
Definition: Property.h:38
Property * property(const std::string &name) const
Definition: PropertyMgr.cpp:85
bool PropertyMgr::hasProperty ( const std::string name) const
override

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

See also
IProperty

Definition at line 201 of file PropertyMgr.cpp.

201  {
203  [&name](const Property* prop) {
204  return noCaseCmp(prop->name(), name);
205  });
206 }
const std::string & name() const
property name
Definition: Property.h:45
auto begin(reverse_wrapper< T > &w)
Definition: reverse.h:45
Properties m_properties
Collection of all declared properties.
Definition: PropertyMgr.h:172
auto end(reverse_wrapper< T > &w)
Definition: reverse.h:47
Property base class allowing Property* collections to be "homogeneous".
Definition: Property.h:38
T any_of(T...args)
PropertyMgr& PropertyMgr::operator= ( const PropertyMgr )
delete
Property * PropertyMgr::property ( const std::string name) const
protected

Definition at line 85 of file PropertyMgr.cpp.

86 {
87  // local property ?
88  Property* lp = property ( name , m_properties ) ;
89  if ( lp ) { return lp ; } // RETURN
90  // look for remote property
91  for ( const auto& it : m_remoteProperties )
92  {
93  if ( !noCaseCmp(it.first,name) ) { continue ; } // CONTINUE
94  const IProperty* p = it.second.first ;
95  if ( !p ) { continue ; } // CONTINUE
96  return property ( it.second.second , p->getProperties() ) ; // RETURN
97  }
98  return nullptr ; // RETURN
99 }
virtual const std::vector< Property * > & getProperties() const =0
Get list of properties.
Properties m_properties
Collection of all declared properties.
Definition: PropertyMgr.h:172
RemoteProperties m_remoteProperties
Collection of all declared remote properties.
Definition: PropertyMgr.h:174
Property base class allowing Property* collections to be "homogeneous".
Definition: Property.h:38
The IProperty is the basic interface for all components which have properties that can be set or get...
Definition: IProperty.h:21
Property * property(const std::string &name) const
Definition: PropertyMgr.cpp:85
Property * PropertyMgr::property ( const std::string name,
const std::vector< Property * > &  props 
) const
private

get the property by name form the proposed list

Definition at line 75 of file PropertyMgr.cpp.

77 {
78  auto it = std::find_if( props.begin(), props.end(), PropByName{ name } ) ;
79  return ( it != props.end() ) ? *it : nullptr; // RETURN
80 }
T end(T...args)
T find_if(T...args)
T begin(T...args)
StatusCode PropertyMgr::queryInterface ( const InterfaceID iid,
void **  pinterface 
)
override

Definition at line 190 of file PropertyMgr.cpp.

190  {
191  // try local interfaces
192  StatusCode sc= base_class::queryInterface(iid, pinterface);
193  if (sc.isSuccess()) return sc;
194  // fall back on the owner
195  return m_pOuter ? m_pOuter->queryInterface(iid, pinterface)
196  : sc; // FAILURE
197 }
IInterface * m_pOuter
Interface hub reference (ApplicationMgr)
Definition: PropertyMgr.h:178
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:76
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
StatusCode queryInterface(const InterfaceID &ti, void **pp) override
Implementation of IInterface::queryInterface.
Definition: implements.h:22
virtual StatusCode queryInterface(const InterfaceID &ti, void **pp)=0
Set the void** to the pointer to the requested interface of the instance.
StatusCode PropertyMgr::setProperty ( const Property p)
override

set the property form another property

See also
IProperty

Definition at line 105 of file PropertyMgr.cpp.

106 {
107  Property* pp = property( p.name() ) ;
108  try
109  { if ( pp && pp->assign(p) ) { return StatusCode::SUCCESS ; } } // RETURN
110  catch(...) { }
111  //
112  return StatusCode::FAILURE;
113 }
virtual bool assign(const Property &source)=0
import the property value form the source
const std::string & name() const
property name
Definition: Property.h:45
Property base class allowing Property* collections to be "homogeneous".
Definition: Property.h:38
Property * property(const std::string &name) const
Definition: PropertyMgr.cpp:85
StatusCode PropertyMgr::setProperty ( const std::string s)
override

set the property from the property formatted string

See also
IProperty

Definition at line 120 of file PropertyMgr.cpp.

121 {
122  std::string name ;
124  StatusCode sc = Gaudi::Parsers::parse( name , value , i ) ;
125  if ( sc.isFailure() ) { return sc ; }
126  return setProperty ( name , value ) ;
127 }
StatusCode setProperty(const Property &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
Test for a status code of FAILURE.
Definition: StatusCode.h:86
STL class.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
list i
Definition: ana.py:128
StatusCode PropertyMgr::setProperty ( const std::string n,
const std::string v 
)
override

set the property from name and the value

See also
IProperty

Definition at line 134 of file PropertyMgr.cpp.

135 {
136  Property* p = property( n ) ;
137  return ( p && p->fromString(v) ) ? StatusCode::SUCCESS : StatusCode::FAILURE ;
138 }
Property base class allowing Property* collections to be "homogeneous".
Definition: Property.h:38
Property * property(const std::string &name) const
Definition: PropertyMgr.cpp:85
virtual StatusCode fromString(const std::string &value)=0
string -> value

Member Data Documentation

IInterface* PropertyMgr::m_pOuter
private

Interface hub reference (ApplicationMgr)

Definition at line 178 of file PropertyMgr.h.

Properties PropertyMgr::m_properties
private

Collection of all declared properties.

Definition at line 172 of file PropertyMgr.h.

RemoteProperties PropertyMgr::m_remoteProperties
private

Collection of all declared remote properties.

Definition at line 174 of file PropertyMgr.h.

std::vector<std::unique_ptr<Property> > PropertyMgr::m_todelete
private

Properties to be deleted.

Definition at line 176 of file PropertyMgr.h.


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