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