Anope IRC Services  Version 2.0
extensible.cpp
Go to the documentation of this file.
1 /*
2  *
3  * (C) 2003-2014 Anope Team
4  * Contact us at team@anope.org
5  *
6  * Please read COPYING and README for further details.
7  *
8  *
9  */
10 
11 #include "extensible.h"
12 
13 static std::set<ExtensibleBase *> extensible_items;
14 
15 ExtensibleBase::ExtensibleBase(Module *m, const Anope::string &n) : Service(m, "Extensible", n)
16 {
17  extensible_items.insert(this);
18 }
19 
21 {
22  extensible_items.erase(this);
23 }
24 
26 {
27  while (!extension_items.empty())
28  (*extension_items.begin())->Unset(this);
29 }
30 
32 {
33  ExtensibleRef<void *> ref(name);
34  if (ref)
35  return ref->HasExt(this);
36 
37  Log(LOG_DEBUG) << "HasExt for nonexistent type " << name << " on " << static_cast<const void *>(this);
38  return false;
39 }
40 
42 {
43  for (std::set<ExtensibleBase *>::iterator it = e->extension_items.begin(); it != e->extension_items.end(); ++it)
44  {
45  ExtensibleBase *eb = *it;
46  eb->ExtensibleSerialize(e, s, data);
47  }
48 }
49 
51 {
52  for (std::set<ExtensibleBase *>::iterator it = extensible_items.begin(); it != extensible_items.end(); ++it)
53  {
54  ExtensibleBase *eb = *it;
55  eb->ExtensibleUnserialize(e, s, data);
56  }
57 }
58 
59 template<>
60 bool* Extensible::Extend(const Anope::string &name, const bool &what)
61 {
62  ExtensibleRef<bool> ref(name);
63  if (ref)
64  return ref->Set(this);
65 
66  Log(LOG_DEBUG) << "Extend for nonexistant type " << name << " on " << static_cast<void *>(this);
67  return NULL;
68 }
69 
virtual void ExtensibleUnserialize(Extensible *, Serializable *, Serialize::Data &)
Definition: extensible.h:33
ExtensibleBase(Module *m, const Anope::string &n)
Definition: extensible.cpp:15
T * Extend(const Anope::string &name, const T &what)
Definition: extensible.h:224
virtual ~Extensible()
Definition: extensible.cpp:25
virtual void ExtensibleSerialize(const Extensible *, const Serializable *, Serialize::Data &) const
Definition: extensible.h:32
static std::set< ExtensibleBase * > extensible_items
Definition: extensible.cpp:13
static void ExtensibleUnserialize(Extensible *, Serializable *, Serialize::Data &data)
Definition: extensible.cpp:50
std::set< ExtensibleBase * > extension_items
Definition: extensible.h:39
Anope::string name
Definition: access.cpp:22
Definition: logger.h:53
static void ExtensibleSerialize(const Extensible *, const Serializable *, Serialize::Data &data)
Definition: extensible.cpp:41
bool HasExt(const Anope::string &name) const
Definition: extensible.cpp:31