UFO: Alien Invasion
Toggle main menu visibility
Loading...
Searching...
No Matches
sharedptr.h
Go to the documentation of this file.
1
5
6
#pragma once
7
8
#include <assert.h>
9
10
class
SharedPtrDeletionInternal
{
11
public
:
12
virtual
~SharedPtrDeletionInternal
()
13
{
14
}
15
};
16
17
template
<
class
T>
18
class
SharedPtrDeletionImpl
:
public
SharedPtrDeletionInternal
{
19
public
:
20
SharedPtrDeletionImpl
(T *ptr) :
21
_ptr
(ptr)
22
{
23
}
24
~SharedPtrDeletionImpl
()
25
{
26
// Checks if the supplied type is not just a plain
27
// forward definition, taken from boost::checked_delete
28
// This makes the user really aware what he tries to do
29
// when using this with an incomplete type.
30
typedef
char
completeCheck[
sizeof
(T) ? 1 : -1];(
void
)
sizeof
(completeCheck);
31
delete
_ptr
;
32
}
33
private
:
34
T *
_ptr
;
35
};
36
37
template
<
class
T,
class
D>
38
class
SharedPtrDeletionDeleterImpl
:
public
SharedPtrDeletionInternal
{
39
public
:
40
SharedPtrDeletionDeleterImpl
(T *ptr, D d) :
41
_ptr
(ptr),
_deleter
(d)
42
{
43
}
44
~SharedPtrDeletionDeleterImpl
()
45
{
46
_deleter
(
_ptr
);
47
}
48
private
:
49
T *
_ptr
;
50
D
_deleter
;
51
};
52
94
template
<
class
T>
95
class
SharedPtr
{
96
#if !((__GNUC__ == 2) && (__GNUC_MINOR__ >= 95))
97
template
<
class
T2>
friend
class
SharedPtr
;
98
#endif
99
public
:
100
typedef
int
RefValue
;
101
typedef
T
ValueType
;
102
typedef
T *
PointerType
;
103
typedef
const
T *
ConstPointerType
;
104
typedef
T &
ReferenceType
;
105
typedef
const
T &
ConstReferenceType
;
106
107
SharedPtr
() :
108
_refCount
(0),
_deletion
(0),
_pointer
(0)
109
{
110
}
111
112
template
<
class
T2>
113
explicit
SharedPtr
(T2 *p) :
114
_refCount
(new
RefValue
(1)),
_deletion
(new
SharedPtrDeletionImpl
<T2>(p)),
_pointer
(p)
115
{
116
}
117
118
template
<
class
T2,
class
D>
119
SharedPtr
(T2 *p, D d) :
120
_refCount
(new
RefValue
(1)),
_deletion
(new
SharedPtrDeletionDeleterImpl
<T2, D>(p, d)),
_pointer
(p)
121
{
122
}
123
124
SharedPtr
(
const
SharedPtr
&r) :
125
_refCount
(r.
_refCount
),
_deletion
(r.
_deletion
),
_pointer
(r.
_pointer
)
126
{
127
if
(
_refCount
)
128
++(*
_refCount
);
129
}
130
template
<
class
T2>
131
SharedPtr
(
const
SharedPtr<T2>
&r) :
132
_refCount
(r.
_refCount
),
_deletion
(r.
_deletion
),
_pointer
(r.
_pointer
)
133
{
134
if
(
_refCount
)
135
++(*
_refCount
);
136
}
137
138
~SharedPtr
()
139
{
140
decRef
();
141
}
142
143
SharedPtr
&
operator=
(
const
SharedPtr
&r)
144
{
145
if
(r.
_refCount
)
146
++(*r.
_refCount
);
147
decRef
();
148
149
_refCount
= r.
_refCount
;
150
_deletion
= r.
_deletion
;
151
_pointer
= r.
_pointer
;
152
153
return
*
this
;
154
}
155
156
template
<
class
T2>
157
SharedPtr
&
operator=
(
const
SharedPtr<T2>
&r)
158
{
159
if
(r.
_refCount
)
160
++(*r.
_refCount
);
161
decRef
();
162
163
_refCount
= r.
_refCount
;
164
_deletion
= r.
_deletion
;
165
_pointer
= r.
_pointer
;
166
167
return
*
this
;
168
}
169
170
inline
ReferenceType
operator*
()
const
171
{
172
assert(
_pointer
);
173
return
*
_pointer
;
174
}
175
inline
PointerType
operator->
()
const
176
{
177
assert(
_pointer
);
178
return
_pointer
;
179
}
180
181
inline
bool
operator<
(
ConstPointerType
other)
const
182
{
183
return
*
_pointer
< *other;
184
}
185
186
inline
bool
operator<
(
ConstReferenceType
other)
const
187
{
188
return
*
_pointer
< other;
189
}
190
197
inline
PointerType
get
()
const
198
{
199
return
_pointer
;
200
}
201
206
inline
operator
bool ()
const
207
{
208
return
_pointer
!= 0;
209
}
210
216
inline
bool
unique
()
const
217
{
218
return
refCount
() == 1;
219
}
220
224
void
reset
()
225
{
226
decRef
();
227
_deletion
= 0;
228
_refCount
= 0;
229
_pointer
= 0;
230
}
231
232
template
<
class
T2>
233
bool
operator==
(
const
SharedPtr<T2>
&r)
const
234
{
235
return
_pointer
== r.
get
();
236
}
237
238
template
<
class
T2>
239
bool
operator!=
(
const
SharedPtr<T2>
&r)
const
240
{
241
return
_pointer
!= r.
get
();
242
}
243
248
RefValue
refCount
()
const
249
{
250
return
_refCount
? *
_refCount
: 0;
251
}
252
#if !((__GNUC__ == 2) && (__GNUC_MINOR__ >= 95))
253
private
:
254
#endif
255
void
decRef
()
256
{
257
if
(
_refCount
) {
258
--(*_refCount);
259
if
(!*
_refCount
) {
260
delete
_refCount
;
261
delete
_deletion
;
262
_deletion
= 0;
263
_refCount
= 0;
264
_pointer
= 0;
265
}
266
}
267
}
268
269
RefValue
*
_refCount
;
270
SharedPtrDeletionInternal
*
_deletion
;
271
PointerType
_pointer
;
272
};
SharedPtrDeletionDeleterImpl
Definition
sharedptr.h:38
SharedPtrDeletionDeleterImpl::_ptr
T * _ptr
Definition
sharedptr.h:49
SharedPtrDeletionDeleterImpl::_deleter
D _deleter
Definition
sharedptr.h:50
SharedPtrDeletionDeleterImpl::SharedPtrDeletionDeleterImpl
SharedPtrDeletionDeleterImpl(T *ptr, D d)
Definition
sharedptr.h:40
SharedPtrDeletionDeleterImpl::~SharedPtrDeletionDeleterImpl
~SharedPtrDeletionDeleterImpl()
Definition
sharedptr.h:44
SharedPtrDeletionImpl
Definition
sharedptr.h:18
SharedPtrDeletionImpl::~SharedPtrDeletionImpl
~SharedPtrDeletionImpl()
Definition
sharedptr.h:24
SharedPtrDeletionImpl::SharedPtrDeletionImpl
SharedPtrDeletionImpl(T *ptr)
Definition
sharedptr.h:20
SharedPtrDeletionImpl::_ptr
T * _ptr
Definition
sharedptr.h:34
SharedPtrDeletionInternal
Definition
sharedptr.h:10
SharedPtrDeletionInternal::~SharedPtrDeletionInternal
virtual ~SharedPtrDeletionInternal()
Definition
sharedptr.h:12
SharedPtr< uiNode >::ConstReferenceType
const uiNode & ConstReferenceType
Definition
sharedptr.h:105
SharedPtr::operator<
bool operator<(ConstPointerType other) const
Definition
sharedptr.h:181
SharedPtr< uiNode >::_deletion
SharedPtrDeletionInternal * _deletion
Definition
sharedptr.h:270
SharedPtr< uiNode >::RefValue
int RefValue
Definition
sharedptr.h:100
SharedPtr::get
PointerType get() const
Definition
sharedptr.h:197
SharedPtr< uiNode >::_pointer
PointerType _pointer
Definition
sharedptr.h:271
SharedPtr::operator!=
bool operator!=(const SharedPtr< T2 > &r) const
Definition
sharedptr.h:239
SharedPtr::operator==
bool operator==(const SharedPtr< T2 > &r) const
Definition
sharedptr.h:233
SharedPtr::operator=
SharedPtr & operator=(const SharedPtr &r)
Definition
sharedptr.h:143
SharedPtr< uiNode >::PointerType
uiNode * PointerType
Definition
sharedptr.h:102
SharedPtr::reset
void reset()
Definition
sharedptr.h:224
SharedPtr< uiNode >::_refCount
RefValue * _refCount
Definition
sharedptr.h:269
SharedPtr::SharedPtr
SharedPtr()
Definition
sharedptr.h:107
SharedPtr::decRef
void decRef()
Definition
sharedptr.h:255
SharedPtr< uiNode >::ConstPointerType
const uiNode * ConstPointerType
Definition
sharedptr.h:103
SharedPtr::SharedPtr
SharedPtr(T2 *p, D d)
Definition
sharedptr.h:119
SharedPtr::refCount
RefValue refCount() const
Definition
sharedptr.h:248
SharedPtr::operator->
PointerType operator->() const
Definition
sharedptr.h:175
SharedPtr::SharedPtr
SharedPtr(T2 *p)
Definition
sharedptr.h:113
SharedPtr::SharedPtr
SharedPtr(const SharedPtr< T2 > &r)
Definition
sharedptr.h:131
SharedPtr::unique
bool unique() const
Definition
sharedptr.h:216
SharedPtr< uiNode >::ReferenceType
uiNode & ReferenceType
Definition
sharedptr.h:104
SharedPtr< uiNode >::ValueType
uiNode ValueType
Definition
sharedptr.h:101
SharedPtr::SharedPtr
friend class SharedPtr
Definition
sharedptr.h:97
SharedPtr::SharedPtr
SharedPtr(const SharedPtr &r)
Definition
sharedptr.h:124
SharedPtr::operator*
ReferenceType operator*() const
Definition
sharedptr.h:170
SharedPtr::~SharedPtr
~SharedPtr()
Definition
sharedptr.h:138
void
QGL_EXTERN void(APIENTRY *qglActiveTexture)(GLenum texture)
src
shared
sharedptr.h
Generated on __DATE__ __TIME__ for UFO: Alien Invasion by
1.17.0