1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
7 * <brain@chatspike.net>
8 * <Craig@chatspike.net>
10 * Written by Craig Edwards, Craig McLure, and others.
11 * This program is free but copyrighted software; see
12 * the file COPYING for details.
14 * ---------------------------------------------------
17 #include "inspircd_config.h"
25 #include "helperfuncs.h"
27 const int bitfields[] = {1,2,4,8,16,32,64,128};
28 const int inverted_bitfields[] = {~1,~2,~4,~8,~16,~32,~64,~128};
32 /* This is now a template in base.h
34 * bool Extensible::Extend(const std::string &key, char* p)
36 * // only add an item if it doesnt already exist
37 * if (this->Extension_Items.find(key) == this->Extension_Items.end())
39 * this->Extension_Items[key] = p;
40 * log(DEBUG,"Extending object with item %s",key.c_str());
43 * // item already exists, return false
48 bool Extensible::Shrink(const std::string &key)
50 /* map::size_type map::erase( const key_type& key );
51 * returns the number of elements removed, std::map
52 * is single-associative so this should only be 0 or 1
54 if(this->Extension_Items.erase(key))
56 log(DEBUG, "Shrinking object with item %s",key.c_str());
61 log(DEBUG, "Tried to shrink object with item %s but no items removed", key.c_str());
66 char* Extensible::GetExt(const std::string &key)
68 /* This was calling ExtensibleStore::find() twice,
69 * once to see if there was a value, and again to
70 * get that value if it was there. Now we store
71 * the iterator so we only have to search for it once.
73 ExtensibleStore::iterator iter = this->Extension_Items.find(key);
75 if(iter != this->Extension_Items.end())
85 void Extensible::GetExtList(std::deque<std::string> &list)
87 for (ExtensibleStore::iterator u = Extension_Items.begin(); u != Extension_Items.end(); u++)
89 list.push_back(u->first);
93 void BoolSet::Set(int number)
95 this->bits |= bitfields[number];
98 void BoolSet::Unset(int number)
100 this->bits &= inverted_bitfields[number];
103 void BoolSet::Invert(int number)
105 this->bits ^= bitfields[number];
108 bool BoolSet::Get(int number)
110 return ((this->bits | bitfields[number]) > 0);
113 bool BoolSet::operator==(BoolSet other)
115 return (this->bits == other.bits);
118 BoolSet BoolSet::operator|(BoolSet other)
120 BoolSet x(this->bits | other.bits);
124 BoolSet BoolSet::operator&(BoolSet other)
126 BoolSet x(this->bits & other.bits);
135 BoolSet::BoolSet(char bitmask)
137 this->bits = bitmask;
140 bool BoolSet::operator=(BoolSet other)
142 this->bits = other.bits;