Gaudi Framework, version v20r2

Generated: 18 Jul 2008

PropertyMgr Class Reference

#include <GaudiKernel/PropertyMgr.h>

Inheritance diagram for PropertyMgr:

Inheritance graph
[legend]
Collaboration diagram for PropertyMgr:

Collaboration graph
[legend]
List of all members.

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.

Public Member Functions

 PropertyMgr (IInterface *iface=0)
 contructor from the interface
 PropertyMgr (const PropertyMgr &)
virtual ~PropertyMgr ()
 virtual destructor
PropertyMgroperator= (const PropertyMgr &)
template<class TYPE>
PropertydeclareProperty (const std::string &name, TYPE &value, const std::string &doc="none")
 Declare a property (templated).
template<class TYPE>
PropertydeclareProperty (const std::string &name, SimpleProperty< TYPE > &prop, const std::string &doc="none")
 Declare a property (specialization).
template<class TYPE>
PropertydeclareProperty (const std::string &name, SimplePropertyRef< TYPE > &prop, const std::string &doc="none")
 Declare a property (specialization).
template<class TYPE>
PropertydeclareProperty (const std::string &name, ToolHandle< TYPE > &ref, const std::string &doc="none")
 Declare a property (specialization).
template<class TYPE>
PropertydeclareProperty (const std::string &name, ServiceHandle< TYPE > &ref, const std::string &doc="none")
 Declare a property (specialization).
template<class TYPE>
PropertydeclareProperty (const std::string &name, ToolHandleArray< TYPE > &ref, const std::string &doc="none")
 Declare a property (specialization).
PropertydeclareRemoteProperty (const std::string &name, IProperty *rsvc, const std::string &rname="")
 Declare a remote property.
StatusCode setProperty (const Property &p)
 set the property form another property
StatusCode setProperty (const std::string &s)
 set the property from the property formatted string
StatusCode setProperty (const std::string &n, const std::string &v)
 set the property from the property fomr name and the value
StatusCode getProperty (Property *p) const
 get the property
const PropertygetProperty (const std::string &name) const
 get the propery by name
StatusCode getProperty (const std::string &n, std::string &v) const
 convert the property to the string
const std::vector< Property * > & getProperties () const
 get all properties
StatusCode queryInterface (const InterfaceID &riid, void **ppvInterface)
 Query interfaces of Interface.
unsigned long addRef ()
 Increment the reference count of Interface instance.
unsigned long release ()
 Release Interface instance.

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

Private Attributes

Properties m_properties
 Collection of all declared properties.
RemoteProperties m_remoteProperties
 Collection of all declared remote properties.
Properties m_todelete
 Properties to be deleted.
std::vector< bool > m_isOwned
 Flag to decide to delete or not a propertyRef.
IInterfacem_pOuter
 Interface hub reference (ApplicationMgr).
unsigned long m_refcount
 Reference counter.


Member Typedef Documentation

typedef std::vector<Property*> PropertyMgr::Properties [private]

Definition at line 148 of file PropertyMgr.h.

typedef std::pair<std::string, std::pair<IProperty*, std::string> > PropertyMgr::RemProperty [private]

Definition at line 150 of file PropertyMgr.h.

typedef std::vector<RemProperty> PropertyMgr::RemoteProperties [private]

Definition at line 151 of file PropertyMgr.h.


Constructor & Destructor Documentation

PropertyMgr::PropertyMgr ( IInterface iface = 0  ) 

contructor from the interface

Definition at line 52 of file PropertyMgr.cpp.

00053   : m_properties       () 
00054   , m_remoteProperties ()
00055   , m_todelete         ()
00056   , m_pOuter           ( iface )
00057   , m_refcount         ( 1 )
00058 {} 

PropertyMgr::PropertyMgr ( const PropertyMgr  ) 

Definition at line 62 of file PropertyMgr.cpp.

References std::vector< _Tp, _Alloc >::begin(), Property::clone(), std::vector< _Tp, _Alloc >::end(), m_todelete, std::mem_fun(), and std::transform().

00063   : IInterface(right), IProperty(right)
00064   , m_properties       ( right.m_properties       ) 
00065   , m_remoteProperties ( right.m_remoteProperties )
00066   , m_todelete         ( right.m_todelete         )
00067   , m_pOuter           ( right.m_pOuter )
00068   , m_refcount         ( 1 )
00069 {
00070   std::transform
00071     ( m_todelete.begin() , m_todelete.end  () , 
00072       m_todelete.begin() , std::mem_fun(&Property::clone));
00073 } 

PropertyMgr::~PropertyMgr (  )  [virtual]

virtual destructor

delete all owned properties

