From feaef7cc4aa97a0851ad404fc76652560bb14a70 Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 31 Aug 2011 10:07:15 -0400 Subject: [PATCH] Allow services to register or unregister themselves --- include/services.h | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/include/services.h b/include/services.h index 3a7ff65c2..47e9b8940 100644 --- a/include/services.h +++ b/include/services.h @@ -374,12 +374,22 @@ template class CoreExport Service : public Base Service(Module *o, const Anope::string &n) : owner(o), name(n) { - if (Service::services.find(n) != Service::services.end()) - throw ModuleException("Service with name " + n + " already exists"); - Service::services[n] = static_cast(this); + this->Register(); } virtual ~Service() + { + this->Unregister(); + } + + void Register() + { + if (Service::services.find(this->name) != Service::services.end()) + throw ModuleException("Service with name " + this->name + " already exists"); + Service::services[this->name] = static_cast(this); + } + + void Unregister() { Service::services.erase(this->name); }