summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/services.h16
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);
}
};