Definition at line 77 of file PropertyMgr.cpp.

References std::vector< _Tp, _Alloc >::begin(), std::vector< _Tp, _Alloc >::end(), and m_todelete.

00078 {
00080   for ( Properties::iterator ip  = m_todelete.begin() ; 
00081         m_todelete.end() != ip ; ++ip ) { delete *ip ; }
00082 } 


Member Function Documentation

PropertyMgr & PropertyMgr::operator= ( const PropertyMgr  ) 

Definition at line 86 of file PropertyMgr.cpp.

References std::vector< _Tp, _Alloc >::begin(), Property::clone(), std::vector< _Tp, _Alloc >::end(), m_pOuter, m_properties, m_remoteProperties, m_todelete, std::mem_fun(), and std::transform().

00087 {
00088   if  ( &right == this ) { return *this ; }
00089   //
00090   for ( Properties::iterator ip  = m_todelete.begin() ; 
00091         m_todelete.end() != ip ; ++ip ) { delete *ip ; }
00092   //
00093   m_properties       = right.m_properties       ;
00094   m_remoteProperties = right.m_remoteProperties ;
00095   m_todelete         = right.m_todelete         ;
00096   m_pOuter           = right.m_pOuter           ;
00097   //
00098   std::transform
00099     ( m_todelete.begin() , m_todelete.end  () , 
00100       m_todelete.begin() , std::mem_fun(&Property::clone));  
00101   // 
00102   return *this ;
00103 } 

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 174 of file PropertyMgr.h.

References name, and Property::setDocumentation().

Referenced by Auditor::declareProperty(), and Algorithm::declareProperty().

00177 {
00178   Property* p = new SimplePropertyRef<TYPE> ( name , value ) ;
00179   //
00180   p->setDocumentation( doc );
00181   m_properties .push_back( p ) ;
00182   m_todelete   .push_back( p ) ;
00183   //
00184   return p ;
00185 }

template<class TYPE>
Property * PropertyMgr::declareProperty ( const std::string name,
SimpleProperty< TYPE > &  prop,
const std::string doc = "none" 
) [inline]

Declare a property (specialization).

Definition at line 192 of file PropertyMgr.h.

References name.

00195 {
00196   Property* p = &prop ;
00197   //
00198   p -> setName           ( name  ) ; 
00199   p -> setDocumentation  ( doc   ) ;
00200   m_properties.push_back ( p     ) ; 
00201   //
00202   return p ;
00203 }

template<class TYPE>
Property * PropertyMgr::declareProperty ( const std::string name,
SimplePropertyRef< TYPE > &  prop,
const std::string doc = "none" 
) [inline]

Declare a property (specialization).

Definition at line 210 of file PropertyMgr.h.

References name.

00213 {
00214   Property* p = &prop ;
00215   //
00216   p -> setName             ( name  ) ; 
00217   p -> setDocumentation    ( doc   ) ;
00218   m_properties.push_back   ( p     ) ;
00219   //
00220   return p ;
00221 }

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 228 of file PropertyMgr.h.

References name.

00231 {
00232   Property* p = new GaudiHandleProperty( name, ref );
00233   //
00234   p -> setDocumentation    ( doc ) ;
00235   m_properties . push_back ( p   ) ;
00236   m_todelete   . push_back ( p   ) ;
00237   //
00238   return p ;
00239 }

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 244 of file PropertyMgr.h.

References name.

00247 {
00248   Property* p = new GaudiHandleProperty( name, ref );
00249   //
00250   p -> setDocumentation    ( doc ) ;
00251   m_properties . push_back ( p   ) ;
00252   m_todelete   . push_back ( p   ) ;  
00253   //
00254   return p ;
00255 }

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 260 of file PropertyMgr.h.

References name.

00263 {
00264   Property* p = new GaudiHandleArrayProperty( name, ref );
00265   //
00266   p -> setDocumentation    ( doc ) ;
00267   m_properties . push_back ( p   ) ;
00268   m_todelete   . push_back ( p   ) ;
00269   //
00270   return p ;
00271 }

Property * PropertyMgr::declareRemoteProperty ( const std::string name,
IProperty rsvc,
const std::string rname = "" 
)

Declare a remote property.

Definition at line 108 of file PropertyMgr.cpp.

References std::basic_string< _CharT, _Traits, _Alloc >::empty(), IProperty::getProperties(), std::make_pair(), name, and std::basic_string< _CharT, _Traits, _Alloc >::push_back().

00111 {
00112   if ( 0 == rsvc ) { return 0 ; }
00113   const std::string& nam = rname.empty() ? name : rname ;
00114   Property* p = property ( nam , rsvc->getProperties() )  ;
00115   m_remoteProperties.push_back ( RemProperty ( name , std::make_pair ( rsvc , nam ) ) ) ;
00116   return p ;
00117 } 

