Debian Codegraph @

CodeLite/clBitset.cpp

raw
1 #include "clBitset.hpp"
2
3 #define CHECK_SIZE_RET_FALSE(pos) \
4 if(pos >= BITS_SIZE) \
5 return false
6
7 #define CHECK_SIZE_RET(pos) \
8 if(pos >= BITS_SIZE) \
9 return
10
11 clBitset::clBitset() { memset(bits, 0, sizeof(bits)); }
12
13 clBitset::~clBitset() {}
14
15 void clBitset::set(size_t pos, bool b)
16 {
17 CHECK_SIZE_RET(pos);
18 bits[pos] = b ? 1 : 0;
19 }
20
21 bool clBitset::test(size_t pos) const
22 {
23 CHECK_SIZE_RET_FALSE(pos);
24 return bits[pos] == 1;
25 }
26
27 void clBitset::rese() { memset(bits, 0, sizeof(bits)); }
28
29 wxString clBitset::to_string() const
30 {
31 wxString str;
32 for(auto ch : bits) {
33 str << (ch == 1 ? "1" : "0");
34 }
35 return str;
36 }
37
38 void clBitset::from_string(const wxString& str)
39 {
40 if(str.length() < BITS_SIZE)
41 return;
42
43 for(size_t i = 0; i < BITS_SIZE; ++i) {
44 bits[i] = (str[i] == '1' ? 1 : 0);
45 }
46 }