aboutsummaryrefslogtreecommitdiff
path: root/src/old
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2007-05-15 05:25:19 +0000
committerMike Buland <eichlan@xagasoft.com>2007-05-15 05:25:19 +0000
commitdda94f3b53e02e117e6eb5758afa1410e1664c9f (patch)
treeec6df681df119c854bd0d1da2dffa45aba1f233b /src/old
parent033c41ed57348abb3a418166b1fb39bfad3312de (diff)
downloadlibbu++-dda94f3b53e02e117e6eb5758afa1410e1664c9f.tar.gz
libbu++-dda94f3b53e02e117e6eb5758afa1410e1664c9f.tar.bz2
libbu++-dda94f3b53e02e117e6eb5758afa1410e1664c9f.tar.xz
libbu++-dda94f3b53e02e117e6eb5758afa1410e1664c9f.zip
SPtr is now Bu::ified, and the List class now acts the way we think const lists
should act, you can't change anything in there. I'm still debating changing the const_iterator to a constIterator, or something else that's more Bu::worthy. Heh, the namespaces are funny...ok...I'm really tired.
Diffstat (limited to '')
-rw-r--r--src/old/sptr.cpp1
-rw-r--r--src/old/sptr.h99
2 files changed, 0 insertions, 100 deletions
diff --git a/src/old/sptr.cpp b/src/old/sptr.cpp
deleted file mode 100644
index 7f5e894..0000000
--- a/src/old/sptr.cpp
+++ /dev/null
@@ -1 +0,0 @@
1#include "sptr.h"
diff --git a/src/old/sptr.h b/src/old/sptr.h
deleted file mode 100644
index deae94d..0000000
--- a/src/old/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