From 9eb7562bee7f2a52cf91b0ab0ebc10351f2a46f2 Mon Sep 17 00:00:00 2001 From: Adam Date: Fri, 10 Sep 2010 15:46:19 -0400 Subject: Fixed bug #1187 - Fixed releasing enforcer clients on TS6 IRCds --- include/anope.h | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) (limited to 'include/anope.h') diff --git a/include/anope.h b/include/anope.h index 020abd4cd..a2cdc2d06 100644 --- a/include/anope.h +++ b/include/anope.h @@ -13,6 +13,7 @@ #include #include +#include #include "hashcomp.h" struct Message; @@ -396,4 +397,81 @@ class spacesepstream : public sepstream spacesepstream(const Anope::string &source) : sepstream(source, ' ') { } }; +/** The base class that most classes in Anope inherit from + */ +class dynamic_reference_base; +class CoreExport Base +{ + /* References to this base class */ + std::set References; + public: + Base(); + virtual ~Base(); + void AddReference(dynamic_reference_base *r); + void DelReference(dynamic_reference_base *r); +}; + +class dynamic_reference_base : public virtual Base +{ + protected: + bool invalid; + public: + dynamic_reference_base() : invalid(false) { } + virtual ~dynamic_reference_base() { } + inline void Invalidate() { this->invalid = true; } +}; + +template +class dynamic_reference : public dynamic_reference_base +{ + protected: + T *ref; + public: + dynamic_reference(T *obj) : ref(obj) + { + if (ref) + ref->AddReference(this); + } + + virtual ~dynamic_reference() + { + if (this->invalid) + { + this->invalid = false; + this->ref = NULL; + } + else if (ref) + ref->DelReference(this); + } + + virtual operator bool() + { + if (this->invalid) + { + this->invalid = false; + this->ref = NULL; + } + return this->ref; + } + + virtual inline void operator=(T *newref) + { + if (this->invalid) + { + this->invalid = false; + this->ref = NULL; + } + else if (this->ref) + this->ref->DelReference(this); + this->ref = newref; + if (this->ref) + this->ref->AddReference(this); + } + + virtual inline T *operator->() + { + return this->ref; + } +}; + #endif // ANOPE_H -- cgit