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 ObjGrp> friend class GeoModel::TransientConstSharedPtr;
17  Obj* get() { return m_ptr.get(); }
18  Obj* operator->() { return get(); }
20  const Obj* get() const { return m_ptr.get(); }
21  const Obj* operator->() const { return get(); }
23  const Obj& operator*() const { return *m_ptr; }
24  Obj& operator*() { return *m_ptr; }
25 
27  template <typename ObjGrp>
28  TransientConstSharedPtr(std::unique_ptr<ObjGrp> ptr) : m_ptr{std::move(ptr)} {}
30  template <typename ObjGrp>
31  TransientConstSharedPtr(std::shared_ptr<ObjGrp> ptr) : m_ptr{std::move(ptr)} {}
34 
38  template <typename ObjGrp>
40  m_ptr{other.m_ptr}{}
42  template <typename ObjGrp>
44  m_ptr{std::move(other.m_ptr)}{}
45 
47  template <typename ObjGrp>
49  if (&other != this) {
50  m_ptr = other.m_ptr;
51  }
52  return *this;
53  }
54  template <typename ObjGrp>
55  TransientConstSharedPtr& operator=(const std::shared_ptr<ObjGrp>& other) {
56  m_ptr = other.m_ptr;
57  return *this;
58  }
60  template <typename ObjGrp>
62  m_ptr = std::move(other.m_ptr);
63  return *this;
64  }
65  template <typename ObjGrp>
66  TransientConstSharedPtr& operator=(std::unique_ptr<ObjGrp>&& other) {
67  m_ptr = std::move(other);
68  return *this;
69  }
70  template <typename ObjGrp>
71  TransientConstSharedPtr& operator=(std::shared_ptr<ObjGrp>&& other) {
72  m_ptr = std::move(other);
73  return *this;
74  }
76  template <typename ObjGrp>
77  void reset(std::unique_ptr<ObjGrp> newObj) { m_ptr = std::move(newObj); }
78  void reset() { m_ptr.reset(); }
80  std::shared_ptr<const Obj> release() { return std::move(m_ptr); }
82  operator bool() const { return m_ptr.get() != nullptr; }
83  bool operator!() const { return !m_ptr; }
85  size_t use_count() const { return m_ptr.use_count(); }
86 
88  bool operator<(const TransientConstSharedPtr& other) const { return m_ptr.get() < other.m_ptr.get(); }
89 
90  private:
91  std::shared_ptr<Obj> m_ptr{};
92  };
93 } // namespace GeoModel
94 #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:91
GeoModel::TransientConstSharedPtr::use_count
size_t use_count() const
How many clients does the pointer have.
Definition: TransientConstSharedPtr.h:85
GeoModel::TransientConstSharedPtr::operator->
const Obj * operator->() const
Definition: TransientConstSharedPtr.h:21
GeoModel::TransientConstSharedPtr::reset
void reset()
Definition: TransientConstSharedPtr.h:78
GeoModel::TransientConstSharedPtr::TransientConstSharedPtr
TransientConstSharedPtr()=default
Standard constructor.
GeoModel::TransientConstSharedPtr::release
std::shared_ptr< const Obj > release()
Release the memory.
Definition: TransientConstSharedPtr.h:80
dbg::ptr
void * ptr(T *p)
Definition: SGImplSvc.cxx:74
GeoModel::TransientConstSharedPtr::operator<
bool operator<(const TransientConstSharedPtr &other) const
Smaller operator to insert the pointer into sets.
Definition: TransientConstSharedPtr.h:88
GeoModel::TransientConstSharedPtr::operator=
TransientConstSharedPtr & operator=(TransientConstSharedPtr< ObjGrp > &&other)
Move assignment operator.
Definition: TransientConstSharedPtr.h:61
GeoModel::TransientConstSharedPtr::operator*
Obj & operator*()
Definition: TransientConstSharedPtr.h:24
GeoModel::TransientConstSharedPtr::operator!
bool operator!() const
Definition: TransientConstSharedPtr.h:83
GeoModel::TransientConstSharedPtr::TransientConstSharedPtr
TransientConstSharedPtr(Obj *ptr)
Constructor from raw ptr.
Definition: TransientConstSharedPtr.h:33
GeoModel::TransientConstSharedPtr::TransientConstSharedPtr
TransientConstSharedPtr(TransientConstSharedPtr< ObjGrp > &&other)
Standard move constructor.
Definition: TransientConstSharedPtr.h:43
GeoModel::TransientConstSharedPtr::operator=
TransientConstSharedPtr & operator=(std::shared_ptr< ObjGrp > &&other)
Definition: TransientConstSharedPtr.h:71
GeoModel::TransientConstSharedPtr::TransientConstSharedPtr
TransientConstSharedPtr(const TransientConstSharedPtr< ObjGrp > &other)
Delete the copy constructor if the object is const.
Definition: TransientConstSharedPtr.h:39
GeoModel::TransientConstSharedPtr::operator=
TransientConstSharedPtr & operator=(const TransientConstSharedPtr< ObjGrp > &other)
Assignment operator.
Definition: TransientConstSharedPtr.h:48
GeoModel::TransientConstSharedPtr::TransientConstSharedPtr
TransientConstSharedPtr(std::shared_ptr< ObjGrp > ptr)
Constructor from shared_ptr.
Definition: TransientConstSharedPtr.h:31
GeoModel::TransientConstSharedPtr::get
Obj * get()
Get (non-const) access to the underlying object.
Definition: TransientConstSharedPtr.h:17
GeoModel::TransientConstSharedPtr::get
const Obj * get() const
Get const access to the underlying object.
Definition: TransientConstSharedPtr.h:20
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
GeoModel::TransientConstSharedPtr::reset
void reset(std::unique_ptr< ObjGrp > newObj)
Overload the pointer.
Definition: TransientConstSharedPtr.h:77
GeoModel::TransientConstSharedPtr::operator*
const Obj & operator*() const
Dereference operator.
Definition: TransientConstSharedPtr.h:23
GeoModel::TransientConstSharedPtr::operator->
Obj * operator->()
Definition: TransientConstSharedPtr.h:18
GeoModel::TransientConstSharedPtr::operator=
TransientConstSharedPtr & operator=(const std::shared_ptr< ObjGrp > &other)
Definition: TransientConstSharedPtr.h:55
GeoModel::TransientConstSharedPtr::TransientConstSharedPtr
TransientConstSharedPtr(std::unique_ptr< ObjGrp > ptr)
Constructor from unique_ptr.
Definition: TransientConstSharedPtr.h:28
xAOD::bool
setBGCode setTAP setLVL2ErrorBits bool
Definition: TrigDecision_v1.cxx:60
GeoModel::TransientConstSharedPtr::operator=
TransientConstSharedPtr & operator=(std::unique_ptr< ObjGrp > &&other)
Definition: TransientConstSharedPtr.h:66