From 379b2ccf92b6124f2026a5ec683cfc98f08e223a Mon Sep 17 00:00:00 2001 From: Adam Date: Thu, 27 Dec 2012 21:43:19 -0500 Subject: The timestamp column in SQL should actually be null sometimes, and fixed some valgrind errors with db_sql_live --- include/base.h | 26 ++++++++++++++++---------- include/serialize.h | 46 ++++++++++++++++++++++++++++------------------ 2 files changed, 44 insertions(+), 28 deletions(-) (limited to 'include') diff --git a/include/base.h b/include/base.h index 6fb974ec4..3bf9eefef 100644 --- a/include/base.h +++ b/include/base.h @@ -73,6 +73,22 @@ class Reference : public ReferenceBase ref->DelReference(this); } + inline Reference& operator=(const Reference &other) + { + if (this != &other) + { + if (*this) + this->ref->DelReference(this); + + this->ref = other.ref; + this->invalid = other.invalid; + + if (*this) + this->ref->AddReference(this); + } + return *this; + } + /* We explicitly call operator bool here in several places to prevent other * operators, such operator T*, from being called instead, which will mess * with any class inheriting from this that overloads this operator. @@ -105,16 +121,6 @@ class Reference : public ReferenceBase return NULL; } - inline void operator=(T *newref) - { - if (operator bool()) - this->ref->DelReference(this); - this->ref = newref; - this->invalid = false; - if (operator bool()) - this->ref->AddReference(this); - } - inline bool operator<(const Reference &other) const { return this < &other; diff --git a/include/serialize.h b/include/serialize.h index edbf1facf..a7ac33dfa 100644 --- a/include/serialize.h +++ b/include/serialize.h @@ -258,18 +258,34 @@ class Serialize::Reference : public ReferenceBase obj->AddReference(this); } - Reference(const Reference &other) : ref(other.ref) + Reference(const Reference &other) : ReferenceBase(other), ref(other.ref) { - if (*this) + if (ref && !invalid) this->ref->AddReference(this); } ~Reference() { - if (*this) + if (ref && !invalid) this->ref->DelReference(this); } + inline Reference& operator=(const Reference &other) + { + if (this != &other) + { + if (ref && !invalid) + this->ref->DelReference(this); + + this->ref = other.ref; + this->invalid = other.invalid; + + if (ref && !invalid) + this->ref->AddReference(this); + } + return *this; + } + inline operator bool() const { if (!this->invalid) @@ -277,25 +293,15 @@ class Serialize::Reference : public ReferenceBase return false; } - inline void operator=(T *newref) - { - if (*this) - this->ref->DelReference(this); - - this->ref = newref; - this->invalid = false; - - if (newref) - this->ref->AddReference(this); - } - inline operator T*() const { if (!this->invalid) { if (this->ref) + // This can invalidate me this->ref->QueueUpdate(); - return this->ref; + if (!this->invalid) + return this->ref; } return NULL; } @@ -305,8 +311,10 @@ class Serialize::Reference : public ReferenceBase if (!this->invalid) { if (this->ref) + // This can invalidate me this->ref->QueueUpdate(); - return this->ref; + if (!this->invalid) + return this->ref; } return NULL; } @@ -316,8 +324,10 @@ class Serialize::Reference : public ReferenceBase if (!this->invalid) { if (this->ref) + // This can invalidate me this->ref->QueueUpdate(); - return this->ref; + if (!this->invalid) + return this->ref; } return NULL; } -- cgit