ATLAS Offline Software
Loading...
Searching...
No Matches
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>
9namespace Trk {
16template<typename T>
18{
19
20public:
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
33protected:
34// cases where we want different behaviour for release/debug
35#ifndef NDEBUG
37 {
38 s_numberOfInstantiations.fetch_add(1, std::memory_order_relaxed);
39 }
41 {
42 s_numberOfInstantiations.fetch_add(1, std::memory_order_relaxed);
43 }
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
57};
58
59}
60#endif
Helper to enable counting number of instantiations in debug builds.
ObjectCounter & operator=(ObjectCounter &&)=default
ObjectCounter & operator=(const ObjectCounter &)=default
ObjectCounter(const ObjectCounter &)
static std::size_t numberOfInstantiations()
ObjectCounter(ObjectCounter &&)=default
static std::atomic_size_t s_numberOfInstantiations
Ensure that the ATLAS eigen extensions are properly loaded.