diff options
| author | John Schoenick <[email protected]> | 2015-09-09 18:35:41 -0700 |
|---|---|---|
| committer | John Schoenick <[email protected]> | 2015-09-09 18:35:41 -0700 |
| commit | 0d8dceea4310fde5706b3ce1c70609d72a38efdf (patch) | |
| tree | c831ef32c2c801a5c5a80401736b52c7b5a528ec /mp/src/public/tier1/refcount.h | |
| parent | Updated the SDK with the latest code from the TF and HL2 branches. (diff) | |
| download | source-sdk-2013-master.tar.xz source-sdk-2013-master.zip | |
Diffstat (limited to 'mp/src/public/tier1/refcount.h')
| -rw-r--r-- | mp/src/public/tier1/refcount.h | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/mp/src/public/tier1/refcount.h b/mp/src/public/tier1/refcount.h index 264da100..9c756b84 100644 --- a/mp/src/public/tier1/refcount.h +++ b/mp/src/public/tier1/refcount.h @@ -14,6 +14,40 @@ #pragma once #endif +template <typename T> +inline void SafeAssign(T** ppInoutDst, T* pInoutSrc ) +{ + Assert( ppInoutDst ); + + // Do addref before release + if ( pInoutSrc ) + ( pInoutSrc )->AddRef(); + + // Do addref before release + if ( *ppInoutDst ) + ( *ppInoutDst )->Release(); + + // Do the assignment + ( *ppInoutDst ) = pInoutSrc; +} + +template <typename T> +inline void SafeAddRef( T* pObj ) +{ + if ( pObj ) + pObj->AddRef(); +} + +template <typename T> +inline void SafeRelease( T** ppInoutPtr ) +{ + Assert( ppInoutPtr ); + if ( *ppInoutPtr ) + ( *ppInoutPtr )->Release(); + + ( *ppInoutPtr ) = NULL; +} + //----------------------------------------------------------------------------- // Purpose: Implement a standard reference counted interface. Use of this // is optional insofar as all the concrete tools only require |