ATLAS Offline Software
RefCountedPtr.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-2025 CERN for the benefit of the ATLAS collaboration.
4  */
13 #ifndef CXXUTILS_REFCOUNTEDPTR_H
14 #define CXXUTILS_REFCOUNTEDPTR_H
15 
16 
17 #include "CxxUtils/concepts.h"
18 #include <memory> // For unique_ptr
19 
20 
21 namespace CxxUtils {
22 
23 
37 template <CxxUtils::detail::RefCounted T>
39 {
40 public:
41  using element_type = T;
42 
44  RefCountedPtr() = default;
45 
48 
50  template <CxxUtils::detail::RefCounted OTHER>
51  requires std::convertible_to<OTHER*, T*>
52  RefCountedPtr (std::unique_ptr<OTHER>&& other);
53 
56 
59 
61  template <CxxUtils::detail::RefCounted OTHER>
62  requires std::convertible_to<OTHER*, T*>
64 
66  template <CxxUtils::detail::RefCounted OTHER>
67  requires std::convertible_to<OTHER*, T*>
69 
72 
75 
78 
80  template <CxxUtils::detail::RefCounted OTHER>
81  requires std::convertible_to<OTHER*, T*>
83 
85  template <CxxUtils::detail::RefCounted OTHER>
86  requires std::convertible_to<OTHER*, T*>
88 
91 
93  void reset (T* ptr = nullptr);
94 
96  bool isValid() const;
97 
99  explicit operator bool() const;
100 
102  bool operator!() const;
103 
105  T* get();
106  const T* get() const;
107 
109  operator T*();
110  operator const T*() const;
111 
114  const T* operator->() const;
115 
117  T& operator*();
118  const T& operator*() const;
119 
120 
121 private:
122  template <CxxUtils::detail::RefCounted OTHER> friend class RefCountedPtr;
123 
124  // Return the pointer and give up ownership.
125  T* release();
126 
128  T* m_ptr = nullptr;
129 };
130 
131 
132 } // namespace CxxUtils
133 
134 
136 
137 
138 #endif // not CXXUTILS_REFCOUNTEDPTR_H
CxxUtils::RefCountedPtr::operator*
T & operator*()
Dereference.
CxxUtils::RefCountedPtr::operator->
T * operator->()
Dereference.
CxxUtils::RefCountedPtr::reset
void reset(T *ptr=nullptr)
Change the pointer.
CxxUtils::RefCountedPtr::RefCountedPtr
RefCountedPtr(T *p)
Constructor from pointer. Adds to the refcount.
CxxUtils::RefCountedPtr
Simple smart pointer for Gaudi-style refcounted objects.
Definition: RefCountedPtr.h:39
dbg::ptr
void * ptr(T *p)
Definition: SGImplSvc.cxx:74
CxxUtils::RefCountedPtr::RefCountedPtr
requires std::convertible_to< OTHER *, T * > RefCountedPtr(std::unique_ptr< OTHER > &&other)
Constructor from unique_ptr. Adds to the refcount.
CxxUtils::RefCountedPtr::operator!
bool operator!() const
Check if the pointer is invalid.
CxxUtils::RefCountedPtr::RefCountedPtr
RefCountedPtr(RefCountedPtr &&other)
Move constructor.
CxxUtils::RefCountedPtr::operator*
const T & operator*() const
CxxUtils::RefCountedPtr::isValid
bool isValid() const
Check if the pointer is valid.
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:209
CxxUtils::RefCountedPtr::operator->
const T * operator->() const
RefCountedPtr.icc
CxxUtils
Definition: aligned_vector.h:29
CxxUtils::requires
requires(detail::IsConcurrentHashmapPayload< KEY > &&detail::IsConcurrentHashmapPayload< VALUE > &&detail::IsUpdater< UPDATER > &&detail::IsHash< HASHER, KEY > &&detail::IsBinaryPredicate< MATCHER, KEY >) class ConcurrentMap
Hash map from integers/pointers allowing concurrent, lockless reads.
Definition: ConcurrentMap.h:94
CxxUtils::RefCountedPtr::operator=
RefCountedPtr & operator=(const RefCountedPtr &other)
Assignment.
CxxUtils::RefCountedPtr::release
T * release()
CxxUtils::RefCountedPtr::m_ptr
T * m_ptr
Pointer.
Definition: RefCountedPtr.h:128
CxxUtils::RefCountedPtr::get
const T * get() const
CxxUtils::RefCountedPtr::RefCountedPtr
RefCountedPtr(const RefCountedPtr &other)
Copy constructor.
CxxUtils::RefCountedPtr::~RefCountedPtr
~RefCountedPtr()
Destructor.
concepts.h
A couple standard-library related concepts.
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
CxxUtils::RefCountedPtr::RefCountedPtr
requires std::convertible_to< OTHER *, T * > RefCountedPtr(RefCountedPtr< OTHER > &&other)
Move from another RefCountedPtr, with a different type.
CxxUtils::RefCountedPtr::RefCountedPtr
requires std::convertible_to< OTHER *, T * > RefCountedPtr(const RefCountedPtr< OTHER > &other)
Constructor from another RefCountedPtr, with a different type.
CxxUtils::RefCountedPtr::get
T * get()
Get the pointer.
xAOD::bool
setBGCode setTAP setLVL2ErrorBits bool
Definition: TrigDecision_v1.cxx:60
CxxUtils::RefCountedPtr< IOpaqueAddress >::element_type
T element_type
Definition: RefCountedPtr.h:41
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35
CxxUtils::RefCountedPtr::RefCountedPtr
RefCountedPtr()=default
Default constructor.