Compact/clean up OBSRef class just a bit more

Replace a NULL with nullptr and reduce code duplication with the =
operators
master
jp9000 2014-02-02 15:34:02 -07:00
parent 933549ca76
commit cfa62354cd
1 changed files with 11 additions and 16 deletions

View File

@ -27,6 +27,14 @@ template<class RefClass> class OBSRef {
typedef typename RefClass::type T; typedef typename RefClass::type T;
T val; T val;
inline OBSRef &Replace(T valIn)
{
RefClass::AddRef(valIn);
RefClass::Release(val);
val = valIn;
return *this;
}
public: public:
inline OBSRef() : val(nullptr) {} inline OBSRef() : val(nullptr) {}
inline OBSRef(T val_) : val(val_) {RefClass::AddRef(val);} inline OBSRef(T val_) : val(val_) {RefClass::AddRef(val);}
@ -35,27 +43,14 @@ public:
inline ~OBSRef() {RefClass::Release(val);} inline ~OBSRef() {RefClass::Release(val);}
inline OBSRef &operator=(T valIn) inline OBSRef &operator=(T valIn) {return Replace(valIn);}
{ inline OBSRef &operator=(const OBSRef &ref) {return Replace(ref.val);}
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=(OBSRef &&ref) inline OBSRef &operator=(OBSRef &&ref)
{ {
if (this != &ref) { if (this != &ref) {
val = ref.val; val = ref.val;
ref.val = NULL; ref.val = nullptr;
} }
return *this; return *this;