]>
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 | /** | |
10 | @class wxSharedPtrT | |
11 | @wxheader{ptr_shrd.h} | |
7c913512 | 12 | |
23324ae1 | 13 | A smart pointer with non-intrusive reference counting. It is modeled |
7c913512 | 14 | after @b boost::shared_ptr and can be used with STL containers |
e54c96f1 FM |
15 | and wxVector() - unlike @b std::auto_ptr |
16 | and wxScopedPtr(). | |
7c913512 | 17 | |
23324ae1 FM |
18 | @library{wxbase} |
19 | @category{FIXME} | |
7c913512 | 20 | |
e54c96f1 | 21 | @see wxScopedPtr, wxWeakRef, wxObjectDataPtr |
23324ae1 | 22 | */ |
7c913512 | 23 | class wxSharedPtr<T> |
23324ae1 FM |
24 | { |
25 | public: | |
26 | //@{ | |
27 | /** | |
28 | Constructors. | |
29 | */ | |
4cc4bfaf | 30 | wxSharedPtrT(T* ptr = NULL); |
7c913512 | 31 | wxSharedPtrT(const wxSharedPtr<T>& tocopy); |
23324ae1 FM |
32 | //@} |
33 | ||
34 | /** | |
35 | Destructor. | |
36 | */ | |
37 | ~wxSharedPtrT(); | |
38 | ||
39 | /** | |
40 | Returns pointer to its object or @NULL. | |
41 | */ | |
328f5751 | 42 | T* get() const; |
23324ae1 FM |
43 | |
44 | /** | |
7c913512 | 45 | Conversion to a boolean expression (in a variant which is not |
23324ae1 FM |
46 | convertable to anything but a boolean expression). If this class |
47 | contains a valid pointer it will return @e @true, if it contains | |
48 | a @NULL pointer it will return @e @false. | |
49 | */ | |
328f5751 | 50 | operator unspecified_bool_type() const; |
23324ae1 FM |
51 | |
52 | /** | |
53 | Returns a reference to the object. If the internal pointer is @NULL this | |
54 | method will cause an assert in debug mode. | |
55 | */ | |
328f5751 | 56 | T operator*() const; |
23324ae1 FM |
57 | |
58 | /** | |
59 | Returns pointer to its object or @NULL. | |
60 | */ | |
328f5751 | 61 | T* operator-() const; |
23324ae1 FM |
62 | |
63 | /** | |
64 | Assignment operator. Releases any previously held pointer | |
65 | and creates a reference to @e ptr. | |
66 | */ | |
4cc4bfaf | 67 | wxSharedPtrT& operator operator=(T* ptr); |
23324ae1 FM |
68 | |
69 | /** | |
70 | Reset pointer to @e ptr. If the reference count of the | |
71 | previously owned pointer was 1 it will be deleted. | |
72 | */ | |
4cc4bfaf | 73 | void reset(T* ptr = NULL); |
23324ae1 FM |
74 | |
75 | /** | |
76 | Returns @true if this is the only pointer pointing to its object. | |
77 | */ | |
328f5751 | 78 | bool unique() const; |
23324ae1 FM |
79 | |
80 | /** | |
81 | Returns the number of pointers pointing to its object. | |
82 | */ | |
328f5751 | 83 | long use_count() const; |
23324ae1 | 84 | }; |
e54c96f1 | 85 |