aboutsummaryrefslogtreecommitdiff
path: root/src/sptr.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/sptr.h')
-rw-r--r--src/sptr.h99
1 files changed, 0 insertions, 99 deletions
diff --git a/src/sptr.h b/src/sptr.h
deleted file mode 100644
index deae94d..0000000
--- a/src/sptr.h
+++ /dev/null
@@ -1,99 +0,0 @@
1#ifndef SPTR_H
2#define SPTR_H
3
4#include <stdint.h>
5#include <stdio.h>
6
7template<typename T>
8class SPtr
9{
10public:
11 SPtr() :
12 pRefCnt( NULL ),
13 pData( NULL )
14 {
15 }
16
17 ~SPtr()
18 {
19 decCount();
20 }
21
22 SPtr( const SPtr<T> &src ) :
23 pRefCnt( src.pRefCnt ),
24 pData( src.pData )
25 {
26 if( pRefCnt )
27 (*pRefCnt) += 1;
28 }
29
30 SPtr( T *pSrc ) :
31 pRefCnt( NULL ),
32 pData( pSrc )
33 {
34 pRefCnt = new int32_t;
35 (*pRefCnt) = 1;
36 }
37
38 int32_t count()
39 {
40 return *pRefCnt;
41 }
42
43 T *operator->() const
44 {
45 return pData;
46 }
47
48 T *operator*() const
49 {
50 return pData;
51 }
52
53 SPtr<T> operator=( const SPtr<T> &src )
54 {
55 decCount();
56 pRefCnt = src.pRefCnt;
57 pData = src.pData;
58 (*pRefCnt) += 1;
59
60 return *this;
61 }
62
63 bool operator==( const SPtr<T> &src )
64 {
65 return pData == src.pData;
66 }
67
68 operator bool()
69 {
70 return pRefCnt != NULL;
71 }
72
73 bool isSet()
74 {
75 return pRefCnt != NULL;
76 }
77
78private:
79 void decCount()
80 {
81 if( pRefCnt )
82 {
83 (*pRefCnt) -= 1;
84 //printf("Decrementing ref-count to %d\n", *pRefCnt );
85 if( (*pRefCnt) == 0 )
86 {
87 delete pRefCnt;
88 delete pData;
89 pRefCnt = NULL;
90 pData = NULL;
91 }
92 }
93 }
94
95 int32_t *pRefCnt;
96 T *pData;
97};
98
99#endif