summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2007-04-10 20:43:15 +0000
committerMike Buland <eichlan@xagasoft.com>2007-04-10 20:43:15 +0000
commitcc0a8e19f2bb9b80c15aca1ceac2faf79fc4278b (patch)
tree5e680e0c0b0cc373587a6cd38d9e90d95d72e2a0
parent79ee50a1cf4415e214298bf696aa3fc44e308d02 (diff)
downloadlibbu++-cc0a8e19f2bb9b80c15aca1ceac2faf79fc4278b.tar.gz
libbu++-cc0a8e19f2bb9b80c15aca1ceac2faf79fc4278b.tar.bz2
libbu++-cc0a8e19f2bb9b80c15aca1ceac2faf79fc4278b.tar.xz
libbu++-cc0a8e19f2bb9b80c15aca1ceac2faf79fc4278b.zip
Updated SPtr to (hopefully) handle null values and assignments well, and you
should be able to compare them to pointers of the same type (and nulls?).
Diffstat (limited to '')
-rw-r--r--src/sptr.h18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/sptr.h b/src/sptr.h
index 3304501..a3e6dc7 100644
--- a/src/sptr.h
+++ b/src/sptr.h
@@ -36,8 +36,11 @@ public:
36 pRefCnt( NULL ), 36 pRefCnt( NULL ),
37 pData( pSrc ) 37 pData( pSrc )
38 { 38 {
39 pRefCnt = new int32_t; 39 if( pData )
40 (*pRefCnt) = 1; 40 {
41 pRefCnt = new int32_t;
42 (*pRefCnt) = 1;
43 }
41 } 44 }
42 45
43 int32_t count() const 46 int32_t count() const
@@ -70,7 +73,8 @@ public:
70 decCount(); 73 decCount();
71 pRefCnt = src.pRefCnt; 74 pRefCnt = src.pRefCnt;
72 pData = src.pData; 75 pData = src.pData;
73 (*pRefCnt) += 1; 76 if( pRefCnt )
77 (*pRefCnt) += 1;
74 78
75 return *this; 79 return *this;
76 } 80 }
@@ -80,7 +84,8 @@ public:
80 decCount(); 84 decCount();
81 pRefCnt = src.pRefCnt; 85 pRefCnt = src.pRefCnt;
82 pData = src.pData; 86 pData = src.pData;
83 (*pRefCnt) += 1; 87 if( pRefCnt )
88 (*pRefCnt) += 1;
84 89
85 return *this; 90 return *this;
86 } 91 }
@@ -90,6 +95,11 @@ public:
90 return pData == src.pData; 95 return pData == src.pData;
91 } 96 }
92 97
98 bool operator==( const T *src ) const
99 {
100 return pData == src;
101 }
102
93 operator bool() const 103 operator bool() const
94 { 104 {
95 return pRefCnt != NULL; 105 return pRefCnt != NULL;