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 bool Extensible::Extend(std::string key, char* p)
34 // only add an item if it doesnt already exist
35 if (this->Extension_Items.find(key) == this->Extension_Items.end())
37 this->Extension_Items[key] = p;
38 log(DEBUG,"Extending object with item %s",key.c_str());
41 // item already exists, return false
45 bool Extensible::Shrink(std::string key)
47 // only attempt to remove a map item that exists
48 if (this->Extension_Items.find(key) != this->Extension_Items.end())
50 this->Extension_Items.erase(this->Extension_Items.find(key));
51 log(DEBUG,"Shrinking object with item %s",key.c_str());
57 char* Extensible::GetExt(std::string key)
59 if (this->Extension_Items.find(key) != this->Extension_Items.end())
61 return (this->Extension_Items.find(key))->second;
66 void Extensible::GetExtList(std::deque<std::string> &list)
68 for (std::map<std::string,char*>::iterator u = Extension_Items.begin(); u != Extension_Items.end(); u++)
70 list.push_back(u->first);
74 void BoolSet::Set(int number)
76 this->bits |= bitfields[number];
79 void BoolSet::Unset(int number)
81 this->bits &= inverted_bitfields[number];
84 void BoolSet::Invert(int number)
86 this->bits ^= bitfields[number];
89 bool BoolSet::Get(int number)
91 return ((this->bits | bitfields[number]) > 0);
94 bool BoolSet::operator==(BoolSet other)
96 return (this->bits == other.bits);
99 BoolSet BoolSet::operator|(BoolSet other)
101 BoolSet x(this->bits | other.bits);
105 BoolSet BoolSet::operator&(BoolSet other)
107 BoolSet x(this->bits & other.bits);
116 BoolSet::BoolSet(char bitmask)
118 this->bits = bitmask;
121 bool BoolSet::operator=(BoolSet other)
123 this->bits = other.bits;