The Gaudi Framework  master (37c0b60a)
SmartIF Class Reference

#include <GaudiKernel/SmartIF.h>

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...
 
SmartIFoperator= (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...
 
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 = nullptr
 Pointer to the instance. More...
 

Detailed Description

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 25 of file IConverter.h.

Constructor & Destructor Documentation

◆ SmartIF() [1/6]

SmartIF::SmartIF ( )
inlinedefault

Default constructor.

◆ SmartIF() [2/6]

SmartIF::SmartIF ( TYPE *  ptr)
inline

Standard constructor from pointer.

Definition at line 39 of file SmartIF.h.

39  : m_interface( ptr ) {
40  if ( m_interface ) m_interface->addRef();
41  }

◆ SmartIF() [3/6]

template<class OTHER >
SmartIF::SmartIF ( OTHER *  ptr)
inline

Standard constructor from any (IInterface-derived) pointer.

Definition at line 44 of file SmartIF.h.

44  {
45  if ( ptr ) reset( ptr );
46  }

◆ SmartIF() [4/6]

SmartIF::SmartIF ( const SmartIF rhs)
inline

Copy constructor.

Definition at line 48 of file SmartIF.h.

48  : m_interface( rhs.get() ) {
49  if ( m_interface ) m_interface->addRef();
50  }

◆ SmartIF() [5/6]

SmartIF::SmartIF ( SmartIF &&  rhs)
inline

Move constructor.

Definition at line 52 of file SmartIF.h.

52 : m_interface( rhs.m_interface ) { rhs.m_interface = nullptr; }

◆ SmartIF() [6/6]

template<class T >
SmartIF::SmartIF ( const SmartIF< T > &  rhs)
inlineexplicit

Constructor from another SmartIF, with a different type.

Note
it cannot replace the copy constructor.

Definition at line 64 of file SmartIF.h.

64  {
65  reset( rhs.get() );
66  }

◆ ~SmartIF()

SmartIF::~SmartIF ( )
inline

Standard Destructor.

Definition at line 68 of file SmartIF.h.

68 { reset(); }

Member Function Documentation

◆ as()

template<typename IFace >
SmartIF<IFace> SmartIF::as ( ) const
inline

return a new SmartIF instance to another interface

Definition at line 117 of file SmartIF.h.

117  {
118  return SmartIF<IFace>{ *this };
119  }

◆ get()

TYPE* SmartIF::get ( ) const
inline

Get interface pointer.

Definition at line 86 of file SmartIF.h.

86 { return m_interface; }

◆ isValid()

bool SmartIF::isValid ( ) const
inline

Allow for check if smart pointer is valid.

Definition at line 72 of file SmartIF.h.

72 { return m_interface != nullptr; }

◆ operator bool()

SmartIF::operator bool ( ) const
inlineexplicit

Definition at line 74 of file SmartIF.h.

74 { return isValid(); }

◆ operator TYPE *()

SmartIF::operator TYPE * ( ) const
inline

Automatic conversion to pointer.

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

Definition at line 80 of file SmartIF.h.

80 { return m_interface; }

◆ operator!()

bool SmartIF::operator! ( ) const
inline

Definition at line 75 of file SmartIF.h.

75 { return !isValid(); }

◆ operator*()

TYPE& SmartIF::operator* ( ) const
inline

Dereference operator.

Definition at line 84 of file SmartIF.h.

84 { return *m_interface; }

◆ operator->()

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

Dereference operator.

Definition at line 82 of file SmartIF.h.

82 { return m_interface; }

◆ operator=() [1/4]

SmartIF& SmartIF::operator= ( const SmartIF rhs)
inline

Assignment operator.

Definition at line 133 of file SmartIF.h.

133  {
134  reset( rhs.get() );
135  return *this;
136  }

◆ operator=() [2/4]

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

Assignment operator from a different SmartIF.

Note
it cannot replace the assignment operator.

Definition at line 140 of file SmartIF.h.

140  {
141  reset( rhs.get() );
142  return *this;
143  }

◆ operator=() [3/4]

SmartIF& SmartIF::operator= ( IInterface ptr)
inline

Assignment operator from IInterface pointer.

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

Definition at line 128 of file SmartIF.h.

128  {
129  reset( ptr );
130  return *this;
131  }

◆ operator=() [4/4]

SmartIF& SmartIF::operator= ( SmartIF &&  rhs)
inline

Move assignement.

Definition at line 54 of file SmartIF.h.

54  {
55  if ( m_interface ) m_interface->release();
57  rhs.m_interface = nullptr;
58  return *this;
59  }

◆ pRef()

TYPE*& SmartIF::pRef ( )
inline

Get reference to the pointer.

Definition at line 89 of file SmartIF.h.

89 { return m_interface; }

◆ reset() [1/2]

template<class OTHER >
void SmartIF::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 105 of file SmartIF.h.

105  {
106  if ( static_cast<IInterface*>( ptr ) == static_cast<IInterface*>( m_interface ) ) return;
107  if ( m_interface ) m_interface->release();
108  if ( ptr ) {
109  ptr->queryInterface( TYPE::interfaceID(), pp_cast<void>( &m_interface ) ).ignore();
110  } else {
111  m_interface = nullptr;
112  }
113  }

◆ reset() [2/2]

void SmartIF::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 96 of file SmartIF.h.

96  {
97  if ( ptr == m_interface ) return;
98  if ( m_interface ) m_interface->release();
99  m_interface = ptr;
100  if ( m_interface ) m_interface->addRef();
101  }

Member Data Documentation

◆ m_interface

TYPE* SmartIF::m_interface = nullptr
private

Pointer to the instance.

Definition at line 32 of file SmartIF.h.


The documentation for this class was generated from the following files:
SmartIF::reset
void reset(TYPE *ptr=nullptr)
Set the internal pointer to the passed one disposing of the old one.
Definition: SmartIF.h:96
SmartIF::isValid
bool isValid() const
Allow for check if smart pointer is valid.
Definition: SmartIF.h:72
SmartIF::m_interface
TYPE * m_interface
Pointer to the instance.
Definition: SmartIF.h:32
SmartIF
Definition: IConverter.h:25
SmartIF::get
TYPE * get() const
Get interface pointer.
Definition: SmartIF.h:86
IInterface
Definition: IInterface.h:239