| The Gaudi Framework v29r1 (5cd95fa2)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | Private Attributes | List of all members
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 >:
[legend]

## Public Member Functions
| SmartIF ()=default
| 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...
| SmartIF (SmartIF &&rhs)
| Move constructor. More...
SmartIF & | operator= (SmartIF &&rhs)
| Move assignement. 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 bool () const
bool | operator! () const
| 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=nullptr)
| 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...
template<typename IFace >
SmartIF< IFace > | as () const
| return a new SmartIF instance to another interface More...
SmartIF & | operator= (IInterface *ptr)
| Assignment operator from IInterface pointer. More...
SmartIF & | operator= (const SmartIF &rhs)
| Assignment operator. More...
template<class T >
SmartIF & | operator= (const SmartIF< T > &rhs)
| Assignment operator from a different SmartIF. More...

## Private Attributes
TYPE * | m_interface = nullptr
| 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 15 of file IConverter.h.

## Constructor & Destructor Documentation

template<class TYPE>

SmartIF< TYPE >::SmartIF | ( |  | ) |
| inline default

Default constructor.

template<class TYPE>

SmartIF< TYPE >::SmartIF | ( | TYPE * | ptr | ) |
| inline

Standard constructor from pointer.

Definition at line 30 of file SmartIF.h.

30 : m_interface( ptr )
31 {
32 if ( m_interface ) m_interface->addRef();
33 }
SmartIF::m_interface
TYPE * m_interface
Pointer to the instance.
Definition: SmartIF.h:23
template<class TYPE>
template<class OTHER >

SmartIF< TYPE >::SmartIF | ( | OTHER * | ptr | ) |
| inline

Standard constructor from any (IInterface-derived) pointer.

Definition at line 36 of file SmartIF.h.

37 {
38 if ( ptr ) reset( ptr );
39 }
SmartIF::reset
void reset(TYPE *ptr=nullptr)
Set the internal pointer to the passed one disposing of the old one.
Definition: SmartIF.h:92
template<class TYPE>

SmartIF< TYPE >::SmartIF | ( | const SmartIF< TYPE > & | rhs | ) |
| inline

Copy constructor.

Definition at line 41 of file SmartIF.h.

41 : m_interface( rhs.get() )
42 {
43 if ( m_interface ) m_interface->addRef();
44 }
SmartIF::get
TYPE * get() const
Get interface pointer.
Definition: SmartIF.h:82
SmartIF::m_interface
TYPE * m_interface
Pointer to the instance.
Definition: SmartIF.h:23
template<class TYPE>

SmartIF< TYPE >::SmartIF | ( | SmartIF< TYPE > && | rhs | ) |
| inline

Move constructor.

Definition at line 46 of file SmartIF.h.

46 : m_interface( rhs.m_interface ) { rhs.m_interface = nullptr; }
SmartIF::m_interface
TYPE * m_interface
Pointer to the instance.
Definition: SmartIF.h:23
template<class TYPE>
template<class T >

SmartIF< TYPE >::SmartIF | ( | const SmartIF< T > & | rhs | ) |
| inline explicit

Constructor from another SmartIF, with a different type.

Note
  it cannot replace the copy constructor.

Definition at line 59 of file SmartIF.h.

60 {
61 reset( rhs.get() );
62 }
SmartIF::get
TYPE * get() const
Get interface pointer.
Definition: SmartIF.h:82
SmartIF::reset
void reset(TYPE *ptr=nullptr)
Set the internal pointer to the passed one disposing of the old one.
Definition: SmartIF.h:92
template<class TYPE>

SmartIF< TYPE >::~SmartIF | ( |  | ) |
| inline

Standard Destructor.

Definition at line 64 of file SmartIF.h.

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

## Member Function Documentation

template<class TYPE>
template<typename IFace >

SmartIF<IFace> SmartIF< TYPE >::as | ( |  | ) | const
| inline

return a new SmartIF instance to another interface

Definition at line 115 of file SmartIF.h.

116 {
117 return SmartIF<IFace>{*this};
118 }
SmartIF
Small smart pointer class with automatic reference counting for IInterface.
Definition: IConverter.h:15
template<class TYPE>

TYPE* SmartIF< TYPE >::get | ( |  | ) | const
| inline

Get interface pointer.

Definition at line 82 of file SmartIF.h.

82 { return m_interface; }
SmartIF::m_interface
TYPE * m_interface
Pointer to the instance.
Definition: SmartIF.h:23
template<class TYPE>

bool SmartIF< TYPE >::isValid | ( |  | ) | const
| inline

Allow for check if smart pointer is valid.

Definition at line 68 of file SmartIF.h.

68 { return m_interface != nullptr; }
SmartIF::m_interface
TYPE * m_interface
Pointer to the instance.
Definition: SmartIF.h:23
template<class TYPE>

