ACF $AcfVersion:0$
TPointerBase.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-2.1-or-later OR GPL-2.0-or-later OR GPL-3.0-or-later OR LicenseRef-ACF-Commercial
2#pragma once
3
4
5namespace istd
6{
7
8
13template <class Type>
15{
16public:
17 static void Delete(Type* ptr)
18 {
19 Q_ASSERT(ptr != NULL);
20 if (ptr != NULL){
21 delete ptr;
22 }
23 }
24};
25
26
31template <class Type>
33{
34public:
35 static void Delete(Type* ptr)
36 {
37 Q_ASSERT(ptr != NULL);
38 if (ptr != NULL){
39 delete[] ptr;
40 }
41 }
42};
43
44
48template <class Type>
50{
51public:
55 TPointerBase(Type* ptr = NULL);
56
60 void SetPtr(Type* ptr);
61
65 void Reset();
66
70 Type* GetPtr() const;
75 bool IsValid() const;
76
80 void Swap(TPointerBase& ptr);
81
85 Type& operator*() const;
86
87 template <class CastedType>
88 CastedType Cast() const
89 {
90 return dynamic_cast<CastedType>(GetPtr());
91 }
92
93 // operators
94 Type* operator->() const;
95 bool operator==(const TPointerBase<Type>& ptr) const;
96 bool operator!=(const TPointerBase<Type>& ptr) const;
97 bool operator<(const TPointerBase<Type>& ptr) const;
98 bool operator>(const TPointerBase<Type>& ptr) const;
99 bool operator<=(const TPointerBase<Type>& ptr) const;
100 bool operator>=(const TPointerBase<Type>& ptr) const;
101 bool operator==(const Type* ptr) const;
102 bool operator!=(const Type* ptr) const;
103 bool operator<(const Type* ptr) const;
104 bool operator>(const Type* ptr) const;
105 bool operator<=(const Type* ptr) const;
106 bool operator>=(const Type* ptr) const;
107
108protected:
109 // blocked operators
111
112 Type*& GetPtrRef();
113
114private:
115 Type* m_ptr = nullptr;
116};
117
118
119// inline methods
120
121template <class Type>
123{
124 m_ptr = NULL;
125}
126
127
128template <class Type>
129inline Type* TPointerBase<Type>::GetPtr() const
130{
131 return m_ptr;
132}
133
134
135template <class Type>
137{
138 return (m_ptr != NULL);
139}
140
141
142template <class Type>
144{
145 qSwap(m_ptr, ptr.m_ptr);
146}
147
148
149template <class Type>
151{
152 Q_ASSERT(m_ptr != NULL);
153
154 return *m_ptr;
155}
156
157
158template <class Type>
160{
161 return m_ptr;
162}
163
164
165template <class Type>
167{
168 return (m_ptr == ptr.m_ptr);
169}
170
171
172template <class Type>
174{
175 return (m_ptr != ptr.m_ptr);
176}
177
178
179template <class Type>
181{
182 return m_ptr < ptr.m_ptr;
183}
184
185
186template <class Type>
188{
189 return m_ptr > ptr.m_ptr;
190}
191
192
193template <class Type>
195{
196 return m_ptr <= ptr.m_ptr;
197}
198
199
200template <class Type>
202{
203 return m_ptr >= ptr.m_ptr;
204}
205
206
207template <class Type>
208inline bool TPointerBase<Type>::operator==(const Type* ptr) const
209{
210 return (m_ptr == ptr);
211}
212
213
214template <class Type>
215inline bool TPointerBase<Type>::operator!=(const Type* ptr) const
216{
217 return (m_ptr != ptr);
218}
219
220
221template <class Type>
222bool TPointerBase<Type>::operator<(const Type* ptr) const
223{
224 return (m_ptr < ptr);
225}
226
227
228template <class Type>
229bool TPointerBase<Type>::operator>(const Type* ptr) const
230{
231 return (m_ptr > ptr);
232}
233
234
235template <class Type>
236bool TPointerBase<Type>::operator<=(const Type* ptr) const
237{
238 return (m_ptr <= ptr);
239}
240
241
242template <class Type>
243bool TPointerBase<Type>::operator>=(const Type* ptr) const
244{
245 return (m_ptr >= ptr);
246}
247
248
249// protected inline methods
250
251template <class Type>
253{
254 m_ptr = ptr;
255}
256
257
258template <class Type>
259inline void TPointerBase<Type>::SetPtr(Type* ptr)
260{
261 m_ptr = ptr;
262}
263
264
265template <class Type>
267{
268 m_ptr = ptr.m_ptr;
269
270 return *this;
271}
272
273
274template <class Type>
276{
277 return m_ptr;
278}
279
280
281} // namespace istd
282
283
284
285
static void Delete(Type *ptr)
static void Delete(Type *ptr)
Implementation of pointer wrapper.
bool operator==(const Type *ptr) const
bool operator>(const Type *ptr) const
TPointerBase< Type > & operator=(const TPointerBase< Type > ptr)
CastedType Cast() const
bool operator>=(const Type *ptr) const
Type & operator*() const
Get an access to object pointed at.
bool operator>=(const TPointerBase< Type > &ptr) const
void Swap(TPointerBase &ptr)
Swap two pointers.
bool IsValid() const
Check if internal pointer not NULL.
Type * operator->() const
void SetPtr(Type *ptr)
Set value of internal stored pointer.
Type * GetPtr() const
Return access to internal stored pointer.
void Reset()
Set internal pointer value to NULL.
bool operator<(const TPointerBase< Type > &ptr) const
bool operator>(const TPointerBase< Type > &ptr) const
TPointerBase(Type *ptr=NULL)
Construct and assign internal pointer.
bool operator<=(const TPointerBase< Type > &ptr) const
bool operator!=(const Type *ptr) const
bool operator!=(const TPointerBase< Type > &ptr) const
bool operator<(const Type *ptr) const
bool operator<=(const Type *ptr) const
bool operator==(const TPointerBase< Type > &ptr) const
#define NULL
Definition istd.h:74
Standard library.
Definition IComponent.h:17