-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpmap.h
More file actions
48 lines (36 loc) · 831 Bytes
/
Copy pathpmap.h
File metadata and controls
48 lines (36 loc) · 831 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#ifndef PMAP_H_
#define PMAP_H_
#include <cstdint>
namespace FIX {
class PMap {
public:
PMap() : bitmap_(0), bitmask_(1) { }
PMap(const PMap& m) : bitmap_(m.bitmap_), bitmask_(1) { }
bool operator*() const { return bitmap_ & bitmask_; }
void next() { bitmask_ <<= 1; }
bool fetch_bit() {
bool result = bitmap_ & bitmask_;
bitmask_ <<= 1;
return result;
}
void set_bit() {
bitmap_ |= bitmask_;
bitmask_ <<= 1;
}
void clear_bit() {
bitmap_ &= ~bitmask_;
bitmask_ <<= 1;
}
void push_back(bool flag) {
if (flag) bitmap_ |= bitmask_;
bitmask_ <<= 1;
}
void reset() { bitmask_ = 1; }
void clear() { bitmap_ = 0; bitmask_ = 1; }
bool empty() const { return bitmap_==0; }
private:
uint64_t bitmap_;
uint64_t bitmask_; // mask to extract a bit by (bitmap_ & bitmask_)
};
}
#endif // PMAP_H_