StatusCode PropertyMgr::setProperty ( const Property p  )  [virtual]

set the property form another property

See also:
IProperty

Implements IProperty.

Definition at line 156 of file PropertyMgr.cpp.

References Property::assign(), StatusCode::FAILURE, Property::name(), property(), and StatusCode::SUCCESS.

Referenced by JobOptionsSvc::setProperty(), Service::setProperty(), setProperty(), Auditor::setProperty(), AlgTool::setProperty(), and Algorithm::setProperty().

00157 {
00158   Property* pp = property( p.name() ) ;    
00159   if ( 0 == pp            ) { return StatusCode::FAILURE ; } // RETURN 
00160   //
00161   try
00162   { if ( !pp->assign(p) ) { return StatusCode::FAILURE ; } } // RETURN 
00163   catch(...)              { return StatusCode::FAILURE ;   } // RETURN 
00164   //
00165   return StatusCode::SUCCESS;      // Property value set
00166 }

StatusCode PropertyMgr::setProperty ( const std::string s  )  [virtual]

set the property from the property formatted string

See also:
IProperty

Implements IProperty.

Definition at line 173 of file PropertyMgr.cpp.

References StatusCode::isFailure(), name, Gaudi::Parsers::parse(), and setProperty().

00174 {
00175   std::string name  ;
00176   std::string value ;
00177   StatusCode sc = Gaudi::Parsers::parse( name , value , i ) ;
00178   if ( sc.isFailure() ) { return sc ; }
00179   return setProperty ( name , value ) ;
00180 }

StatusCode PropertyMgr::setProperty ( const std::string n,
const std::string v 
) [virtual]

set the property from the property fomr name and the value

See also:
IProperty

Implements IProperty.

Definition at line 187 of file PropertyMgr.cpp.

References StatusCode::FAILURE, Property::fromString(), property(), and StatusCode::SUCCESS.

00188 {
00189   Property* p = property( n ) ;
00190   if ( 0 == p ) { return StatusCode::FAILURE ; }  // RETURN
00191   bool result =  p->fromString( v ) != 0 ;
00192   return result ? StatusCode::SUCCESS : StatusCode::FAILURE ;  
00193 } 

StatusCode PropertyMgr::getProperty ( Property p  )  const [virtual]

get the property

See also:
IProperty

Implements IProperty.

Definition at line 199 of file PropertyMgr.cpp.

References StatusCode::FAILURE, Property::load(), Property::name(), property(), and StatusCode::SUCCESS.

Referenced by JobOptionsSvc::getProperty(), Service::getProperty(), Auditor::getProperty(), AlgTool::getProperty(), and Algorithm::getProperty().

00200 {
00201   try 
00202   {
00203     const Property* pp = property( p->name() ) ;
00204     if ( 0 == pp         ) { return StatusCode::FAILURE ; }   // RETURN 
00205     if ( !pp->load( *p ) ) { return StatusCode::FAILURE ; }   // RETURN 
00206   }
00207   catch ( ... )            { return StatusCode::FAILURE;  }   // RETURN 
00208   return StatusCode::SUCCESS ;                                // RETURN 
00209 } 

const Property & PropertyMgr::getProperty ( const std::string name  )  const [virtual]

get the propery by name

See also:
IProperty

Implements IProperty.

Definition at line 215 of file PropertyMgr.cpp.

References name, and property().

00216 {
00217   const Property* p = property( name ) ;
00218   if ( 0 != p ) { return *p ; }                        // RETURN 
00219   //
00220   throw std::out_of_range( "Property "+name+" not found." );    // Not found
00221 }

StatusCode PropertyMgr::getProperty ( const std::string n,
std::string v 
) const [virtual]

convert the property to the string

See also:
IProperty

Implements IProperty.

Definition at line 228 of file PropertyMgr.cpp.

References StatusCode::FAILURE, StatusCode::SUCCESS, and Property::toString().

00230 {
00231   // get the property
00232   const Property* p = property( n ) ;
00233   if ( 0 == p ) { return StatusCode::FAILURE ; }
00234   // convert the value into the string 
00235   v = p->toString() ;
00236   //
00237   return StatusCode::SUCCESS ;
00238 } 

const std::vector< Property * > & PropertyMgr::getProperties (  )  const [virtual]

get all properties

See also:
IProperty

Implements IProperty.

Definition at line 243 of file PropertyMgr.cpp.

References m_properties.

Referenced by ApplicationMgr::configure(), Service::getProperties(), Auditor::getProperties(), AlgTool::getProperties(), and Algorithm::getProperties().

