Changeset 420
- Timestamp:
- 07/20/09 10:11:50 (15 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
library/bdm/shared_ptr.h
r419 r420 14 14 #define shared_ptr_h 15 15 16 #include <assert.h>17 16 #include <limits.h> 18 17 #include <algorithm> 19 18 #include <stdexcept> 20 19 #include <string> 20 #include "itpp_ext.h" 21 21 22 22 namespace bdm { … … 33 33 34 34 public: 35 //! Creates an empty shared_ptr - one that doesn't point anywhere. 35 36 shared_ptr(): 36 37 payload(0), … … 39 40 } 40 41 42 //! Constructs a shared_ptr that owns the pointer p (unless p is 43 //! null, in which case this constructor creates an empty 44 //! shared_ptr). 41 45 shared_ptr(T *p): 42 46 payload(p), … … 45 49 } 46 50 51 //! If other is empty, constructs an empty shared_ptr; otherwise, 52 //! constructs a shared_ptr that shares ownership with other. 47 53 shared_ptr(const shared_ptr &other): 48 54 payload(other.payload), … … 68 74 } 69 75 76 //! Returns the stored pointer (which remains owned by this 77 //! instance). 70 78 T *get() { return payload; } 71 79 80 //! Returns the stored pointer (which remains owned by this 81 //! instance). This method may only be called when the stored 82 //! pointer isn't NULL. 72 83 T *operator->() 73 84 { 74 assert(payload);85 it_assert_debug(payload, "dereferencing NULL"); 75 86 return payload; 76 87 } 77 88 89 //! Returns a reference to the object pointed to by the stored 90 //! pointer. This method may only be called when the stored pointer 91 //! isn't NULL. 78 92 T &operator*() 79 93 { 80 assert(payload);94 it_assert_debug(payload, "dereferencing NULL"); 81 95 return *payload; 82 96 } 83 97 98 //! Returns the stored pointer (which remains owned by this 99 //! instance). 84 100 const T* get() const { return payload; } 85 101 102 //! Returns the stored pointer (which remains owned by this 103 //! instance). This method may only be called when the stored 104 //! pointer isn't NULL. 86 105 const T *operator->() const 87 106 { 88 assert(payload);107 it_assert_debug(payload, "dereferencing NULL"); 89 108 return payload; 90 109 } 91 110 111 //! Returns a reference to the object pointed to by the stored 112 //! pointer. This method may only be called when the stored pointer 113 //! isn't NULL. 92 114 const T &operator*() const 93 115 { 94 assert(payload);116 it_assert_debug(payload, "dereferencing NULL"); 95 117 return *payload; 96 118 }