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