]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/base.cpp
ModeParser::InsertMode is no longer required -- this is auto-generated by the ModePar...
[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 <map>
21 #include <deque>
22 #include <string>
23 #include "inspircd.h"
24 #include "modules.h"
25
26
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};
29
30 classbase::classbase()
31 {
32         this->age = time(NULL);
33 }
34
35 bool Extensible::Shrink(const std::string &key)
36 {
37         /* map::size_type map::erase( const key_type& key );
38          * returns the number of elements removed, std::map
39          * is single-associative so this should only be 0 or 1
40          */
41         return this->Extension_Items.erase(key);
42 }
43
44 void Extensible::GetExtList(std::deque<std::string> &list)
45 {
46         for (ExtensibleStore::iterator u = Extension_Items.begin(); u != Extension_Items.end(); u++)
47         {
48                 list.push_back(u->first);
49         }
50 }
51
52 void BoolSet::Set(int number)
53 {
54         this->bits |= bitfields[number];
55 }
56
57 void BoolSet::Unset(int number)
58 {
59         this->bits &= inverted_bitfields[number];
60 }
61
62 void BoolSet::Invert(int number)
63 {
64         this->bits ^= bitfields[number];
65 }
66
67 bool BoolSet::Get(int number)
68 {
69         return ((this->bits | bitfields[number]) > 0);
70 }
71
72 bool BoolSet::operator==(BoolSet other)
73 {
74         return (this->bits == other.bits);
75 }
76
77 BoolSet BoolSet::operator|(BoolSet other)
78 {
79         BoolSet x(this->bits | other.bits);
80         return x;
81 }
82
83 BoolSet BoolSet::operator&(BoolSet other)
84 {
85         BoolSet x(this->bits & other.bits);
86         return x;
87 }
88
89 BoolSet::BoolSet()
90 {
91         this->bits = 0;
92 }
93
94 BoolSet::BoolSet(char bitmask)
95 {
96         this->bits = bitmask;
97 }
98
99 bool BoolSet::operator=(BoolSet other)
100 {
101         this->bits = other.bits;
102         return true;
103 }