The Gaudi Framework  master (ff829712)
Loading...
Searching...
No Matches
implements< Interfaces > Struct Template Reference

Base class used to implement the interfaces. More...

#include </builds/gaudi/Gaudi/GaudiKernel/include/GaudiKernel/implements.h>

Inheritance diagram for implements< Interfaces >:
Collaboration diagram for implements< Interfaces >:

Public Types

using base_class = implements<Interfaces...>
 Typedef to this class.
 
using extend_interfaces_base = extend_interfaces<Interfaces...>
 Typedef to the base of this class.
 
using iids = typename extend_interfaces_base::ext_iids
 
- Public Types inherited from extend_interfaces< Interfaces... >
using ext_iids
 take union of the ext_iids of all Interfaces...
 

Public Member Functions

void const * i_cast (const InterfaceID &tid) const override
 Implementation of IInterface::i_cast.
 
StatusCode queryInterface (const InterfaceID &ti, void **pp) override
 Implementation of IInterface::queryInterface.
 
std::vector< std::string > getInterfaceNames () const override
 Implementation of IInterface::getInterfaceNames.
 
 implements ()=default
 Default constructor.
 
 implements (const implements &)
 Copy constructor (zero the reference count)
 
implementsoperator= (const implements &)
 Assignment operator (do not touch the reference count).
 
unsigned long addRef () const override
 Reference Interface instance.
 
unsigned long release () const override
 Release Interface instance.
 
unsigned long refCount () const override
 Current reference count.
 

Protected Member Functions

unsigned long decRef () const override
 

Protected Attributes

std::atomic_ulong m_refCount = { 0 }
 Reference counter.
 

Detailed Description

template<typename... Interfaces>
struct implements< Interfaces >

Base class used to implement the interfaces.

Definition at line 19 of file implements.h.

Member Typedef Documentation

◆ base_class

template<typename... Interfaces>
using implements< Interfaces >::base_class = implements<Interfaces...>

Typedef to this class.

Definition at line 21 of file implements.h.

◆ extend_interfaces_base

template<typename... Interfaces>
using implements< Interfaces >::extend_interfaces_base = extend_interfaces<Interfaces...>

Typedef to the base of this class.

Definition at line 23 of file implements.h.

◆ iids

template<typename... Interfaces>
using implements< Interfaces >::iids = typename extend_interfaces_base::ext_iids

Definition at line 24 of file implements.h.

Constructor & Destructor Documentation

◆ implements() [1/2]

template<typename... Interfaces>
implements< Interfaces >::implements ( )
default

Default constructor.

◆ implements() [2/2]

template<typename... Interfaces>
implements< Interfaces >::implements ( const implements< Interfaces > & )
inline

Copy constructor (zero the reference count)

Definition at line 42 of file implements.h.

42: m_refCount{ 0 } {}
std::atomic_ulong m_refCount
Reference counter.
Definition implements.h:73

Member Function Documentation

◆ addRef()

template<typename... Interfaces>
unsigned long implements< Interfaces >::addRef ( ) const
inlineoverride

Reference Interface instance.

Definition at line 48 of file implements.h.

48{ return ++m_refCount; }

◆ decRef()

template<typename... Interfaces>
unsigned long implements< Interfaces >::decRef ( ) const
inlineoverrideprotected

Definition at line 62 of file implements.h.

62 {
63 auto count = m_refCount.load();
64 // thread-safe decrement, but make sure we don't go below 0
65 // (if the last two references are being released at the same time, this guarantees that
66 // one decrements m_refCount from 2 to 1 and the other from 1 to 0)
67 while ( count > 0 && !m_refCount.compare_exchange_weak( count, count - 1 ) ) { assert( count > 0 ); }
68 // when we reach this point, we managed to set m_refCount to "count - 1", so no need to read it again
69 return count - 1;
70 }
Base class used to implement the interfaces.
Definition implements.h:19

◆ getInterfaceNames()

template<typename... Interfaces>
std::vector< std::string > implements< Interfaces >::getInterfaceNames ( ) const
inlineoverride

Implementation of IInterface::getInterfaceNames.

Definition at line 38 of file implements.h.

38{ return Gaudi::getInterfaceNames( iids{} ); }
std::vector< std::string > getInterfaceNames(Gaudi::interface_list< Is... >)
Definition IInterface.h:158
typename extend_interfaces_base::ext_iids iids
Definition implements.h:24

◆ i_cast()

template<typename... Interfaces>
void const * implements< Interfaces >::i_cast ( const InterfaceID & tid) const
inlineoverride

Implementation of IInterface::i_cast.

Definition at line 28 of file implements.h.

28{ return Gaudi::iid_cast( tid, iids{}, this ); }
void * iid_cast(const InterfaceID &tid, Gaudi::interface_list< Is... >, P *ptr)
Definition IInterface.h:163

◆ operator=()

template<typename... Interfaces>
implements & implements< Interfaces >::operator= ( const implements< Interfaces > & )
inline

Assignment operator (do not touch the reference count).

Definition at line 44 of file implements.h.

44{ return *this; } // cppcheck-suppress operatorEqVarError

◆ queryInterface()

template<typename... Interfaces>
StatusCode implements< Interfaces >::queryInterface ( const InterfaceID & ti,
void ** pp )
inlineoverride

Implementation of IInterface::queryInterface.

Definition at line 30 of file implements.h.

30 {
31 if ( !pp ) return StatusCode::FAILURE;
32 *pp = Gaudi::iid_cast( ti, iids{}, this );
33 if ( !*pp ) return StatusCode::FAILURE; /* cast failed */
34 this->addRef();
36 }
unsigned long addRef() const override
Reference Interface instance.
Definition implements.h:48

◆ refCount()

template<typename... Interfaces>
unsigned long implements< Interfaces >::refCount ( ) const
inlineoverride

Current reference count.

Definition at line 59 of file implements.h.

59{ return m_refCount.load(); }

◆ release()

template<typename... Interfaces>
unsigned long implements< Interfaces >::release ( ) const
inlineoverride

Release Interface instance.

Definition at line 50 of file implements.h.

50 {
51 if ( auto count = decRef() ) {
52 return count;
53 } else {
54 delete this;
55 return 0;
56 }
57 }
unsigned long decRef() const override
Definition implements.h:62

Member Data Documentation

◆ m_refCount

template<typename... Interfaces>
std::atomic_ulong implements< Interfaces >::m_refCount = { 0 }
mutableprotected

Reference counter.

Definition at line 73 of file implements.h.

73{ 0 };

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