SmartIF< TYPE > Class Template Reference

Small smart pointer class with automatic reference counting for IInterface. More...

#include <GaudiKernel/SmartIF.h>

Collaboration diagram for SmartIF< TYPE >:

Public Member Functions

 SmartIF ()
 Default constructor. More...
 
 SmartIF (TYPE *ptr)
 Standard constructor from pointer. More...
 
template<class OTHER >
 SmartIF (OTHER *ptr)
 Standard constructor from any (IInterface-derived) pointer. More...
 
 SmartIF (const SmartIF &rhs)
 Copy constructor. More...
 
template<class T >
 SmartIF (const SmartIF< T > &rhs)
 Constructor from another SmartIF, with a different type. More...
 
 ~SmartIF ()
 Standard Destructor. More...
 
bool isValid () const
 Allow for check if smart pointer is valid. More...
 
 operator TYPE * () const
 Automatic conversion to pointer. More...
 
TYPE * operator-> () const
 Dereference operator. More...
 
TYPE & operator* () const
 Dereference operator. More...
 
TYPE * get () const
 Get interface pointer. More...
 
TYPE *& pRef ()
 Get reference to the pointer. More...
 
void reset (TYPE *ptr=0)
 Set the internal pointer to the passed one disposing of the old one. More...
 
template<class OTHER >
void reset (OTHER *ptr)
 Set the internal pointer to the passed one disposing of the old one. More...
 
SmartIFoperator= (IInterface *ptr)
 Assignment operator from IInterface pointer. More...
 
SmartIFoperator= (const SmartIF &rhs)
 Assignment operator. More...
 
template<class T >
SmartIFoperator= (const SmartIF< T > &rhs)
 Assignment operator from a different SmartIF. More...
 
 SmartIF ()
 Default constructor. More...
 
 SmartIF (TYPE *ptr)
 Standard constructor from pointer. More...
 
template<class OTHER >
 SmartIF (OTHER *ptr)
 Standard constructor from any (IInterface-derived) pointer. More...
 
 SmartIF (const SmartIF &rhs)
 Copy constructor. More...
 
template<class T >
 SmartIF (const SmartIF< T > &rhs)
 Constructor from another SmartIF, with a different type. More...
 
 ~SmartIF ()
 Standard Destructor. More...
 
bool isValid () const
 Allow for check if smart pointer is valid. More...
 
 operator TYPE * () const
 Automatic conversion to pointer. More...
 
TYPE * operator-> () const
 Dereference operator. More...
 
TYPE & operator* () const
 Dereference operator. More...
 
TYPE * get () const
 Get interface pointer. More...
 
TYPE *& pRef ()
 Get reference to the pointer. More...
 
void reset (TYPE *ptr=0)
 Set the internal pointer to the passed one disposing of the old one. More...
 
template<class OTHER >
void reset (OTHER *ptr)
 Set the internal pointer to the passed one disposing of the old one. More...
 
SmartIFoperator= (IInterface *ptr)
 Assignment operator from IInterface pointer. More...
 
SmartIFoperator= (const SmartIF &rhs)
 Assignment operator. More...
 
template<class T >
SmartIFoperator= (const SmartIF< T > &rhs)
 Assignment operator from a different SmartIF. More...
 

Private Attributes

TYPE * m_interface
 Pointer to the instance. More...
 

Detailed Description

template<class TYPE>
class SmartIF< TYPE >

Small smart pointer class with automatic reference counting for IInterface.

SmartIF simplifies the interaction with components in Gaudi by implementing an automatic reference counting and the casting (via IInterface::queryInterface).

Author
Markus Frank
Sebastien Ponce
Marco Clemencic

Definition at line 14 of file IConverter.h.

Constructor & Destructor Documentation

template<class TYPE>
SmartIF< TYPE >::SmartIF ( )
inline

Default constructor.

Definition at line 26 of file SmartIF.h.

26 : m_interface(0) {}
TYPE * m_interface
Pointer to the instance.
Definition: SmartIF.h:22
template<class TYPE>
SmartIF< TYPE >::SmartIF ( TYPE *  ptr)
inline

Standard constructor from pointer.

Definition at line 28 of file SmartIF.h.

28  : m_interface(ptr) {
29  if (m_interface) m_interface->addRef();
30  }
TYPE * m_interface
Pointer to the instance.
Definition: SmartIF.h:22
template<class TYPE>
template<class OTHER >
SmartIF< TYPE >::SmartIF ( OTHER *  ptr)
inline

Standard constructor from any (IInterface-derived) pointer.

Definition at line 33 of file SmartIF.h.

