]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/base.cpp
OOPS! We try again, since I'm smoking craq. LF is 0x0a NOT CR.
[user/henk/code/inspircd.git] / src / base.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "inspircd_config.h"
15 #include "base.h"
16 #include <time.h>
17 #include "inspircd.h"
18
19 const int bitfields[]           =       {1,2,4,8,16,32,64,128};
20 const int inverted_bitfields[]  =       {~1,~2,~4,~8,~16,~32,~64,~128};
21
22 classbase::classbase()
23 {
24         this->age = time(NULL);
25 }
26
27 bool Extensible::Shrink(const std::string &key)
28 {
29         /* map::size_type map::erase( const key_type& key );
30          * returns the number of elements removed, std::map
31          * is single-associative so this should only be 0 or 1
32          */
33         return this->Extension_Items.erase(key);
34 }
35
36 void Extensible::GetExtList(std::deque<std::string> &list)
37 {
38         for (ExtensibleStore::iterator u = Extension_Items.begin(); u != Extension_Items.end(); u++)
39         {
40                 list.push_back(u->first);
41         }
42 }
43
44 void BoolSet::Set(int number)
45 {
46         this->bits |= bitfields[number];
47 }
48
49 void BoolSet::Unset(int number)
50 {
51         this->bits &= inverted_bitfields[number];
52 }
53
54 void BoolSet::Invert(int number)
55 {
56         this->bits ^= bitfields[number];
57 }
58
59 bool BoolSet::Get(int number)
60 {
61         return ((this->bits | bitfields[number]) > 0);
62 }
63
64 bool BoolSet::operator==(BoolSet other)
65 {
66         return (this->bits == other.bits);
67 }
68
69 BoolSet BoolSet::operator|(BoolSet other)
70 {
71         BoolSet x(this->bits | other.bits);
72         return x;
73 }
74
75 BoolSet BoolSet::operator&(BoolSet other)
76 {
77         BoolSet x(this->bits & other.bits);
78         return x;
79 }
80
81 BoolSet::BoolSet()
82 {
83         this->bits = 0;
84 }
85
86 BoolSet::BoolSet(char bitmask)
87 {
88         this->bits = bitmask;
89 }
90
91 bool BoolSet::operator=(BoolSet other)
92 {
93         this->bits = other.bits;
94         return true;
95 }