00243 { return m_properties; }

StatusCode PropertyMgr::queryInterface ( const InterfaceID riid,
void **  ppvInterface 
) [virtual]

Query interfaces of Interface.

Parameters:
riid ID of Interface to be retrieved
ppvInterface Pointer to Location for interface pointer

Implements IInterface.

Definition at line 248 of file PropertyMgr.cpp.

References StatusCode::FAILURE, IProperty::interfaceID(), IInterface::interfaceID(), and StatusCode::SUCCESS.

00250 { 
00251   // invalid destination
00252   if ( 0 == pinterface ) { return StatusCode::FAILURE ; }
00253   
00254   if      ( IInterface ::interfaceID () == iid ) 
00255   { *pinterface = static_cast<IInterface*> ( this ) ; } 
00256   else if ( IProperty  ::interfaceID () == iid ) 
00257   { *pinterface = static_cast<IProperty*>  ( this ) ; }
00258   else if ( 0 != m_pOuter ) // get the interface from the hub
00259   { return m_pOuter->queryInterface(iid, pinterface) ; }   // RETURN 
00260   else { return StatusCode::FAILURE ; }                    // RETURN 
00261   //
00262   addRef() ;
00263   return StatusCode::SUCCESS ; 
00264 }

unsigned long PropertyMgr::addRef (  )  [virtual]

Increment the reference count of Interface instance.

Implements IInterface.

Definition at line 268 of file PropertyMgr.cpp.

References m_refcount.

00268 { return ++m_refcount; }

unsigned long PropertyMgr::release (  )  [virtual]

Release Interface instance.

Implements IInterface.

Definition at line 272 of file PropertyMgr.cpp.

References count(), and m_refcount.

Referenced by ApplicationMgr::~ApplicationMgr().

00273 {
00274   unsigned long count =  --m_refcount;
00275   if ( 0 == count ) {  delete this; }
00276   return count;
00277 } 

Property * PropertyMgr::property ( const std::string name  )  const [protected]

Definition at line 134 of file PropertyMgr.cpp.

References IProperty::getProperties(), and name.

Referenced by getProperty(), and setProperty().

00135 { 
00136   // local property ?
00137   Property* lp = property ( name , m_properties ) ;
00138   if ( 0 != lp ) { return lp ; }                       // RETURN 
00139   // look for remote property 
00140   Nocase cmp ;
00141   for ( RemoteProperties::const_iterator it = m_remoteProperties.begin() ;
00142         m_remoteProperties.end() != it ; ++it ) 
00143   {
00144     if ( !cmp(it->first,name) ) { continue ; }   // CONTINUE 
00145     const IProperty* p = it->second.first ;
00146     if ( 0 == p               ) { continue ; }   // CONITNUE 
00147     return property ( it->second.second , p->getProperties() ) ; // RETURN 
00148   }
00149   return 0 ;                                           // RETURN 
00150 } 

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 122 of file PropertyMgr.cpp.

References std::vector< _Tp, _Alloc >::begin(), std::vector< _Tp, _Alloc >::end(), std::find_if(), and name.

00124 {
00125   Properties::const_iterator it = 
00126     std::find_if ( props.begin() , props.end() , PropByName( name ) ) ;
00127   if ( props.end() != it ) { return *it ; }                // RETURN  
00128   return 0 ;                                               // RETURN 
00129 }


Member Data Documentation

Properties PropertyMgr::m_properties [private]

Collection of all declared properties.

Definition at line 156 of file PropertyMgr.h.

Referenced by getProperties(), and operator=().

RemoteProperties PropertyMgr::m_remoteProperties [private]

Collection of all declared remote properties.

Definition at line 158 of file PropertyMgr.h.

Referenced by operator=().

Properties PropertyMgr::m_todelete [private]

Properties to be deleted.

Definition at line 160 of file PropertyMgr.h.

Referenced by operator=(), PropertyMgr(), and ~PropertyMgr().

std::vector<bool> PropertyMgr::m_isOwned [private]

Flag to decide to delete or not a propertyRef.

Definition at line 162 of file PropertyMgr.h.

IInterface* PropertyMgr::m_pOuter [private]

Interface hub reference (ApplicationMgr).

Definition at line 164 of file PropertyMgr.h.

Referenced by operator=().

unsigned long PropertyMgr::m_refcount [private]

Reference counter.

Definition at line 166 of file PropertyMgr.h.

Referenced by addRef(), and release().


The documentation for this class was generated from the following files:
Generated at Fri Jul 18 12:09:04 2008 for Gaudi Framework, version v20r2 by Doxygen version 1.5.1 written by Dimitri van Heesch, © 1997-2004