ATLAS Offline Software
Tracking
TrkEvent
TrkEventPrimitives
TrkEventPrimitives
TrkObjectCounter.h
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#ifndef TRKEVENTPRIMITIVES_TRKOBJECTCOUNTER_H
6
#define TRKEVENTPRIMITIVES_TRKOBJECTCOUNTER_H
7
#include <atomic>
8
#include <cstddef>
9
namespace
Trk
{
16
template
<
typename
T>
17
class
ObjectCounter
18
{
19
20
public
:
21
#ifndef NDEBUG
22
static
inline
std::atomic_size_t
s_numberOfInstantiations
= 0;
23
#endif
24
25
static
std::size_t
numberOfInstantiations
()
26
{
27
#ifndef NDEBUG
28
return
s_numberOfInstantiations
.load();
29
#endif
30
return
0;
31
}
32
33
protected
:
34
// cases where we want different behaviour for release/debug
35
#ifndef NDEBUG
36
ObjectCounter
()
37
{
38
s_numberOfInstantiations
.fetch_add(1, std::memory_order_relaxed);
39
}
40
ObjectCounter
(
const
ObjectCounter
&)
41
{
42
s_numberOfInstantiations
.fetch_add(1, std::memory_order_relaxed);
43
}
44
~ObjectCounter
()
45
{
46
s_numberOfInstantiations
.fetch_sub(1, std::memory_order_relaxed);
47
}
48
#else
49
ObjectCounter
() =
default
;
50
ObjectCounter
(
const
ObjectCounter
&) =
default
;
51
~ObjectCounter
() =
default
;
52
#endif
53
// The rest
54
ObjectCounter
&
operator=
(
const
ObjectCounter
&) =
default
;
55
ObjectCounter
(
ObjectCounter
&&) =
default
;
56
ObjectCounter
&
operator=
(
ObjectCounter
&&) =
default
;
57
};
58
59
}
60
#endif
Trk::ObjectCounter::ObjectCounter
ObjectCounter(ObjectCounter &&)=default
Trk::ObjectCounter::ObjectCounter
ObjectCounter(const ObjectCounter &)
Definition:
TrkObjectCounter.h:40
Trk::ObjectCounter::operator=
ObjectCounter & operator=(const ObjectCounter &)=default
Trk::ObjectCounter
Helper to enable counting number of instantiations in debug builds.
Definition:
TrkObjectCounter.h:18
Trk::ObjectCounter::numberOfInstantiations
static std::size_t numberOfInstantiations()
Definition:
TrkObjectCounter.h:25
Trk::ObjectCounter::ObjectCounter
ObjectCounter()
Definition:
TrkObjectCounter.h:36
Trk
Ensure that the ATLAS eigen extensions are properly loaded.
Definition:
FakeTrackBuilder.h:9
Trk::ObjectCounter::operator=
ObjectCounter & operator=(ObjectCounter &&)=default
Trk::ObjectCounter::~ObjectCounter
~ObjectCounter()
Definition:
TrkObjectCounter.h:44
Trk::ObjectCounter::s_numberOfInstantiations
static std::atomic_size_t s_numberOfInstantiations
Definition:
TrkObjectCounter.h:22
Generated on Thu Nov 7 2024 21:30:21 for ATLAS Offline Software by
1.8.18