diff options
author | Adam <Adam@anope.org> | 2011-08-31 10:07:15 -0400 |
---|---|---|
committer | Adam <Adam@anope.org> | 2011-09-10 02:05:03 -0400 |
commit | feaef7cc4aa97a0851ad404fc76652560bb14a70 (patch) | |
tree | 9bff377a58b7281dbbefc57796a9424a319015ec | |
parent | c6d3fbdfabefc7b12ccb0810083e4108d28b5182 (diff) |
Allow services to register or unregister themselves
-rw-r--r-- | include/services.h | 16 |
1 files 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,13 +374,23 @@ template<typename T> class CoreExport Service : public Base Service(Module *o, const Anope::string &n) : owner(o), name(n) { - if (Service<T>::services.find(n) != Service<T>::services.end()) - throw ModuleException("Service with name " + n + " already exists"); - Service<T>::services[n] = static_cast<T *>(this); + this->Register(); } virtual ~Service() { + this->Unregister(); + } + + void Register() + { + if (Service<T>::services.find(this->name) != Service<T>::services.end()) + throw ModuleException("Service with name " + this->name + " already exists"); + Service<T>::services[this->name] = static_cast<T *>(this); + } + + void Unregister() + { Service<T>::services.erase(this->name); } }; |