Repository navigation
Expand file tree
/
Copy pathproxy_ptr.hpp
More file actions
263 lines (222 loc) · 7.37 KB
/
Copy pathproxy_ptr.hpp
File metadata and controls
263 lines (222 loc) · 7.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
/* /////////////////////////////////////////////////////////////////////////
* File: stlsoft/smartptr/proxy_ptr.hpp
*
* Purpose: Contains the proxy_ptr template class.
*
* Created: 17th January 1999
* Updated: 9th November 2026
*
* Home: http://stlsoft.org/
*
* Copyright (c) 2019-2026, Matthew Wilson and Synesis Information Systems
* Copyright (c) 1999-2019, Matthew Wilson and Synesis Software
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name(s) of Matthew Wilson and Synesis Information Systems
* nor the names of any contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* ////////////////////////////////////////////////////////////////////// */
/** \file stlsoft/smartptr/proxy_ptr.hpp
*
* \brief [C++] Definition of the stlsoft::proxy_ptr smart
* pointer class template
* (\ref group__library__SmartPointer "Smart Pointer" Library).
*/
#ifndef STLSOFT_INCL_STLSOFT_SMARTPTR_HPP_PROXY_PTR
#define STLSOFT_INCL_STLSOFT_SMARTPTR_HPP_PROXY_PTR
#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
# define STLSOFT_VER_STLSOFT_SMARTPTR_HPP_PROXY_PTR_MAJOR 5
# define STLSOFT_VER_STLSOFT_SMARTPTR_HPP_PROXY_PTR_MINOR 2
# define STLSOFT_VER_STLSOFT_SMARTPTR_HPP_PROXY_PTR_REVISION 2
# define STLSOFT_VER_STLSOFT_SMARTPTR_HPP_PROXY_PTR_EDIT 89
#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
/* /////////////////////////////////////////////////////////////////////////
* includes
*/
#ifndef STLSOFT_INCL_STLSOFT_H_STLSOFT
# include <stlsoft/stlsoft.h>
#endif /* !STLSOFT_INCL_STLSOFT_H_STLSOFT */
#ifdef STLSOFT_TRACE_INCLUDE
# pragma message(__FILE__)
#endif /* STLSOFT_TRACE_INCLUDE */
/* /////////////////////////////////////////////////////////////////////////
* namespace
*/
#ifndef STLSOFT_NO_NAMESPACE
namespace stlsoft
{
#endif /* STLSOFT_NO_NAMESPACE */
/* /////////////////////////////////////////////////////////////////////////
* classes
*/
// class proxy_ptr
/** This class emulates a pointer in all respects, and is useful as
* a generic code testing tool, and is simply an aid to
* self-documentation.
*
* \ingroup group__library__SmartPointer
*
* \param T The value type
*/
template <ss_typename_param_k T>
class proxy_ptr
{
public:
/// The value type
typedef T value_type;
/// The current specialisation of the type
typedef proxy_ptr<T> class_type;
typedef value_type* resource_type;
typedef value_type const* const_resource_type;
// Construction
public:
/// Construct from a pointer to "borrow"
ss_explicit_k proxy_ptr(value_type *t)
: m_value(t)
{}
/// Assignment from a new pointer
proxy_ptr& operator =(value_type *t)
{
m_value = t;
return *this;
}
// Conversion
public:
/// Implicit conversion to pointer to the underlying pointer
operator value_type *()
{
return m_value;
}
/// Implicit conversion to pointer-to-const to the underlying pointer
operator value_type const* () const
{
return m_value;
}
/// Indirection operator
///
/// \note This method does a debug-time assertion that the underlying pointer is non-null
value_type& operator *() // indirection
{
STLSOFT_MESSAGE_ASSERT("Dereferencing a null pointer!", NULL != m_value);
return *m_value;
}
/// Indirection operator
///
/// \note This method does a debug-time assertion that the underlying pointer is non-null
value_type const& operator *() const // indirection
{
STLSOFT_MESSAGE_ASSERT("Dereferencing a null pointer!", NULL != m_value);
return *m_value;
}
/// Member-selection operator
///
/// \note This method does a debug-time assertion that the underlying pointer is non-null
value_type* operator ->() // member-selection
{
STLSOFT_MESSAGE_ASSERT("Dereferencing a null pointer!", NULL != m_value);
return m_value;
}
/// Member-selection operator
///
/// \note This method does a debug-time assertion that the underlying pointer is non-null
value_type const* operator ->() const // member-selection
{
STLSOFT_MESSAGE_ASSERT("Dereferencing a null pointer!", NULL != m_value);
return m_value;
}
/// Returns the underlying pointer value
///
/// \deprecated This function will be removed in a future release. Users
/// should instead invoke get()
value_type* get_ptr() const STLSOFT_NOEXCEPT
{
return get();
}
/// Returns the underlying pointer value
value_type* get() const STLSOFT_NOEXCEPT
{
return m_value;
}
/// Returns the underlying pointer value
///
/// \deprecated This method will be removed in a future version
value_type* GetPointer() const STLSOFT_NOEXCEPT
{
return m_value;
}
/// Sets the underlying pointer value to null
void clear() STLSOFT_NOEXCEPT
{
m_value = NULL;
}
// Members
private:
value_type *m_value;
};
/* /////////////////////////////////////////////////////////////////////////
* shims
*/
/** get_ptr shim
*
* \ingroup group__library__SmartPointer
*/
template <ss_typename_param_k T>
inline
T*
get_ptr(
proxy_ptr<T> const& p
) STLSOFT_NOEXCEPT
{
return p.get();
}
/** is_null shim
*
* \ingroup group__library__SmartPointer
*/
template <ss_typename_param_k T>
inline
bool
is_null(
proxy_ptr<T> const& p
) STLSOFT_NOEXCEPT
{
return NULL == p.get();
}
/* /////////////////////////////////////////////////////////////////////////
* namespace
*/
#ifndef STLSOFT_NO_NAMESPACE
} // namespace stlsoft
#endif /* STLSOFT_NO_NAMESPACE */
/* /////////////////////////////////////////////////////////////////////////
* inclusion control
*/
#ifdef STLSOFT_PPF_pragma_message_SUPPORT
# pragma once
#endif /* STLSOFT_PPF_pragma_message_SUPPORT */
/* ////////////////////////////////////////////////////////////////////// */
#endif /* !STLSOFT_INCL_STLSOFT_SMARTPTR_HPP_PROXY_PTR */
/* ///////////////////////////// end of file //////////////////////////// */