00001 // 00002 // The Austria library is copyright (c) Gianni Mariani 2004. 00003 // 00004 // Grant Of License. Grants to LICENSEE the non-exclusive right to use the Austria 00005 // library subject to the terms of the LGPL. 00006 // 00007 // A copy of the license is available in this directory or one may be found at this URL: 00008 // http://www.gnu.org/copyleft/lesser.txt 00009 // 00019 #ifndef x_at_lifetime_h_x 00020 #define x_at_lifetime_h_x 1 00021 00022 #include "at_exports.h" 00023 #include "at_assert.h" 00024 #include "at_types.h" 00025 00026 #include "at_pointers.h" 00027 00028 // Austria namespace 00029 namespace at 00030 { 00031 00032 // ======== Forward references ========================================= 00033 // 00034 00035 template < typename w_ClassRef > class COMPtrTraits; 00036 template < typename w_ClassRef > class PtrTraits; 00037 template < 00038 typename w_ClassRef, 00039 typename w_First, 00040 typename w_Second 00041 > 00042 class PtrSelect 00043 { 00044 public: 00045 00050 typedef w_First type; 00051 }; 00052 00053 template < 00054 typename w_ClassRef, 00055 typename w_RefTraits = typename PtrSelect< 00056 w_ClassRef, 00057 PtrTraits< w_ClassRef >, 00058 COMPtrTraits< w_ClassRef > 00059 >::type 00060 > class PtrView; 00061 00062 00063 #define AT_Friend_LifeTime \ 00064 template < \ 00065 typename wa_ClassRef, \ 00066 typename wa_RefTraits \ 00067 > friend class Ptr; \ 00068 // end macro 00069 00070 template < 00071 typename w_ClassRef, 00072 typename w_RefTraits = typename PtrSelect< 00073 w_ClassRef, 00074 PtrTraits< w_ClassRef >, 00075 COMPtrTraits< w_ClassRef > 00076 >::type 00077 > class Ptr; 00078 00079 #define AT_Friend_LifeView \ 00080 template < \ 00081 typename wa_ClassRef, \ 00082 typename wa_RefTraits \ 00083 > friend class PtrView; \ 00084 // end macro 00085 00086 #define AT_Friend_LifeLine \ 00087 template < \ 00088 typename wa_ClassRef, \ 00089 typename wa_RefTraits \ 00090 > friend class PtrDelegate; \ 00091 // end macro 00092 00093 00094 // ======== PtrTarget =========================================== 00106 class AUSTRIA_EXPORT PtrTarget 00107 { 00108 public: 00109 00110 virtual ~PtrTarget() {}; // Virtual destructor 00111 00118 virtual int AddRef() const = 0; 00119 00130 virtual int Release() const = 0; 00131 }; 00132 00133 00134 // ======== PtrStyle ================================================== 00140 class PtrStyle 00141 { 00142 public: 00143 00144 enum { 00145 00146 // ======== InitCount ========================================= 00152 InitCount = 0, 00153 00154 // ======== DeleteCheck ======================================= 00160 DeleteCheck = 1 00161 }; 00162 00163 00164 // ======== BaseType ============================================== 00170 struct BaseType 00171 { 00172 }; 00173 00174 00175 // ======== ZeroReferenceAction =================================== 00185 template <typename w_type> 00186 inline static void ZeroReferenceAction( w_type i_obj ) 00187 { 00188 delete i_obj; 00189 } 00190 00191 }; 00192 00193 00194 // ======== PtrCOMStyle =============================================== 00201 class PtrCOMStyle 00202 { 00203 public: 00204 00205 enum { 00206 00207 // ======== InitCount ========================================= 00213 InitCount = 1, 00214 00215 // ======== DeleteCheck ======================================= 00222 DeleteCheck = 0 00223 }; 00224 00225 00226 // ======== BaseType ============================================== 00232 struct BaseType 00233 { 00238 typedef int PtrTargetMarker; 00239 }; 00240 00241 // ======== ZeroReferenceAction =================================== 00251 template <typename w_type> 00252 inline static void ZeroReferenceAction( w_type i_obj ) 00253 { 00254 delete i_obj; 00255 } 00256 00257 }; 00258 00259 00260 // ======== PtrTarget_Helpers ========================================= 00266 template <typename w_count_t, typename w_ptr_style_traits = PtrStyle> 00267 class PtrTarget_Generic; 00268 00269 template <typename w_count_t, typename w_ptr_style_traits> 00270 class PtrTarget_Helpers 00271 { 00272 public: 00273 00274 00275 // ======== IsRefCountOne ========================================= 00286 static bool IsRefCountOne( 00287 const PtrTarget_Generic<w_count_t,w_ptr_style_traits> * i_ptr 00288 ) 00289 { 00290 return 1 == i_ptr->m_ref_count; 00291 } 00292 }; 00293 00294 // ======== PtrTarget_Generic ========================================= 00306 template <typename w_count_t, typename w_ptr_style_traits> 00307 class PtrTarget_Generic 00308 : public w_ptr_style_traits::BaseType 00309 { 00310 public: 00311 00316 typedef w_ptr_style_traits t_ptr_style; 00317 00322 friend class PtrTarget_Helpers<w_count_t,w_ptr_style_traits>; 00323 00324 private: 00325 00326 // for unit test only. 00327 friend class AT_TEST_LifeControlExp; 00328 00329 enum { 00330 00331 // ======== DoDeleteCheck ===================================== 00338 DoDeleteCheck = 00339 OSTraitsBase::DebugBuild 00340 && ( ! t_ptr_style::InitCount ) 00341 && t_ptr_style::DeleteCheck 00342 }; 00343 00344 // m_ref_count is mutable becuase references may increment 00345 // or decrement on const versions of this object as well 00346 // as the non-const version. 00347 mutable w_count_t m_ref_count; 00348 00349 // friend class declaration that allows the MPT_Finder 00350 // to find the PtrTargetMarker. 00351 template < 00352 typename wa_D, 00353 typename wa_TD 00354 > friend struct MPT_Finder; 00355 00356 // ======== AssertGreater ========================================== 00362 template <typename w_count_basis, typename w_compare_t> 00363 static inline w_count_basis AssertGreater( w_count_basis i_v, w_compare_t i_cmp ) 00364 { 00365 AT_Assert( i_v > i_cmp ); 00366 return i_v; 00367 } 00368 00369 public: 00370 // 00371 // this should force derived destructors to be virtual 00372 virtual ~PtrTarget_Generic() {}; // Virtual destructor 00373 00380 PtrTarget_Generic() 00381 : m_ref_count( t_ptr_style::InitCount ) 00382 { 00383 } 00384 00392 PtrTarget_Generic( const PtrTarget_Generic & ) 00393 : m_ref_count( t_ptr_style::InitCount ) 00394 { 00395 } 00396 00403 PtrTarget_Generic & operator = ( const PtrTarget_Generic & ) 00404 { 00405 return * this; 00406 } 00407 00414 int AddRef() const 00415 { 00416 return AssertGreater( 00417 ++ m_ref_count, 00418 static_cast<int>( t_ptr_style::InitCount ) 00419 ); 00420 } 00421 00432 int Release() const 00433 { 00434 00435 int l_ret_val = AssertGreater( m_ref_count --, 0 ) - 1; 00436 00437 if ( l_ret_val == 0 ) 00438 { 00439 // Here we do an extra decrement if we are doing 00440 // assert checking. This is because we want to 00441 // find cases where deleted pointers have their 00442 // reference count incremented. There is no 00443 // guarentee that this check will work because the 00444 // allocated memory may be allocated. 00445 if ( DoDeleteCheck ) 00446 { 00447 -- m_ref_count; 00448 } 00449 00450 // ZeroReferenceAction usually deletes the 00451 // pointer passed in. 00452 t_ptr_style::ZeroReferenceAction( this ); 00453 return 0; 00454 } 00455 00456 return l_ret_val; 00457 } 00458 }; 00459 00460 // ======== IsRefCountOne ============================================= 00469 template <typename w_count_t, typename w_ptr_style_traits> 00470 bool IsRefCountOne( 00471 const PtrTarget_Generic<w_count_t, w_ptr_style_traits> * i_ptr 00472 ) { 00473 00474 if ( i_ptr ) 00475 { 00476 return PtrTarget_Helpers<w_count_t, w_ptr_style_traits>::IsRefCountOne( i_ptr ); 00477 } 00478 else 00479 { 00480 return false; 00481 } 00482 } 00483 00484 // ======== PtrTarget_Basic ========================================= 00494 AUSTRIA_TEMPLATE_EXPORT(PtrTarget_Generic, int) 00495 typedef PtrTarget_Generic<int> PtrTarget_Basic; 00496 00497 00498 00773 // ======== PtrTraits ========================================= 00788 template <typename w_ClassRef> 00789 class PtrTraits 00790 { 00791 public: 00792 00802 static inline w_ClassRef FixRawPtrRefCount( w_ClassRef i_ptr ) 00803 { 00804 if ( i_ptr ) 00805 { 00806 i_ptr->AddRef(); 00807 } 00808 return i_ptr; 00809 } 00810 00817 static inline void IncRefCount( w_ClassRef i_ptr ) 00818 { 00819 i_ptr->AddRef(); 00820 } 00821 00830 static inline void DecRefCount( w_ClassRef i_ptr ) 00831 { 00832 i_ptr->Release(); 00833 } 00834 }; 00835 00836 00837 // ======== PtrDelegate ================================================ 00920 template < 00921 typename w_ClassRef, 00922 typename w_RefTraits = typename PtrSelect< 00923 w_ClassRef, 00924 PtrTraits< w_ClassRef >, 00925 COMPtrTraits< w_ClassRef > 00926 >::type 00927 > 00928 class PtrDelegate 00929 { 00930 AT_Friend_LifeView 00931 AT_Friend_LifeTime 00932 AT_Friend_LifeLine 00933 00940 mutable w_ClassRef m_ptrVal; 00941 00951 inline w_ClassRef ReleasePointee( w_ClassRef i_ptrVal ) 00952 { 00953 // 00954 // The order in which this happens is critical. 00955 // The new pointer must be in place before decrementing 00956 // the reference count. 00957 // 00958 00959 // Save a pointer to the old managed pointer. 00960 w_ClassRef l_ptrVal = m_ptrVal; 00961 00962 // Point to the new managed pointer. 00963 m_ptrVal = i_ptrVal; 00964 00965 // Decrement the old managed pointer's reference count. 00966 if ( l_ptrVal ) { 00967 w_RefTraits::DecRefCount( l_ptrVal ); 00968 } 00969 00970 // Return a regular pointer to the new managed pointer. 00971 return i_ptrVal; 00972 } 00973 00974 public: 00975 00983 inline PtrDelegate( 00984 const PtrDelegate & i_ptr 00985 ) 00986 : m_ptrVal( i_ptr.Transfer() ) 00987 { 00988 } 00989 00999 template < typename w_ClassRefRhs, typename w_RefTraitsRhs > 01000 inline PtrDelegate( 01001 const PtrDelegate< w_ClassRefRhs, w_RefTraitsRhs > & i_ptr 01002 ) 01003 : m_ptrVal( i_ptr.Transfer() ) 01004 { 01005 } 01006 01016 template < typename w_ClassRefRhs, typename w_RefTraitsRhs > 01017 inline PtrDelegate( 01018 const Ptr < w_ClassRefRhs, w_RefTraitsRhs > & i_ptr 01019 ) 01020 : m_ptrVal( i_ptr.m_ptrVal ) 01021 { 01022 // Increment the managed pointer's reference count. 01023 if ( m_ptrVal ) { 01024 w_RefTraits::IncRefCount( m_ptrVal ); 01025 } 01026 } 01027 01036 template < typename w_ClassRefRhs, typename w_RefTraitsRhs > 01037 inline PtrDelegate( 01038 const PtrView< w_ClassRefRhs, w_RefTraitsRhs > & i_ptr 01039 ) 01040 : m_ptrVal( i_ptr.m_ptrVal ) 01041 { 01042 // Increment the managed pointer's reference count. 01043 if ( m_ptrVal ) { 01044 w_RefTraits::IncRefCount( m_ptrVal ); 01045 } 01046 } 01047 01048 01057 inline PtrDelegate( w_ClassRef i_ptr = 0 ) 01058 : m_ptrVal( w_RefTraits::FixRawPtrRefCount( i_ptr ) ) 01059 { 01060 } 01061 01075 inline PtrDelegate( w_ClassRef i_ptr, bool i_takeOwnership ) 01076 : m_ptrVal( i_ptr ) 01077 { 01078 if ( i_takeOwnership ) { 01079 if ( i_ptr ) { 01080 w_RefTraits::IncRefCount( i_ptr ); 01081 } 01082 } 01083 } 01084 01090 inline ~PtrDelegate() 01091 { 01092 if ( m_ptrVal ) { 01093 w_RefTraits::DecRefCount( m_ptrVal ); 01094 } 01095 } 01096 01113 inline PtrDelegate & operator= ( const w_ClassRef i_ptr ) 01114 { 01115 01116 // Perform assignment and use the FixRawPtrRefCount 01117 // RefTraits method to fix the reference count if 01118 // needed. 01119 ReleasePointee( w_RefTraits::FixRawPtrRefCount( i_ptr ) ); 01120 01121 // Return a reference to the PtrDelegate, so that 01122 // assignment operations can be chained together. 01123 return *this; 01124 } 01125 01138 template < typename w_ClassRefRhs, typename w_RefTraitsRhs > 01139 inline PtrDelegate & operator= ( 01140 const PtrDelegate< w_ClassRefRhs, w_RefTraitsRhs > & i_ptr 01141 ) 01142 { 01143 // Perform assignment by transferring responsibility. 01144 // 01145 ReleasePointee( i_ptr.Transfer() ); 01146 01147 // Return a reference to the destination PtrDelegate, 01148 // so that assignment operations can be chained together. 01149 return * this; 01150 } 01151 01163 inline PtrDelegate & operator= ( 01164 const PtrDelegate & i_ptr 01165 ) 01166 { 01167 // Perform assignment by transferring responsibility. 01168 // 01169 ReleasePointee( i_ptr.Transfer() ); 01170 01171 // Return a reference to the destination PtrDelegate, 01172 // so that assignment operations can be chained together. 01173 return * this; 01174 } 01175 01188 template < typename w_ClassRefRhs, typename w_RefTraitsRhs > 01189 inline PtrDelegate & operator= ( 01190 const Ptr< w_ClassRefRhs, w_RefTraitsRhs > & i_ptr 01191 ) 01192 { 01193 01194 w_ClassRef l_ptrVal = i_ptr.m_ptrVal; 01195 01196 // Increment the new managed pointer's reference count. 01197 if ( l_ptrVal ) 01198 { 01199 w_RefTraits::IncRefCount( l_ptrVal ); 01200 } 01201 01202 // Perform assignment 01203 // 01204 ReleasePointee( l_ptrVal ); 01205 01206 // Return a reference to the PtrDelegate, so that 01207 // assignment operations can be chained together. 01208 return *this; 01209 } 01210 01223 template < typename w_ClassRefRhs, typename w_RefTraitsRhs > 01224 inline PtrDelegate & operator= ( 01225 const PtrView< w_ClassRefRhs, w_RefTraitsRhs > & i_ptr 01226 ) 01227 { 01228 01229 w_ClassRef l_ptrVal = i_ptr.m_ptrVal; 01230 01231 // Increment the new managed pointer's reference count. 01232 if ( l_ptrVal != 0 ) 01233 { 01234 w_RefTraits::IncRefCount( l_ptrVal ); 01235 } 01236 01237 // Perform assignment 01238 // 01239 ReleasePointee( l_ptrVal ); 01240 01241 // Return a reference to the PtrDelegate, so that 01242 // assignment operations can be chained together. 01243 return *this; 01244 } 01245 01257 inline w_ClassRef Transfer() const 01258 { 01259 // Save a pointer to the pointer. 01260 w_ClassRef l_ptrVal = m_ptrVal; 01261 01262 m_ptrVal = 0; 01263 01264 return l_ptrVal; 01265 } 01266 01275 inline PtrView< w_ClassRef, w_RefTraits > LifeView() const 01276 { 01277 return PtrView< w_ClassRef, w_RefTraits >( m_ptrVal ); 01278 } 01279 01288 inline typename PointerTo<w_ClassRef>::value_type * operator-> () const 01289 { 01290 return & ( * m_ptrVal ); 01291 } 01292 01299 inline typename PointerTo<w_ClassRef>::value_type & operator* () const 01300 { 01301 return * m_ptrVal; 01302 } 01303 01314 inline w_ClassRef Get() const 01315 { 01316 return m_ptrVal; 01317 } 01318 01326 inline operator bool () const 01327 { 01328 return m_ptrVal != 0; 01329 } 01330 01338 inline bool operator! () const 01339 { 01340 return m_ptrVal == 0; 01341 } 01342 01343 // operator == 01358 template < typename w_ClassRefRhs, typename w_RefTraitsRhs > 01359 inline bool operator== ( 01360 const PtrDelegate< w_ClassRefRhs, w_RefTraitsRhs > & i_ptr 01361 ) 01362 { 01363 return m_ptrVal == i_ptr.m_ptrVal; 01364 } 01365 01367 template < typename w_ClassRefRhs, typename w_RefTraitsRhs > 01368 inline bool operator== ( 01369 const Ptr< w_ClassRefRhs, w_RefTraitsRhs > & i_ptr 01370 ) 01371 { 01372 return m_ptrVal == i_ptr.m_ptrVal; 01373 } 01374 01376 template < typename w_ClassRefRhs, typename w_RefTraitsRhs > 01377 inline bool operator== ( 01378 const PtrView< w_ClassRefRhs, w_RefTraitsRhs > & i_ptr 01379 ) 01380 { 01381 return m_ptrVal == i_ptr.m_ptrVal; 01382 } 01383 01384 // operator != 01399 template < typename w_ClassRefRhs, typename w_RefTraitsRhs > 01400 inline bool operator!= ( 01401 const PtrDelegate< w_ClassRefRhs, w_RefTraitsRhs > & i_ptr 01402 ) 01403 { 01404 return m_ptrVal != i_ptr.m_ptrVal; 01405 } 01406 01408 template < typename w_ClassRefRhs, typename w_RefTraitsRhs > 01409 inline bool operator!= ( 01410 const Ptr< w_ClassRefRhs, w_RefTraitsRhs > & i_ptr 01411 ) 01412 { 01413 return m_ptrVal != i_ptr.m_ptrVal; 01414 } 01415 01417 template < typename w_ClassRefRhs, typename w_RefTraitsRhs > 01418 inline bool operator!= ( 01419 const PtrView< w_ClassRefRhs, w_RefTraitsRhs > & i_ptr 01420 ) 01421 { 01422 return m_ptrVal != i_ptr.m_ptrVal; 01423 } 01424 01425 // operator < 01443 template < typename w_ClassRefRhs, typename w_RefTraitsRhs > 01444 inline bool operator< ( 01445 const PtrDelegate< w_ClassRefRhs, w_RefTraitsRhs > & i_ptr 01446 ) 01447 { 01448 return m_ptrVal < i_ptr.m_ptrVal; 01449 } 01450 01452 template < typename w_ClassRefRhs, typename w_RefTraitsRhs > 01453 inline bool operator< ( 01454 const Ptr< w_ClassRefRhs, w_RefTraitsRhs > & i_ptr 01455 ) 01456 { 01457 return m_ptrVal < i_ptr.m_ptrVal; 01458 } 01459 01461 template < typename w_ClassRefRhs, typename w_RefTraitsRhs > 01462 inline bool operator< ( 01463 const PtrView< w_ClassRefRhs, w_RefTraitsRhs > & i_ptr 01464 ) 01465 { 01466 return m_ptrVal < i_ptr.m_ptrVal; 01467 } 01468 01469 // operator > 01487 template < typename w_ClassRefRhs, typename w_RefTraitsRhs > 01488 inline bool operator> ( 01489 const PtrDelegate< w_ClassRefRhs, w_RefTraitsRhs > & i_ptr 01490 ) 01491 { 01492 return m_ptrVal > i_ptr.m_ptrVal; 01493 } 01494 01496 template < typename w_ClassRefRhs, typename w_RefTraitsRhs > 01497 inline bool operator> ( 01498 const Ptr< w_ClassRefRhs, w_RefTraitsRhs > & i_ptr 01499 ) 01500 { 01501 return m_ptrVal > i_ptr.m_ptrVal; 01502 } 01503 01505 template < typename w_ClassRefRhs, typename w_RefTraitsRhs > 01506 inline bool operator> ( 01507 const PtrView< w_ClassRefRhs, w_RefTraitsRhs > & i_ptr 01508 ) 01509 { 01510 return m_ptrVal > i_ptr.m_ptrVal; 01511 } 01512 01513 // operator <= 01532 template < typename w_ClassRefRhs, typename w_RefTraitsRhs > 01533 inline bool operator<= ( 01534 const PtrDelegate< w_ClassRefRhs, w_RefTraitsRhs > & i_ptr 01535 ) 01536 { 01537 return m_ptrVal <= i_ptr.m_ptrVal; 01538 } 01539 01541 template < typename w_ClassRefRhs, typename w_RefTraitsRhs > 01542 inline bool operator<= ( 01543 const Ptr< w_ClassRefRhs, w_RefTraitsRhs > & i_ptr 01544 ) 01545 { 01546 return m_ptrVal <= i_ptr.m_ptrVal; 01547 } 01548 01550 template < typename w_ClassRefRhs, typename w_RefTraitsRhs > 01551 inline bool operator<= ( 01552 const PtrView< w_ClassRefRhs, w_RefTraitsRhs > & i_ptr 01553 ) 01554 { 01555 return m_ptrVal <= i_ptr.m_ptrVal; 01556 } 01557 01558 // operator >= 01577 template < typename w_ClassRefRhs, typename w_RefTraitsRhs > 01578 inline bool operator>= ( 01579 const PtrDelegate< w_ClassRefRhs, w_RefTraitsRhs > & i_ptr 01580 ) 01581 { 01582 return m_ptrVal >= i_ptr.m_ptrVal; 01583 } 01584 01586 template < typename w_ClassRefRhs, typename w_RefTraitsRhs > 01587 inline bool operator>= ( 01588 const Ptr< w_ClassRefRhs, w_RefTraitsRhs > & i_ptr 01589 ) 01590 { 01591 return m_ptrVal >= i_ptr.m_ptrVal; 01592 } 01593 01595 template < typename w_ClassRefRhs, typename w_RefTraitsRhs > 01596 inline bool operator>= ( 01597 const PtrView< w_ClassRefRhs, w_RefTraitsRhs > & i_ptr 01598 ) 01599 { 01600 return m_ptrVal >= i_ptr.m_ptrVal; 01601 } 01602 }; 01603 01604 01605 // ======== Ptr ================================================ 01641 template < typename w_ClassRef, typename w_RefTraits > 01642 class Ptr 01643 { 01644 AT_Friend_LifeView 01645 AT_Friend_LifeTime 01646 AT_Friend_LifeLine 01647 01654 mutable w_ClassRef m_ptrVal; 01655 01656 private: 01657 01667 inline w_ClassRef ReleasePointee( w_ClassRef i_ptrVal ) 01668 { 01669 // 01670 // The order in which this happens is critical. 01671 // The new pointer must be in place before decrementing 01672 // the reference count. 01673 // 01674 01675 // Save a pointer to the old managed pointer. 01676 w_ClassRef l_ptrVal = m_ptrVal; 01677 01678 // Point to the new managed pointer. 01679 m_ptrVal = i_ptrVal; 01680 01681 // Decrement the old managed pointer's reference count. 01682 if ( l_ptrVal ) { 01683 w_RefTraits::DecRefCount( l_ptrVal ); 01684 } 01685 01686 // Return a regular pointer to the new managed pointer. 01687 return i_ptrVal; 01688 } 01689 01690 public: 01691 01698 inline Ptr() 01699 : m_ptrVal( 0 ) 01700 { 01701 } 01702 01709 inline Ptr( w_ClassRef i_ptr ) 01710 : m_ptrVal( w_RefTraits::FixRawPtrRefCount( i_ptr ) ) 01711 { 01712 } 01713 01725 inline Ptr( w_ClassRef i_ptr, bool i_takeOwnership ) 01726 : m_ptrVal( i_ptr ) 01727 { 01728 if ( i_takeOwnership ) { 01729 if ( m_ptrVal ) { 01730 w_RefTraits::IncRefCount( m_ptrVal ); 01731 } 01732 } 01733 } 01734 01744 template < typename w_ClassRefRhs, typename w_RefTraitsRhs > 01745 inline Ptr( 01746 const Ptr< w_ClassRefRhs, w_RefTraitsRhs > & i_ptr 01747 ) 01748 : m_ptrVal( i_ptr.m_ptrVal ) 01749 { 01750 // Bump the managed pointer's reference count. 01751 if ( m_ptrVal ) { 01752 w_RefTraits::IncRefCount(m_ptrVal); 01753 } 01754 } 01755 01767 inline Ptr( 01768 const Ptr & i_ptr 01769 ) 01770 : m_ptrVal( i_ptr.m_ptrVal ) 01771 { 01772 // Bump the managed pointer's reference count. 01773 if ( m_ptrVal ) { 01774 w_RefTraits::IncRefCount(m_ptrVal); 01775 } 01776 } 01777 01784 template < typename w_ClassRefRhs, typename w_RefTraitsRhs > 01785 inline Ptr( 01786 const PtrView< w_ClassRefRhs, w_RefTraitsRhs > & i_ptr 01787 ) 01788 : m_ptrVal( i_ptr.m_ptrVal ) 01789 { 01790 // Bump the managed pointer's reference count. 01791 if ( m_ptrVal ) { 01792 w_RefTraits::IncRefCount(m_ptrVal); 01793 } 01794 } 01795 01802 template < typename w_ClassRefRhs, typename w_RefTraitsRhs > 01803 inline Ptr( 01804 const PtrDelegate< w_ClassRefRhs, w_RefTraitsRhs > & i_ptr 01805 ) 01806 : m_ptrVal( i_ptr.Transfer() ) 01807 { 01808 } 01809 01815 inline ~Ptr() 01816 { 01817 // Releases the managed pointer 01818 if ( m_ptrVal ) { 01819 w_RefTraits::DecRefCount( m_ptrVal ); 01820 } 01821 } 01822 01836 inline Ptr & operator= ( 01837 w_ClassRef i_ptr 01838 ) 01839 { 01840 // Release the old managed pointer, and adopt the new one. 01841 ReleasePointee( w_RefTraits::FixRawPtrRefCount( i_ptr ) ); 01842 01843 // Return a reference to the Ptr pointer on 01844 // the left-hand side of the '=' sign, so that assign- 01845 // ment operations can be chained together. 01846 return *this; 01847 } 01848 01862 template < typename w_ClassRefRhs, typename w_RefTraitsRhs > 01863 01864 inline Ptr & operator=( 01865 const Ptr< w_ClassRefRhs, w_RefTraitsRhs > & i_ptr 01866 ) 01867 { 01868 // this will increment the reference count 01869 // of the pointer passed in and replace the 01870 // pointer currently being managed by this. 01871 01872 Reset( i_ptr.m_ptrVal ); // pointer conversion happens here 01873 01874 // Return a reference to the Ptr pointer on 01875 // the left-hand side of the '=' sign, so that assign- 01876 // ment operations can be chained together. 01877 return *this; 01878 } 01879 01895 inline Ptr & operator= ( 01896 const Ptr & i_ptr 01897 ) 01898 { 01899 // this will increment the reference count 01900 // of the pointer passed in and replace the 01901 // pointer currently being managed by this. 01902 Reset( i_ptr.m_ptrVal ); 01903 01904 return *this; 01905 } 01906 01919 template < typename w_ClassRefRhs, typename w_RefTraitsRhs > 01920 inline Ptr & operator=( 01921 const PtrView< w_ClassRefRhs, w_RefTraitsRhs > & i_ptr 01922 ) 01923 { 01924 // this will increment the reference count 01925 // of the pointer passed in and replace the 01926 // pointer currently being managed by this. 01927 Reset( i_ptr.m_ptrVal ); 01928 01929 // Return a reference to the Ptr pointer on 01930 // the left-hand side of the '=' sign, so that assign- 01931 // ment operations can be chained together. 01932 return *this; 01933 } 01934 01952 template < typename w_ClassRefRhs, typename w_RefTraitsRhs > 01953 inline Ptr & operator=( 01954 PtrDelegate< w_ClassRefRhs, w_RefTraitsRhs > & i_ptr 01955 ) 01956 { 01957 // Transfer the PtrDelegate to this. The optimization 01958 // for passing PtrDelegate is that the 01959 01960 ReleasePointee( i_ptr.Transfer() ); 01961 01962 // Return a reference to the Ptr pointer on 01963 // the left-hand side of the '=' sign, so that assign- 01964 // ment operations can be chained together. 01965 return *this; 01966 } 01967 01975 inline typename PointerTo<w_ClassRef>::value_type * operator-> () const 01976 { 01977 return & ( * m_ptrVal ); 01978 } 01979 01986 inline typename PointerTo<w_ClassRef>::value_type & operator* () const 01987 { 01988 return * m_ptrVal; 01989 } 01990 02003 inline w_ClassRef * InnerReference() 02004 { 02005 // Release the managed pointer. 02006 ReleasePointee( 0 ); 02007 02008 // Return the address of the private data member used 02009 // to store the address of the managed pointer. 02010 return & m_ptrVal; 02011 } 02012 02019 inline w_ClassRef Get() const 02020 { 02021 return m_ptrVal; 02022 } 02023 02031 inline operator bool () const 02032 { 02033 return m_ptrVal != 0; 02034 } 02035 02045 inline w_ClassRef Reset( const w_ClassRef i_ptr ) 02046 { 02047 // Add a reference to the regular pointer's managed pointer. 02048 if ( i_ptr ) { 02049 w_RefTraits::IncRefCount( i_ptr ); 02050 } 02051 02052 // Set this Ptr equal to the regular pointer. 02053 ReleasePointee( i_ptr ); 02054 02055 return i_ptr; 02056 } 02057 02070 template < typename w_ClassRefRhs, typename w_RefTraitsRhs > 02071 inline Ptr & Reset( 02072 const PtrDelegate< w_ClassRefRhs, w_RefTraitsRhs > & i_ptr 02073 ) 02074 { 02075 Reset( i_ptr.Get() ); 02076 02077 return * this; 02078 } 02079 02089 inline w_ClassRef Transfer() 02090 { 02091 w_ClassRef l_ptr = m_ptrVal; 02092 02093 m_ptrVal = 0; 02094 02095 return l_ptr; 02096 } 02097 02106 inline PtrView< w_ClassRef, w_RefTraits > LifeView() const 02107 { 02108 return PtrView< w_ClassRef, w_RefTraits >( m_ptrVal ); 02109 } 02110 02111 // operator ! 02120 inline bool operator ! () const 02121 { 02122 return m_ptrVal == 0; 02123 } 02124 02125 // operator == 02140 template < typename w_ClassRefRhs, typename w_RefTraitsRhs > 02141 inline bool operator== ( 02142 const PtrDelegate< w_ClassRefRhs, w_RefTraitsRhs > & i_ptr 02143 ) 02144 { 02145 return m_ptrVal == i_ptr.m_ptrVal; 02146 } 02147 02149 template < typename w_ClassRefRhs, typename w_RefTraitsRhs > 02150 inline bool operator== ( 02151 const Ptr< w_ClassRefRhs, w_RefTraitsRhs > & i_ptr 02152 ) 02153 { 02154 return m_ptrVal == i_ptr.m_ptrVal; 02155 } 02156 02158 template < typename w_ClassRefRhs, typename w_RefTraitsRhs > 02159 inline bool operator== ( 02160 const PtrView< w_ClassRefRhs, w_RefTraitsRhs > & i_ptr 02161 ) 02162 { 02163 return m_ptrVal == i_ptr.m_ptrVal; 02164 } 02165 02166 // operator != 02181 template < typename w_ClassRefRhs, typename w_RefTraitsRhs > 02182 inline bool operator!= ( 02183 const PtrDelegate< w_ClassRefRhs, w_RefTraitsRhs > & i_ptr 02184 ) 02185 { 02186 return m_ptrVal != i_ptr.m_ptrVal; 02187 } 02188 02190 template < typename w_ClassRefRhs, typename w_RefTraitsRhs > 02191 inline bool operator!= ( 02192 const Ptr< w_ClassRefRhs, w_RefTraitsRhs > & i_ptr 02193 ) 02194 { 02195 return m_ptrVal != i_ptr.m_ptrVal; 02196 } 02197 02199 template < typename w_ClassRefRhs, typename w_RefTraitsRhs > 02200 inline bool operator!= ( 02201 const PtrView< w_ClassRefRhs, w_RefTraitsRhs > & i_ptr 02202 ) 02203 { 02204 return m_ptrVal != i_ptr.m_ptrVal; 02205 } 02206 02207 // operator < 02225 template < typename w_ClassRefRhs, typename w_RefTraitsRhs > 02226 inline bool operator< ( 02227 const PtrDelegate< w_ClassRefRhs, w_RefTraitsRhs > & i_ptr 02228 ) 02229 { 02230 return m_ptrVal < i_ptr.m_ptrVal; 02231 } 02232 02234 template < typename w_ClassRefRhs, typename w_RefTraitsRhs > 02235 inline bool operator< ( 02236 const Ptr< w_ClassRefRhs, w_RefTraitsRhs > & i_ptr 02237 ) 02238 { 02239 return m_ptrVal < i_ptr.m_ptrVal; 02240 } 02241 02243 template < typename w_ClassRefRhs, typename w_RefTraitsRhs > 02244 inline bool operator< ( 02245 const PtrView< w_ClassRefRhs, w_RefTraitsRhs > & i_ptr 02246 ) 02247 { 02248 return m_ptrVal < i_ptr.m_ptrVal; 02249 } 02250 02268 template < typename w_ClassRefRhs, typename w_RefTraitsRhs > 02269 inline bool operator> ( 02270 const PtrDelegate< w_ClassRefRhs, w_RefTraitsRhs > & i_ptr 02271 ) 02272 { 02273 return m_ptrVal > i_ptr.m_ptrVal; 02274 } 02275 02277 template < typename w_ClassRefRhs, typename w_RefTraitsRhs > 02278 inline bool operator> ( 02279 const Ptr< w_ClassRefRhs, w_RefTraitsRhs > & i_ptr 02280 ) 02281 { 02282 return m_ptrVal > i_ptr.m_ptrVal; 02283 } 02284 02286 template < typename w_ClassRefRhs, typename w_RefTraitsRhs > 02287 inline bool operator> ( 02288 const PtrView< w_ClassRefRhs, w_RefTraitsRhs > & i_ptr 02289 ) 02290 { 02291 return m_ptrVal > i_ptr.m_ptrVal; 02292 } 02293 02294 // operator>= 02312 template < typename w_ClassRefRhs, typename w_RefTraitsRhs > 02313 inline bool operator<= ( 02314 const PtrDelegate< w_ClassRefRhs, w_RefTraitsRhs > & i_ptr 02315 ) 02316 { 02317 return m_ptrVal <= i_ptr.m_ptrVal; 02318 } 02319 02321 template < typename w_ClassRefRhs, typename w_RefTraitsRhs > 02322 inline bool operator<= ( 02323 const Ptr< w_ClassRefRhs, w_RefTraitsRhs > & i_ptr 02324 ) 02325 { 02326 return m_ptrVal <= i_ptr.m_ptrVal; 02327 } 02328 02330 template < typename w_ClassRefRhs, typename w_RefTraitsRhs > 02331 inline bool operator<= ( 02332 const PtrView< w_ClassRefRhs, w_RefTraitsRhs > & i_ptr 02333 ) 02334 { 02335 return m_ptrVal <= i_ptr.m_ptrVal; 02336 } 02337 02338 // operator>= 02357 template < typename w_ClassRefRhs, typename w_RefTraitsRhs > 02358 inline bool operator>= ( 02359 const PtrDelegate< w_ClassRefRhs, w_RefTraitsRhs > & i_ptr 02360 ) 02361 { 02362 return m_ptrVal >= i_ptr.m_ptrVal; 02363 } 02364 02366 template < typename w_ClassRefRhs, typename w_RefTraitsRhs > 02367 inline bool operator>= ( 02368 const Ptr< w_ClassRefRhs, w_RefTraitsRhs > & i_ptr 02369 ) 02370 { 02371 return m_ptrVal >= i_ptr.m_ptrVal; 02372 } 02373 02375 template < typename w_ClassRefRhs, typename w_RefTraitsRhs > 02376 inline bool operator>= ( 02377 const PtrView< w_ClassRefRhs, w_RefTraitsRhs > & i_ptr 02378 ) 02379 { 02380 return m_ptrVal >= i_ptr.m_ptrVal; 02381 } 02382 }; 02383 02384 02385 // ======== PtrView ================================================ 02425 template < typename w_ClassRef, typename w_RefTraits > 02426 02427 class PtrView 02428 { 02429 AT_Friend_LifeView 02430 AT_Friend_LifeTime 02431 AT_Friend_LifeLine 02432 02439 mutable w_ClassRef m_ptrVal; 02440 02441 public: 02442 02450 inline PtrView( w_ClassRef i_ptr = 0 ) 02451 : m_ptrVal( i_ptr ) 02452 { 02453 } 02454 02464 template < typename w_ClassRefRhs, typename w_RefTraitsRhs > 02465 inline PtrView( 02466 const PtrView< w_ClassRefRhs, w_RefTraitsRhs > & i_ptr 02467 ) 02468 : m_ptrVal( i_ptr.m_ptrVal ) 02469 { 02470 } 02471 02483 inline PtrView( 02484 const PtrView & i_ptr 02485 ) 02486 : m_ptrVal( i_ptr.m_ptrVal ) 02487 { 02488 } 02489 02497 template < typename w_ClassRefRhs, typename w_RefTraitsRhs > 02498 inline PtrView( 02499 const Ptr< w_ClassRefRhs, w_RefTraitsRhs > & i_ptr ) 02500 : m_ptrVal( i_ptr.m_ptrVal ) 02501 { 02502 } 02503 02511 template < typename w_ClassRefRhs, typename w_RefTraitsRhs > 02512 inline PtrView( 02513 const PtrDelegate< w_ClassRefRhs, w_RefTraitsRhs > & i_ptr 02514 ) 02515 : m_ptrVal( i_ptr.m_ptrVal ) 02516 { 02517 } 02518 02531 inline PtrView< w_ClassRef, w_RefTraits > & operator= ( 02532 const w_ClassRef i_ptr 02533 ) 02534 { 02535 m_ptrVal = i_ptr; 02536 return *this; 02537 } 02538 02551 template < typename w_ClassRefRhs, typename w_RefTraitsRhs > 02552 inline PtrView & operator= ( 02553 const PtrView< w_ClassRefRhs, w_RefTraitsRhs > & i_ptr 02554 ) 02555 { 02556 m_ptrVal = i_ptr.m_ptrVal; 02557 return *this; 02558 } 02559 02570 inline PtrView & operator= ( 02571 const PtrView & i_ptr 02572 ) 02573 { 02574 m_ptrVal = i_ptr.m_ptrVal; 02575 return *this; 02576 } 02577 02590 template < typename w_ClassRefRhs, typename w_RefTraitsRhs > 02591 inline PtrView & operator= ( 02592 const Ptr< w_ClassRefRhs, w_RefTraitsRhs > & i_ptr 02593 ) 02594 { 02595 m_ptrVal = i_ptr.m_ptrVal; 02596 return *this; 02597 } 02598 02611 template < typename w_ClassRefRhs, typename w_RefTraitsRhs > 02612 inline PtrView & operator= ( 02613 const PtrDelegate< w_ClassRefRhs, w_RefTraitsRhs > & i_ptr 02614 ) 02615 { 02616 m_ptrVal = i_ptr.m_ptrVal; 02617 return *this; 02618 } 02619 02627 inline typename PointerTo<w_ClassRef>::value_type * operator-> () const 02628 { 02629 return & ( * m_ptrVal ); 02630 } 02631 02638 inline typename PointerTo<w_ClassRef>::value_type & operator* () const 02639 { 02640 return * m_ptrVal; 02641 } 02642 02649 inline w_ClassRef Get() const 02650 { 02651 return m_ptrVal; 02652 } 02653 02661 inline PtrView< w_ClassRef > LifeView() const 02662 { 02663 return *this; 02664 } 02665 02674 inline operator bool() const 02675 { 02676 return m_ptrVal != 0; 02677 } 02678 02686 inline bool operator! () const 02687 { 02688 return m_ptrVal == 0; 02689 } 02690 02691 // operator == 02706 template < typename w_ClassRefRhs, typename w_RefTraitsRhs > 02707 inline bool operator== ( 02708 const PtrDelegate< w_ClassRefRhs, w_RefTraitsRhs > & i_ptr 02709 ) 02710 { 02711 return m_ptrVal == i_ptr.m_ptrVal; 02712 } 02713 02715 template < typename w_ClassRefRhs, typename w_RefTraitsRhs > 02716 inline bool operator== ( 02717 const Ptr< w_ClassRefRhs, w_RefTraitsRhs > & i_ptr 02718 ) 02719 { 02720 return m_ptrVal == i_ptr.m_ptrVal; 02721 } 02722 02724 template < typename w_ClassRefRhs, typename w_RefTraitsRhs > 02725 inline bool operator== ( 02726 const PtrView< w_ClassRefRhs, w_RefTraitsRhs > & i_ptr 02727 ) 02728 { 02729 return m_ptrVal == i_ptr.m_ptrVal; 02730 } 02731 02732 // operator != 02747 template < typename w_ClassRefRhs, typename w_RefTraitsRhs > 02748 inline bool operator!= ( 02749 const PtrDelegate< w_ClassRefRhs, w_RefTraitsRhs > & i_ptr 02750 ) 02751 { 02752 return m_ptrVal != i_ptr.m_ptrVal; 02753 } 02754 02756 template < typename w_ClassRefRhs, typename w_RefTraitsRhs > 02757 inline bool operator!= ( 02758 const Ptr< w_ClassRefRhs, w_RefTraitsRhs > & i_ptr 02759 ) 02760 { 02761 return m_ptrVal != i_ptr.m_ptrVal; 02762 } 02763 02765 template < typename w_ClassRefRhs, typename w_RefTraitsRhs > 02766 inline bool operator!= ( 02767 const PtrView< w_ClassRefRhs, w_RefTraitsRhs > & i_ptr 02768 ) 02769 { 02770 return m_ptrVal != i_ptr.m_ptrVal; 02771 } 02772 02773 // operator < 02791 template < typename w_ClassRefRhs, typename w_RefTraitsRhs > 02792 inline bool operator< ( 02793 const PtrDelegate< w_ClassRefRhs, w_RefTraitsRhs > & i_ptr 02794 ) 02795 { 02796 return m_ptrVal < i_ptr.m_ptrVal; 02797 } 02798 02800 template < typename w_ClassRefRhs, typename w_RefTraitsRhs > 02801 inline bool operator< ( 02802 const Ptr< w_ClassRefRhs, w_RefTraitsRhs > & i_ptr 02803 ) 02804 { 02805 return m_ptrVal < i_ptr.m_ptrVal; 02806 } 02807 02809 template < typename w_ClassRefRhs, typename w_RefTraitsRhs > 02810 inline bool operator< ( 02811 const PtrView< w_ClassRefRhs, w_RefTraitsRhs > & i_ptr 02812 ) 02813 { 02814 return m_ptrVal < i_ptr.m_ptrVal; 02815 } 02816 02817 // operator > 02835 template < typename w_ClassRefRhs, typename w_RefTraitsRhs > 02836 inline bool operator> ( 02837 const PtrDelegate< w_ClassRefRhs, w_RefTraitsRhs > & i_ptr 02838 ) 02839 { 02840 return m_ptrVal > i_ptr.m_ptrVal; 02841 } 02842 02844 template < typename w_ClassRefRhs, typename w_RefTraitsRhs > 02845 inline bool operator> ( 02846 const Ptr< w_ClassRefRhs, w_RefTraitsRhs > & i_ptr 02847 ) 02848 { 02849 return m_ptrVal > i_ptr.m_ptrVal; 02850 } 02851 02853 template < typename w_ClassRefRhs, typename w_RefTraitsRhs > 02854 inline bool operator> ( 02855 const PtrView< w_ClassRefRhs, w_RefTraitsRhs > & i_ptr 02856 ) 02857 { 02858 return m_ptrVal > i_ptr.m_ptrVal; 02859 } 02860 02861 // operator <= 02879 02880 template < typename w_ClassRefRhs, typename w_RefTraitsRhs > 02881 inline bool operator<= ( 02882 const PtrDelegate< w_ClassRefRhs, w_RefTraitsRhs > & i_ptr 02883 ) 02884 { 02885 return m_ptrVal <= i_ptr.m_ptrVal; 02886 } 02887 02889 template < typename w_ClassRefRhs, typename w_RefTraitsRhs > 02890 inline bool operator<= ( 02891 const Ptr< w_ClassRefRhs, w_RefTraitsRhs> & i_ptr 02892 ) 02893 { 02894 return m_ptrVal <= i_ptr.m_ptrVal; 02895 } 02896 02898 template < typename w_ClassRefRhs, typename w_RefTraitsRhs > 02899 inline bool operator<= ( 02900 const PtrView< w_ClassRefRhs, w_RefTraitsRhs > & i_ptr 02901 ) 02902 { 02903 return m_ptrVal <= i_ptr.m_ptrVal; 02904 } 02906 02907 // operator >= 02926 02927 template < typename w_ClassRefRhs, typename w_RefTraitsRhs > 02928 inline bool operator>= ( 02929 const PtrDelegate< w_ClassRefRhs, w_RefTraitsRhs > & i_ptr 02930 ) 02931 { 02932 return m_ptrVal >= i_ptr.m_ptrVal; 02933 } 02934 02936 template < typename w_ClassRefRhs, typename w_RefTraitsRhs > 02937 inline bool operator>= ( 02938 const Ptr< w_ClassRefRhs, w_RefTraitsRhs > & i_ptr 02939 ) 02940 { 02941 return m_ptrVal >= i_ptr.m_ptrVal; 02942 } 02943 02945 template < typename w_ClassRefRhs, typename w_RefTraitsRhs > 02946 inline bool operator>= ( 02947 const PtrView< w_ClassRefRhs, w_RefTraitsRhs > & i_ptr 02948 ) 02949 { 02950 return m_ptrVal >= i_ptr.m_ptrVal; 02951 } 02953 }; 02954 // end of SmartPointerTrio ( Doxygen group ) 02956 02957 02958 // ======== Pointer ================================================= 02969 template < typename w_ClassRef > 02970 class Pointer 02971 { 02972 public: 02973 02979 mutable w_ClassRef m_ptrVal; 02980 02981 private: 02982 02987 inline void DeletePointee() 02988 { 02989 if ( m_ptrVal ) { 02990 delete m_ptrVal; 02991 } 02992 } 02993 03004 inline w_ClassRef DeletePointee( w_ClassRef i_ptrVal ) 03005 { 03006 // Save a pointer to the old managed pointer. 03007 // ---------------------------------- 03008 w_ClassRef l_ptrVal = m_ptrVal; 03009 03010 // Point to the new managed pointer. 03011 // ------------------------- 03012 m_ptrVal = i_ptrVal; 03013 03014 // Delete the old managed pointer. 03015 // ----------------------- 03016 if ( l_ptrVal ) { 03017 delete l_ptrVal; 03018 } 03019 03020 // Return a regular pointer to the new managed pointer. 03021 // ----------------------------------------- 03022 return i_ptrVal; 03023 } 03024 03025 public: 03026 03039 inline Pointer( w_ClassRef i_ptr = 0 ) 03040 : m_ptrVal( i_ptr ) 03041 { 03042 } 03043 03054 inline Pointer( 03055 const Pointer< w_ClassRef > & i_ptr ) 03056 03057 : m_ptrVal( i_ptr.m_ptrVal ) 03058 { 03059 // Zero out the managed pointer address in the Pointer 03060 // being copied, so that it is impossible to delete 03061 // the managed pointer twice accidentally. 03062 // ------------------------------------------------ 03063 i_ptr.m_ptrVal = 0; 03064 } 03065 03072 inline ~Pointer() 03073 { 03074 DeletePointee(); 03075 } 03076 03092 inline Pointer & operator= ( const w_ClassRef i_ptr ) 03093 { 03094 // Delete the old managed pointer, and replace it with the 03095 // new one. 03096 // ----------------------------------------------- 03097 DeletePointee( i_ptr ); 03098 03099 // Return a reference to the Pointer on the left- 03100 // hand side of the '=' sign, so that assignment 03101 // operations can be chained together. 03102 // ---------------------------------------------- 03103 return *this; 03104 } 03105 03121 inline Pointer & operator= ( 03122 const Pointer< w_ClassRef > & i_ptr ) 03123 { 03124 // If the two AT_Pointers both point to the same 03125 // managed pointer, then just return. 03126 // --------------------------------------------- 03127 if ( & m_ptrVal == & i_ptr.m_ptrVal ) { 03128 return *this; 03129 } 03130 03131 // Save the address of the new managed pointer. 03132 // ------------------------------------ 03133 w_ClassRef l_ptrVal = i_ptr.m_ptrVal; 03134 03135 // Zero out the managed pointer's address in the Pointer 03136 // on the right-hand side of the '=' sign, so that 03137 // the managed pointer can't be deleted twice accidentally. 03138 // ------------------------------------------------ 03139 i_ptr.m_ptrVal = 0; 03140 03141 // Delete the old managed pointer, and store the new managed pointer's 03142 // address in the Pointer on the left-hand side of 03143 // the '=' sign. 03144 // --------------------------------------------------- 03145 DeletePointee( l_ptrVal ); 03146 03147 // Return a reference to the Pointer on the left- 03148 // hand side of the '=' sign, so that assignment 03149 // operations can be chained together. 03150 // ---------------------------------------------- 03151 return *this; 03152 } 03153 03162 inline typename PointerTo<w_ClassRef>::value_type * operator->() const 03163 { 03164 return & ( * m_ptrVal ); 03165 } 03166 03173 inline typename PointerTo<w_ClassRef>::value_type & operator* () const 03174 { 03175 return * m_ptrVal; 03176 } 03177 03186 inline operator w_ClassRef () const 03187 { 03188 return m_ptrVal; 03189 } 03190 03201 inline operator bool () const 03202 { 03203 return m_ptrVal != 0; 03204 } 03205 03215 inline w_ClassRef Transfer() 03216 { 03217 w_ClassRef l_ptrVal = m_ptrVal; 03218 03219 m_ptrVal = 0; 03220 03221 return l_ptrVal; 03222 } 03223 }; 03224 03225 03226 // ======== IsRefCountOne ============================================= 03235 template < typename w_ClassRef, typename w_RefTraits > 03236 inline bool IsRefCountOne( 03237 const Ptr<w_ClassRef,w_RefTraits> & i_ptr 03238 ) { 03239 03240 if ( i_ptr ) 03241 { 03242 return IsRefCountOne( i_ptr.Get() ); 03243 } 03244 else 03245 { 03246 return false; 03247 } 03248 } 03249 03250 03251 03252 #undef AT_Friend_LifeTime 03253 #undef AT_Friend_LifeView 03254 #undef AT_Friend_LifeLine 03255 03256 }; // namespace 03257 #endif // x_at_lifetime_h_x 03258
Generated for Austria by
and
MakeXS at Sun Oct 24 17:35:34 PDT 2004