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
|
/////////////////////////////////////////////////////////////////////////////
// Name: sharedptr.h
// Purpose: interface of wxSharedPtr<T>
// Author: wxWidgets team
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
/**
A smart pointer with non-intrusive reference counting.
It is modelled after @c boost::shared_ptr<> and can be used with STL
containers and wxVector<T> unlike @c std::auto_ptr<> and wxScopedPtr<T>.
@library{wxbase}
@category{smartpointers}
@see wxScopedPtr<T>, wxWeakRef<T>, wxObjectDataPtr<T>
*/
template<typename T>
class wxSharedPtr<T>
{
public:
/**
Constructor.
Creates shared pointer from the raw pointer @a ptr and takes ownership
of it.
*/
wxEXPLICIT wxSharedPtr(T* ptr = NULL);
/**
Constructor.
Creates shared pointer from the raw pointer @a ptr and deleter @a d
and takes ownership of it.
@param ptr The raw pointer.
@param d Deleter - a functor that is called instead of delete to
free the @a ptr raw pointer when its reference count drops to
zero.
@since 3.0
*/
template<typename Deleter>
wxEXPLICIT wxSharedPtr(T* ptr, Deleter d);
/**
Copy constructor.
*/
wxSharedPtr(const wxSharedPtr<T>& tocopy);
/**
Destructor.
*/
~wxSharedPtr();
/**
Returns pointer to its object or @NULL.
*/
T* get() const;
/**
Conversion to a boolean expression (in a variant which is not
convertible to anything but a boolean expression).
If this class contains a valid pointer it will return @true, if it contains
a @NULL pointer it will return @false.
*/
operator unspecified_bool_type() const;
/**
Returns a reference to the object.
If the internal pointer is @NULL this method will cause an assert in debug mode.
*/
T operator*() const;
/**
Smart pointer member access. Returns pointer to its object.
If the internal pointer is @NULL this method will cause an assert in debug mode.
*/
T* operator->() const;
/**
Assignment operator.
Releases any previously held pointer and creates a reference to @a ptr.
*/
wxSharedPtr<T>& operator=(T* ptr);
/**
Assignment operator.
Releases any previously held pointer and creates a reference to the
same object as @a topcopy.
*/
wxSharedPtr<T>& operator=(const wxSharedPtr<T>& tocopy);
/**
Reset pointer to @a ptr.
If the reference count of the previously owned pointer was 1 it will be deleted.
*/
void reset(T* ptr = NULL);
/**
Reset pointer to @a ptr.
If the reference count of the previously owned pointer was 1 it will be deleted.
@param ptr The new raw pointer.
@param d Deleter - a functor that is called instead of delete to
free the @a ptr raw pointer when its reference count drops to
zero.
@since 3.0
*/
template<typename Deleter>
void reset(T* ptr, Deleter d);
/**
Returns @true if this is the only pointer pointing to its object.
*/
bool unique() const;
/**
Returns the number of pointers pointing to its object.
*/
long use_count() const;
};
|