ATLAS Offline Software
Loading...
Searching...
No Matches
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 */
11
12
13#ifndef CXXUTILS_CACHEDUNIQUEPTR_H
14#define CXXUTILS_CACHEDUNIQUEPTR_H
15
16
17#include <atomic>
18#include <memory>
19
20
21namespace CxxUtils {
22
23
52template <class T>
54{
55public:
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
107private:
109 mutable std::atomic<T*> m_ptr;
110};
111
112
113template <class T>
115
116
117} // namespace CxxUtils
118
119
120#include "CxxUtils/CachedUniquePtr.icc"
121
122
123#endif // not CXXUTILS_CACHEDUNIQUEPTR_H
Cached pointer with atomic update.
void store(std::unique_ptr< T > elt) noexcept
CachedUniquePtrT(std::unique_ptr< T > elt)
CachedUniquePtrT(CachedUniquePtrT &&other) noexcept
CachedUniquePtrT & operator=(CachedUniquePtrT &&other) noexcept
Move.
std::unique_ptr< T > release() noexcept
CachedUniquePtrT()
Default constructor. Sets the element to null.
T * set(std::unique_ptr< T > elt) const
CachedUniquePtrT< const T > CachedUniquePtr
STL namespace.
#define private