The Gaudi Framework  master (98f5f38d)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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. More...
 
using extend_interfaces_base = extend_interfaces< Interfaces... >
 Typedef to the base of this class. More...
 
using iids = typename extend_interfaces_base::ext_iids
 
- Public Types inherited from extend_interfaces< Interfaces... >
using ext_iids = typename Gaudi::interface_list_cat< typename Interfaces::ext_iids... >::type
 take union of the ext_iids of all Interfaces... More...
 

Public Member Functions

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

Protected Member Functions

unsigned long decRef () const override
 

Protected Attributes

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

Detailed Description

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

Base class used to implement the interfaces.

Definition at line 20 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 22 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 24 of file implements.h.

◆ iids

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

Definition at line 25 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 43 of file implements.h.

43 : m_refCount{ 0 } {}

Member Function Documentation

◆ addRef()

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

Reference Interface instance

Definition at line 49 of file implements.h.

49 { return ++m_refCount; }

◆ decRef()

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

Definition at line 63 of file implements.h.

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

◆ getInterfaceNames()

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

Implementation of IInterface::getInterfaceNames.

Definition at line 39 of file implements.h.

39 { return Gaudi::getInterfaceNames( iids{} ); }

◆ i_cast()

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

Implementation of IInterface::i_cast.

Definition at line 29 of file implements.h.

29 { return Gaudi::iid_cast( tid, iids{}, this ); }

◆ operator=()

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

Assignment operator (do not touch the reference count).

Definition at line 45 of file implements.h.

45 { 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 31 of file implements.h.

31  {
32  if ( !pp ) return StatusCode::FAILURE;
33  *pp = Gaudi::iid_cast( ti, iids{}, this );
34  if ( !*pp ) return StatusCode::FAILURE; /* cast failed */
35  this->addRef();
36  return StatusCode::SUCCESS;
37  }

◆ refCount()

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

Current reference count

Definition at line 60 of file implements.h.

60 { return m_refCount.load(); }

◆ release()

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

Release Interface instance

Definition at line 51 of file implements.h.

51  {
52  if ( auto count = decRef() ) {
53  return count;
54  } else {
55  delete this;
56  return 0;
57  }
58  }

Member Data Documentation

◆ m_refCount

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

Reference counter

Definition at line 74 of file implements.h.


The documentation for this struct was generated from the following file:
implements::iids
typename extend_interfaces_base::ext_iids iids
Definition: implements.h:25
implements::m_refCount
std::atomic_ulong m_refCount
Reference counter
Definition: implements.h:74
implements::addRef
unsigned long addRef() const override
Reference Interface instance
Definition: implements.h:49
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
Gaudi::iid_cast
void * iid_cast(const InterfaceID &tid, Gaudi::interface_list< Is... >, P *ptr)
Definition: IInterface.h:165
Gaudi::getInterfaceNames
std::vector< std::string > getInterfaceNames(Gaudi::interface_list< Is... >)
Definition: IInterface.h:160
implements::decRef
unsigned long decRef() const override
Definition: implements.h:63
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:101
compareOutputFiles.pp
pp
Definition: compareOutputFiles.py:507