From cfa62354cd15362abd0e441dc22e8e67dfd567a9 Mon Sep 17 00:00:00 2001 From: jp9000 Date: Sun, 2 Feb 2014 15:34:02 -0700 Subject: [PATCH] Compact/clean up OBSRef class just a bit more Replace a NULL with nullptr and reduce code duplication with the = operators --- libobs/obs.hpp | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/libobs/obs.hpp b/libobs/obs.hpp index 41d16b82d..09803f306 100644 --- a/libobs/obs.hpp +++ b/libobs/obs.hpp @@ -27,6 +27,14 @@ template class OBSRef { typedef typename RefClass::type T; T val; + inline OBSRef &Replace(T valIn) + { + RefClass::AddRef(valIn); + RefClass::Release(val); + val = valIn; + return *this; + } + public: inline OBSRef() : val(nullptr) {} inline OBSRef(T val_) : val(val_) {RefClass::AddRef(val);} @@ -35,27 +43,14 @@ public: inline ~OBSRef() {RefClass::Release(val);} - inline OBSRef &operator=(T valIn) - { - RefClass::AddRef(valIn); - RefClass::Release(val); - val = valIn; - return *this; - } - - inline OBSRef &operator=(const OBSRef &ref) - { - RefClass::AddRef(ref.val); - RefClass::Release(val); - val = ref.val; - return *this; - } + inline OBSRef &operator=(T valIn) {return Replace(valIn);} + inline OBSRef &operator=(const OBSRef &ref) {return Replace(ref.val);} inline OBSRef &operator=(OBSRef &&ref) { if (this != &ref) { val = ref.val; - ref.val = NULL; + ref.val = nullptr; } return *this;