]> git.saurik.com Git - wxWidgets.git/blame - interface/ptr_shrd.h
Initial review of various [q-r] by Utensil Candel.
[wxWidgets.git] / interface / ptr_shrd.h
CommitLineData
23324ae1
FM
1/////////////////////////////////////////////////////////////////////////////
2// Name: ptr_shrd.h
e54c96f1 3// Purpose: interface of wxSharedPtr<T>
23324ae1
FM
4// Author: wxWidgets team
5// RCS-ID: $Id$
6// Licence: wxWindows license
7/////////////////////////////////////////////////////////////////////////////
8
9/**
23324ae1 10 @wxheader{ptr_shrd.h}
7c913512 11
9fa8c9bf 12 A smart pointer with non-intrusive reference counting. It is modeled after
b1b95a65
FM
13 @c boost::shared_ptr<> and can be used with STL containers and wxVector<T> -
14 unlike @c std::auto_ptr<> and wxScopedPtr<T>.
7c913512 15
23324ae1 16 @library{wxbase}
9fa8c9bf 17 @category{smartpointers}
7c913512 18
73473b3e 19 @see wxScopedPtr<T>, wxWeakRef<T>, wxObjectDataPtr<T>
23324ae1 20*/
b1b95a65 21
9fa8c9bf 22template<typename T>
7c913512 23class wxSharedPtr<T>
23324ae1
FM
24{
25public:
23324ae1 26 /**
9fa8c9bf
VS
27 Constructor.
28
29 Creates shared pointer from the raw pointer @a ptr and takes ownership
30 of it.
23324ae1 31 */
b1b95a65 32 wxEXPLICIT wxSharedPtr(T* ptr = NULL);
9fa8c9bf 33
b1b95a65
FM
34 /**
35 Copy constructor.
36 */
9fa8c9bf 37 wxSharedPtr(const wxSharedPtr<T>& tocopy);
23324ae1
FM
38
39 /**
40 Destructor.
41 */
5cb947fd 42 ~wxSharedPtr();
23324ae1
FM
43
44 /**
45 Returns pointer to its object or @NULL.
46 */
328f5751 47 T* get() const;
23324ae1
FM
48
49 /**
7c913512 50 Conversion to a boolean expression (in a variant which is not
b1b95a65
FM
51 convertable to anything but a boolean expression).
52
53 If this class contains a valid pointer it will return @true, if it contains
54 a @NULL pointer it will return @false.
23324ae1 55 */
328f5751 56 operator unspecified_bool_type() const;
23324ae1
FM
57
58 /**
b1b95a65
FM
59 Returns a reference to the object.
60
61 If the internal pointer is @NULL this method will cause an assert in debug mode.
23324ae1 62 */
328f5751 63 T operator*() const;
23324ae1
FM
64
65 /**
66 Returns pointer to its object or @NULL.
67 */
b1b95a65 68 T* operator->() const;
23324ae1
FM
69
70 /**
b1b95a65
FM
71 Assignment operator.
72
73 Releases any previously held pointer and creates a reference to @a ptr.
23324ae1 74 */
b1b95a65 75 wxSharedPtr<T>& operator=(T* ptr);
23324ae1
FM
76
77 /**
b1b95a65
FM
78 Assignment operator.
79
80 Releases any previously held pointer and creates a reference to the
81 same object as @a topcopy.
82 */
83 wxSharedPtr<T>& operator=(const wxSharedPtr<T>& tocopy)
84
85 /**
86 Reset pointer to @a ptr.
87
88 If the reference count of the previously owned pointer was 1 it will be deleted.
23324ae1 89 */
4cc4bfaf 90 void reset(T* ptr = NULL);
23324ae1
FM
91
92 /**
93 Returns @true if this is the only pointer pointing to its object.
94 */
328f5751 95 bool unique() const;
23324ae1
FM
96
97 /**
98 Returns the number of pointers pointing to its object.
99 */
328f5751 100 long use_count() const;
23324ae1 101};
e54c96f1 102