]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/base.cpp
extern time_t TIME -> InspIRCd::Time()
[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 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         if(this->Extension_Items.erase(key))
37         {
38                 log(DEBUG, "Shrinking object with item %s",key.c_str());
39                 return true;
40         }
41         else
42         {
43                 log(DEBUG, "Tried to shrink object with item %s but no items removed", key.c_str());            
44                 return false;
45         }
46 }
47
48 void Extensible::GetExtList(std::deque<std::string> &list)
49 {
50         for (ExtensibleStore::iterator u = Extension_Items.begin(); u != Extension_Items.end(); u++)
51         {
52                 list.push_back(u->first);
53         }
54 }
55
56 void BoolSet::Set(int number)
57 {
58         this->bits |= bitfields[number];
59 }
60
61 void BoolSet::Unset(int number)
62 {
63         this->bits &= inverted_bitfields[number];
64 }
65
66 void BoolSet::Invert(int number)
67 {
68         this->bits ^= bitfields[number];
69 }
70
71 bool BoolSet::Get(int number)
72 {
73         return ((this->bits | bitfields[number]) > 0);
74 }
75
76 bool BoolSet::operator==(BoolSet other)
77 {
78         return (this->bits == other.bits);
79 }
80
81 BoolSet BoolSet::operator|(BoolSet other)
82 {
83         BoolSet x(this->bits | other.bits);
84         return x;
85 }
86
87 BoolSet BoolSet::operator&(BoolSet other)
88 {
89         BoolSet x(this->bits & other.bits);
90         return x;
91 }
92
93 BoolSet::BoolSet()
94 {
95         this->bits = 0;
96 }
97
98 BoolSet::BoolSet(char bitmask)
99 {
100         this->bits = bitmask;
101 }
102
103 bool BoolSet::operator=(BoolSet other)
104 {
105         this->bits = other.bits;
106         return true;
107 }