diff options
Diffstat (limited to 'src/sptr.h')
-rw-r--r-- | src/sptr.h | 20 |
1 files changed, 15 insertions, 5 deletions
@@ -40,7 +40,7 @@ public: | |||
40 | (*pRefCnt) = 1; | 40 | (*pRefCnt) = 1; |
41 | } | 41 | } |
42 | 42 | ||
43 | int32_t count() | 43 | int32_t count() const |
44 | { | 44 | { |
45 | return *pRefCnt; | 45 | return *pRefCnt; |
46 | } | 46 | } |
@@ -65,7 +65,17 @@ public: | |||
65 | return *this; | 65 | return *this; |
66 | } | 66 | } |
67 | 67 | ||
68 | bool operator==( const SPtr<T> &src ) | 68 | const SPtr<T> operator=( const SPtr<T> &src ) const |
69 | { | ||
70 | decCount(); | ||
71 | pRefCnt = src.pRefCnt; | ||
72 | pData = src.pData; | ||
73 | (*pRefCnt) += 1; | ||
74 | |||
75 | return *this; | ||
76 | } | ||
77 | |||
78 | bool operator==( const SPtr<T> &src ) const | ||
69 | { | 79 | { |
70 | return pData == src.pData; | 80 | return pData == src.pData; |
71 | } | 81 | } |
@@ -81,7 +91,7 @@ public: | |||
81 | } | 91 | } |
82 | 92 | ||
83 | private: | 93 | private: |
84 | void decCount() | 94 | void decCount() const |
85 | { | 95 | { |
86 | if( pRefCnt ) | 96 | if( pRefCnt ) |
87 | { | 97 | { |
@@ -97,8 +107,8 @@ private: | |||
97 | } | 107 | } |
98 | } | 108 | } |
99 | 109 | ||
100 | int32_t *pRefCnt; | 110 | mutable int32_t *pRefCnt; |
101 | T *pData; | 111 | mutable T *pData; |
102 | }; | 112 | }; |
103 | 113 | ||
104 | template< typename Tb, typename Ta > SPtr<Tb> SPtrCast( SPtr<Ta> src ) | 114 | template< typename Tb, typename Ta > SPtr<Tb> SPtrCast( SPtr<Ta> src ) |