]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/base.cpp
Added proper administrativia notices to CONNECT and inbound connections
[user/henk/code/inspircd.git] / src / base.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  Inspire is copyright (C) 2002-2004 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 <string>
22 #include "inspircd.h"
23 #include "modules.h"
24 #include "helperfuncs.h"
25
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};
28
29 extern time_t TIME;
30
31 bool Extensible::Extend(std::string key, char* p)
32 {
33         // only add an item if it doesnt already exist
34         if (this->Extension_Items.find(key) == this->Extension_Items.end())
35         {
36                 this->Extension_Items[key] = p;
37                 log(DEBUG,"Extending object with item %s",key.c_str());
38                 return true;
39         }
40         // item already exists, return false
41         return false;
42 }
43
44 bool Extensible::Shrink(std::string key)
45 {
46         // only attempt to remove a map item that exists
47         if (this->Extension_Items.find(key) != this->Extension_Items.end())
48         {
49                 this->Extension_Items.erase(this->Extension_Items.find(key));
50                 log(DEBUG,"Shrinking object with item %s",key.c_str());
51                 return true;
52         }
53         return false;
54 }
55
56 char* Extensible::GetExt(std::string key)
57 {
58         if (this->Extension_Items.find(key) != this->Extension_Items.end())
59         {
60                 return (this->Extension_Items.find(key))->second;
61         }
62         log(DEBUG,"Cant find item %s",key.c_str());
63         return NULL;
64 }
65
66 void BoolSet::Set(int number)
67 {
68         this->bits |= bitfields[number];
69 }
70
71 void BoolSet::Unset(int number)
72 {
73         this->bits &= inverted_bitfields[number];
74 }
75
76 void BoolSet::Invert(int number)
77 {
78         this->bits ^= bitfields[number];
79 }
80
81 bool BoolSet::Get(int number)
82 {
83         return ((this->bits | bitfields[number]) > 0);
84 }
85
86 bool BoolSet::operator==(BoolSet other)
87 {
88         return (this->bits == other.bits);
89 }
90
91 BoolSet BoolSet::operator|(BoolSet other)
92 {
93         BoolSet x(this->bits | other.bits);
94         return x;
95 }
96
97 BoolSet BoolSet::operator&(BoolSet other)
98 {
99         BoolSet x(this->bits & other.bits);
100         return x;
101 }
102
103 BoolSet::BoolSet()
104 {
105         this->bits = 0;
106 }
107
108 BoolSet::BoolSet(char bitmask)
109 {
110         this->bits = bitmask;
111 }
112
113 bool BoolSet::operator=(BoolSet other)
114 {
115         this->bits = other.bits;
116         return true;
117 }