33  : m_interface(0) {
34  if (ptr) reset(ptr);
35  }
TYPE * m_interface
Pointer to the instance.
Definition: SmartIF.h:22
void reset(TYPE *ptr=0)
Set the internal pointer to the passed one disposing of the old one.
Definition: SmartIF.h:74
template<class TYPE>
SmartIF< TYPE >::SmartIF ( const SmartIF< TYPE > &  rhs)
inline

Copy constructor.

Definition at line 37 of file SmartIF.h.

37  : m_interface(rhs.get()) {
38  if (m_interface) m_interface->addRef();
39  }
TYPE * m_interface
Pointer to the instance.
Definition: SmartIF.h:22
TYPE * get() const
Get interface pointer.
Definition: SmartIF.h:62
template<class TYPE>
template<class T >
SmartIF< TYPE >::SmartIF ( const SmartIF< T > &  rhs)
inlineexplicit

Constructor from another SmartIF, with a different type.

Note
it cannot replace the copy constructor.

Definition at line 43 of file SmartIF.h.

43  : m_interface(0) {
44  reset(rhs.get());
45  }
TYPE * m_interface
Pointer to the instance.
Definition: SmartIF.h:22
TYPE * get() const
Get interface pointer.
Definition: SmartIF.h:62
void reset(TYPE *ptr=0)
Set the internal pointer to the passed one disposing of the old one.
Definition: SmartIF.h:74
template<class TYPE>
SmartIF< TYPE >::~SmartIF ( )
inline

Standard Destructor.

Definition at line 47 of file SmartIF.h.

47 { reset(); }
void reset(TYPE *ptr=0)
Set the internal pointer to the passed one disposing of the old one.
Definition: SmartIF.h:74
template<class TYPE>
SmartIF< TYPE >::SmartIF ( )
inline

Default constructor.

Definition at line 26 of file SmartIF.h.

26 : m_interface(0) {}
TYPE * m_interface
Pointer to the instance.
Definition: SmartIF.h:22
template<class TYPE>
SmartIF< TYPE >::SmartIF ( TYPE *  ptr)
inline

Standard constructor from pointer.

Definition at line 28 of file SmartIF.h.

28  : m_interface(ptr) {
29  if (m_interface) m_interface->addRef();
30  }
TYPE * m_interface
Pointer to the instance.
Definition: SmartIF.h:22
template<class TYPE>
template<class OTHER >
SmartIF< TYPE >::SmartIF ( OTHER *  ptr)
inline

Standard constructor from any (IInterface-derived) pointer.

Definition at line 33 of file SmartIF.h.

33  : m_interface(0) {
34  if (ptr) reset(ptr);
35  }
TYPE * m_interface
Pointer to the instance.
Definition: SmartIF.h:22
void reset(TYPE *ptr=0)
Set the internal pointer to the passed one disposing of the old one.
Definition: SmartIF.h:74
template<class TYPE>
SmartIF< TYPE >::SmartIF ( const SmartIF< TYPE > &  rhs)
inline

Copy constructor.

Definition at line 37 of file SmartIF.h.

37  : m_interface(rhs.get()) {
38  if (m_interface) m_interface->addRef();
39  }
TYPE * m_interface
Pointer to the instance.
Definition: SmartIF.h:22
TYPE * get() const
Get interface pointer.
Definition: SmartIF.h:62
template<class TYPE>
template<class T >
SmartIF< TYPE >::SmartIF ( const SmartIF< T > &  rhs)
inlineexplicit

Constructor from another SmartIF, with a different type.

Note
it cannot replace the copy constructor.

Definition at line 43 of file SmartIF.h.

43  : m_interface(0) {
44  reset(rhs.get());
45  }
TYPE * m_interface
Pointer to the instance.
Definition: SmartIF.h:22
TYPE * get() const
Get interface pointer.
Definition: SmartIF.h:62
void reset(TYPE *ptr=0)
Set the internal pointer to the passed one disposing of the old one.
Definition: SmartIF.h:74
template<class TYPE>
SmartIF< TYPE >::~SmartIF ( )
inline

Standard Destructor.

Definition at line 47 of file SmartIF.h.

47 { reset(); }
void reset(TYPE *ptr=0)
Set the internal pointer to the passed one disposing of the old one.
Definition: SmartIF.h:74

Member Function Documentation

template<class TYPE>
TYPE* SmartIF< TYPE >::get ( ) const
inline

Get interface pointer.

Definition at line 62 of file SmartIF.h.

