aboutsummaryrefslogtreecommitdiff
path: root/mp/src/public/tier1/refcount.h
diff options
context:
space:
mode:
authorJohn Schoenick <[email protected]>2015-09-09 18:35:41 -0700
committerJohn Schoenick <[email protected]>2015-09-09 18:35:41 -0700
commit0d8dceea4310fde5706b3ce1c70609d72a38efdf (patch)
treec831ef32c2c801a5c5a80401736b52c7b5a528ec /mp/src/public/tier1/refcount.h
parentUpdated the SDK with the latest code from the TF and HL2 branches. (diff)
downloadsource-sdk-2013-master.tar.xz
source-sdk-2013-master.zip
Updated the SDK with the latest code from the TF and HL2 branches.HEADmaster
Diffstat (limited to 'mp/src/public/tier1/refcount.h')
-rw-r--r--mp/src/public/tier1/refcount.h34
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