diff options
author | danieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7> | 2009-10-19 20:12:12 +0000 |
---|---|---|
committer | danieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7> | 2009-10-19 20:12:12 +0000 |
commit | aa7cc18468f4b16bf79cd1788cad0cbf0d926817 (patch) | |
tree | c34c0433dc5b166b17bab1e325942e1ca0610e3e /include | |
parent | a813344b935e4adab163334669df969a586e67d5 (diff) |
Fix implementation of reference to const, use reference counting for ExtensibleItem
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11924 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'include')
-rw-r--r-- | include/base.h | 17 | ||||
-rw-r--r-- | include/extensible.h | 10 |
2 files changed, 16 insertions, 11 deletions
diff --git a/include/base.h b/include/base.h index 856cd64c2..13efdd2dd 100644 --- a/include/base.h +++ b/include/base.h @@ -76,7 +76,7 @@ class CoreExport interfacebase */ class CoreExport refcountbase { - unsigned int refcount; + mutable unsigned int refcount; public: refcountbase(); virtual ~refcountbase(); @@ -102,7 +102,7 @@ class reference : public reference_base public: reference() : value(0) { } reference(T* v) : value(v) { if (value) inc(value); } - reference(const reference& v) : value(v.value) { if (value) inc(value); } + reference(const reference<T>& v) : value(v.value) { if (value) inc(value); } reference<T>& operator=(const reference<T>& other) { if (other.value) @@ -121,12 +121,17 @@ class reference : public reference_base delete value; } } - inline const T* operator->() const { return value; } - inline const T& operator*() const { return *value; } - inline T* operator->() { return value; } - inline T& operator*() { return *value; } inline operator bool() const { return value; } inline operator T*() const { return value; } + inline T* operator->() const { return value; } + inline T& operator*() const { return *value; } + inline bool operator<(const reference<T>& other) const { return value < other.value; } + inline bool operator>(const reference<T>& other) const { return value > other.value; } + inline bool operator==(const reference<T>& other) const { return value == other.value; } + inline bool operator!=(const reference<T>& other) const { return value != other.value; } + private: + void* operator new(size_t); + void operator delete(void*); }; /** This class can be used on its own to represent an exception, or derived to represent a module-specific exception. diff --git a/include/extensible.h b/include/extensible.h index 62edb8896..e77c1cc30 100644 --- a/include/extensible.h +++ b/include/extensible.h @@ -15,7 +15,7 @@ enum SerializeFormat /** Class represnting an extension of some object */ -class CoreExport ExtensionItem +class CoreExport ExtensionItem : public refcountbase { public: const std::string key; @@ -57,7 +57,7 @@ class CoreExport ExtensionItem class CoreExport Extensible : public classbase { public: - typedef std::map<ExtensionItem*,void*> ExtensibleStore; + typedef std::map<reference<ExtensionItem>,void*> ExtensibleStore; // Friend access for the protected getter/setter friend class ExtensionItem; @@ -75,15 +75,15 @@ class CoreExport Extensible : public classbase Extensible(); virtual CullResult cull(); virtual ~Extensible(); - void doUnhookExtensions(const std::vector<ExtensionItem*>& toRemove); + void doUnhookExtensions(const std::vector<reference<ExtensionItem> >& toRemove); }; class CoreExport ExtensionManager { - std::map<std::string, ExtensionItem*> types; + std::map<std::string, reference<ExtensionItem> > types; public: void Register(ExtensionItem* item); - void BeginUnregister(Module* module, std::vector<ExtensionItem*>& list); + void BeginUnregister(Module* module, std::vector<reference<ExtensionItem> >& list); ExtensionItem* GetItem(const std::string& name); }; |