62 { return m_interface; }
TYPE * m_interface
Pointer to the instance.
Definition: SmartIF.h:22
template<class TYPE>
TYPE* SmartIF< TYPE >::get ( ) const
inline

Get interface pointer.

Definition at line 62 of file SmartIF.h.

62 { return m_interface; }
TYPE * m_interface
Pointer to the instance.
Definition: SmartIF.h:22
template<class TYPE>
bool SmartIF< TYPE >::isValid ( ) const
inline

Allow for check if smart pointer is valid.

Definition at line 51 of file SmartIF.h.

51 { return m_interface != 0; }
TYPE * m_interface
Pointer to the instance.
Definition: SmartIF.h:22
template<class TYPE>
bool SmartIF< TYPE >::isValid ( ) const
inline

Allow for check if smart pointer is valid.

Definition at line 51 of file SmartIF.h.

51 { return m_interface != 0; }
TYPE * m_interface
Pointer to the instance.
Definition: SmartIF.h:22
template<class TYPE>
SmartIF< TYPE >::operator TYPE * ( ) const
inline

Automatic conversion to pointer.

It is also used by the compiler for automatic conversion to boolean.

Definition at line 56 of file SmartIF.h.

56 { return m_interface; }
TYPE * m_interface
Pointer to the instance.
Definition: SmartIF.h:22
template<class TYPE>
SmartIF< TYPE >::operator TYPE * ( ) const
inline

Automatic conversion to pointer.

It is also used by the compiler for automatic conversion to boolean.

Definition at line 56 of file SmartIF.h.

56 { return m_interface; }
TYPE * m_interface
Pointer to the instance.
Definition: SmartIF.h:22
template<class TYPE>
TYPE& SmartIF< TYPE >::operator* ( ) const
inline

Dereference operator.

Definition at line 60 of file SmartIF.h.

60 { return *m_interface; }
TYPE * m_interface
Pointer to the instance.
Definition: SmartIF.h:22
template<class TYPE>
TYPE& SmartIF< TYPE >::operator* ( ) const
inline

Dereference operator.

Definition at line 60 of file SmartIF.h.

60 { return *m_interface; }
TYPE * m_interface
Pointer to the instance.
Definition: SmartIF.h:22
template<class TYPE>
TYPE* SmartIF< TYPE >::operator-> ( ) const
inline

Dereference operator.

Definition at line 58 of file SmartIF.h.

58 { return m_interface; }
TYPE * m_interface
Pointer to the instance.
Definition: SmartIF.h:22
template<class TYPE>
TYPE* SmartIF< TYPE >::operator-> ( ) const
inline

Dereference operator.

Definition at line 58 of file SmartIF.h.

58 { return m_interface; }
TYPE * m_interface
Pointer to the instance.
Definition: SmartIF.h:22
template<class TYPE>
SmartIF& SmartIF< TYPE >::operator= ( IInterface ptr)
inline

Assignment operator from IInterface pointer.

It allows things like SmartIF<T> x; x = 0;

Definition at line 104 of file SmartIF.h.

104  {
105  reset(ptr);
106  return *this;
107  }
void reset(TYPE *ptr=0)
Set the internal pointer to the passed one disposing of the old one.
Definition: SmartIF.h:74
template<class TYPE>
SmartIF& SmartIF< TYPE >::operator= ( IInterface ptr)
inline

Assignment operator from IInterface pointer.

It allows things like SmartIF<T> x; x = 0;

Definition at line 104 of file SmartIF.h.

104  {
105  reset(ptr);
106  return *this;
107  }
void reset(TYPE *ptr=0)
Set the internal pointer to the passed one disposing of the old one.
Definition: SmartIF.h:74
template<class TYPE>
SmartIF& SmartIF< TYPE >::operator= ( const SmartIF< TYPE > &  rhs)
inline

Assignment operator.

Definition at line 109 of file SmartIF.h.

109  {
110  reset(rhs.get());
111  return *this;
112  }
TYPE * get() const
Get interface pointer.
Definition: SmartIF.h:62
void reset(TYPE *ptr=0)
Set the internal pointer to the passed one disposing of the old one.
Definition: SmartIF.h:74
template<class TYPE>
SmartIF& SmartIF< TYPE >::operator= ( const SmartIF< TYPE > &  rhs)
inline

Assignment operator.

Definition at line 109 of file SmartIF.h.

109  {
110  reset(rhs.get());
111  return *this;
112  }
TYPE * get() const
Get interface pointer.
Definition: SmartIF.h:62
void reset(TYPE *ptr=0)
Set the internal pointer to the passed one disposing of the old one.
Definition: SmartIF.h:74
template<class TYPE>
template<class T >
SmartIF& SmartIF< TYPE >::operator= ( const SmartIF< T > &  rhs)
inline

