X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fbase.cpp;h=2e2dbfb287d365c78e3022e8c5c5089dca02884d;hb=9db7af579c46a9f0379fdf71fb773a0a76a94846;hp=126e5b824069d35a9ee9bcc8d728c1dc6d149bed;hpb=76ebc88ccd6fef0bf2d97b607829fb3466e273af;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/base.cpp b/src/base.cpp index 126e5b824..2e2dbfb28 100644 --- a/src/base.cpp +++ b/src/base.cpp @@ -2,106 +2,247 @@ * | Inspire Internet Relay Chat Daemon | * +------------------------------------+ * - * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev. - * E-mail: - * - * - * - * Written by Craig Edwards, Craig McLure, and others. + * InspIRCd: (C) 2002-2009 InspIRCd Development Team + * See: http://wiki.inspircd.org/Credits + * * This program is free but copyrighted software; see * the file COPYING for details. * * --------------------------------------------------- */ +/* $Core */ + #include "inspircd_config.h" #include "base.h" #include -#include -#include -#include #include "inspircd.h" -#include "modules.h" -#include "helperfuncs.h" -const int bitfields[] = {1,2,4,8,16,32,64,128}; -const int inverted_bitfields[] = {~1,~2,~4,~8,~16,~32,~64,~128}; +classbase::classbase() +{ +} + +CullResult classbase::cull() +{ + return CullResult(); +} + +classbase::~classbase() +{ +} + +CullResult::CullResult() +{ +} + +refcountbase::refcountbase() : refcount(0) +{ +} + +refcountbase::~refcountbase() +{ +} + +ExtensionItem::ExtensionItem(const std::string& Key, Module* mod) : key(Key), owner(mod) +{ +} + +ExtensionItem::~ExtensionItem() +{ +} -bool Extensible::Shrink(const std::string &key) +void* ExtensionItem::get_raw(const Extensible* container) const { - /* map::size_type map::erase( const key_type& key ); - * returns the number of elements removed, std::map - * is single-associative so this should only be 0 or 1 - */ - if(this->Extension_Items.erase(key)) + Extensible::ExtensibleStore::const_iterator i = + container->extensions.find(const_cast(this)); + if (i == container->extensions.end()) + return NULL; + return i->second; +} + +void* ExtensionItem::set_raw(Extensible* container, void* value) +{ + std::pair rv = + container->extensions.insert(std::make_pair(this, value)); + if (rv.second) { - log(DEBUG, "Shrinking object with item %s",key.c_str()); - return true; + return NULL; } else { - log(DEBUG, "Tried to shrink object with item %s but no items removed", key.c_str()); - return false; + void* old = rv.first->second; + rv.first->second = value; + return old; } } -void Extensible::GetExtList(std::deque &list) +void* ExtensionItem::unset_raw(Extensible* container) { - for (ExtensibleStore::iterator u = Extension_Items.begin(); u != Extension_Items.end(); u++) + Extensible::ExtensibleStore::iterator i = container->extensions.find(this); + if (i == container->extensions.end()) + return NULL; + void* rv = i->second; + container->extensions.erase(i); + return rv; +} + +void ExtensionManager::Register(ExtensionItem* item) +{ + types.insert(std::make_pair(item->key, item)); +} + +void ExtensionManager::BeginUnregister(Module* module, std::vector& list) +{ + std::map::iterator i = types.begin(); + while (i != types.end()) { - list.push_back(u->first); + std::map::iterator me = i++; + ExtensionItem* item = me->second; + if (item->owner == module) + { + list.push_back(item); + types.erase(me); + } } } -void BoolSet::Set(int number) +ExtensionItem* ExtensionManager::GetItem(const std::string& name) +{ + std::map::iterator i = types.find(name); + if (i == types.end()) + return NULL; + return i->second; +} + +void Extensible::doUnhookExtensions(const std::vector& toRemove) { - this->bits |= bitfields[number]; + for(std::vector::const_iterator i = toRemove.begin(); i != toRemove.end(); ++i) + { + ExtensionItem* item = *i; + ExtensibleStore::iterator e = extensions.find(item); + if (e != extensions.end()) + { + item->free(e->second); + extensions.erase(e); + } + } } -void BoolSet::Unset(int number) +CullResult Extensible::cull() { - this->bits &= inverted_bitfields[number]; + for(ExtensibleStore::iterator i = extensions.begin(); i != extensions.end(); ++i) + { + i->first->free(i->second); + } + return classbase::cull(); } -void BoolSet::Invert(int number) +Extensible::~Extensible() { - this->bits ^= bitfields[number]; } -bool BoolSet::Get(int number) +LocalExtItem::LocalExtItem(const std::string& Key, Module* mod) : ExtensionItem(Key, mod) { - return ((this->bits | bitfields[number]) > 0); } -bool BoolSet::operator==(BoolSet other) +LocalExtItem::~LocalExtItem() { - return (this->bits == other.bits); } -BoolSet BoolSet::operator|(BoolSet other) +std::string LocalExtItem::serialize(SerializeFormat format, const Extensible* container, void* item) const { - BoolSet x(this->bits | other.bits); - return x; + return ""; } -BoolSet BoolSet::operator&(BoolSet other) +void LocalExtItem::unserialize(SerializeFormat format, Extensible* container, const std::string& value) { - BoolSet x(this->bits & other.bits); - return x; } -BoolSet::BoolSet() +LocalStringExt::LocalStringExt(const std::string& Key, Module* Owner) + : SimpleExtItem(Key, Owner) { } + +LocalStringExt::~LocalStringExt() +{ +} + +std::string LocalStringExt::serialize(SerializeFormat format, const Extensible* container, void* item) const +{ + if (item && format == FORMAT_USER) + return *static_cast(item); + return ""; +} + +LocalIntExt::LocalIntExt(const std::string& Key, Module* mod) : LocalExtItem(Key, mod) +{ +} + +LocalIntExt::~LocalIntExt() +{ +} + +std::string LocalIntExt::serialize(SerializeFormat format, const Extensible* container, void* item) const +{ + if (format != FORMAT_USER) + return ""; + return ConvToStr(reinterpret_cast(item)); +} + +intptr_t LocalIntExt::get(const Extensible* container) const +{ + return reinterpret_cast(get_raw(container)); +} + +intptr_t LocalIntExt::set(Extensible* container, intptr_t value) +{ + if (value) + return reinterpret_cast(set_raw(container, reinterpret_cast(value))); + else + return reinterpret_cast(unset_raw(container)); +} + +void LocalIntExt::free(void*) +{ +} + +StringExtItem::StringExtItem(const std::string& Key, Module* mod) : ExtensionItem(Key, mod) +{ +} + +StringExtItem::~StringExtItem() +{ +} + +std::string* StringExtItem::get(const Extensible* container) const +{ + return static_cast(get_raw(container)); +} + +std::string StringExtItem::serialize(SerializeFormat format, const Extensible* container, void* item) const +{ + return item ? *static_cast(item) : ""; +} + +void StringExtItem::unserialize(SerializeFormat format, Extensible* container, const std::string& value) +{ + if (value.empty()) + unset(container); + else + set(container, value); +} + +void StringExtItem::set(Extensible* container, const std::string& value) { - this->bits = 0; + void* old = set_raw(container, new std::string(value)); + delete static_cast(old); } -BoolSet::BoolSet(char bitmask) +void StringExtItem::unset(Extensible* container) { - this->bits = bitmask; + void* old = unset_raw(container); + delete static_cast(old); } -bool BoolSet::operator=(BoolSet other) +void StringExtItem::free(void* item) { - this->bits = other.bits; - return true; + delete static_cast(item); }