1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * Inspire is copyright (C) 2002-2004 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"
24 #include "helperfuncs.h"
26 const int bitfields[] = {1,2,4,8,16,32,64,128};
27 const int inverted_bitfields[] = {~1,~2,~4,~8,~16,~32,~64,~128};
31 bool Extensible::Extend(std::string key, char* p)
33 // only add an item if it doesnt already exist
34 if (this->Extension_Items.find(key) == this->Extension_Items.end())
36 this->Extension_Items[key] = p;
37 log(DEBUG,"Extending object with item %s",key.c_str());
40 // item already exists, return false
44 bool Extensible::Shrink(std::string key)
46 // only attempt to remove a map item that exists
47 if (this->Extension_Items.find(key) != this->Extension_Items.end())
49 this->Extension_Items.erase(this->Extension_Items.find(key));
50 log(DEBUG,"Shrinking object with item %s",key.c_str());
56 char* Extensible::GetExt(std::string key)
58 if (this->Extension_Items.find(key) != this->Extension_Items.end())
60 return (this->Extension_Items.find(key))->second;
62 log(DEBUG,"Cant find item %s",key.c_str());
66 void BoolSet::Set(int number)
68 this->bits |= bitfields[number];
71 void BoolSet::Unset(int number)
73 this->bits &= inverted_bitfields[number];
76 void BoolSet::Invert(int number)
78 this->bits ^= bitfields[number];
81 bool BoolSet::Get(int number)
83 return ((this->bits | bitfields[number]) > 0);
86 bool BoolSet::operator==(BoolSet other)
88 return (this->bits == other.bits);
91 BoolSet BoolSet::operator|(BoolSet other)
93 BoolSet x(this->bits | other.bits);
97 BoolSet BoolSet::operator&(BoolSet other)
99 BoolSet x(this->bits & other.bits);
108 BoolSet::BoolSet(char bitmask)
110 this->bits = bitmask;
113 bool BoolSet::operator=(BoolSet other)
115 this->bits = other.bits;