ATLAS Offline Software
Loading...
Searching...
No Matches
D3PD::ObjGetterTool< T > Class Template Referenceabstract

This is a type-safe wrapper for the IObjGetterTool interface. More...

#include <ObjGetterTool.h>

Inheritance diagram for D3PD::ObjGetterTool< T >:
Collaboration diagram for D3PD::ObjGetterTool< T >:

Public Member Functions

 ObjGetterTool (const std::string &type, const std::string &name, const IInterface *parent)
 Standard Gaudi tool constructor.
virtual const void * getUntyped (bool allowMissing=false)
 Return the target object.
virtual const std::type_info & typeinfo () const
 Return the type of object retrieved by this tool.
virtual const T * get (bool allowMissing=false)=0
 Return the target object.
virtual void releaseObject (const T *p)
 Release an object retrieved from the getter.
virtual void releaseObjectUntyped (const void *p)
 Release an object retrieved from the getter.
virtual const void * getTypeinfo (const std::type_info &ti, bool allowMissing=false)
 Return the target object cast to a different pointer type.
virtual StatusCode configureTypeinfo (const std::type_info &ti)
 Test type compatibility.
void releaseObjectTypeinfo (const void *p, const std::type_info &ti)
 Release an object retrieved from the getter.

Private Attributes

TypeConverter m_converter
 Helper to convert pointers.
TypeConverter m_backConverter
 Helper to convert pointers back, for releaseObject.

Detailed Description

template<class T>
class D3PD::ObjGetterTool< T >

This is a type-safe wrapper for the IObjGetterTool interface.

The template argument gives the type of object being retrieved. Derived classes should implement the get() method, to retrieve an object, and optionally releaseObject() to dispose of an object.

Definition at line 34 of file ObjGetterTool.h.

Constructor & Destructor Documentation

◆ ObjGetterTool()

template<class T>
D3PD::ObjGetterTool< T >::ObjGetterTool ( const std::string & type,
const std::string & name,
const IInterface * parent )

Standard Gaudi tool constructor.

Parameters
typeThe name of the tool type.
nameThe tool name.
parentThe tool's Gaudi parent.

Member Function Documentation

◆ configureTypeinfo()

StatusCode D3PD::ObjGetterToolImpl::configureTypeinfo ( const std::type_info & ti)
virtualinherited

Test type compatibility.

Parameters
tiThe desired type.

Test to see if the object being returned by the tool can be converted to a pointer to T. This can be used to perform type checks during job initialization.

Definition at line 124 of file ObjGetterToolImpl.cxx.

125{
126 return this->m_converter.init(this->typeinfo(), ti);
127}
TypeConverter m_converter
Helper to convert pointers.

◆ get()

template<class T>
virtual const T * D3PD::ObjGetterTool< T >::get ( bool allowMissing = false)
pure virtual

Return the target object.

Parameters
allowMissingIf true, then we should not generate errors if the requested object is missing.

Return 0 on failure.

◆ getTypeinfo()

const void * D3PD::ObjGetterToolImpl::getTypeinfo ( const std::type_info & ti,
bool allowMissing = false )
virtualinherited

Return the target object cast to a different pointer type.

Parameters
tiThe desired type.
allowMissingIf true, then we should not generate errors if the requested object is missing.

Return the object as a pointer to the ti type. Return 0 if the get fails or if the pointer can't be converted.

Definition at line 45 of file ObjGetterToolImpl.cxx.

47{
48 // Configure the converter if needed.
49 if (!this->m_converter.isValid() ||
50 this->m_converter.dstTypeinfo() != ti)
51 {
52 if (this->configureTypeinfo(ti).isFailure())
53 return 0;
54 }
55
56 // Get the object.
57 const void* p = this->getUntyped (allowMissing);
58
59 // Convert to the desired type.
60 if (p) {
61 p = this->m_converter.convertUntyped (p);
62 if (!p) {
63 REPORT_MESSAGE (MSG::WARNING)
64 << "Pointer conversion from " << m_converter.srcName() << " to "
65 << m_converter.dstName() << "failed.";
66 }
67 }
68 return p;
69}
#define REPORT_MESSAGE(LVL)
Report a message.
virtual StatusCode configureTypeinfo(const std::type_info &ti)
Test type compatibility.

◆ getUntyped()

template<class T>
virtual const void * D3PD::ObjGetterTool< T >::getUntyped ( bool allowMissing = false)
virtual

Return the target object.

Parameters
allowMissingIf true, then we should not generate errors if the requested object is missing.

Should be of the type given by typeinfo. Return 0 on failure.

◆ releaseObject()

template<class T>
virtual void D3PD::ObjGetterTool< T >::releaseObject ( const T * p)
virtual

Release an object retrieved from the getter.

Parameters
pThe object to release.

Call this when you are done with the object returned by get(). The default implementation is a no-op, but if the getter dynamically allocated the object which it returned, this gives it a chance to free it.

◆ releaseObjectTypeinfo()

void D3PD::ObjGetterToolImpl::releaseObjectTypeinfo ( const void * p,
const std::type_info & ti )
inherited

Release an object retrieved from the getter.

Parameters
pThe object to release.
tiThe type of p.

Call this when you are done with the object returned by getUntyped(). The default implementation is a no-op, but if the getter dynamically allocated the object which it returned, this gives it a chance to free it.

Definition at line 82 of file ObjGetterToolImpl.cxx.

84{
85 if (!p)
86 return;
87
88 // Configure the converter if needed.
89 if (!this->m_backConverter.isValid() ||
90 this->m_backConverter.srcTypeinfo() != ti)
91 {
92 if (this->m_backConverter.init (ti, this->typeinfo()).isFailure()) {
93 REPORT_MESSAGE (MSG::WARNING)
94 << "Can't configure pointer conversion from "
95 << System::typeinfoName (ti) << " to "
96 << System::typeinfoName (this->typeinfo());
97 return;
98 }
99 }
100
101 // Convert to the desired type.
102 p = this->m_backConverter.convertUntyped (p);
103
104 // Release.
105 if (p)
106 this->releaseObjectUntyped (p);
107 else {
108 REPORT_MESSAGE (MSG::WARNING)
109 << "Pointer conversion from " << m_backConverter.srcName() << " to "
110 << m_backConverter.dstName() << "failed.";
111 }
112}
TypeConverter m_backConverter
Helper to convert pointers back, for releaseObject.

◆ releaseObjectUntyped()

template<class T>
virtual void D3PD::ObjGetterTool< T >::releaseObjectUntyped ( const void * p)
virtual

Release an object retrieved from the getter.

Parameters
pThe object to release.

Call this when you are done with the object returned by getUntyped(). The default implementation is a no-op, but if the getter dynamically allocated the object which it returned, this gives it a chance to free it.

◆ typeinfo()

template<class T>
virtual const std::type_info & D3PD::ObjGetterTool< T >::typeinfo ( ) const
virtual

Return the type of object retrieved by this tool.

Member Data Documentation

◆ m_backConverter

TypeConverter D3PD::ObjGetterToolImpl::m_backConverter
privateinherited

Helper to convert pointers back, for releaseObject.

Definition at line 97 of file ObjGetterToolImpl.h.

◆ m_converter

TypeConverter D3PD::ObjGetterToolImpl::m_converter
privateinherited

Helper to convert pointers.

Definition at line 94 of file ObjGetterToolImpl.h.


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