aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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;