Changeset 555
- Timestamp:
- 08/18/09 16:49:39 (15 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
library/bdm/shared_ptr.h
r554 r555 22 22 namespace bdm { 23 23 24 /*! \brief A naive implementation of roughly a subset of the std::tr1: shared_ptr spec24 /*! \brief A naive implementation of roughly a subset of the std::tr1::shared_ptr spec 25 25 26 26 Really just roughly - it ignores memory 27 27 exceptions, for example; also note I didn't read the spec. 28 28 29 The standard template would naturally be preferable, _if_it was29 The standard template would naturally be preferable, \b if it was 30 30 included in the standard libraries of all supported compilers - but 31 31 as of 2009, that's still a problem... … … 40 40 41 41 public: 42 //! Creates an empty shared_ptr - one that doesn't point anywhere. 42 /*! 43 \brief Default constructor 44 45 Creates an empty shared_ptr - one that doesn't point anywhere. 46 */ 43 47 shared_ptr() : 44 48 payload ( 0 ), … … 57 61 } 58 62 59 //! If other is empty, constructs an empty shared_ptr; otherwise, 60 //! constructs a shared_ptr that shares ownership with other. 63 /*! 64 \brief Copy constructor 65 66 If other is empty, constructs an empty shared_ptr; otherwise, 67 constructs a shared_ptr that shares ownership with other. 68 */ 61 69 shared_ptr ( const shared_ptr<T> &other ) : 62 70 payload ( other.payload ), … … 65 73 } 66 74 67 //! If other is empty, constructs an empty shared_ptr; otherwise, 68 //! constructs a shared_ptr that shares ownership with other. 75 /*! 76 \brief Generalized copy 77 78 Allows initialization of shared pointer of a base type from 79 raw pointer to a derived type. 80 81 If other is empty, constructs an empty shared_ptr; otherwise, 82 constructs a shared_ptr that shares ownership with other. 83 */ 69 84 template<typename U> 70 85 shared_ptr ( const shared_ptr<U> &other ) : … … 74 89 } 75 90 91 /*! 92 Destructor. 93 */ 76 94 ~shared_ptr() { 77 95 del_ref(); 78 96 } 79 97 98 /*! 99 \brief Assignment operator 100 */ 80 101 shared_ptr<T> &operator= ( const shared_ptr<T> &other ) { 81 102 other.add_ref(); … … 88 109 } 89 110 90 //! Returns the stored pointer (which remains owned by this 91 //! instance). 111 /*! 112 Returns the stored pointer (which remains owned by this 113 instance). For empty instances, this method returns NULL. 114 */ 92 115 T *get() { 93 116 return payload; 94 117 } 95 118 96 //! Returns the stored pointer (which remains owned by this 97 //! instance). This method may only be called when the stored 98 //! pointer isn't NULL. 119 /*! 120 Dereferences the stored pointer (which remains owned by 121 this instance). This method may only be called when the 122 stored pointer isn't NULL. 123 */ 99 124 T *operator->() { 100 125 it_assert_debug ( payload, "dereferencing NULL" ); … … 110 135 } 111 136 112 //! Returns the stored pointer (which remains owned by this 113 //! instance). 137 /*! 138 Returns the stored pointer (which remains owned by this 139 instance). For empty instances, this method returns NULL. 140 */ 114 141 const T* get() const { 115 142 return payload; … … 132 159 } 133 160 161 //! Returns use_count() == 1 134 162 bool unique() const { 135 163 return refCnt && ( *refCnt == 1 ); 136 164 } 137 165 166 /*! 167 Returns the number of shared_ptr instances (including 168 this instance) that share ownership with this instance. For 169 empty instances, this method returns 0. 170 */ 138 171 long use_count() const { 139 172 return refCnt ? *refCnt : 0; 140 173 } 141 174 175 /*! 176 \brief Boolean cast 177 178 This operator returns true if and only if the instance isn't empty. 179 */ 142 180 operator bool() const { 143 181 return !!payload; 144 182 } 145 183 184 /*! 185 \brief Efficient swap for shared_ptr. 186 */ 146 187 void swap ( shared_ptr &other ) { 147 188 std::swap ( payload, other.payload ); … … 224 265 } 225 266 267 /*! 268 \brief Assignment operator 269 */ 226 270 object_ptr<T> &operator= ( const object_ptr<T> &other ) { 227 271 shared_ptr<T>::operator= ( other );