-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathflags.h
More file actions
50 lines (39 loc) · 801 Bytes
/
flags.h
File metadata and controls
50 lines (39 loc) · 801 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
49
50
#ifndef FLAGS_H
#define FLAGS_H
#include <stdint.h>
#include <limits>
template<typename FlagType>
class Flags
{
uint32_t flags = 0;
public:
bool hasFlagSet(FlagType val) const
{
return static_cast<bool>(this->flags & (1 << static_cast<uint32_t>(val)));
}
bool hasNone() const
{
return flags == 0;
}
bool hasAll() const
{
return flags == std::numeric_limits<uint32_t>::max();
}
void setFlag(FlagType val)
{
flags |= (1 << static_cast<uint32_t>(val));
}
void clearFlag(FlagType val)
{
flags &= ~(1 << static_cast<uint32_t>(val));
}
void clearAll()
{
flags = 0;
}
void setAll()
{
flags = std::numeric_limits<uint32_t>::max();
}
};
#endif // FLAGS_H