diff options
Diffstat (limited to 'src/sptr.h')
-rw-r--r-- | src/sptr.h | 15 |
1 files changed, 15 insertions, 0 deletions
@@ -4,9 +4,14 @@ | |||
4 | #include <stdint.h> | 4 | #include <stdint.h> |
5 | #include <stdio.h> | 5 | #include <stdio.h> |
6 | 6 | ||
7 | template<typename T> class SPtr; | ||
8 | template< typename Tb, typename Ta > SPtr<Tb> SPtrCast( SPtr<Ta> src ); | ||
9 | |||
7 | template<typename T> | 10 | template<typename T> |
8 | class SPtr | 11 | class SPtr |
9 | { | 12 | { |
13 | template<typename Tb, typename Ta> | ||
14 | friend SPtr<Tb> SPtrCast( SPtr<Ta> pt ); | ||
10 | public: | 15 | public: |
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 | ||
104 | template< 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 |