Elaztek Developer Hub
Blamite Game Engine - Strings  00386.06.16.23.0646.blamite
A library containing general purpose utilities and classes for use in multiple projects.
saferelease.h
Go to the documentation of this file.
1 #pragma once
2 
9 template <class Type> void SafeRelease(Type** pointer)
10 {
11  if (*pointer)
12  {
13  (*pointer)->Release();
14  *pointer = NULL;
15  }
16 }
17 
24 template <typename Type> Type* SafeAcquire(Type* newObject)
25 {
26  if (newObject != NULL)
27  {
28  newObject->AddRef();
29  }
30 
31  return newObject;
32 }
33 
41 template <typename Type> void SafeSet(Type** currentObject, Type* newObject)
42 {
43  SafeAcquire(newObject);
44  SafeRelease(&currentObject);
45  currentObject = newObject;
46 }
47 
SafeRelease
void SafeRelease(Type **pointer)
Releases a pointer.
Definition: saferelease.h:9
SafeSet
void SafeSet(Type **currentObject, Type *newObject)
Sets a new COM object, releasing the old one.
Definition: saferelease.h:41
SafeAcquire
Type * SafeAcquire(Type *newObject)
Acquires an additional reference, if non-null.
Definition: saferelease.h:24