| # Gaudi Framework, version v25r0 |

Home |  | Generated: Mon Feb 17 2014

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

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

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Public Member Functions | Private Attributes | List of all members
SmartIF< T > Class Template Reference

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

`#include <GaudiKernel/SmartIF.h>`

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

## Private Attributes
TYPE * | m_interface
| Pointer to the instance.

## Detailed Description

### template<class T>
class SmartIF< T >

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 T>

SmartIF< T >::SmartIF | ( |  | ) |
| inline

Default constructor.

Definition at line 26 of file SmartIF.h.

: m_interface(0) {}
template<class T>

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

Standard constructor from pointer.

Definition at line 28 of file SmartIF.h.

: m_interface(ptr) {
if (m_interface) m_interface->addRef();
}
template<class T>
template<class OTHER >

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

Standard constructor from any (IInterface-derived) pointer.

Definition at line 33 of file SmartIF.h.

: m_interface(0) {
if (ptr) reset(ptr);
}
template<class T>

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

Copy constructor.

Definition at line 37 of file SmartIF.h.

: m_interface(rhs.get()) {
if (m_interface) m_interface->addRef();
}
template<class T>
template<class T >

SmartIF< T >::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 43 of file SmartIF.h.

: m_interface(0) {
reset(rhs.get());
}
template<class T>

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

Standard Destructor.

Definition at line 47 of file SmartIF.h.

{ reset(); }

## Member Function Documentation

template<class T>

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

Get interface pointer.

Definition at line 62 of file SmartIF.h.

{ return m_interface; }
template<class T>

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

Allow for check if smart pointer is valid.

Definition at line 51 of file SmartIF.h.

{ return m_interface != 0; }
template<class T>

SmartIF< T >::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.

{ return m_interface; }
template<class T>

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

Dereference operator.

Definition at line 60 of file SmartIF.h.

{ return *m_interface; }
template<class T>

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

Dereference operator.

Definition at line 58 of file SmartIF.h.

{ return m_interface; }
template<class T>

SmartIF& SmartIF< T >::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.

{
reset(ptr);
return *this;
}
template<class T>

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

Assignment operator.

Definition at line 109 of file SmartIF.h.

{
reset(rhs.get());
return *this;
}
template<class T>
template<class T >

SmartIF& SmartIF< T >::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.

{
reset(rhs.get());
return *this;
}
template<class T>

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

Get reference to the pointer.

Definition at line 65 of file SmartIF.h.

{
return m_interface;
}
template<class T>

void SmartIF< T >::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.

{
if (ptr == m_interface) return;
if (m_interface) m_interface->release();
if (ptr) {
m_interface = ptr;
m_interface->addRef();
} else {
m_interface = 0;
}
}
template<class T>
template<class OTHER >

void SmartIF< T >::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.

{
if (static_cast<IInterface*>(ptr) == static_cast<IInterface*>(m_interface)) return;
if (m_interface) m_interface->release();
if (ptr) {
ptr->queryInterface(TYPE::interfaceID(), pp_cast<void>(&m_interface)).ignore();
} else {
m_interface = 0;
}
}

## Member Data Documentation

template<class T>

TYPE* SmartIF< T >::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:

- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v25r0/GaudiKernel/GaudiKernel/IConverter.h
- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v25r0/GaudiKernel/GaudiKernel/SmartIF.h