]>
Commit | Line | Data |
---|---|---|
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 VS |
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>. | |
7c913512 | 15 | |
23324ae1 | 16 | @library{wxbase} |
9fa8c9bf | 17 | @category{smartpointers} |
7c913512 | 18 | |
73473b3e | 19 | @see wxScopedPtr<T>, wxWeakRef<T>, wxObjectDataPtr<T> |
23324ae1 | 20 | */ |
9fa8c9bf | 21 | template<typename T> |
7c913512 | 22 | class wxSharedPtr<T> |
23324ae1 FM |
23 | { |
24 | public: | |
23324ae1 | 25 | /** |
9fa8c9bf VS |
26 | Constructor. |
27 | ||
28 | Creates shared pointer from the raw pointer @a ptr and takes ownership | |
29 | of it. | |
23324ae1 | 30 | */ |
9fa8c9bf VS |
31 | wxSharedPtr(T* ptr = NULL); |
32 | ||
33 | /// Copy constructor. | |
34 | wxSharedPtr(const wxSharedPtr<T>& tocopy); | |
23324ae1 FM |
35 | |
36 | /** | |
37 | Destructor. | |
38 | */ | |
5cb947fd | 39 | ~wxSharedPtr(); |
23324ae1 FM |
40 | |
41 | /** | |
42 | Returns pointer to its object or @NULL. | |
43 | */ | |
328f5751 | 44 | T* get() const; |
23324ae1 FM |
45 | |
46 | /** | |
7c913512 | 47 | Conversion to a boolean expression (in a variant which is not |
23324ae1 FM |
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 | */ | |
328f5751 | 52 | operator unspecified_bool_type() const; |
23324ae1 FM |
53 | |
54 | /** | |
9fa8c9bf VS |
55 | Returns a reference to the object. If the internal pointer is @NULL |
56 | this method will cause an assert in debug mode. | |
23324ae1 | 57 | */ |
328f5751 | 58 | T operator*() const; |
23324ae1 FM |
59 | |
60 | /** | |
61 | Returns pointer to its object or @NULL. | |
62 | */ | |
328f5751 | 63 | T* operator-() const; |
23324ae1 FM |
64 | |
65 | /** | |
66 | Assignment operator. Releases any previously held pointer | |
67 | and creates a reference to @e ptr. | |
68 | */ | |
5cb947fd | 69 | wxSharedPtr& operator operator=(T* ptr); |
23324ae1 FM |
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 | */ | |
4cc4bfaf | 75 | void reset(T* ptr = NULL); |
23324ae1 FM |
76 | |
77 | /** | |
78 | Returns @true if this is the only pointer pointing to its object. | |
79 | */ | |
328f5751 | 80 | bool unique() const; |
23324ae1 FM |
81 | |
82 | /** | |
83 | Returns the number of pointers pointing to its object. | |
84 | */ | |
328f5751 | 85 | long use_count() const; |
23324ae1 | 86 | }; |
e54c96f1 | 87 |