summaryrefslogtreecommitdiff
path: root/include/services.h
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2012-01-25 15:48:07 -0500
committerAdam <Adam@anope.org>2012-01-25 15:48:07 -0500
commit52eaa7d6d61e3373340fd5a69b92b0fb3b5609e0 (patch)
tree428f2b440ab5675ae3a9c19ae5b813f132497c79 /include/services.h
parente88e37c59b45cc43b714d1d28719eb3c2ca9579a (diff)
Windows
Diffstat (limited to 'include/services.h')
-rw-r--r--include/services.h43
1 files changed, 26 insertions, 17 deletions
diff --git a/include/services.h b/include/services.h
index cd15fed68..37b8df1ad 100644
--- a/include/services.h
+++ b/include/services.h
@@ -306,30 +306,38 @@ template<typename T, size_t Size = 32> class Flags
class Module;
-template<typename T> class Service : public Base
+class CoreExport Service : public Base
{
- static Anope::map<T *> services;
+ static Anope::map<Anope::map<Service *> > services;
public:
- static T* FindService(const Anope::string &n)
+ static Service *FindService(const Anope::string &t, const Anope::string &n)
{
- typename Anope::map<T *>::iterator it = Service<T>::services.find(n);
- if (it != Service<T>::services.end())
- return it->second;
+ Anope::map<Anope::map<Service *> >::iterator it = services.find(t);
+ if (it != services.end())
+ {
+ Anope::map<Service *>::iterator it2 = it->second.find(n);
+ if (it2 != it->second.end())
+ return it2->second;
+ }
+
return NULL;
}
- static std::vector<Anope::string> GetServiceKeys()
+ static std::vector<Anope::string> GetServiceKeys(const Anope::string &t)
{
std::vector<Anope::string> keys;
- for (typename Anope::map<T *>::iterator it = Service<T>::services.begin(), it_end = Service<T>::services.end(); it != it_end; ++it)
- keys.push_back(it->first);
+ Anope::map<Anope::map<Service *> >::iterator it = services.find(t);
+ if (it != services.end())
+ for (Anope::map<Service *>::iterator it2 = it->second.begin(); it2 != it->second.end(); ++it2)
+ keys.push_back(it2->first);
return keys;
}
Module *owner;
+ Anope::string type;
Anope::string name;
- Service(Module *o, const Anope::string &n) : owner(o), name(n)
+ Service(Module *o, const Anope::string &t, const Anope::string &n) : owner(o), type(t), name(n)
{
this->Register();
}
@@ -341,19 +349,20 @@ template<typename T> class Service : public Base
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);
+ Anope::map<Service *> &smap = services[this->type];
+ if (smap.find(this->name) != smap.end())
+ throw ModuleException("Service " + this->type + " with name " + this->name + " already exists");
+ smap[this->name] = this;
}
void Unregister()
{
- Service<T>::services.erase(this->name);
+ Anope::map<Service *> &smap = services[this->type];
+ smap.erase(this->name);
+ if (smap.empty())
+ services.erase(this->type);
}
};
-template<typename T> Anope::map<T *> Service<T>::services;
-
-template class Service<Base>;
#include "sockets.h"
#include "socketengine.h"