File: classwx_scoped_ptr.html

package info (click to toggle)
wxpython3.0 3.0.2.0%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 482,760 kB
  • ctags: 518,293
  • sloc: cpp: 2,127,226; python: 294,045; makefile: 51,942; ansic: 19,033; sh: 3,013; xml: 1,629; perl: 17
file content (311 lines) | stat: -rw-r--r-- 19,451 bytes parent folder | download | duplicates (2)
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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>wxWidgets: wxScopedPtr Class Reference</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="extra_stylesheet.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="page_container">
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0" style="width: 100%;">
 <tbody>
 <tr>
  <td id="projectlogo">
    <a href="http://www.wxwidgets.org/" target="_new">
      <img alt="wxWidgets" src="logo.png"/>
    </a>
  </td>
  <td style="padding-left: 0.5em; text-align: right;">
   <span id="projectnumber">Version: 3.0.2</span>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- Generated by Doxygen 1.8.2 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="modules.html"><span>Categories</span></a></li>
      <li class="current"><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="annotated.html"><span>Class&#160;List</span></a></li>
      <li><a href="classes.html"><span>Class&#160;Index</span></a></li>
      <li><a href="hierarchy.html"><span>Class&#160;Hierarchy</span></a></li>
      <li><a href="functions.html"><span>Class&#160;Members</span></a></li>
    </ul>
  </div>
</div><!-- top -->
<div class="header">
  <div class="summary">
<a href="#pub-methods">Public Member Functions</a> &#124;
<a href="classwx_scoped_ptr-members.html">List of all members</a>  </div>
  <div class="headertitle">
<div class="title">wxScopedPtr Class Reference<div class="ingroups"><a class="el" href="group__group__class__smartpointers.html">Smart Pointers</a></div></div>  </div>
</div><!--header-->
<div class="contents">

<p><code>#include &lt;wx/scopedptr.h&gt;</code></p>
<div id="dynsection-0" onclick="return toggleVisibility(this)" class="dynheader closed" style="cursor:pointer;">
  <img id="dynsection-0-trigger" src="closed.png" alt="+"/> Inheritance diagram for wxScopedPtr:</div>
