ATLAS Offline Software
TransientConstSharedPtr.h
Go to the documentation of this file.
1 
2 /*
3  * Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration.
4  */
5 #ifndef GEOMODELUTILITIES_TRANSIENTCONSTSHAREDPTR_H
6 #define GEOMODELUTILITIES_TRANSIENTCONSTSHAREDPTR_H
7 
8 #include <memory>
9 namespace GeoModel {
13  template <typename Obj> class TransientConstSharedPtr {
14  public:
15  template <typename DerivType> friend class GeoModel::TransientConstSharedPtr;
17  using element_type = Obj;
19  Obj* get() { return m_ptr.get(); }
20  Obj* operator->() { return get(); }
22  const Obj* get() const { return m_ptr.get(); }
23  const Obj* operator->() const { return get(); }
25  const Obj& operator*() const { return *m_ptr; }
26  Obj& operator*() { return *m_ptr; }
27 
29  template <typename DerivType>
30  TransientConstSharedPtr(std::unique_ptr<DerivType> ptr)
31  requires(std::is_base_of_v<Obj, DerivType>): m_ptr{std::move(ptr)} {}
33  template <typename DerivType>
34  TransientConstSharedPtr(std::shared_ptr<DerivType> ptr)
35  requires(std::is_base_of_v<Obj, DerivType>) : m_ptr{std::move(ptr)} {}
38 
42  template <typename DerivType>
44  requires(std::is_base_of_v<Obj, DerivType>) :
45  m_ptr{other.m_ptr}{}
47  template <typename DerivType>
49  requires(std::is_base_of_v<Obj, DerivType>) :
50  m_ptr{std::move(other.m_ptr)}{}
51 
53  template <typename DerivType>
55  requires(std::is_base_of_v<Obj, DerivType>) {
56  if (&other != this) {
57  m_ptr = other.m_ptr;
58  }
59  return *this;
60  }
61  template <typename DerivType>
62  TransientConstSharedPtr& operator=(const std::shared_ptr<DerivType>& other)
63  requires(std::is_base_of_v<Obj, DerivType>) {
64  m_ptr = other.m_ptr;
65  return *this;
66  }
68  template <typename DerivType>
70  requires(std::is_base_of_v<Obj, DerivType>) {
71  m_ptr = std::move(other.m_ptr);
72  return *this;
73  }
74  template <typename DerivType>
75  TransientConstSharedPtr& operator=(std::unique_ptr<DerivType>&& other)
76  requires(std::is_base_of_v<Obj, DerivType>) {
77  m_ptr = std::move(other);
78  return *this;
79  }
80  template <typename DerivType>
81  TransientConstSharedPtr& operator=(std::shared_ptr<DerivType>&& other)
82  requires(std::is_base_of_v<Obj, DerivType>) {
83  m_ptr = std::move(other);
84  return *this;
85  }
87  template <typename DerivType>
88  void reset(std::unique_ptr<DerivType> newObj)
89  requires(std::is_base_of_v<Obj, DerivType>) {
90  m_ptr = std::move(newObj);
91  }
92  template <typename DerivType>
93  void reset(std::shared_ptr<DerivType>&& newObj)
94  requires(std::is_base_of_v<Obj, DerivType>) {
95  m_ptr = std::move(newObj);
96  }
97  template <typename DerivType>
98  void reset(const std::shared_ptr<DerivType>& newObj)
99  requires(std::is_base_of_v<Obj, DerivType>) {
100  m_ptr = std::move(newObj);
101  }
102  void reset() { m_ptr.reset(); }
104  std::shared_ptr<const Obj> release() { return std::move(m_ptr); }
106  operator bool() const { return m_ptr.get() != nullptr; }
107  bool operator!() const { return !m_ptr; }
109  size_t use_count() const { return m_ptr.use_count(); }
110 
113  return get() < other.get();
114  }
117  return other.get() == get();
118  }
120  return other.get() != get();
121  }
122 
123  private:
124  std::shared_ptr<Obj> m_ptr{};
125  };
126 } // namespace GeoModel
127 #endif
GeoModel
Definition: IGeoDbTagSvc.h:16
GeoModel::TransientConstSharedPtr
The TransientConstSharedPtr allows non-const access if the pointer itself is non-const but in the con...
Definition: TransientConstSharedPtr.h:13
GeoModel::TransientConstSharedPtr::m_ptr
std::shared_ptr< Obj > m_ptr
Definition: TransientConstSharedPtr.h:124
GeoModel::TransientConstSharedPtr::use_count
size_t use_count() const
How many clients does the pointer have.
Definition: TransientConstSharedPtr.h:109
GeoModel::TransientConstSharedPtr::operator->
const Obj * operator->() const
Definition: TransientConstSharedPtr.h:23
GeoModel::TransientConstSharedPtr::reset
void reset(std::unique_ptr< DerivType > newObj) requires(std
Overload the pointer.
Definition: TransientConstSharedPtr.h:88
GeoModel::TransientConstSharedPtr::operator=
TransientConstSharedPtr & operator=(const std::shared_ptr< DerivType > &other) requires(std
Definition: TransientConstSharedPtr.h:62
GeoModel::TransientConstSharedPtr::TransientConstSharedPtr
TransientConstSharedPtr(std::shared_ptr< DerivType > ptr) requires(std
Constructor from shared_ptr.
Definition: TransientConstSharedPtr.h:34
GeoModel::TransientConstSharedPtr::operator=
TransientConstSharedPtr & operator=(const TransientConstSharedPtr< DerivType > &other) requires(std
Assignment operator.
Definition: TransientConstSharedPtr.h:54
GeoModel::TransientConstSharedPtr::TransientConstSharedPtr
TransientConstSharedPtr(std::unique_ptr< DerivType > ptr) requires(std
Constructor from a unique_ptr.
Definition: TransientConstSharedPtr.h:30
GeoModel::TransientConstSharedPtr::reset
void reset()
Definition: TransientConstSharedPtr.h:102
requires
requires requires()
This specialization is used for classes deriving from DataObject.
Definition: Control/AthenaKernel/AthenaKernel/ClassID_traits.h:68
GeoModel::TransientConstSharedPtr::TransientConstSharedPtr
TransientConstSharedPtr()=default
Standard constructor.
GeoModel::TransientConstSharedPtr::release
std::shared_ptr< const Obj > release()
Release the memory.
Definition: TransientConstSharedPtr.h:104
GeoModel::TransientConstSharedPtr::operator=
TransientConstSharedPtr & operator=(std::shared_ptr< DerivType > &&other) requires(std
Definition: TransientConstSharedPtr.h:81
dbg::ptr
void * ptr(T *p)
Definition: SGImplSvc.cxx:74
GeoModel::TransientConstSharedPtr::operator==
bool operator==(const TransientConstSharedPtr &other) const
Equal operator.
Definition: TransientConstSharedPtr.h:116
GeoModel::TransientConstSharedPtr::operator<
bool operator<(const TransientConstSharedPtr &other) const
Smaller operator to insert the pointer into sets.
Definition: TransientConstSharedPtr.h:112
GeoModel::TransientConstSharedPtr::operator!=
bool operator!=(const TransientConstSharedPtr &other) const
Definition: TransientConstSharedPtr.h:119
GeoModel::TransientConstSharedPtr::TransientConstSharedPtr
TransientConstSharedPtr(const TransientConstSharedPtr< DerivType > &other) requires(std
Delete the copy constructor if the object is const.
Definition: TransientConstSharedPtr.h:43
GeoModel::TransientConstSharedPtr::reset
void reset(std::shared_ptr< DerivType > &&newObj) requires(std
Definition: TransientConstSharedPtr.h:93
GeoModel::TransientConstSharedPtr::operator*
Obj & operator*()
Definition: TransientConstSharedPtr.h:26
GeoModel::TransientConstSharedPtr::operator!
bool operator!() const
Definition: TransientConstSharedPtr.h:107
GeoModel::TransientConstSharedPtr::TransientConstSharedPtr
TransientConstSharedPtr(Obj *ptr)
Constructor from raw ptr.
Definition: TransientConstSharedPtr.h:37
GeoModel::TransientConstSharedPtr::operator=
TransientConstSharedPtr & operator=(std::unique_ptr< DerivType > &&other) requires(std
Definition: TransientConstSharedPtr.h:75
GeoModel::TransientConstSharedPtr::operator=
TransientConstSharedPtr & operator=(TransientConstSharedPtr< DerivType > &&other) requires(std
Move assignment operator.
Definition: TransientConstSharedPtr.h:69
GeoModel::TransientConstSharedPtr< WireGroupDesign >::element_type
WireGroupDesign element_type
type name
Definition: TransientConstSharedPtr.h:17
GeoModel::TransientConstSharedPtr::get
Obj * get()
Get (non-const) access to the underlying object.
Definition: TransientConstSharedPtr.h:19
GeoModel::TransientConstSharedPtr::get
const Obj * get() const
Get const access to the underlying object.
Definition: TransientConstSharedPtr.h:22
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
GeoModel::TransientConstSharedPtr::TransientConstSharedPtr
TransientConstSharedPtr(TransientConstSharedPtr< DerivType > &&other) requires(std
Standard move constructor.
Definition: TransientConstSharedPtr.h:48
GeoModel::TransientConstSharedPtr::operator*
const Obj & operator*() const
Dereference operator.
Definition: TransientConstSharedPtr.h:25
GeoModel::TransientConstSharedPtr::operator->
Obj * operator->()
Definition: TransientConstSharedPtr.h:20
xAOD::bool
setBGCode setTAP setLVL2ErrorBits bool
Definition: TrigDecision_v1.cxx:60
GeoModel::TransientConstSharedPtr::reset
void reset(const std::shared_ptr< DerivType > &newObj) requires(std
Definition: TransientConstSharedPtr.h:98