]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/base.cpp
Add explicit reference-counting base class
[user/henk/code/inspircd.git] / src / base.cpp
index 1e4f746af3dd5cb7ac8f04c66060ecf860291acf..9307928540639b721cda966221dac65cdd06cb27 100644 (file)
@@ -26,60 +26,33 @@ classbase::classbase()
 {
 }
 
-void BoolSet::Set(int number)
+bool classbase::cull()
 {
-       this->bits |= bitfields[number];
-}
-
-void BoolSet::Unset(int number)
-{
-       this->bits &= inverted_bitfields[number];
-}
-
-void BoolSet::Invert(int number)
-{
-       this->bits ^= bitfields[number];
-}
-
-bool BoolSet::Get(int number)
-{
-       return ((this->bits | bitfields[number]) > 0);
-}
-
-bool BoolSet::operator==(BoolSet other)
-{
-       return (this->bits == other.bits);
+       return true;
 }
 
-BoolSet BoolSet::operator|(BoolSet other)
+classbase::~classbase()
 {
-       BoolSet x(this->bits | other.bits);
-       return x;
 }
 
-BoolSet BoolSet::operator&(BoolSet other)
+refcountbase::refcountbase() : refcount(0)
 {
-       BoolSet x(this->bits & other.bits);
-       return x;
 }
 
-BoolSet::BoolSet()
+bool refcountbase::cull()
 {
-       this->bits = 0;
+       return (refcount == 0);
 }
 
-BoolSet::BoolSet(char bitmask)
+refcountbase::~refcountbase()
 {
-       this->bits = bitmask;
 }
 
-bool BoolSet::operator=(BoolSet other)
+ExtensionItem::ExtensionItem(const std::string& Key, Module* mod) : key(Key), owner(mod)
 {
-       this->bits = other.bits;
-       return true;
 }
 
-ExtensionItem::ExtensionItem(const std::string& Key, Module* mod) : key(Key), owner(mod)
+ExtensionItem::~ExtensionItem()
 {
 }
 
@@ -122,14 +95,32 @@ bool Extensible::Register(ExtensionItem* item)
        return Extensible::extension_types.insert(std::make_pair(item->key, item)).second;
 }
 
-void Extensible::UnRegister(Module* module)
+std::vector<ExtensionItem*> Extensible::BeginUnregister(Module* module)
 {
+       std::vector<ExtensionItem*> rv;
        ExtensibleTypes::iterator i = extension_types.begin();
        while (i != extension_types.end())
        {
                ExtensibleTypes::iterator c = i++;
                if (c->second->owner == module)
+               {
+                       rv.push_back(c->second);
                        extension_types.erase(c);
+               }
+       }
+       return rv;
+}
+
+void Extensible::doUnhookExtensions(const std::vector<ExtensionItem*>& toRemove)
+{
+       for(std::vector<ExtensionItem*>::const_iterator i = toRemove.begin(); i != toRemove.end(); i++)
+       {
+               ExtensibleStore::iterator e = extensions.find((**i).key);
+               if (e != extensions.end())
+               {
+                       (**i).free(e->second);
+                       extensions.erase(e);
+               }
        }
 }
 
@@ -137,9 +128,11 @@ Extensible::~Extensible()
 {
        for(ExtensibleStore::iterator i = extensions.begin(); i != extensions.end(); ++i)
        {
-               ExtensionItem* type = extension_types[i->first];
+               ExtensionItem* type = GetItem(i->first);
                if (type)
                        type->free(i->second);  
+               else if (ServerInstance && ServerInstance->Logs)
+                       ServerInstance->Logs->Log("BASE", ERROR, "Extension type %s is not registered", i->first.c_str());
        }
 }
 
@@ -147,6 +140,10 @@ LocalExtItem::LocalExtItem(const std::string& Key, Module* mod) : ExtensionItem(
 {
 }
 
+LocalExtItem::~LocalExtItem()
+{
+}
+
 std::string LocalExtItem::serialize(SerializeFormat format, const Extensible* container, void* item)
 {
        return "";
@@ -159,6 +156,10 @@ void LocalExtItem::unserialize(SerializeFormat format, Extensible* container, co
 LocalStringExt::LocalStringExt(const std::string& Key, Module* Owner)
        : SimpleExtItem<std::string>(Key, Owner) { }
 
+LocalStringExt::~LocalStringExt()
+{
+}
+
 std::string LocalStringExt::serialize(SerializeFormat format, const Extensible* container, void* item)
 {
        if (item && format == FORMAT_USER)
@@ -170,6 +171,10 @@ LocalIntExt::LocalIntExt(const std::string& Key, Module* mod) : LocalExtItem(Key
 {
 }
 
+LocalIntExt::~LocalIntExt()
+{
+}
+
 std::string LocalIntExt::serialize(SerializeFormat format, const Extensible* container, void* item)
 {
        if (format != FORMAT_USER)
@@ -198,6 +203,10 @@ StringExtItem::StringExtItem(const std::string& Key, Module* mod) : ExtensionIte
 {
 }
 
+StringExtItem::~StringExtItem()
+{
+}
+
 std::string* StringExtItem::get(const Extensible* container)
 {
        return static_cast<std::string*>(get_raw(container));