summaryrefslogtreecommitdiff
path: root/include/anope.h
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2010-09-10 15:46:19 -0400
committerAdam <Adam@anope.org>2010-09-10 15:46:19 -0400
commit9eb7562bee7f2a52cf91b0ab0ebc10351f2a46f2 (patch)
tree1dcc4928486a08643af70f69f094ab44c41642e5 /include/anope.h
parent46813ccb8c6ab572b8a9ff0a39afb1d92dc4482b (diff)
Fixed bug #1187 - Fixed releasing enforcer clients on TS6 IRCds
Diffstat (limited to 'include/anope.h')
-rw-r--r--include/anope.h78
1 files changed, 78 insertions, 0 deletions
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 <string>
#include <vector>
+#include <set>
#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<dynamic_reference_base *> 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<typename T>
+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