The Gaudi Framework
master (3de0aae8)
Toggle main menu visibility
Loading...
Searching...
No Matches
implements.h
Go to the documentation of this file.
1
/***********************************************************************************\
2
* (c) Copyright 1998-2025 CERN for the benefit of the LHCb and ATLAS collaborations *
3
* *
4
* This software is distributed under the terms of the Apache version 2 licence, *
5
* copied verbatim in the file "LICENSE". *
6
* *
7
* In applying this licence, CERN does not waive the privileges and immunities *
8
* granted to it by virtue of its status as an Intergovernmental Organization *
9
* or submit itself to any jurisdiction. *
10
\***********************************************************************************/
11
#pragma once
12
13
#include <
GaudiKernel/IInterface.h
>
14
#include <atomic>
15
#include <cassert>
16
18
template
<
typename
... Interfaces>
19
struct
GAUDI_API
implements
:
virtual
public
extend_interfaces
<Interfaces...> {
21
using
base_class
=
implements
<Interfaces...>;
23
using
extend_interfaces_base
=
extend_interfaces
<Interfaces...>;
24
using
iids
=
typename
extend_interfaces_base::ext_iids
;
25
26
public
:
27
using
extend_interfaces_base::i_cast;
28
30
void
const
*
i_cast
(
const
InterfaceID
& tid )
const override
{
return
Gaudi::iid_cast
( tid,
iids
{}, this ); }
32
StatusCode
queryInterface
(
const
InterfaceID
& ti,
void
** pp )
override
{
33
if
( !pp )
return
StatusCode::FAILURE
;
34
*pp =
i_cast
( ti );
35
if
( !*pp )
return
StatusCode::FAILURE
;
/* cast failed */
36
this->
addRef
();
37
return
StatusCode::SUCCESS
;
38
}
39
40
std::vector<std::string>
getInterfaceNames
()
const override
{
return
Gaudi::getInterfaceNames
(
iids
{} ); }
42
implements
() =
default
;
44
implements
(
const
implements
&
/*other*/
) :
m_refCount
{ 0 } {}
46
implements
&
operator=
(
const
implements
&
/*other*/
) {
return
*
this
; }
// cppcheck-suppress operatorEqVarError
47
48
public
:
50
unsigned
long
addRef
()
const override
{
return
++
m_refCount
; }
52
unsigned
long
release
()
const override
{
53
if
(
auto
count =
decRef
() ) {
54
return
count;
55
}
else
{
56
delete
this
;
57
return
0;
58
}
59
}
60
61
unsigned
long
refCount
()
const override
{
return
m_refCount
.load(); }
62
63
protected
:
64
unsigned
long
decRef
()
const override
{
65
auto
count =
m_refCount
.load();
66
// thread-safe decrement, but make sure we don't go below 0
67
// (if the last two references are being released at the same time, this guarantees that
68
// one decrements m_refCount from 2 to 1 and the other from 1 to 0)
69
while
( count > 0 && !
m_refCount
.compare_exchange_weak( count, count - 1 ) ) { assert( count > 0 ); }
70
// when we reach this point, we managed to set m_refCount to "count - 1", so no need to read it again
71
return
count - 1;
72
}
73
75
mutable
std::atomic_ulong
m_refCount
= { 0 };
76
};
77
78
template
<
typename
I1>
79
using
implements1
=
implements<I1>
;
80
template
<
typename
I1,
typename
I2>
81
using
implements2
=
implements<I1, I2>
;
82
template
<
typename
I1,
typename
I2,
typename
I3>
83
using
implements3
=
implements<I1, I2, I3>
;
84
template
<
typename
I1,
typename
I2,
typename
I3,
typename
I4>
85
using
implements4
=
implements<I1, I2, I3, I4>
;
IInterface.h
GAUDI_API
#define GAUDI_API
Definition
Kernel.h:49
InterfaceID
Interface ID class.
Definition
IInterface.h:38
StatusCode
This class is used for returning status codes from appropriate routines.
Definition
StatusCode.h:64
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition
StatusCode.h:99
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition
StatusCode.h:100
implements2
implements< I1, I2 > implements2
Definition
implements.h:81
implements1
implements< I1 > implements1
Definition
implements.h:79
implements4
implements< I1, I2, I3, I4 > implements4
Definition
implements.h:85
implements3
implements< I1, I2, I3 > implements3
Definition
implements.h:83
Gaudi::iid_cast
void * iid_cast(const InterfaceID &tid, Gaudi::interface_list< Is... >, P *ptr)
Definition
IInterface.h:163
Gaudi::getInterfaceNames
std::vector< std::string > getInterfaceNames(Gaudi::interface_list< Is... >)
Definition
IInterface.h:158
extend_interfaces
Base class to be used to extend an interface.
Definition
extend_interfaces.h:23
extend_interfaces< Interfaces... >::ext_iids
typename Gaudi::interface_list_cat< typename Interfaces::ext_iids... >::type ext_iids
Definition
extend_interfaces.h:25
implements
Base class used to implement the interfaces.
Definition
implements.h:19
implements::release
unsigned long release() const override
Release Interface instance.
Definition
implements.h:52
implements< Interfaces... >::m_refCount
std::atomic_ulong m_refCount
Definition
implements.h:75
implements::operator=
implements & operator=(const implements &)
Assignment operator (do not touch the reference count).
Definition
implements.h:46
implements::getInterfaceNames
std::vector< std::string > getInterfaceNames() const override
Implementation of IInterface::getInterfaceNames.
Definition
implements.h:40
implements::implements
implements()=default
Default constructor.
implements::queryInterface
StatusCode queryInterface(const InterfaceID &ti, void **pp) override
Implementation of IInterface::queryInterface.
Definition
implements.h:32
implements< Interfaces... >::extend_interfaces_base
extend_interfaces< Interfaces... > extend_interfaces_base
Definition
implements.h:23
implements::refCount
unsigned long refCount() const override
Current reference count.
Definition
implements.h:61
implements::base_class
implements< Interfaces... > base_class
Typedef to this class.
Definition
implements.h:21
implements< Interfaces... >::iids
typename extend_interfaces_base::ext_iids iids
Definition
implements.h:24
implements< Interfaces... >::addRef
unsigned long addRef() const override
Definition
implements.h:50
implements< Interfaces... >::decRef
unsigned long decRef() const override
Definition
implements.h:64
implements::i_cast
void const * i_cast(const InterfaceID &tid) const override
Implementation of IInterface::i_cast.
Definition
implements.h:30
implements::implements
implements(const implements &)
Copy constructor (zero the reference count).
Definition
implements.h:44
GaudiKernel
include
GaudiKernel
implements.h
Generated on
for The Gaudi Framework by
1.17.0