]>
git.saurik.com Git - wxWidgets.git/blob - interface/wx/sharedptr.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxSharedPtr<T>
4 // Author: wxWidgets team
5 // Licence: wxWindows licence
6 /////////////////////////////////////////////////////////////////////////////
9 A smart pointer with non-intrusive reference counting.
11 It is modelled after @c boost::shared_ptr<> and can be used with STL
12 containers and wxVector<T> unlike @c std::auto_ptr<> and wxScopedPtr<T>.
15 @category{smartpointers}
17 @see wxScopedPtr<T>, wxWeakRef<T>, wxObjectDataPtr<T>
26 Creates shared pointer from the raw pointer @a ptr and takes ownership
29 wxEXPLICIT
wxSharedPtr(T
* ptr
= NULL
);
34 Creates shared pointer from the raw pointer @a ptr and deleter @a d
35 and takes ownership of it.
37 @param ptr The raw pointer.
38 @param d Deleter - a functor that is called instead of delete to
39 free the @a ptr raw pointer when its reference count drops to
44 template<typename Deleter
>
45 wxEXPLICIT
wxSharedPtr(T
* ptr
, Deleter d
);
50 wxSharedPtr(const wxSharedPtr
<T
>& tocopy
);
58 Returns pointer to its object or @NULL.
63 Conversion to a boolean expression (in a variant which is not
64 convertible to anything but a boolean expression).
66 If this class contains a valid pointer it will return @true, if it contains
67 a @NULL pointer it will return @false.
69 operator unspecified_bool_type() const;
72 Returns a reference to the object.
74 If the internal pointer is @NULL this method will cause an assert in debug mode.
79 Smart pointer member access. Returns pointer to its object.
81 If the internal pointer is @NULL this method will cause an assert in debug mode.
83 T
* operator->() const;
88 Releases any previously held pointer and creates a reference to @a ptr.
90 wxSharedPtr
<T
>& operator=(T
* ptr
);
95 Releases any previously held pointer and creates a reference to the
96 same object as @a topcopy.
98 wxSharedPtr
<T
>& operator=(const wxSharedPtr
<T
>& tocopy
);
101 Reset pointer to @a ptr.
103 If the reference count of the previously owned pointer was 1 it will be deleted.
105 void reset(T
* ptr
= NULL
);
108 Reset pointer to @a ptr.
110 If the reference count of the previously owned pointer was 1 it will be deleted.
112 @param ptr The new raw pointer.
113 @param d Deleter - a functor that is called instead of delete to
114 free the @a ptr raw pointer when its reference count drops to
119 template<typename Deleter
>
120 void reset(T
* ptr
, Deleter d
);
123 Returns @true if this is the only pointer pointing to its object.
128 Returns the number of pointers pointing to its object.
130 long use_count() const;