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