From aa7cc18468f4b16bf79cd1788cad0cbf0d926817 Mon Sep 17 00:00:00 2001 From: danieldg Date: Mon, 19 Oct 2009 20:12:12 +0000 Subject: 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 --- include/base.h | 17 +++++++++++------ include/extensible.h | 10 +++++----- src/base.cpp | 15 +++++++++------ src/commands/cmd_info.cpp | 2 +- src/commands/cmd_modules.cpp | 2 +- src/modules.cpp | 2 +- 6 files changed, 28 insertions(+), 20 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& v) : value(v.value) { if (value) inc(value); } reference& operator=(const reference& 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& other) const { return value < other.value; } + inline bool operator>(const reference& other) const { return value > other.value; } + inline bool operator==(const reference& other) const { return value == other.value; } + inline bool operator!=(const reference& 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 ExtensibleStore; + typedef std::map,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& toRemove); + void doUnhookExtensions(const std::vector >& toRemove); }; class CoreExport ExtensionManager { - std::map types; + std::map > types; public: void Register(ExtensionItem* item); - void BeginUnregister(Module* module, std::vector& list); + void BeginUnregister(Module* module, std::vector >& list); ExtensionItem* GetItem(const std::string& name); }; diff --git a/src/base.cpp b/src/base.cpp index 2a89a4830..389f3915a 100644 --- a/src/base.cpp +++ b/src/base.cpp @@ -47,6 +47,9 @@ refcountbase::refcountbase() : refcount(0) refcountbase::~refcountbase() { + if (refcount && ServerInstance && ServerInstance->Logs) + ServerInstance->Logs->Log("CULLLIST", DEBUG, "refcountbase::~ @%p with refcount %d", + (void*)this, refcount); } ExtensionItem::ExtensionItem(const std::string& Key, Module* mod) : key(Key), owner(mod) @@ -97,12 +100,12 @@ void ExtensionManager::Register(ExtensionItem* item) types.insert(std::make_pair(item->key, item)); } -void ExtensionManager::BeginUnregister(Module* module, std::vector& list) +void ExtensionManager::BeginUnregister(Module* module, std::vector >& list) { - std::map::iterator i = types.begin(); + std::map >::iterator i = types.begin(); while (i != types.end()) { - std::map::iterator me = i++; + std::map >::iterator me = i++; ExtensionItem* item = me->second; if (item->owner == module) { @@ -114,15 +117,15 @@ void ExtensionManager::BeginUnregister(Module* module, std::vector::iterator i = types.find(name); + std::map >::iterator i = types.find(name); if (i == types.end()) return NULL; return i->second; } -void Extensible::doUnhookExtensions(const std::vector& toRemove) +void Extensible::doUnhookExtensions(const std::vector >& toRemove) { - for(std::vector::const_iterator i = toRemove.begin(); i != toRemove.end(); ++i) + for(std::vector >::const_iterator i = toRemove.begin(); i != toRemove.end(); ++i) { ExtensionItem* item = *i; ExtensibleStore::iterator e = extensions.find(item); diff --git a/src/commands/cmd_info.cpp b/src/commands/cmd_info.cpp index f239b9f78..2f759837b 100644 --- a/src/commands/cmd_info.cpp +++ b/src/commands/cmd_info.cpp @@ -61,7 +61,7 @@ CmdResult CommandInfo::Handle (const std::vector&, User *user) user->WriteNumeric(RPL_INFO, "%s : Thomas Stagner, aquanight, ", user->nick.c_str()); user->WriteNumeric(RPL_INFO, "%s : Uli Schlachter, psychon, ", user->nick.c_str()); user->WriteNumeric(RPL_INFO, "%s : Matt Smith, dz, ", user->nick.c_str()); - user->WriteNumeric(RPL_INFO, "%s : Daniel De Graaf danieldg, ", user->nick.c_str()); + user->WriteNumeric(RPL_INFO, "%s : Daniel De Graaf, danieldg, ", user->nick.c_str()); user->WriteNumeric(RPL_INFO, "%s : ", user->nick.c_str()); user->WriteNumeric(RPL_INFO, "%s :\2Regular Contributors\2:", user->nick.c_str()); user->WriteNumeric(RPL_INFO, "%s : Majic MacGyver Namegduf Ankit", user->nick.c_str()); diff --git a/src/commands/cmd_modules.cpp b/src/commands/cmd_modules.cpp index 1b0f1da13..5f7dabdbf 100644 --- a/src/commands/cmd_modules.cpp +++ b/src/commands/cmd_modules.cpp @@ -52,7 +52,7 @@ CmdResult CommandModules::Handle (const std::vector&, User *user) if (user->HasPrivPermission("servers/auspex")) { - std::string flags("SvscC"); + std::string flags("SvcC"); int pos = 0; for (int mult = 1; mult <= VF_OPTCOMMON; mult *= 2, ++pos) if (!(V.Flags & mult)) diff --git a/src/modules.cpp b/src/modules.cpp index c5bd87cde..87d25ac42 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -460,7 +460,7 @@ void ModuleManager::DoSafeUnload(Module* mod) { std::map::iterator modfind = Modules.find(mod->ModuleSourceFile); - std::vector items; + std::vector > items; ServerInstance->Extensions.BeginUnregister(modfind->second, items); /* Give the module a chance to tidy out all its metadata */ for (chan_hash::iterator c = ServerInstance->chanlist->begin(); c != ServerInstance->chanlist->end(); c++) -- cgit v1.2.3