forked from microsoft/AirSim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEnumFlags.hpp
97 lines (88 loc) · 2.15 KB
/
EnumFlags.hpp
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#ifndef CommonUtils_EnumFlags_hpp
#define CommonUtils_EnumFlags_hpp
namespace mavlink_utils {
template<class TEnum,class TUnderlying=typename std::underlying_type<TEnum>::type>
class EnumFlags
{
protected:
TUnderlying flags_;
public:
EnumFlags()
: flags_(0)
{}
EnumFlags(TEnum singleFlag)
: flags_(singleFlag)
{}
EnumFlags(TUnderlying flags)
: flags_(flags)
{}
EnumFlags(const EnumFlags& original)
: flags_(original.flags_)
{}
EnumFlags& operator |=(TEnum add_value)
{
flags_ |= add_value;
return *this;
}
EnumFlags operator |(TEnum add_value) const
{
EnumFlags result(*this);
result |= add_value;
return result;
}
EnumFlags& operator &=(TEnum mask_value)
{
flags_ &= mask_value;
return *this;
}
EnumFlags operator &(TEnum mask_value) const
{
EnumFlags result(*this);
result &= mask_value;
return result;
}
// EnumFlags& operator ~=(TEnum mask_value)
// {
// flags_ ~= mask_value;
// return *this;
// }
EnumFlags operator ~() const
{
EnumFlags result(*this);
result.flags_ = ~result.flags_;
return result;
}
// EnumFlags& operator ^=(TEnum mask_value)
// {
// flags_ ^= mask_value;
// return *this;
// }
// EnumFlags operator ^(TEnum mask_value) const
// {
// EnumFlags result(*this);
// result.flags_ ^= mask_value;
// return result;
// }
//equality operators
bool operator==(const EnumFlags& rhs) const
{
return flags_ == rhs.flags_;
}
inline bool operator!=(const EnumFlags& rhs) const
{
return !(*this == rhs);
}
//type conversion
operator bool() const
{
return flags_ != 0;
}
operator TUnderlying() const
{
return flags_;
}
};
#endif
} //namespace