-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbool_flags.h
44 lines (36 loc) · 962 Bytes
/
bool_flags.h
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
#ifndef BOOL_FLAGS_H
#define BOOL_FLAGS_H
#include <vector>
#include <cassert>
#include <algorithm>
class BoolFlags{
public:
BoolFlags(){}
explicit BoolFlags(int flag_count)
:flag(flag_count, false){
}
int flag_count()const{
return flag.size();
}
void set(int f){
assert(flag_count () != 0 && "You forgot to pass the flag_count to the constructor");
assert(0 <= f && f < flag_count() && "flag is out of bounds");
flag[f] = true;
}
void unset(int f){
assert(flag_count () != 0 && "You forgot to pass the flag_count to the constructor");
assert(0 <= f && f < flag_count() && "flag is out of bounds");
flag[f] = false;
}
bool is_set(int f)const{
assert(flag_count () != 0 && "You forgot to pass the flag_count to the constructor");
assert(0 <= f && f < flag_count() && "flag is out of bounds");
return flag[f];
}
void unset_all(){
std::fill(flag.begin(), flag.end(), false);
}
private:
std::vector<bool>flag;
};
#endif