summaryrefslogtreecommitdiff
path: root/include/base.h
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2012-04-23 05:08:26 -0400
committerAdam <Adam@anope.org>2012-04-23 05:08:26 -0400
commit573e49a7ead331219eb6f0d3ca9cf83e793a5c9c (patch)
treee145e04fa3d041cf92ce46da4ac790b63231059c /include/base.h
parent63c639e108a00d7dbb0d7ac9891684fc83a3b207 (diff)
Reworked live SQL support yet again
Diffstat (limited to 'include/base.h')
-rw-r--r--include/base.h50
1 files changed, 26 insertions, 24 deletions
diff --git a/include/base.h b/include/base.h
index 2a7cb5147..cc0e84bf9 100644
--- a/include/base.h
+++ b/include/base.h
@@ -30,6 +30,7 @@ class dynamic_reference_base
bool invalid;
public:
dynamic_reference_base() : invalid(false) { }
+ dynamic_reference_base(const dynamic_reference_base &other) : invalid(other.invalid) { }
virtual ~dynamic_reference_base() { }
inline void Invalidate() { this->invalid = true; }
};
@@ -40,66 +41,67 @@ class dynamic_reference : public dynamic_reference_base
protected:
T *ref;
public:
+ dynamic_reference() : ref(NULL)
+ {
+ }
+
dynamic_reference(T *obj) : ref(obj)
{
if (ref)
ref->AddReference(this);
}
- dynamic_reference(const dynamic_reference<T> &obj) : ref(obj.ref)
+ dynamic_reference(const dynamic_reference<T> &other) : dynamic_reference_base(other), ref(other.ref)
{
- if (ref)
+ if (*this)
ref->AddReference(this);
}
virtual ~dynamic_reference()
{
- if (this->invalid)
+ if (*this)
{
- this->invalid = false;
- this->ref = NULL;
- }
- else if (this->operator bool())
ref->DelReference(this);
+ }
}
virtual operator bool()
{
- if (this->invalid)
- {
- this->invalid = false;
- this->ref = NULL;
- }
- return this->ref != NULL;
+ if (!this->invalid)
+ return this->ref != NULL;
+ return false;
}
- virtual inline operator T*()
+ virtual inline operator T*() const
{
- if (this->operator bool())
+ if (!this->invalid)
return this->ref;
return NULL;
}
- virtual inline T *operator->()
+ virtual inline T* operator->()
{
- if (this->operator bool())
+ if (!this->invalid)
return this->ref;
return NULL;
}
virtual inline void operator=(T *newref)
{
- if (this->invalid)
- {
- this->invalid = false;
- this->ref = NULL;
- }
- else if (this->operator bool())
+ if (*this)
this->ref->DelReference(this);
this->ref = newref;
- if (this->operator bool())
+ this->invalid = false;
+ if (*this)
this->ref->AddReference(this);
}
+
+ virtual inline bool operator==(const dynamic_reference<T> &other) const
+ {
+ if (!this->invalid)
+ return this->ref == other;
+ return false;
+ }
};
#endif // BASE_H