]> git.saurik.com Git - wxWidgets.git/blame - interface/ptr_scpd.h
adjust comments for latex Doxyfile; no real change; add Id keyword
[wxWidgets.git] / interface / ptr_scpd.h
CommitLineData
23324ae1
FM
1/////////////////////////////////////////////////////////////////////////////
2// Name: ptr_scpd.h
3// Purpose: documentation for wxScopedPtr class
4// Author: wxWidgets team
5// RCS-ID: $Id$
6// Licence: wxWindows license
7/////////////////////////////////////////////////////////////////////////////
8
9/**
10 @class wxScopedPtr
11 @wxheader{ptr_scpd.h}
7c913512
FM
12
13 This is a simple scoped smart pointer implementation that is similar to
23324ae1
FM
14 the Boost smart pointers but rewritten to
15 use macros instead.
7c913512 16
23324ae1
FM
17 Since wxWidgets 2.9.0 there is also a templated version of this class
18 with the same name. See wxScopedPtrT.
7c913512 19
23324ae1
FM
20 A smart pointer holds a pointer to an object. The memory used by the object is
21 deleted when the smart pointer goes out of scope. This class is different from
22 the @c std::auto_ptr in so far as it doesn't provide copy constructor
23 nor assignment operator. This limits what you can do with it but is much less
24 surprizing than the "destructive copy'' behaviour of the standard class.
7c913512 25
23324ae1
FM
26 @library{wxbase}
27 @category{FIXME}
7c913512 28
23324ae1
FM
29 @seealso
30 wxScopedArray
31*/
7c913512 32class wxScopedPtr
23324ae1
FM
33{
34public:
35 /**
36 Creates the smart pointer with the given pointer or none if @NULL. On
37 compilers that support it, this uses the explicit keyword.
38 */
39 explicit wxScopedPtr(type T = @NULL);
40
41 /**
42 Destructor frees the pointer help by this object if it is not @NULL.
43 */
44 ~wxScopedPtr();
45
46 /**
47 This operator gets the pointer stored in the smart pointer or returns @NULL if
48 there is none.
49 */
50 const T* get();
51
52 /**
53 This operator works like the standard C++ pointer operator to return the object
54 being pointed to by the pointer. If the pointer is @NULL or invalid this will
55 crash.
56 */
57 const T operator *();
58
59 /**
60 This operator works like the standard C++ pointer operator to return the pointer
61 in the smart pointer or @NULL if it is empty.
62 */
63 const T* operator -();
64
65 /**
7c913512 66 Returns the currently hold pointer and resets the smart pointer object to
23324ae1
FM
67 @NULL. After a call to this function the caller is responsible for
68 deleting the pointer.
69 */
70 T * release();
71
72 /**
7c913512 73 Deletes the currently held pointer and sets it to @e p or to @NULL if no
23324ae1
FM
74 arguments are specified. This function does check to make sure that the
75 pointer you are assigning is not the same pointer that is already stored.
76 */
7c913512 77 reset(T p = @NULL);
23324ae1
FM
78
79 /**
80 Swap the pointer inside the smart pointer with @e other. The pointer being
81 swapped must be of the same type (hence the same class name).
82 */
7c913512 83 swap(wxScopedPtr amp; other);
23324ae1
FM
84};
85
86
87/**
88 @class wxScopedArray
89 @wxheader{ptr_scpd.h}
7c913512
FM
90
91 This is a simple scoped smart pointer array implementation that is similar to
23324ae1
FM
92 the Boost smart pointers but rewritten to
93 use macros instead.
7c913512 94
23324ae1
FM
95 @library{wxbase}
96 @category{FIXME}
7c913512 97
23324ae1
FM
98 @seealso
99 wxScopedPtr
100*/
7c913512 101class wxScopedArray
23324ae1
FM
102{
103public:
104 /**
105 Creates the smart pointer with the given pointer or none if @NULL. On
106 compilers that support it, this uses the explicit keyword.
107 */
108 wxScopedArray(type T = @NULL);
109
110 /**
111 This operator gets the pointer stored in the smart pointer or returns @NULL if
112 there is none.
113 */
114 const T* get();
115
116 /**
117 This operator acts like the standard [] indexing operator for C++ arrays. The
118 function does not do bounds checking.
119 */
120 const T operator [](long int i);
121
122 /**
7c913512 123 Deletes the currently held pointer and sets it to 'p' or to @NULL if no
23324ae1
FM
124 arguments are specified. This function does check to make sure that the
125 pointer you are assigning is not the same pointer that is already stored.
126 */
7c913512 127 reset(T p = @NULL);
23324ae1
FM
128
129 /**
130 Swap the pointer inside the smart pointer with 'ot'. The pointer being swapped
131 must be of the same type (hence the same class name).
132 */
7c913512 133 swap(wxScopedPtr amp; ot);
23324ae1
FM
134};
135
136
137/**
138 @class wxScopedTiedPtr
139 @wxheader{ptr_scpd.h}
7c913512 140
23324ae1
FM
141 This is a variation on the topic of wxScopedPtr. This
142 class is also a smart pointer but in addition it "ties'' the pointer value to
143 another variable. In other words, during the life time of this class the value
144 of that variable is set to be the same as the value of the pointer itself and
145 it is reset to its old value when the object is destroyed. This class is
146 especially useful when converting the existing code (which may already store
147 the pointers value in some variable) to the smart pointers.
7c913512 148
23324ae1
FM
149 @library{wxbase}
150 @category{FIXME}
151*/
7c913512 152class wxScopedTiedPtr
23324ae1
FM
153{
154public:
155 /**
7c913512
FM
156 Constructor creates a smart pointer initialized with @e ptr and stores
157 @e ptr in the location specified by @e ppTie which must not be
23324ae1
FM
158 @NULL.
159 */
160 wxScopedTiedPtr(T ** ppTie, T * ptr);
161
162 /**
163 Destructor frees the pointer help by this object and restores the value stored
164 at the tied location (as specified in the @ref ctor() constructor)
165 to the old value.
166
167 Warning: this location may now contain an uninitialized value if it hadn't been
7c913512 168 initialized previously, in particular don't count on it magically being
23324ae1
FM
169 @NULL!
170 */
171 ~wxScopedTiedPtr();
172};
173
174
175/**
176 @class wxScopedPtrT
177 @wxheader{ptr_scpd.h}
7c913512 178
23324ae1
FM
179 A scoped pointer template class. It is the template version of
180 the old-style @ref overview_wxscopedptr "scoped pointer macros".
7c913512 181
23324ae1
FM
182 @library{wxbase}
183 @category{FIXME}
7c913512 184
23324ae1
FM
185 @seealso
186 wxSharedPtr, wxWeakRef
187*/
7c913512 188class wxScopedPtr<T>
23324ae1
FM
189{
190public:
191 /**
192 Constructor.
193 */
194 wxScopedPtrT(T * ptr = @NULL);
195
196 /**
197 Destructor.
198 */
199 ~wxScopedPtrT();
200
201 /**
202 Returns pointer to object or @NULL.
203 */
204 T * get();
205
206 /**
7c913512 207 Conversion to a boolean expression (in a variant which is not
23324ae1
FM
208 convertable to anything but a boolean expression). If this class
209 contains a valid pointer it will return @e @true, if it contains
210 a @NULL pointer it will return @e @false.
211 */
7c913512 212 operator unspecified_bool_type();
23324ae1
FM
213
214 /**
215 Returns a reference to the object. If the internal pointer is @NULL
216 this method will cause an assert in debug mode.
217 */
218 T operator*();
219
220 /**
7c913512 221 Returns pointer to object. If the pointer is @NULL this method will
23324ae1
FM
222 cause an assert in debug mode.
223 */
224 T * operator-();
225
226 /**
227 Releases the current pointer and returns it.
228 Afterwards the caller is responsible for deleting
229 the data contained in the scoped pointer before.
230 */
231 T* release();
232
233 /**
234 Reset pointer to the value of @e ptr. The
235 previous pointer will be deleted.
236 */
237 void reset(T * ptr = @NULL);
238
239 /**
240 Swaps pointers.
241 */
242 void swap(wxScopedPtr<T> & ot);
243};