diff options
author | David <david@xagasoft.com> | 2007-04-10 00:26:26 +0000 |
---|---|---|
committer | David <david@xagasoft.com> | 2007-04-10 00:26:26 +0000 |
commit | 531761d77331915b3e6495d10e03191ba10c04d2 (patch) | |
tree | 4ed256755d1379a87efb1d85974ba484e8e98441 /src/sptr.h | |
parent | 015b1ee8079175cace17917d375d24175311b2f8 (diff) | |
download | libbu++-531761d77331915b3e6495d10e03191ba10c04d2.tar.gz libbu++-531761d77331915b3e6495d10e03191ba10c04d2.tar.bz2 libbu++-531761d77331915b3e6495d10e03191ba10c04d2.tar.xz libbu++-531761d77331915b3e6495d10e03191ba10c04d2.zip |
david - wow... that seems a little kludgy... see the constsptr test for details, but basically i had to make the members of sptr mutable to get this to work the way it seems it should... maybe i'm missing something...
Diffstat (limited to '')
-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 ) |