1
0
mirror of https://github.com/anope/anope.git synced 2026-07-01 01:26:39 +02:00

Allow services to register or unregister themselves

This commit is contained in:
Adam
2011-08-31 10:07:15 -04:00
parent c6d3fbdfab
commit feaef7cc4a
+13 -3
View File
@@ -374,12 +374,22 @@ 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);
}