summaryrefslogtreecommitdiff
path: root/src/sptr.h
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2007-04-09 22:17:25 +0000
committerMike Buland <eichlan@xagasoft.com>2007-04-09 22:17:25 +0000
commit015b1ee8079175cace17917d375d24175311b2f8 (patch)
tree14ad9a8863957b28d18e7a8e6ba3611f70aee5bf /src/sptr.h
parent92312a5ab76a934f3e79896722d8ec46deffb233 (diff)
downloadlibbu++-015b1ee8079175cace17917d375d24175311b2f8.tar.gz
libbu++-015b1ee8079175cace17917d375d24175311b2f8.tar.bz2
libbu++-015b1ee8079175cace17917d375d24175311b2f8.tar.xz
libbu++-015b1ee8079175cace17917d375d24175311b2f8.zip
The SPtr is castable now. just say SPtrCast<TypeToCastTo>( ASPtr );
Diffstat (limited to 'src/sptr.h')
-rw-r--r--src/sptr.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/sptr.h b/src/sptr.h
index 23c21dc..0ea8bca 100644
--- a/src/sptr.h
+++ b/src/sptr.h
@@ -4,9 +4,14 @@
4#include <stdint.h> 4#include <stdint.h>
5#include <stdio.h> 5#include <stdio.h>
6 6
7template<typename T> class SPtr;
8template< typename Tb, typename Ta > SPtr<Tb> SPtrCast( SPtr<Ta> src );
9
7template<typename T> 10template<typename T>
8class SPtr 11class SPtr
9{ 12{
13 template<typename Tb, typename Ta>
14 friend SPtr<Tb> SPtrCast( SPtr<Ta> pt );
10public: 15public:
11 SPtr() : 16 SPtr() :
12 pRefCnt( NULL ), 17 pRefCnt( NULL ),
@@ -96,4 +101,14 @@ private:
96 T *pData; 101 T *pData;
97}; 102};
98 103
104template< typename Tb, typename Ta > SPtr<Tb> SPtrCast( SPtr<Ta> src )
105{
106 SPtr<Tb> ret;
107 ret.pRefCnt = src.pRefCnt;
108 ret.pData = dynamic_cast<Tb *>(src.pData);
109 if( ret.pRefCnt )
110 (*(ret.pRefCnt)) += 1;
111 return ret;
112}
113
99#endif 114#endif