From cc0a8e19f2bb9b80c15aca1ceac2faf79fc4278b Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Tue, 10 Apr 2007 20:43:15 +0000 Subject: 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?). --- src/sptr.h | 18 ++++++++++++++---- 1 file 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: pRefCnt( NULL ), pData( pSrc ) { - pRefCnt = new int32_t; - (*pRefCnt) = 1; + if( pData ) + { + pRefCnt = new int32_t; + (*pRefCnt) = 1; + } } int32_t count() const @@ -70,7 +73,8 @@ public: decCount(); pRefCnt = src.pRefCnt; pData = src.pData; - (*pRefCnt) += 1; + if( pRefCnt ) + (*pRefCnt) += 1; return *this; } @@ -80,7 +84,8 @@ public: decCount(); pRefCnt = src.pRefCnt; pData = src.pData; - (*pRefCnt) += 1; + if( pRefCnt ) + (*pRefCnt) += 1; return *this; } @@ -90,6 +95,11 @@ public: return pData == src.pData; } + bool operator==( const T *src ) const + { + return pData == src; + } + operator bool() const { return pRefCnt != NULL; -- cgit v1.2.3