Assignment operator from a different SmartIF.

Note
it cannot replace the assignment operator.

Definition at line 116 of file SmartIF.h.

116  {
117  reset(rhs.get());
118  return *this;
119  }
TYPE * get() const
Get interface pointer.
Definition: SmartIF.h:62
void reset(TYPE *ptr=0)
Set the internal pointer to the passed one disposing of the old one.
Definition: SmartIF.h:74
template<class TYPE>
template<class T >
SmartIF& SmartIF< TYPE >::operator= ( const SmartIF< T > &  rhs)
inline

Assignment operator from a different SmartIF.

Note
it cannot replace the assignment operator.

Definition at line 116 of file SmartIF.h.

116  {
117  reset(rhs.get());
118  return *this;
119  }
TYPE * get() const
Get interface pointer.
Definition: SmartIF.h:62
void reset(TYPE *ptr=0)
Set the internal pointer to the passed one disposing of the old one.
Definition: SmartIF.h:74
template<class TYPE>
TYPE*& SmartIF< TYPE >::pRef ( )
inline

Get reference to the pointer.

Definition at line 65 of file SmartIF.h.

65  {
66  return m_interface;
67  }
TYPE * m_interface
Pointer to the instance.
Definition: SmartIF.h:22
template<class TYPE>
TYPE*& SmartIF< TYPE >::pRef ( )
inline

Get reference to the pointer.

Definition at line 65 of file SmartIF.h.

65  {
66  return m_interface;
67  }
TYPE * m_interface
Pointer to the instance.
Definition: SmartIF.h:22
template<class TYPE>
void SmartIF< TYPE >::reset ( TYPE *  ptr = 0)
inline

Set the internal pointer to the passed one disposing of the old one.

Version for pointers of the same type of the managed ones (no call to queryInterface needed).

Definition at line 74 of file SmartIF.h.

74  {
75  if (ptr == m_interface) return;
76  if (m_interface) m_interface->release();
77  if (ptr) {
78  m_interface = ptr;
79  m_interface->addRef();
80  } else {
81  m_interface = 0;
82  }
83  }
TYPE * m_interface
Pointer to the instance.
Definition: SmartIF.h:22
template<class TYPE>
void SmartIF< TYPE >::reset ( TYPE *  ptr = 0)
inline

Set the internal pointer to the passed one disposing of the old one.

Version for pointers of the same type of the managed ones (no call to queryInterface needed).

Definition at line 74 of file SmartIF.h.

74  {
75  if (ptr == m_interface) return;
76  if (m_interface) m_interface->release();
77  if (ptr) {
78  m_interface = ptr;
79  m_interface->addRef();
80  } else {
81  m_interface = 0;
82  }
83  }
TYPE * m_interface
Pointer to the instance.
Definition: SmartIF.h:22
template<class TYPE>
template<class OTHER >
void SmartIF< TYPE >::reset ( OTHER *  ptr)
inline

Set the internal pointer to the passed one disposing of the old one.

Version for pointers of types inheriting from IInterface.

Definition at line 87 of file SmartIF.h.

87  {
88  if (static_cast<IInterface*>(ptr) == static_cast<IInterface*>(m_interface)) return;
89  if (m_interface) m_interface->release();
90  if (ptr) {
91  ptr->queryInterface(TYPE::interfaceID(), pp_cast<void>(&m_interface)).ignore();
92  } else {
93  m_interface = 0;
94  }
95  }
TYPE * m_interface
Pointer to the instance.
Definition: SmartIF.h:22
template<class TYPE>
template<class OTHER >
void SmartIF< TYPE >::reset ( OTHER *  ptr)
inline

Set the internal pointer to the passed one disposing of the old one.

Version for pointers of types inheriting from IInterface.

Definition at line 87 of file SmartIF.h.

87  {
88  if (static_cast<IInterface*>(ptr) == static_cast<IInterface*>(m_interface)) return;
89  if (m_interface) m_interface->release();
90  if (ptr) {
91  ptr->queryInterface(TYPE::interfaceID(), pp_cast<void>(&m_interface)).ignore();
92  } else {
93  m_interface = 0;
94  }
95  }
TYPE * m_interface
Pointer to the instance.
Definition: SmartIF.h:22

Member Data Documentation

template<class TYPE>
TYPE * SmartIF< TYPE >::m_interface
private

Pointer to the instance.

Definition at line 22 of file SmartIF.h.


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