]>
git.saurik.com Git - wxWidgets.git/blob - interface/ptr_scpd.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxScopedPtr
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
13 This is a simple scoped smart pointer implementation that is similar to
14 the Boost smart pointers but rewritten to
17 Since wxWidgets 2.9.0 there is also a templated version of this class
18 with the same name. See wxScopedPtrT().
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.
35 Creates the smart pointer with the given pointer or none if @NULL. On
36 compilers that support it, this uses the explicit keyword.
38 explicit wxScopedPtr(type T
= NULL
);
41 Destructor frees the pointer help by this object if it is not @NULL.
46 This operator gets the pointer stored in the smart pointer or returns @NULL if
52 This operator works like the standard C++ pointer operator to return the object
53 being pointed to by the pointer. If the pointer is @NULL or invalid this will
59 This operator works like the standard C++ pointer operator to return the pointer
60 in the smart pointer or @NULL if it is empty.
62 const T
* operator -();
65 Returns the currently hold pointer and resets the smart pointer object to
66 @NULL. After a call to this function the caller is responsible for
72 Deletes the currently held pointer and sets it to @a p or to @NULL if no
73 arguments are specified. This function does check to make sure that the
74 pointer you are assigning is not the same pointer that is already stored.
79 Swap the pointer inside the smart pointer with @e other. The pointer being
80 swapped must be of the same type (hence the same class name).
82 swap(wxScopedPtr amp
; other
);
91 This is a simple scoped smart pointer array implementation that is similar to
92 the Boost smart pointers but rewritten to
104 Creates the smart pointer with the given pointer or none if @NULL. On
105 compilers that support it, this uses the explicit keyword.
107 wxScopedArray(type T
= NULL
);
110 This operator gets the pointer stored in the smart pointer or returns @NULL if
116 This operator acts like the standard [] indexing operator for C++ arrays. The
117 function does not do bounds checking.
119 const T
operator [](long int i
);
122 Deletes the currently held pointer and sets it to 'p' or to @NULL if no
123 arguments are specified. This function does check to make sure that the
124 pointer you are assigning is not the same pointer that is already stored.
129 Swap the pointer inside the smart pointer with 'ot'. The pointer being swapped
130 must be of the same type (hence the same class name).
132 swap(wxScopedPtr amp
; ot
);
138 @class wxScopedTiedPtr
139 @wxheader{ptr_scpd.h}
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.
152 class wxScopedTiedPtr
156 Constructor creates a smart pointer initialized with @a ptr and stores
157 @a ptr in the location specified by @a ppTie which must not be
160 wxScopedTiedPtr(T
** ppTie
, T
* ptr
);
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)
166 Warning: this location may now contain an uninitialized value if it hadn't been
167 initialized previously, in particular don't count on it magically being
176 @wxheader{ptr_scpd.h}
178 A scoped pointer template class. It is the template version of
179 the old-style @ref overview_wxscopedptr "scoped pointer macros".
184 @see wxSharedPtr, wxWeakRef
192 wxScopedPtrT(T
* ptr
= NULL
);
200 Returns pointer to object or @NULL.
205 Conversion to a boolean expression (in a variant which is not
206 convertable to anything but a boolean expression). If this class
207 contains a valid pointer it will return @e @true, if it contains
208 a @NULL pointer it will return @e @false.
210 operator unspecified_bool_type() const;
213 Returns a reference to the object. If the internal pointer is @NULL
214 this method will cause an assert in debug mode.
219 Returns pointer to object. If the pointer is @NULL this method will
220 cause an assert in debug mode.
222 T
* operator-() const;
225 Releases the current pointer and returns it.
226 Afterwards the caller is responsible for deleting
227 the data contained in the scoped pointer before.
232 Reset pointer to the value of @e ptr. The
233 previous pointer will be deleted.
235 void reset(T
* ptr
= NULL
);
240 void swap(wxScopedPtr
<T
>& ot
);