]> git.saurik.com Git - wxWidgets.git/blob - interface/ptr_shrd.h
Correct introduction to wxControlWithItems
[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 template<typename T>
22 class wxSharedPtr<T>
23 {
24 public:
25 /**
26 Constructor.
27
28 Creates shared pointer from the raw pointer @a ptr and takes ownership
29 of it.
30 */
31 wxSharedPtr(T* ptr = NULL);
32
33 /// Copy constructor.
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 convertable to anything but a boolean expression). If this class
49 contains a valid pointer it will return @e @true, if it contains
50 a @NULL pointer it will return @e @false.
51 */
52 operator unspecified_bool_type() const;
53
54 /**
55 Returns a reference to the object. If the internal pointer is @NULL
56 this method will cause an assert in debug mode.
57 */
58 T operator*() const;
59
60 /**
61 Returns pointer to its object or @NULL.
62 */
63 T* operator-() const;
64
65 /**
66 Assignment operator. Releases any previously held pointer
67 and creates a reference to @e ptr.
68 */
69 wxSharedPtr& operator operator=(T* ptr);
70
71 /**
72 Reset pointer to @e ptr. If the reference count of the
73 previously owned pointer was 1 it will be deleted.
74 */
75 void reset(T* ptr = NULL);
76
77 /**
78 Returns @true if this is the only pointer pointing to its object.
79 */
80 bool unique() const;
81
82 /**
83 Returns the number of pointers pointing to its object.
84 */
85 long use_count() const;
86 };
87