<div id="dynsection-0-summary" class="dynsummary" style="display:block;">
</div>
<div id="dynsection-0-content" class="dyncontent" style="display:none;">
<div class="center"><img src="classwx_scoped_ptr__inherit__graph.png" border="0" usemap="#wx_scoped_ptr_inherit__map" alt="Inheritance graph"/></div>
<map name="wx_scoped_ptr_inherit__map" id="wx_scoped_ptr_inherit__map">
<area shape="rect" id="node3" href="classwx_scoped_tied_ptr.html" title="This is a variation on the topic of wxScopedPtr." alt="" coords="5,83,128,111"/></map>
<center><span class="legend">[<a href="graph_legend.html">legend</a>]</span></center></div>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><p>This is a simple scoped smart pointer implementation that is similar to the Boost smart pointers (see <a href="http://www.boost.org">http://www.boost.org</a>) but rewritten to use macros instead. </p>
<p>Since wxWidgets 2.9.0 there is also a templated version of this class with the same name. See <a class="el" href="classwx_scoped_ptr_3_01_t_01_4.html" title="A scoped pointer template class.">wxScopedPtr&lt;T&gt;</a>.</p>
<p>A smart pointer holds a pointer to an object. The memory used by the object is deleted when the smart pointer goes out of scope. This class is different from the <code>std::auto_ptr&lt;&gt;</code> in so far as it doesn't provide copy constructor nor assignment operator. This limits what you can do with it but is much less surprising than the "destructive copy" behaviour of the standard class.</p>
<p><b>Example:</b> </p>
<p>Below is an example of using a wxWidgets scoped smart pointer and pointer array.</p>
<div class="fragment"><div class="line"><span class="keyword">class </span>MyClass{ ... };</div>
<div class="line"></div>
<div class="line"><span class="comment">// declare a smart pointer to a MyClass called wxMyClassPtr</span></div>
<div class="line">wxDECLARE_SCOPED_PTR(MyClass, wxMyClassPtr)</div>
<div class="line"><span class="comment">// declare a smart pointer to an array of chars</span></div>
<div class="line">wxDECLARE_SCOPED_ARRAY(<span class="keywordtype">char</span>, wxCharArray)</div>
<div class="line"></div>
<div class="line">...</div>
<div class="line"></div>
<div class="line"><span class="comment">// define the first pointer class, must be complete</span></div>
<div class="line">wxDEFINE_SCOPED_PTR(MyClass, wxMyClassPtr)</div>
<div class="line"><span class="comment">// define the second pointer class</span></div>
<div class="line">wxDEFINE_SCOPED_ARRAY(<span class="keywordtype">char</span>, wxCharArray)</div>
<div class="line"></div>
<div class="line"><span class="comment">// create an object with a new pointer to MyClass</span></div>
<div class="line">wxMyClassPtr theObj(new MyClass());</div>
<div class="line"><span class="comment">// reset the pointer (deletes the previous one)</span></div>
<div class="line">theObj.<a class="code" href="classwx_scoped_ptr.html#a56e9edc9ce458e8170c8cc7f51eb6e6d" title="Deletes the currently held pointer and sets it to p or to NULL if no arguments are specified...">reset</a>(new MyClass());</div>
<div class="line"></div>
<div class="line"><span class="comment">// access the pointer</span></div>
<div class="line">theObj-&gt;MyFunc();</div>
<div class="line"></div>
<div class="line"><span class="comment">// create an object with a new array of chars</span></div>
<div class="line">wxCharArray theCharObj(new <span class="keywordtype">char</span>[100]);</div>
<div class="line"></div>
<div class="line"><span class="comment">// access the array</span></div>
<div class="line">theCharObj[0] = &quot;!&quot;;</div>
</div><!-- fragment --><h1><a class="anchor" id="scopedptr_newpointers"></a>
Declaring new smart pointer types</h1>
<p>To declare the smart pointer class <code>CLASSNAME</code> containing pointer to a (possibly incomplete) type <code>TYPE</code> you should use </p>
<div class="fragment"><div class="line">wxDECLARE_SCOPED_PTR( TYPE,        <span class="comment">// type of the values</span></div>
<div class="line">                      CLASSNAME ); <span class="comment">// name of the class</span></div>
</div><!-- fragment --><p> And later, when <code>TYPE</code> is fully defined, you must also use </p>
<div class="fragment"><div class="line">wxDEFINE_SCOPED_PTR( TYPE, CLASSNAME );</div>
</div><!-- fragment --><p> to implement the scoped pointer class.</p>
<p>The first argument of these macro is the pointer type, the second is the name of the new smart pointer class being created. Below we will use <a class="el" href="classwx_scoped_ptr.html" title="This is a simple scoped smart pointer implementation that is similar to the Boost smart pointers (see...">wxScopedPtr</a> to represent the scoped pointer class, but the user may create the class with any legal name.</p>
<p>Alternatively, if you don't have to separate the point of declaration and definition of this class and if you accept the standard naming convention, that is that the scoped pointer for the class <code>Foo</code> is called <code>FooPtr</code>, you can use a single macro which replaces two macros above: </p>
<div class="fragment"><div class="line">wxDEFINE_SCOPED_PTR_TYPE( TYPE );</div>
</div><!-- fragment --><p> Once again, in this cass <code>CLASSNAME</code> will be <code>TYPEPtr</code>.</p>
<h2></h2>
<div><span class="lib">Library:</span>&#160;&#160;<span class="lib_text"><a class="el" href="page_libs.html#page_libs_wxbase">wxBase</a></span></div><div><span class="category">Category:</span>&#160;&#160;<span class="category_text"><a class="el" href="group__group__class__smartpointers.html">Smart Pointers</a></span></div><dl class="section see"><dt>See Also</dt><dd><a class="el" href="classwx_scoped_array.html" title="A scoped array template class.">wxScopedArray</a> </dd></dl>
</div><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="pub-methods"></a>
Public Member Functions</h2></td></tr>
<tr class="memitem:a30fbfa2b44f99f62320b744b113144d8"><td class="memItemLeft" align="right" valign="top">&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classwx_scoped_ptr.html#a30fbfa2b44f99f62320b744b113144d8">wxScopedPtr</a> (type *T=NULL)</td></tr>
<tr class="memdesc:a30fbfa2b44f99f62320b744b113144d8"><td class="mdescLeft">&#160;</td><td class="mdescRight">Creates the smart pointer with the given pointer or none if <span class="literal">NULL</span>.  <a href="#a30fbfa2b44f99f62320b744b113144d8"></a><br/></td></tr>
<tr class="separator:a30fbfa2b44f99f62320b744b113144d8"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ae824b3ae060054eb348a93c9004269a4"><td class="memItemLeft" align="right" valign="top">&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classwx_scoped_ptr.html#ae824b3ae060054eb348a93c9004269a4">~wxScopedPtr</a> ()</td></tr>
<tr class="memdesc:ae824b3ae060054eb348a93c9004269a4"><td class="mdescLeft">&#160;</td><td class="mdescRight">Destructor frees the pointer help by this object if it is not <span class="literal">NULL</span>.  <a href="#ae824b3ae060054eb348a93c9004269a4"></a><br/></td></tr>
<tr class="separator:ae824b3ae060054eb348a93c9004269a4"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a3ccb3a9b7842b33dd7f05f0f425118ea"><td class="memItemLeft" align="right" valign="top">T *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classwx_scoped_ptr.html#a3ccb3a9b7842b33dd7f05f0f425118ea">get</a> () const </td></tr>
<tr class="memdesc:a3ccb3a9b7842b33dd7f05f0f425118ea"><td class="mdescLeft">&#160;</td><td class="mdescRight">This operator gets the pointer stored in the smart pointer or returns <span class="literal">NULL</span> if there is none.  <a href="#a3ccb3a9b7842b33dd7f05f0f425118ea"></a><br/></td></tr>
<tr class="separator:a3ccb3a9b7842b33dd7f05f0f425118ea"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ad7209afd14b11f0ae06102b59fcfa47f"><td class="memItemLeft" align="right" valign="top">T &amp;&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classwx_scoped_ptr.html#ad7209afd14b11f0ae06102b59fcfa47f">operator*</a> () const </td></tr>
<tr class="memdesc:ad7209afd14b11f0ae06102b59fcfa47f"><td class="mdescLeft">&#160;</td><td class="mdescRight">This operator works like the standard C++ pointer operator to return the object being pointed to by the pointer.  <a href="#ad7209afd14b11f0ae06102b59fcfa47f"></a><br/></td></tr>
<tr class="separator:ad7209afd14b11f0ae06102b59fcfa47f"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a39a4b959af080169c094799804ff889c"><td class="memItemLeft" align="right" valign="top">T *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classwx_scoped_ptr.html#a39a4b959af080169c094799804ff889c">operator-&gt;</a> () const </td></tr>
<tr class="memdesc:a39a4b959af080169c094799804ff889c"><td class="mdescLeft">&#160;</td><td class="mdescRight">Smart pointer member access.  <a href="#a39a4b959af080169c094799804ff889c"></a><br/></td></tr>
<tr class="separator:a39a4b959af080169c094799804ff889c"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:af4f140f5486b9dc3bffee6b7ae6afb88"><td class="memItemLeft" align="right" valign="top">T *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classwx_scoped_ptr.html#af4f140f5486b9dc3bffee6b7ae6afb88">release</a> ()</td></tr>
<tr class="memdesc:af4f140f5486b9dc3bffee6b7ae6afb88"><td class="mdescLeft">&#160;</td><td class="mdescRight">Returns the currently hold pointer and resets the smart pointer object to <span class="literal">NULL</span>.  <a href="#af4f140f5486b9dc3bffee6b7ae6afb88"></a><br/></td></tr>
<tr class="separator:af4f140f5486b9dc3bffee6b7ae6afb88"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a56e9edc9ce458e8170c8cc7f51eb6e6d"><td class="memItemLeft" align="right" valign="top">&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classwx_scoped_ptr.html#a56e9edc9ce458e8170c8cc7f51eb6e6d">reset</a> (T *p=NULL)</td></tr>
<tr class="memdesc:a56e9edc9ce458e8170c8cc7f51eb6e6d"><td class="mdescLeft">&#160;</td><td class="mdescRight">Deletes the currently held pointer and sets it to <em>p</em> or to <span class="literal">NULL</span> if no arguments are specified.  <a href="#a56e9edc9ce458e8170c8cc7f51eb6e6d"></a><br/></td></tr>
<tr class="separator:a56e9edc9ce458e8170c8cc7f51eb6e6d"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a79d42258949a19d90c021dce70dd61c7"><td class="memItemLeft" align="right" valign="top">&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classwx_scoped_ptr.html#a79d42258949a19d90c021dce70dd61c7">swap</a> (<a class="el" href="classwx_scoped_ptr.html">wxScopedPtr</a> &amp;other)</td></tr>
<tr class="memdesc:a79d42258949a19d90c021dce70dd61c7"><td class="mdescLeft">&#160;</td><td class="mdescRight">Swap the pointer inside the smart pointer with <em>other</em>.  <a href="#a79d42258949a19d90c021dce70dd61c7"></a><br/></td></tr>
<tr class="separator:a79d42258949a19d90c021dce70dd61c7"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<h2 class="groupheader">Constructor &amp; Destructor Documentation</h2>
<a class="anchor" id="a30fbfa2b44f99f62320b744b113144d8"></a>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">wxScopedPtr::wxScopedPtr </td>
          <td>(</td>
          <td class="paramtype">type *&#160;</td>
          <td class="paramname"><em>T</em> = <code>NULL</code></td><td>)</td>
          <td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">explicit</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>Creates the smart pointer with the given pointer or none if <span class="literal">NULL</span>. </p>
<p>On compilers that support it, this uses the explicit keyword. </p>

</div>
</div>
<a class="anchor" id="ae824b3ae060054eb348a93c9004269a4"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">wxScopedPtr::~wxScopedPtr </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Destructor frees the pointer help by this object if it is not <span class="literal">NULL</span>. </p>

</div>
</div>
<h2 class="groupheader">Member Function Documentation</h2>
<a class="anchor" id="a3ccb3a9b7842b33dd7f05f0f425118ea"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">T* wxScopedPtr::get </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td> const</td>
        </tr>
      </table>
</div><div class="memdoc">

<p>This operator gets the pointer stored in the smart pointer or returns <span class="literal">NULL</span> if there is none. </p>

</div>
</div>
<a class="anchor" id="ad7209afd14b11f0ae06102b59fcfa47f"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">T&amp; wxScopedPtr::operator* </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td> const</td>
        </tr>
      </table>
</div><div class="memdoc">

<p>This operator works like the standard C++ pointer operator to return the object being pointed to by the pointer. </p>
<p>If the internal pointer is <span class="literal">NULL</span> this method will cause an assert in debug mode. </p>

</div>
</div>
<a class="anchor" id="a39a4b959af080169c094799804ff889c"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">T* wxScopedPtr::operator-&gt; </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td> const</td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Smart pointer member access. </p>
<p>Returns pointer to its object.</p>
<p>If the internal pointer is <span class="literal">NULL</span> this method will cause an assert in debug mode. </p>

</div>
</div>
<a class="anchor" id="af4f140f5486b9dc3bffee6b7ae6afb88"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">T* wxScopedPtr::release </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Returns the currently hold pointer and resets the smart pointer object to <span class="literal">NULL</span>. </p>
<dl class="section remark"><dt>Remarks</dt><dd>After a call to this function the caller is responsible for deleting the pointer. </dd></dl>

</div>
</div>
<a class="anchor" id="a56e9edc9ce458e8170c8cc7f51eb6e6d"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">wxScopedPtr::reset </td>
          <td>(</td>
          <td class="paramtype">T *&#160;</td>
          <td class="paramname"><em>p</em> = <code>NULL</code></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Deletes the currently held pointer and sets it to <em>p</em> or to <span class="literal">NULL</span> if no arguments are specified. </p>
<dl class="section note"><dt>Note</dt><dd>This function does check to make sure that the pointer you are assigning is not the same pointer that is already stored. </dd></dl>

</div>
</div>
<a class="anchor" id="a79d42258949a19d90c021dce70dd61c7"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">wxScopedPtr::swap </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="classwx_scoped_ptr.html">wxScopedPtr</a> &amp;&#160;</td>
          <td class="paramname"><em>other</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Swap the pointer inside the smart pointer with <em>other</em>. </p>
<p>The pointer being swapped must be of the same type (hence the same class name). </p>

</div>
</div>
</div><!-- contents -->

<address class="footer">
	<small>
		Generated on Thu Nov 27 2014 13:46:56 for wxWidgets by <a href="http://www.doxygen.org/index.html" target="_new">Doxygen</a> 1.8.2
	</small>
</address>
<script src="wxwidgets.js" type="text/javascript"></script>
</div><!-- #page_container -->
</body>
</html>