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