GaudiHandle< T > Class Template Referenceabstract

Handle to be used in lieu of naked pointers to gaudis. More...

#include <GaudiKernel/GaudiHandle.h>

Inheritance diagram for GaudiHandle< T >:
Collaboration diagram for GaudiHandle< T >:

Public Member Functions

 GaudiHandle (const GaudiHandle &other)
 Copy constructor needed for correct ref-counting. More...
 
GaudiHandleoperator= (const GaudiHandle &other)
 Assignment operator for correct ref-counting. More...
 
StatusCode retrieve () const
 Retrieve the component. More...
 
StatusCode release () const
 Release the component. More...
 
bool isValid () const
 Check if the handle is valid (try to retrive the object is not done yet). More...
 
 operator bool () const
 For testing if handle has component. More...
 
T * get () const
 Return the wrapped pointer, not calling retrieve() if null. More...
 
bool isSet () const
 True if the wrapped pointer is not null. More...
 
T & operator* ()
 
T * operator-> ()
 
T & operator* () const
 
T * operator-> () const
 
std::string getDefaultType ()
 Helper function to get default type string from the class type. More...
 
std::string getDefaultName ()
 
 GaudiHandle (const GaudiHandle &other)
 Copy constructor needed for correct ref-counting. More...
 
GaudiHandleoperator= (const GaudiHandle &other)
 Assignment operator for correct ref-counting. More...
 
StatusCode retrieve () const
 Retrieve the component. More...
 
StatusCode release () const
 Release the component. More...
 
bool isValid () const
 Check if the handle is valid (try to retrive the object is not done yet). More...
 
 operator bool () const
 For testing if handle has component. More...
 
T * get () const
 Return the wrapped pointer, not calling retrieve() if null. More...
 
bool isSet () const
 True if the wrapped pointer is not null. More...
 
T & operator* ()
 
T * operator-> ()
 
T & operator* () const
 
T * operator-> () const
 
std::string getDefaultType ()
 Helper function to get default type string from the class type. More...
 
std::string getDefaultName ()
 
- Public Member Functions inherited from GaudiHandleBase
std::string typeAndName () const
 The full type and name: "type/name". More...
 
std::string type () const
 The concrete component class name: the part before the '/'. More...
 
std::string name () const
 The instance name: the part after the '/'. More...
 