SmartIF< TYPE >::operator bool | ( |  | ) | const
| inline explicit

Definition at line 70 of file SmartIF.h.

70 { return isValid(); }
SmartIF::isValid
bool isValid() const
Allow for check if smart pointer is valid.
Definition: SmartIF.h:68
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 76 of file SmartIF.h.

76 { return m_interface; }
SmartIF::m_interface
TYPE * m_interface
Pointer to the instance.
Definition: SmartIF.h:23
template<class TYPE>

bool SmartIF< TYPE >::operator! | ( |  | ) | const
| inline

Definition at line 71 of file SmartIF.h.

71 { return !isValid(); }
SmartIF::isValid
bool isValid() const
Allow for check if smart pointer is valid.
Definition: SmartIF.h:68
template<class TYPE>

TYPE& SmartIF< TYPE >::operator* | ( |  | ) | const
| inline

Dereference operator.

Definition at line 80 of file SmartIF.h.

80 { return *m_interface; }
SmartIF::m_interface
TYPE * m_interface
Pointer to the instance.
Definition: SmartIF.h:23
template<class TYPE>

TYPE* SmartIF< TYPE >::operator-> | ( |  | ) | const
| inline

Dereference operator.

Definition at line 78 of file SmartIF.h.

78 { return m_interface; }
SmartIF::m_interface
TYPE * m_interface
Pointer to the instance.
Definition: SmartIF.h:23
template<class TYPE>

SmartIF& SmartIF< TYPE >::operator= | ( | SmartIF< TYPE > && | rhs | ) |
| inline

Move assignement.

Definition at line 48 of file SmartIF.h.

49 {
50 if ( m_interface ) m_interface->release();
51 m_interface = rhs.m_interface;
52 rhs.m_interface = nullptr;
53 return *this;
54 }
SmartIF::m_interface
TYPE * m_interface
Pointer to the instance.
Definition: SmartIF.h:23
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 127 of file SmartIF.h.

128 {
129 reset( ptr );
130 return *this;
131 }
SmartIF::reset
void reset(TYPE *ptr=nullptr)
Set the internal pointer to the passed one disposing of the old one.
Definition: SmartIF.h:92
template<class TYPE>

SmartIF& SmartIF< TYPE >::operator= | ( | const SmartIF< TYPE > & | rhs | ) |
| inline

Assignment operator.

Definition at line 133 of file SmartIF.h.

134 {
135 reset( rhs.get() );
136 return *this;
137 }
SmartIF::get
TYPE * get() const
Get interface pointer.
Definition: SmartIF.h:82
SmartIF::reset
void reset(TYPE *ptr=nullptr)
Set the internal pointer to the passed one disposing of the old one.
Definition: SmartIF.h:92
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 141 of file SmartIF.h.

142 {
143 reset( rhs.get() );
144 return *this;
145 }
SmartIF::get
TYPE * get() const
Get interface pointer.
Definition: SmartIF.h:82
SmartIF::reset
void reset(TYPE *ptr=nullptr)
Set the internal pointer to the passed one disposing of the old one.
Definition: SmartIF.h:92
template<class TYPE>

TYPE*& SmartIF< TYPE >::pRef | ( |  | ) |
| inline

Get reference to the pointer.

Definition at line 85 of file SmartIF.h.

85 { return m_interface; }
SmartIF::m_interface
TYPE * m_interface
Pointer to the instance.
Definition: SmartIF.h:23
template<class TYPE>

void SmartIF< TYPE >::reset | ( | TYPE * | ptr = `nullptr` | ) |
| 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 92 of file SmartIF.h.

93 {
94 if ( ptr == m_interface ) return;
95 if ( m_interface ) m_interface->release();
96 m_interface = ptr;
97 if ( m_interface ) m_interface->addRef();
98 }
SmartIF::m_interface
TYPE * m_interface
Pointer to the instance.
Definition: SmartIF.h:23
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 102 of file SmartIF.h.

103 {
104 if ( static_cast<IInterface*>( ptr ) == static_cast<IInterface*>( m_interface ) ) return;
105 if ( m_interface ) m_interface->release();
106 if ( ptr ) {
107 ptr->queryInterface( TYPE::interfaceID(), pp_cast<void>( &m_interface ) ).ignore();
108 } else {
109 m_interface = nullptr;
110 }
111 }
SmartIF::m_interface
TYPE * m_interface
Pointer to the instance.
Definition: SmartIF.h:23

## Member Data Documentation

template<class TYPE>

TYPE* SmartIF< TYPE >::m_interface = nullptr
| private

Pointer to the instance.

Definition at line 23 of file SmartIF.h.

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

- GaudiKernel/GaudiKernel/IConverter.h
- GaudiKernel/GaudiKernel/SmartIF.h