CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
CaloCellGeometryMayOwnPtr.h
Go to the documentation of this file.
1 #ifndef Geometry_CaloGeometry_CaloCellGeometryMayOwnPtr_h
2 #define Geometry_CaloGeometry_CaloCellGeometryMayOwnPtr_h
3 // -*- C++ -*-
4 //
5 // Package: Geometry/CaloGeometry
6 // Class : CaloCellGeometryMayOwnPtr
7 //
16 //
17 // Original Author: Christopher Jones
18 // Created: Wed, 23 Oct 2024 19:50:05 GMT
19 //
20 
21 // system include files
22 #include <memory>
23 
24 // user include files
27 
28 // forward declarations
29 
31 public:
32  explicit CaloCellGeometryMayOwnPtr(std::unique_ptr<CaloCellGeometry const> iPtr) noexcept
33  : ptr_{iPtr.release()}, own_{ptr_ != nullptr} {
34  if (own_) {
35  ptr_->increment();
36  }
37  }
38  explicit CaloCellGeometryMayOwnPtr(CaloCellGeometryPtr const& iPtr) noexcept : ptr_{iPtr.get()}, own_{false} {}
39 
41  if (own_ and ptr_->decrement()) {
42  delete ptr_;
43  }
44  }
46  CaloCellGeometryMayOwnPtr(const CaloCellGeometryMayOwnPtr& iPtr) noexcept : ptr_{iPtr.ptr_}, own_{iPtr.own_} {
47  if (own_) {
48  ptr_->increment();
49  }
50  }
51  CaloCellGeometryMayOwnPtr(CaloCellGeometryMayOwnPtr&& iPtr) noexcept : ptr_{iPtr.ptr_}, own_{iPtr.own_} {
52  iPtr.ptr_ = nullptr;
53  iPtr.own_ = false;
54  }
56  //Even if someone does `foo = foo` this will work
57  auto tmpPtr = iPtr.ptr_;
58  auto tmpOwn = iPtr.own_;
60  ptr_ = tmpPtr;
61  own_ = tmpOwn;
62  if (own_) {
63  ptr_->increment();
64  }
65  return *this;
66  }
68  if (&iPtr != this) {
70 
71  ptr_ = iPtr.ptr_;
72  own_ = iPtr.own_;
73  iPtr.ptr_ = nullptr;
74  iPtr.own_ = false;
75  }
76  return *this;
77  }
78 
79  CaloCellGeometry const* operator->() const { return ptr_; }
80  CaloCellGeometry const* get() const { return ptr_; }
81  CaloCellGeometry const& operator*() const { return *ptr_; }
82 
83  operator CaloCellGeometry const*() const { return ptr_; }
84 
85 private:
86  struct no_delete {
87  void operator()(const void*) {}
88  };
89 
90  const CaloCellGeometry* ptr_ = nullptr;
91  bool own_ = false;
92 };
93 
94 #endif
CaloCellGeometryMayOwnPtr & operator=(CaloCellGeometryMayOwnPtr const &iPtr) noexcept
CaloCellGeometryMayOwnPtr(std::unique_ptr< CaloCellGeometry const > iPtr) noexcept
CaloCellGeometryMayOwnPtr & operator=(CaloCellGeometryMayOwnPtr &&iPtr) noexcept
const CaloCellGeometry * ptr_
CaloCellGeometryMayOwnPtr(CaloCellGeometryMayOwnPtr &&iPtr) noexcept
bool decrement() const
void increment() const
CaloCellGeometry const & operator*() const
CaloCellGeometryMayOwnPtr() noexcept=default
CaloCellGeometryMayOwnPtr(CaloCellGeometryPtr const &iPtr) noexcept
CaloCellGeometry const * operator->() const
def move(src, dest)
Definition: eostools.py:511