bool empty () const
 Check if the handle has been set to empty string (i.e. More...
 
void setTypeAndName (const std::string &myTypeAndName)
 The component "type/name" string. More...
 
void setName (const std::string &myName)
 Set the instance name (part after the '/') without changing the class type. More...
 
const std::string pythonPropertyClassName () const
 Name of the componentType with "Handle" appended. More...
 
const std::string messageName () const
 name used for printing messages More...
 
virtual const std::string pythonRepr () const
 Python representation of handle, i.e. More...
 
std::string typeAndName () const
 The full type and name: "type/name". More...
 
std::string type () const
 The concrete component class name: the part before the '/'. More...
 
std::string name () const
 The instance name: the part after the '/'. More...
 
bool empty () const
 Check if the handle has been set to empty string (i.e. More...
 
void setTypeAndName (const std::string &myTypeAndName)
 The component "type/name" string. More...
 
void setName (const std::string &myName)
 Set the instance name (part after the '/') without changing the class type. More...
 
const std::string pythonPropertyClassName () const
 Name of the componentType with "Handle" appended. More...
 
const std::string messageName () const
 name used for printing messages More...
 
virtual const std::string pythonRepr () const
 Python representation of handle, i.e. More...
 
- Public Member Functions inherited from GaudiHandleInfo
virtual ~GaudiHandleInfo ()
 virtual destructor so that derived class destructor is called. More...
 
const std::string & componentType () const
 
const std::string & propertyName () const
 name as used in declareProperty(name,gaudiHandle) More...
 
void setPropertyName (const std::string &propName)
 set name as used in declareProperty(name,gaudiHandle). More...
 
const std::string & parentName () const
 The name of the parent. More...
 
virtual ~GaudiHandleInfo ()
 virtual destructor so that derived class destructor is called. More...
 
const std::string & componentType () const
 
const std::string & propertyName () const
 name as used in declareProperty(name,gaudiHandle) More...
 
void setPropertyName (const std::string &propName)
 set name as used in declareProperty(name,gaudiHandle). More...
 
const std::string & parentName () const
 The name of the parent. More...
 

Protected Member Functions

 GaudiHandle (const std::string &myTypeAndName, const std::string &myComponentType, const std::string &myParentName)
 
virtual StatusCode retrieve (T *&) const =0
 Retrieve the component. More...
 
virtual StatusCode release (T *comp) const
 Release the component. More...
 
 GaudiHandle (const std::string &myTypeAndName, const std::string &myComponentType, const std::string &myParentName)
 
virtual StatusCode retrieve (T *&) const =0
 Retrieve the component. More...
 
virtual StatusCode release (T *comp) const
 Release the component. More...
 
- Protected Member Functions inherited from GaudiHandleBase
 GaudiHandleBase (const std::string &myTypeAndName, const std::string &myComponentType, const std::string &myParentName)
 Create a handle ('smart pointer') to a gaudi component. More...
 
 GaudiHandleBase (const std::string &myTypeAndName, const std::string &myComponentType, const std::string &myParentName)
 Create a handle ('smart pointer') to a gaudi component. More...
 
- Protected Member Functions inherited from GaudiHandleInfo
 GaudiHandleInfo (const std::string &myComponentType, const std::string &myParentName)
 Some basic information and helper functions shared between various handles/arrays. More...
 
 GaudiHandleInfo (const std::string &myComponentType, const std::string &myParentName)
 Some basic information and helper functions shared between various handles/arrays. More...
 

Private Member Functions

void setDefaultTypeAndName ()
 Helper function to set default name and type. More...
 
void setDefaultType ()
 Helper function to set default type from the class type T. More...
 
void assertObject () const
 Load the pointer to the component. More...
 
void setDefaultTypeAndName ()
 Helper function to set default name and type. More...
 
void setDefaultType ()
 Helper function to set default type from the class type T. More...
 
void assertObject () const
 Load the pointer to the component. More...
 

Private Attributes

T * m_pObject
 

Detailed Description

template<class T>
class GaudiHandle< T >

Handle to be used in lieu of naked pointers to gaudis.

This allows better control through the framework of gaudi loading and usage. T is the type of the component interface (or concrete class).

Author
Marti.nosp@m.n.Wo.nosp@m.udstr.nosp@m.a@ce.nosp@m.rn.ch

Definition at line 158 of file GaudiHandle.h.

Constructor & Destructor Documentation

template<class T>
GaudiHandle< T >::GaudiHandle ( const std::string &  myTypeAndName,
const std::string &  myComponentType,
const std::string &  myParentName 
)
inlineprotected

Definition at line 163 of file GaudiHandle.h.

165  : GaudiHandleBase(myTypeAndName, myComponentType, myParentName), m_pObject(0)
166  {}
GaudiHandleBase(const std::string &myTypeAndName, const std::string &myComponentType, const std::string &myParentName)
Create a handle ('smart pointer') to a gaudi component.
Definition: GaudiHandle.h:96
template<class T>
GaudiHandle< T >::GaudiHandle ( const GaudiHandle< T > &  other)
inline

Copy constructor needed for correct ref-counting.

Definition at line 170 of file GaudiHandle.h.

171  : GaudiHandleBase( other ) {
172  m_pObject = other.m_pObject;
173  if ( m_pObject ) m_pObject->addRef();
174  }
GaudiHandleBase(const std::string &myTypeAndName, const std::string &myComponentType, const std::string &myParentName)
Create a handle ('smart pointer') to a gaudi component.
Definition: GaudiHandle.h:96
template<class T>
GaudiHandle< T >::GaudiHandle ( const std::string &  myTypeAndName,
const std::string &  myComponentType,
const std::string &  myParentName 
)
inlineprotected

Definition at line 163 of file GaudiHandle.h.

165  : GaudiHandleBase(myTypeAndName, myComponentType, myParentName), m_pObject(0)
166  {}
GaudiHandleBase(const std::string &myTypeAndName, const std::string &myComponentType, const std::string &myParentName)
Create a handle ('smart pointer') to a gaudi component.
Definition: GaudiHandle.h:96
template<class T>
GaudiHandle< T >::GaudiHandle ( const GaudiHandle< T > &  other)
inline

Copy constructor needed for correct ref-counting.

Definition at line 170 of file GaudiHandle.h.

171  : GaudiHandleBase( other ) {
172  m_pObject = other.m_pObject;
173  if ( m_pObject ) m_pObject->addRef();
174  }
GaudiHandleBase(const std::string &myTypeAndName, const std::string &myComponentType, const std::string &myParentName)
Create a handle ('smart pointer') to a gaudi component.
Definition: GaudiHandle.h:96

Member Function Documentation

template<class T>
void GaudiHandle< T >::assertObject ( ) const
inlineprivate

Load the pointer to the component.

Do a retrieve if needed. Throw an exception if retrieval fails.

Definition at line 284 of file GaudiHandle.h.

284  { // not really const, because it may update m_pObject
285  if ( !isValid() ) {
286  throw GaudiException("Failed to retrieve " + componentType() + ": " + typeAndName(),
287  componentType() + " retrieve", StatusCode::FAILURE);
288  }
289  }
Define general base for Gaudi exception.
bool isValid() const
Check if the handle is valid (try to retrive the object is not done yet).
Definition: GaudiHandle.h:208
std::string typeAndName() const
The full type and name: "type/name".
Definition: GaudiHandle.h:107
const std::string & componentType() const
Definition: GaudiHandle.h:33
template<class T>
void GaudiHandle< T >::assertObject ( ) const
inlineprivate

Load the pointer to the component.

Do a retrieve if needed. Throw an exception if retrieval fails.

Definition at line 284 of file GaudiHandle.h.

284  { // not really const, because it may update m_pObject
285  if ( !isValid() ) {
286  throw GaudiException("Failed to retrieve " + componentType() + ": " + typeAndName(),
287  componentType() + " retrieve", StatusCode::FAILURE);
288  }
289  }
Define general base for Gaudi exception.
bool isValid() const
Check if the handle is valid (try to retrive the object is not done yet).
Definition: GaudiHandle.h:208
std::string typeAndName() const
The full type and name: "type/name".
Definition: GaudiHandle.h:107
const std::string & componentType() const
Definition: GaudiHandle.h:33
template<class T>
T* GaudiHandle< T >::get ( ) const
inline

Return the wrapped pointer, not calling retrieve() if null.

Definition at line 219 of file GaudiHandle.h.

219  {
220  return m_pObject;
221  }
template<class T>
T* GaudiHandle< T >::get ( ) const
inline

Return the wrapped pointer, not calling retrieve() if null.

Definition at line 219 of file GaudiHandle.h.

219  {
220  return m_pObject;
221  }
template<class T>
std::string GaudiHandle< T >::getDefaultName ( )
inline

Definition at line 253 of file GaudiHandle.h.

253  {
254  std::string defName = GaudiHandleBase::type();
255  if ( defName.empty() ) defName = getDefaultType();
256  return defName;
257  }
std::string getDefaultType()
Helper function to get default type string from the class type.
Definition: GaudiHandle.h:249
std::string type() const
The concrete component class name: the part before the '/'.
Definition: GaudiHandle.cpp:13
template<class T>
std::string GaudiHandle< T >::getDefaultName ( )
inline

Definition at line 253 of file GaudiHandle.h.

253  {
254  std::string defName = GaudiHandleBase::type();
255  if ( defName.empty() ) defName = getDefaultType();
256  return defName;
257  }
std::string getDefaultType()
Helper function to get default type string from the class type.
Definition: GaudiHandle.h:249
std::string type() const
The concrete component class name: the part before the '/'.
Definition: GaudiHandle.cpp:13
template<class T>
std::string GaudiHandle< T >::getDefaultType ( )
inline

Helper function to get default type string from the class type.

Definition at line 249 of file GaudiHandle.h.

249  {
250  return System::typeinfoName( typeid(T) );
251  }
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition: System.cpp:299
template<class T>
std::string GaudiHandle< T >::getDefaultType ( )
inline

Helper function to get default type string from the class type.

Definition at line 249 of file GaudiHandle.h.

249  {
250  return System::typeinfoName( typeid(T) );
251  }
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition: System.cpp:299
template<class T>
bool GaudiHandle< T >::isSet ( ) const
inline

True if the wrapped pointer is not null.

Definition at line 224 of file GaudiHandle.h.

224  {
225  return get();
226  }
template<class T>
bool GaudiHandle< T >::isSet ( ) const
inline

True if the wrapped pointer is not null.

Definition at line 224 of file GaudiHandle.h.

224  {
225  return get();
226  }
template<class T>
bool GaudiHandle< T >::isValid ( ) const
inline

Check if the handle is valid (try to retrive the object is not done yet).

Definition at line 208 of file GaudiHandle.h.

208  { // not really const, because it may update m_pObject
209  return m_pObject || retrieve().isSuccess();
210  }
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:75
StatusCode retrieve() const
Retrieve the component.
Definition: GaudiHandle.h:188
template<class T>
bool GaudiHandle< T >::isValid ( ) const
inline

Check if the handle is valid (try to retrive the object is not done yet).

Definition at line 208 of file GaudiHandle.h.

208  { // not really const, because it may update m_pObject
209  return m_pObject || retrieve().isSuccess();
210  }
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:75
StatusCode retrieve() const
Retrieve the component.
Definition: GaudiHandle.h:188
template<class T>
GaudiHandle< T >::operator bool ( ) const
inline

For testing if handle has component.

Does retrieve() if needed. If this returns false, the component could not be retrieved.

Definition at line 214 of file GaudiHandle.h.

214  { // not really const, because it may update m_pObject
215  return isValid();
216  }
bool isValid() const
Check if the handle is valid (try to retrive the object is not done yet).
Definition: GaudiHandle.h:208
template<class T>
GaudiHandle< T >::operator bool ( ) const
inline

For testing if handle has component.

Does retrieve() if needed. If this returns false, the component could not be retrieved.

Definition at line 214 of file GaudiHandle.h.

214  { // not really const, because it may update m_pObject
215  return isValid();
216  }
bool isValid() const
Check if the handle is valid (try to retrive the object is not done yet).
Definition: GaudiHandle.h:208
template<class T>
T& GaudiHandle< T >::operator* ( )
inline

Definition at line 228 of file GaudiHandle.h.

228  {
229  assertObject();
230  return *m_pObject;
231  }
void assertObject() const
Load the pointer to the component.
Definition: GaudiHandle.h:284
template<class T>
T& GaudiHandle< T >::operator* ( )
inline

Definition at line 228 of file GaudiHandle.h.

228  {
229  assertObject();
230  return *m_pObject;
231  }
void assertObject() const
Load the pointer to the component.
Definition: GaudiHandle.h:284
template<class T>
T& GaudiHandle< T >::operator* ( ) const
inline

Definition at line 238 of file GaudiHandle.h.

238  { // not really const, because it may update m_pObject
239  assertObject();
240  return *m_pObject;
241  }
void assertObject() const
Load the pointer to the component.
Definition: GaudiHandle.h:284
template<class T>
T& GaudiHandle< T >::operator* ( ) const
inline

Definition at line 238 of file GaudiHandle.h.

238  { // not really const, because it may update m_pObject
239  assertObject();
240  return *m_pObject;
241  }
void assertObject() const
Load the pointer to the component.
Definition: GaudiHandle.h:284
template<class T>
T* GaudiHandle< T >::operator-> ( )
inline

Definition at line 233 of file GaudiHandle.h.

233  {
234  assertObject();
235  return m_pObject;
236  }
void assertObject() const
Load the pointer to the component.
Definition: GaudiHandle.h:284
template<class T>
T* GaudiHandle< T >::operator-> ( )
inline

Definition at line 233 of file GaudiHandle.h.

233  {
234  assertObject();
235  return m_pObject;
236  }
void assertObject() const
Load the pointer to the component.
Definition: GaudiHandle.h:284
template<class T>
T* GaudiHandle< T >::operator-> ( ) const
inline

Definition at line 243 of file GaudiHandle.h.

243  { // not really const, because it may update m_pObject
244  assertObject();
245  return m_pObject;
246  }
void assertObject() const
Load the pointer to the component.
Definition: GaudiHandle.h:284
template<class T>
T* GaudiHandle< T >::operator-> ( ) const
inline

Definition at line 243 of file GaudiHandle.h.

243  { // not really const, because it may update m_pObject
244  assertObject();
245  return m_pObject;
246  }
void assertObject() const
Load the pointer to the component.
Definition: GaudiHandle.h:284
template<class T>
GaudiHandle& GaudiHandle< T >::operator= ( const GaudiHandle< T > &  other)
inline

Assignment operator for correct ref-counting.

Definition at line 177 of file GaudiHandle.h.

177  {
178  GaudiHandleBase::operator=( other );
179  // release any current tool
180  release().ignore();
181  m_pObject = other.m_pObject;
182  // update ref-counting
183  if ( m_pObject ) m_pObject->addRef();
184  return *this;
185  }
StatusCode release() const
Release the component.
Definition: GaudiHandle.h:198
void ignore() const
Definition: StatusCode.h:107
template<class T>
GaudiHandle& GaudiHandle< T >::operator= ( const GaudiHandle< T > &  other)
inline

Assignment operator for correct ref-counting.

Definition at line 177 of file GaudiHandle.h.

177  {
178  GaudiHandleBase::operator=( other );
179  // release any current tool
180  release().ignore();
181  m_pObject = other.m_pObject;
182  // update ref-counting
183  if ( m_pObject ) m_pObject->addRef();
184  return *this;
185  }
StatusCode release() const
Release the component.
Definition: GaudiHandle.h:198
void ignore() const
Definition: StatusCode.h:107
template<class T>
StatusCode GaudiHandle< T >::release ( ) const
inline

Release the component.

Definition at line 198 of file GaudiHandle.h.

198  { // not really const, because it updates m_pObject
199  if ( m_pObject ) {
201  m_pObject = 0;
202  return sc;
203  }
204  return StatusCode::SUCCESS;
205  }
StatusCode release() const
Release the component.
Definition: GaudiHandle.h:198
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
template<class T>
StatusCode GaudiHandle< T >::release ( ) const
inline

Release the component.

Definition at line 198 of file GaudiHandle.h.

198  { // not really const, because it updates m_pObject
199  if ( m_pObject ) {
201  m_pObject = 0;
202  return sc;
203  }
204  return StatusCode::SUCCESS;
205  }
StatusCode release() const
Release the component.
Definition: GaudiHandle.h:198
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
template<class T>
virtual StatusCode GaudiHandle< T >::release ( T *  comp) const
inlineprotectedvirtual

Release the component.

Default implementation calls release() on the component. Can be overridden by the derived class if something else if needed.

Reimplemented in ToolHandle< T >, and ToolHandle< T >.

Definition at line 265 of file GaudiHandle.h.

265  { // not really const, because it updates m_pObject
266  comp->release();
267  return StatusCode::SUCCESS;
268  }
template<class T>
virtual StatusCode GaudiHandle< T >::release ( T *  comp) const
inlineprotectedvirtual

Release the component.

Default implementation calls release() on the component. Can be overridden by the derived class if something else if needed.

Reimplemented in ToolHandle< T >, and ToolHandle< T >.

Definition at line 265 of file GaudiHandle.h.

265  { // not really const, because it updates m_pObject
266  comp->release();
267  return StatusCode::SUCCESS;
268  }
template<class T>
StatusCode GaudiHandle< T >::retrieve ( ) const
inline

Retrieve the component.

Release existing component if needed.

Definition at line 188 of file GaudiHandle.h.

188  { // not really const, because it updates m_pObject
189  if ( m_pObject && release().isFailure() ) return StatusCode::FAILURE;
190  if ( retrieve( m_pObject ).isFailure() ) {
191  m_pObject = 0;
192  return StatusCode::FAILURE;
193  }
194  return StatusCode::SUCCESS;
195  }
StatusCode release() const
Release the component.
Definition: GaudiHandle.h:198
StatusCode retrieve() const
Retrieve the component.
Definition: GaudiHandle.h:188
template<class T>
StatusCode GaudiHandle< T >::retrieve ( ) const
inline

Retrieve the component.

Release existing component if needed.

Definition at line 188 of file GaudiHandle.h.

188  { // not really const, because it updates m_pObject
189  if ( m_pObject && release().isFailure() ) return StatusCode::FAILURE;
190  if ( retrieve( m_pObject ).isFailure() ) {
191  m_pObject = 0;
192  return StatusCode::FAILURE;
193  }
194  return StatusCode::SUCCESS;
195  }
StatusCode release() const
Release the component.
Definition: GaudiHandle.h:198
StatusCode retrieve() const
Retrieve the component.
Definition: GaudiHandle.h:188
template<class T>
virtual StatusCode GaudiHandle< T >::retrieve ( T *&  ) const
protectedpure virtual

Retrieve the component.

To be implemented by the derived class. It will pass the pointer

Implemented in ToolHandle< T >, ToolHandle< T >, ServiceHandle< T >, ServiceHandle< T >, ServiceHandle< IToolSvc >, and ServiceHandle< IToolSvc >.

template<class T>
virtual StatusCode GaudiHandle< T >::retrieve ( T *&  ) const
protectedpure virtual

Retrieve the component.

To be implemented by the derived class. It will pass the pointer

Implemented in ToolHandle< T >, ToolHandle< T >, ServiceHandle< T >, ServiceHandle< T >, ServiceHandle< IToolSvc >, and ServiceHandle< IToolSvc >.

template<class T>
void GaudiHandle< T >::setDefaultType ( )
inlineprivate

Helper function to set default type from the class type T.

Definition at line 278 of file GaudiHandle.h.

278  {
280  }
std::string getDefaultType()
Helper function to get default type string from the class type.
Definition: GaudiHandle.h:249
void setTypeAndName(const std::string &myTypeAndName)
The component "type/name" string.
Definition: GaudiHandle.cpp:9
template<class T>
void GaudiHandle< T >::setDefaultType ( )
inlineprivate

Helper function to set default type from the class type T.

Definition at line 278 of file GaudiHandle.h.

278  {
280  }
std::string getDefaultType()
Helper function to get default type string from the class type.
Definition: GaudiHandle.h:249
void setTypeAndName(const std::string &myTypeAndName)
The component "type/name" string.
Definition: GaudiHandle.cpp:9
template<class T>
void GaudiHandle< T >::setDefaultTypeAndName ( )
inlineprivate

Helper function to set default name and type.

Definition at line 272 of file GaudiHandle.h.

272  {
273  const std::string& myType = getDefaultType();
274  GaudiHandleBase::setTypeAndName(myType+'/'+myType);
275  }
std::string getDefaultType()
Helper function to get default type string from the class type.
Definition: GaudiHandle.h:249
void setTypeAndName(const std::string &myTypeAndName)
The component "type/name" string.
Definition: GaudiHandle.cpp:9
template<class T>
void GaudiHandle< T >::setDefaultTypeAndName ( )
inlineprivate

Helper function to set default name and type.

Definition at line 272 of file GaudiHandle.h.

272  {
273  const std::string& myType = getDefaultType();
274  GaudiHandleBase::setTypeAndName(myType+'/'+myType);
275  }
std::string getDefaultType()
Helper function to get default type string from the class type.
Definition: GaudiHandle.h:249
void setTypeAndName(const std::string &myTypeAndName)
The component "type/name" string.
Definition: GaudiHandle.cpp:9

Member Data Documentation

template<class T>
T * GaudiHandle< T >::m_pObject
mutableprivate

Definition at line 293 of file GaudiHandle.h.


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