]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/base.cpp
Updated copyrights in headers etc using perl inplace edit
[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 #include "helperfuncs.h"
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 extern time_t TIME;
31
32 bool Extensible::Extend(std::string key, char* p)
33 {
34         // only add an item if it doesnt already exist
35         if (this->Extension_Items.find(key) == this->Extension_Items.end())
36         {
37                 this->Extension_Items[key] = p;
38                 log(DEBUG,"Extending object with item %s",key.c_str());
39                 return true;
40         }
41         // item already exists, return false
42         return false;
43 }
44
45 bool Extensible::Shrink(std::string key)
46 {
47         // only attempt to remove a map item that exists
48         if (this->Extension_Items.find(key) != this->Extension_Items.end())
49         {
50                 this->Extension_Items.erase(this->Extension_Items.find(key));
51                 log(DEBUG,"Shrinking object with item %s",key.c_str());
52                 return true;
53         }
54         return false;
55 }
56
57 char* Extensible::GetExt(std::string key)
58 {
59         if (this->Extension_Items.find(key) != this->Extension_Items.end())
60         {
61                 return (this->Extension_Items.find(key))->second;
62         }
63         return NULL;
64 }
65
66 void Extensible::GetExtList(std::deque<std::string> &list)
67 {
68         for (std::map<std::string,char*>::iterator u = Extension_Items.begin(); u != Extension_Items.end(); u++)
69         {
70                 list.push_back(u->first);
71         }
72 }
73
74 void BoolSet::Set(int number)
75 {
76         this->bits |= bitfields[number];
77 }
78
79 void BoolSet::Unset(int number)
80 {
81         this->bits &= inverted_bitfields[number];
82 }
83
84 void BoolSet::Invert(int number)
85 {
86         this->bits ^= bitfields[number];
87 }
88
89 bool BoolSet::Get(int number)
90 {
91         return ((this->bits | bitfields[number]) > 0);
92 }
93
94 bool BoolSet::operator==(BoolSet other)
95 {
96         return (this->bits == other.bits);
97 }
98
99 BoolSet BoolSet::operator|(BoolSet other)
100 {
101         BoolSet x(this->bits | other.bits);
102         return x;
103 }
104
105 BoolSet BoolSet::operator&(BoolSet other)
106 {
107         BoolSet x(this->bits & other.bits);
108         return x;
109 }
110
111 BoolSet::BoolSet()
112 {
113         this->bits = 0;
114 }
115
116 BoolSet::BoolSet(char bitmask)
117 {
118         this->bits = bitmask;
119 }
120
121 bool BoolSet::operator=(BoolSet other)
122 {
123         this->bits = other.bits;
124         return true;
125 }