summaryrefslogtreecommitdiff
path: root/src/sptr.h
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2007-04-03 03:49:53 +0000
committerMike Buland <eichlan@xagasoft.com>2007-04-03 03:49:53 +0000
commitf4c20290509d7ed3a8fd5304577e7a4cc0b9d974 (patch)
tree13cdf64f7cf134f397a7165b7a3fe0807e37026b /src/sptr.h
parent74d4c8cd27334fc7204d5a8773deb3d424565778 (diff)
downloadlibbu++-f4c20290509d7ed3a8fd5304577e7a4cc0b9d974.tar.gz
libbu++-f4c20290509d7ed3a8fd5304577e7a4cc0b9d974.tar.bz2
libbu++-f4c20290509d7ed3a8fd5304577e7a4cc0b9d974.tar.xz
libbu++-f4c20290509d7ed3a8fd5304577e7a4cc0b9d974.zip
Ok, no code is left in src, it's all in src/old. We'll gradually move code back
into src as it's fixed and re-org'd. This includes tests, which, I may write a unit test system into libbu++ just to make my life easier.
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