ICF 3.1.1.10
Technical documentation of ICF Libraries
TPointerBase.h
Go to the documentation of this file.
1/********************************************************************************
2** This file is part of the ICF Framework. Copyright (C) Witold Gantzke & Kirill Lepskiy
3** ICF Framework may be used under the terms of the LGPL License v. 2.1 by the Free Software Foundation.
4********************************************************************************/
5
6#pragma once
7
8
9namespace istd
10{
11
12
17template <class Type>
19{
20public:
21 static void Delete(Type* ptr)
22 {
23 Q_ASSERT(ptr != nullptr);
24 if (ptr != nullptr){
25 delete ptr;
26 }
27 }
28};
29
30
35template <class Type>
37{
38public:
39 static void Delete(Type* ptr)
40 {
41 Q_ASSERT(ptr != nullptr);
42 if (ptr != nullptr){
43 delete[] ptr;
44 }
45 }
46};
47
48
52template <class Type>
54{
55public:
59 TPointerBase(Type* ptr = nullptr);
60
64 void SetPtr(Type* ptr);
65
69 void Reset();
70
74 Type* get() const;
79 bool IsValid() const;
80
84 Type& operator*() const;
85
86 template <class CastedType>
87 CastedType Cast() const
88 {
89 return dynamic_cast<CastedType>(get());
90 }
91
92 // operators
93 Type* operator->() const;
94 bool operator==(const TPointerBase<Type>& ptr) 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 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 operator bool() const
107 {
108 return (m_ptr != nullptr);
109 }
110
111protected:
112 // blocked operators
114
115 Type*& GetPtrRef();
116
120 void Swap(TPointerBase& ptr);
121
122 Type* m_ptr;
123};
124
125
126// inline methods
127
128template <class Type>
130{
131 m_ptr = nullptr;
132}
133
134
135template <class Type>
136inline Type* TPointerBase<Type>::get() const
137{
138 return m_ptr;
139}
140
141
142template <class Type>
144{
145 return (m_ptr != nullptr);
146}
147
148
149template <class Type>
151{
152 Q_ASSERT(m_ptr != nullptr);
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
281template <class Type>
283{
284 std::swap(m_ptr, ptr.m_ptr);
285}
286
287
288} // namespace istd
289
290
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.
TPointerBase(Type *ptr=nullptr)
Construct and assign internal pointer.
bool IsValid() const
Check if internal pointer not nullptr.
Type * operator->() const
void SetPtr(Type *ptr)
Set value of internal stored pointer.
void Reset()
Set internal pointer value to nullptr.
Type * get() const
Return access to internal stored pointer.
bool operator<(const TPointerBase< Type > &ptr) const
bool operator>(const TPointerBase< Type > &ptr) const
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
Standard library.
Definition IComponent.h:17

© Witold Gantzke and Kirill Lepskiy