Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

274 lines
5.2 KiB

  1. //
  2. //
  3. //
  4. //
  5. template< class Type >
  6. inline CRefPtr< Type >::CRefPtr( const CRefPtr< Type >& ref ) :
  7. m_p( ref.m_p ) {
  8. if( m_p )
  9. m_p->AddRef() ;
  10. }
  11. template< class Type >
  12. inline CRefPtr< Type >::CRefPtr( const Type *p ) : m_p( (Type*)p ) {
  13. if( m_p )
  14. m_p->AddRef() ;
  15. }
  16. template< class Type >
  17. inline CRefPtr< Type >::~CRefPtr( ) {
  18. if( m_p && m_p->RemoveRef() < 0 ) {
  19. delete m_p ;
  20. }
  21. }
  22. #if 0
  23. template< class Type >
  24. inline CRefPtr< Type >& CRefPtr< Type >::operator=( CRefPtr< Type >& rhs ) {
  25. if( m_p != rhs.m_p ) {
  26. if( m_p && m_p->RemoveRef() < 0 ) {
  27. delete m_p ;
  28. }
  29. }
  30. m_p = rhs.m_p ;
  31. if( m_p )
  32. m_p->AddRef() ;
  33. return *this ;
  34. } ;
  35. #endif
  36. template< class Type >
  37. inline CRefPtr< Type >& CRefPtr< Type >::operator=( const CRefPtr< Type >& rhs ) {
  38. if( m_p != rhs.m_p ) {
  39. Type* pTemp = m_p ;
  40. m_p = rhs.m_p ;
  41. if( m_p )
  42. m_p->AddRef() ;
  43. if( pTemp && pTemp->RemoveRef() < 0 ) {
  44. delete pTemp ;
  45. }
  46. }
  47. return *this ;
  48. } ;
  49. template< class Type >
  50. inline CRefPtr< Type >& CRefPtr< Type >::operator=( const Type* rhs ) {
  51. if( m_p != rhs ) {
  52. Type* pTemp = m_p ;
  53. m_p = (Type*)rhs ;
  54. if( m_p )
  55. m_p->AddRef() ;
  56. if( pTemp && pTemp->RemoveRef() < 0 ) {
  57. delete pTemp ;
  58. }
  59. }
  60. return *this ;
  61. }
  62. template< class Type >
  63. inline Type* CRefPtr< Type >::operator->() const {
  64. return m_p ;
  65. }
  66. template< class Type >
  67. inline CRefPtr< Type >::operator Type* () const {
  68. return m_p ;
  69. }
  70. #if 0
  71. template< class Type >
  72. inline CRefPtr<Type>::CRefPtr() : m_p( 0 ) {
  73. }
  74. #endif
  75. template< class Type >
  76. inline BOOL CRefPtr<Type>::operator ! ( void ) const {
  77. return !m_p ;
  78. }
  79. template< class Type >
  80. inline BOOL CRefPtr<Type>::operator==( CRefPtr<Type>& rhs ) {
  81. return m_p == rhs.m_p ;
  82. }
  83. template< class Type >
  84. inline BOOL CRefPtr<Type>::operator!=( CRefPtr<Type>& rhs ) {
  85. return m_p != rhs.m_p ;
  86. }
  87. template< class Type >
  88. inline BOOL CRefPtr<Type>::operator==( Type * p ) {
  89. return m_p == p ;
  90. }
  91. template< class Type >
  92. inline BOOL CRefPtr<Type>::operator!=( Type * p ) {
  93. return m_p != p ;
  94. }
  95. template< class Type >
  96. inline Type* CRefPtr<Type>::Release() {
  97. Type* pReturn = 0 ;
  98. if( m_p != 0 ) {
  99. if( m_p->RemoveRef() < 0 ) {
  100. pReturn = m_p ;
  101. }
  102. }
  103. m_p = 0 ;
  104. return pReturn ;
  105. }
  106. template< class Type >
  107. inline Type* CRefPtr<Type>::Replace( Type* p ) {
  108. Type* pReturn = 0 ;
  109. if( m_p != 0 ) {
  110. if( m_p->RemoveRef() < 0 ) {
  111. pReturn = m_p ;
  112. }
  113. }
  114. m_p = p ;
  115. if( m_p != 0 ) {
  116. p->AddRef() ;
  117. if( pReturn == p ) {
  118. pReturn = 0 ;
  119. }
  120. }
  121. return pReturn ;
  122. }
  123. template< class Type >
  124. inline CSmartPtr< Type >::CSmartPtr( const CSmartPtr< Type >& ref ) :
  125. m_p( ref.m_p ) {
  126. if( m_p )
  127. m_p->AddRef() ;
  128. }
  129. template< class Type >
  130. inline CSmartPtr< Type >::CSmartPtr( const Type *p ) : m_p( (Type*)p ) {
  131. if( m_p )
  132. m_p->AddRef() ;
  133. }
  134. template< class Type >
  135. inline CSmartPtr< Type >::~CSmartPtr( ) {
  136. if( m_p && m_p->RemoveRef() < 0 ) {
  137. m_p->DestroySelf() ;
  138. }
  139. }
  140. #if 0
  141. template< class Type >
  142. inline CSmartPtr< Type >& CSmartPtr< Type >::operator=( CSmartPtr< Type >& rhs ) {
  143. if( m_p != rhs.m_p ) {
  144. if( m_p && m_p->RemoveRef() < 0 ) {
  145. delete m_p ;
  146. }
  147. }
  148. m_p = rhs.m_p ;
  149. if( m_p )
  150. m_p->AddRef() ;
  151. return *this ;
  152. } ;
  153. #endif
  154. template< class Type >
  155. inline CSmartPtr< Type >& CSmartPtr< Type >::operator=( const CSmartPtr< Type >& rhs ) {
  156. if( m_p != rhs.m_p ) {
  157. Type* pTemp = m_p ;
  158. m_p = rhs.m_p ;
  159. if( m_p )
  160. m_p->AddRef() ;
  161. if( pTemp && pTemp->RemoveRef() < 0 ) {
  162. pTemp->DestroySelf() ;
  163. }
  164. }
  165. return *this ;
  166. } ;
  167. template< class Type >
  168. inline CSmartPtr< Type >& CSmartPtr< Type >::operator=( const Type* rhs ) {
  169. if( m_p != rhs ) {
  170. Type* pTemp = m_p ;
  171. m_p = (Type*)rhs ;
  172. if( m_p )
  173. m_p->AddRef() ;
  174. if( pTemp && pTemp->RemoveRef() < 0 ) {
  175. pTemp->DestroySelf() ;
  176. }
  177. }
  178. return *this ;
  179. }
  180. template< class Type >
  181. inline Type* CSmartPtr< Type >::operator->() const {
  182. return m_p ;
  183. }
  184. template< class Type >
  185. inline CSmartPtr< Type >::operator Type* () const {
  186. return m_p ;
  187. }
  188. #if 0
  189. template< class Type >
  190. inline CSmartPtr<Type>::CSmartPtr() : m_p( 0 ) {
  191. }
  192. #endif
  193. template< class Type >
  194. inline BOOL CSmartPtr<Type>::operator ! ( void ) const {
  195. return !m_p ;
  196. }
  197. template< class Type >
  198. inline BOOL CSmartPtr<Type>::operator==( CSmartPtr<Type>& rhs ) {
  199. return m_p == rhs.m_p ;
  200. }
  201. template< class Type >
  202. inline BOOL CSmartPtr<Type>::operator!=( CSmartPtr<Type>& rhs ) {
  203. return m_p != rhs.m_p ;
  204. }
  205. template< class Type >
  206. inline BOOL CSmartPtr<Type>::operator==( Type * p ) {
  207. return m_p == p ;
  208. }
  209. template< class Type >
  210. inline BOOL CSmartPtr<Type>::operator!=( Type * p ) {
  211. return m_p != p ;
  212. }
  213. template< class Type >
  214. inline Type* CSmartPtr<Type>::Release() {
  215. Type* pReturn = 0 ;
  216. if( m_p != 0 ) {
  217. if( m_p->RemoveRef() < 0 ) {
  218. pReturn = m_p ;
  219. }
  220. }
  221. m_p = 0 ;
  222. return pReturn ;
  223. }
  224. template< class Type >
  225. inline Type* CSmartPtr<Type>::Replace( Type* p ) {
  226. Type* pReturn = 0 ;
  227. if( m_p != 0 ) {
  228. if( m_p->RemoveRef() < 0 ) {
  229. pReturn = m_p ;
  230. }
  231. }
  232. m_p = p ;
  233. if( m_p != 0 ) {
  234. p->AddRef() ;
  235. if( pReturn == p ) {
  236. pReturn = 0 ;
  237. }
  238. }
  239. return pReturn ;
  240. }