ATLAS Offline Software
CachedUniquePtr.h
Go to the documentation of this file.
1 // This file's extension implies that it's C, but it's really -*- C++ -*-.
2 /*
3  * Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration.
4  */
13 #ifndef CXXUTILS_CACHEDUNIQUEPTR_H
14 #define CXXUTILS_CACHEDUNIQUEPTR_H
15 
16 
17 #include <atomic>
18 #include <memory>
19 
20 
21 namespace CxxUtils {
22 
23 
52 template <class T>
54 {
55 public:
58 
59 
61  CachedUniquePtrT (std::unique_ptr<T> elt);
62 
63 
66 
67 
70 
71 
72  // Destructor.
74 
75 
78  T* set (std::unique_ptr<T> elt) const;
79 
80 
83  void store (std::unique_ptr<T> elt) noexcept;
84 
85 
87  T* get() const;
88 
89 
91  T& operator*() const;
92 
93 
95  T* operator->() const;
96 
97 
99  explicit operator bool() const;
100 
101 
104  std::unique_ptr<T> release() noexcept;
105 
106 
107 private:
109  mutable std::atomic<T*> m_ptr;
110 };
111 
112 
113 template <class T>
115 
116 
117 } // namespace CxxUtils
118 
119 
120 #include "CxxUtils/CachedUniquePtr.icc"
121 
122 
123 #endif // not CXXUTILS_CACHEDUNIQUEPTR_H
CxxUtils::CachedUniquePtrT::operator->
T * operator->() const
Dereference the element.
CxxUtils::CachedUniquePtrT::operator*
T & operator*() const
Dereference the element.
CxxUtils::CachedUniquePtrT::operator=
CachedUniquePtrT & operator=(CachedUniquePtrT &&other) noexcept
Move.
CxxUtils::CachedUniquePtrT::CachedUniquePtrT
CachedUniquePtrT()
Default constructor. Sets the element to null.
CxxUtils::CachedUniquePtrT
Cached pointer with atomic update.
Definition: CachedUniquePtr.h:54
taskman.template
dictionary template
Definition: taskman.py:317
CxxUtils::CachedUniquePtrT::set
T * set(std::unique_ptr< T > elt) const
Atomically set the element.
const
bool const RAWDATA *ch2 const
Definition: LArRodBlockPhysicsV0.cxx:562
CxxUtils::CachedUniquePtrT::release
std::unique_ptr< T > release() noexcept
Transfer ownership from the element: return the current value as a unique_ptr, leaving the element nu...
CxxUtils::CachedUniquePtrT::m_ptr
std::atomic< T * > m_ptr
The cached element.
Definition: CachedUniquePtr.h:109
CxxUtils
Definition: aligned_vector.h:29
CxxUtils::CachedUniquePtrT::CachedUniquePtrT
CachedUniquePtrT(std::unique_ptr< T > elt)
Constructor from an element.
CxxUtils::CachedUniquePtrT::store
void store(std::unique_ptr< T > elt) noexcept
Store a new value to the element.
private
#define private
Definition: DetDescrConditionsDict_dict_fixes.cxx:13
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
CxxUtils::CachedUniquePtrT::get
T * get() const
Return the current value of the element.
CxxUtils::CachedUniquePtrT::CachedUniquePtrT
CachedUniquePtrT(CachedUniquePtrT &&other) noexcept
Move constructor.
xAOD::bool
setBGCode setTAP setLVL2ErrorBits bool
Definition: TrigDecision_v1.cxx:60
CxxUtils::CachedUniquePtrT::~CachedUniquePtrT
~CachedUniquePtrT()