ATLAS Offline Software
Loading...
Searching...
No Matches
SurfaceHolderImpl.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef TRKEVENTPRIMITIVES_SURFACEHOLDER_H
6#define TRKEVENTPRIMITIVES_SURFACEHOLDER_H
7
9
47
48namespace Trk {
49
50/*
51 * Implementation based on plain ptr and
52 * isFree semantics
53 */
54template<typename S>
56{
57public:
61 explicit SurfacePtrHolderImpl(const S& s)
63 {}
64
65 explicit SurfacePtrHolderImpl(const S* s)
67 {}
68
72
75 {
76 // tranfer ownership and leave other nullptr
77 m_associatedSurface = other.m_associatedSurface;
78 other.m_associatedSurface = nullptr;
79 }
80
83 {
84 if (this != &other) {
85 destroySurface(); // clean up ourselves
86 m_associatedSurface = cloneHelper(other.m_associatedSurface);
87 }
88 return *this;
89 }
90
94 {
95 // destroy current surface
97 // steal payload of other and leave it to nullptr
98 this->m_associatedSurface = other.m_associatedSurface;
99 other.m_associatedSurface = nullptr;
100 return *this;
101 }
102
105 void destroySurface() noexcept
106 {
107 if (m_associatedSurface && m_associatedSurface->isFree()) {
108 delete m_associatedSurface;
109 }
110 //
111 m_associatedSurface = nullptr;
112 }
113
114 const S* surfacePtr() { return m_associatedSurface; }
116 const S* release() noexcept
117 {
118 const S* tmp = m_associatedSurface;
119 m_associatedSurface = nullptr;
120 return tmp;
121 }
122
124 static const S* cloneHelper(const S* input)
125 {
126 return (input && input->isFree() ? input->clone() : input);
127 }
128
129protected:
130 const S* m_associatedSurface = nullptr;
131 // protected we can not create instances of this object
132 // is to be used as helper
134};
135
136/*
137 * Implementation based on plain ptr and
138 * has detector Element Semantics
139 */
140template<typename S>
142{
143
144public:
148 explicit SurfacePtrHolderImplDetEl(const S& s)
150 {}
151
152 explicit SurfacePtrHolderImplDetEl(const S* s)
154 {}
155
159
162 {
163 // tranfer ownership and leave other nullptr
164 m_associatedSurface = other.m_associatedSurface;
165 other.m_associatedSurface = nullptr;
166 }
167
170 {
171 if (this != &other) {
172 destroySurface(); // clean up ourselves
173 m_associatedSurface = cloneHelper(other.m_associatedSurface);
174 }
175 return *this;
176 }
177
180 SurfacePtrHolderImplDetEl&& other) noexcept
181 {
182 // destroy current surface
184 // steal payload of other and leave it to nullptr
185 this->m_associatedSurface = other.m_associatedSurface;
186 other.m_associatedSurface = nullptr;
187 return *this;
188 }
189
190 const S* surfacePtr() { return m_associatedSurface; }
192 const S* release() noexcept
193 {
194 const S* tmp = m_associatedSurface;
195 m_associatedSurface = nullptr;
196 return tmp;
197 }
198
201 void destroySurface() noexcept
202 {
204 m_associatedSurface->associatedDetectorElement() == nullptr) {
205 delete m_associatedSurface;
206 }
207 //
208 m_associatedSurface = nullptr;
209 }
210
213 static const S* cloneHelper(const S* input)
214 {
215 return (input && input->associatedDetectorElement() == nullptr
216 ? input->clone()
217 : input);
218 }
219
220protected:
221 const S* m_associatedSurface = nullptr;
222 // protected we can not create instances of this object
223 // is to be used as helper
225};
226
227/*
228 * Implementation based on SurfaceUniquePtr
229 */
230template<typename S>
232{
233public:
236
239
240 explicit SurfaceUniqHolderImpl(const S& s)
241 : m_associatedSurface(s.isFree() ? s.clone() : &s)
242 {}
243
245 explicit SurfaceUniqHolderImpl(const S* s)
247 {}
248
253 other.m_associatedSurface->isFree()
254 ? other.m_associatedSurface->clone()
255 : other.m_associatedSurface.get())
256 {}
257
260
264 {
265 if (this != &other) {
267 (other.m_associatedSurface && other.m_associatedSurface->isFree())
268 ? other.m_associatedSurface->clone()
269 : other.m_associatedSurface.get());
270 }
271 return *this;
272 }
273
276
278 const S* surfacePtr() { return m_associatedSurface.get(); }
279
282 void destroySurface() noexcept { m_associatedSurface.reset(); }
283
285 const S* release() noexcept { return m_associatedSurface.release(); }
286
287protected:
289 // protected we can not create instances of this object
290 // is to be used as helper
292};
293}
294
295#endif
Handle conditional ownership of surfaces.
SurfacePtrHolderImplDetEl(const S &s)
ctor from const Surface ref.
SurfacePtrHolderImplDetEl()=default
default ctor
SurfacePtrHolderImplDetEl & operator=(const SurfacePtrHolderImplDetEl &other)
copy assingmemnt if surface is free we clone/copy.
void destroySurface() noexcept
destroySurface deletes the ptr if not null and the surface has not a associatedDetectorElement Useful...
static const Surface * cloneHelper(const Surface *input)
const S * release() noexcept
release ala unique_ptr release
SurfacePtrHolderImplDetEl & operator=(SurfacePtrHolderImplDetEl &&other) noexcept
Move assignement we just steal the resource and leave other to point to nullptr.
const S * surfacePtr()
return the ptr we hold useful for tests
SurfacePtrHolderImplDetEl(const SurfacePtrHolderImplDetEl &other)
copy ctor
SurfacePtrHolderImplDetEl(SurfacePtrHolderImplDetEl &&other) noexcept
Move constructor we just steal the resource and leave other to point to nullptr.
SurfacePtrHolderImplDetEl(const S *s)
ctor from const Surface ptr. Takes ownership
void destroySurface() noexcept
destroySurface deletes the ptr if not null and the surface isFree Usefull also for testing
SurfacePtrHolderImpl(const SurfacePtrHolderImpl &other)
copy ctor
SurfacePtrHolderImpl(const S &s)
ctor from const Surface ref.
SurfacePtrHolderImpl & operator=(const SurfacePtrHolderImpl &other)
copy assingmemnt if surface is free we clone/copy.
SurfacePtrHolderImpl(SurfacePtrHolderImpl &&other) noexcept
Move constructor we just steal the resource and leave other to point to nullptr.
const S * surfacePtr()
return the ptr we hold useful for tests
SurfacePtrHolderImpl & operator=(SurfacePtrHolderImpl &&other) noexcept
Move assignement we just steal the resource and leave other to point to nullptr.
SurfacePtrHolderImpl(const S *s)
ctor from const Surface ptr. Takes ownership
SurfacePtrHolderImpl()=default
default ctor
const S * release() noexcept
release ala unique_ptr release
static const ConeSurface * cloneHelper(const ConeSurface *input)
void destroySurface() noexcept
destroySurface deletes the ptr if not null and is free usefull also for testing
SurfaceUniqHolderImpl(const S *s)
ctor from const Surface ptr. Takes ownership
SurfaceUniqHolderImpl(const SurfaceUniqHolderImpl &other)
copy ctor, if surface is free we clone/copy.
SurfaceUniqHolderImpl & operator=(SurfaceUniqHolderImpl &&) noexcept=default
default move assignement
SurfaceUniquePtrT< const ConeSurface > m_associatedSurface
SurfaceUniqHolderImpl(SurfaceUniqHolderImpl &&) noexcept=default
default move ctor
const S * release() noexcept
release , release the unique_ptr we hold
SurfaceUniqHolderImpl()=default
default ctor
SurfaceUniqHolderImpl(const S &s)
ctor from const Surface ref.
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition hcg.cxx:130
Ensure that the ATLAS eigen extensions are properly loaded.
std::unique_ptr< S, SurfaceDeleter< S > > SurfaceUniquePtrT