]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/base.cpp
Wahhhhhhhhhhhh bwahahaha. Mass commit to tidy up tons of messy include lists
[user/henk/code/inspircd.git] / src / base.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
6  *                       E-mail:
7  *                <brain@chatspike.net>
8  *                <Craig@chatspike.net>
9  *     
10  * Written by Craig Edwards, Craig McLure, and others.
11  * This program is free but copyrighted software; see
12  *            the file COPYING for details.
13  *
14  * ---------------------------------------------------
15  */
16
17 #include "inspircd_config.h"
18 #include "base.h"
19 #include <time.h>
20 #include "inspircd.h"
21
22 const int bitfields[]           =       {1,2,4,8,16,32,64,128};
23 const int inverted_bitfields[]  =       {~1,~2,~4,~8,~16,~32,~64,~128};
24
25 classbase::classbase()
26 {
27         this->age = time(NULL);
28 }
29
30 bool Extensible::Shrink(const std::string &key)
31 {
32         /* map::size_type map::erase( const key_type& key );
33          * returns the number of elements removed, std::map
34          * is single-associative so this should only be 0 or 1
35          */
36         return this->Extension_Items.erase(key);
37 }
38
39 void Extensible::GetExtList(std::deque<std::string> &list)
40 {
41         for (ExtensibleStore::iterator u = Extension_Items.begin(); u != Extension_Items.end(); u++)
42         {
43                 list.push_back(u->first);
44         }
45 }
46
47 void BoolSet::Set(int number)
48 {
49         this->bits |= bitfields[number];
50 }
51
52 void BoolSet::Unset(int number)
53 {
54         this->bits &= inverted_bitfields[number];
55 }
56
57 void BoolSet::Invert(int number)
58 {
59         this->bits ^= bitfields[number];
60 }
61
62 bool BoolSet::Get(int number)
63 {
64         return ((this->bits | bitfields[number]) > 0);
65 }
66
67 bool BoolSet::operator==(BoolSet other)
68 {
69         return (this->bits == other.bits);
70 }
71
72 BoolSet BoolSet::operator|(BoolSet other)
73 {
74         BoolSet x(this->bits | other.bits);
75         return x;
76 }
77
78 BoolSet BoolSet::operator&(BoolSet other)
79 {
80         BoolSet x(this->bits & other.bits);
81         return x;
82 }
83
84 BoolSet::BoolSet()
85 {
86         this->bits = 0;
87 }
88
89 BoolSet::BoolSet(char bitmask)
90 {
91         this->bits = bitmask;
92 }
93
94 bool BoolSet::operator=(BoolSet other)
95 {
96         this->bits = other.bits;
97         return true;
98 }