AMDiS 2.10
The Adaptive Multi-Dimensional Simulation Toolbox
Flag.hpp
1#pragma once
2
3#include <cstdint>
4
5namespace AMDiS
6{
13 class Flag
14 {
15 public:
17 constexpr Flag() = default;
18
20 constexpr Flag(const std::uint64_t f)
21 : flags_(f)
22 {}
23
25 constexpr Flag(Flag const&) = default;
26
28 constexpr Flag(Flag&&) = default;
29
31 constexpr bool operator==(Flag const& f) const
32 {
33 return (flags_ == f.flags_);
34 }
35
37 constexpr bool operator!=(Flag const& f) const
38 {
39 return !(f == *this);
40 }
41
43 constexpr Flag& operator=(Flag const& f)
44 {
45 if (this != &f)
46 flags_ = f.flags_;
47 return *this;
48 }
49
51 constexpr operator bool() const
52 {
53 return isAnySet();
54 }
55
57 constexpr void setFlags(const std::uint64_t f)
58 {
59 flags_ = f;
60 }
61
63 constexpr void setFlags(Flag const& f)
64 {
65 flags_ = f.flags_;
66 }
67
69 constexpr void setFlag(const std::uint64_t f)
70 {
71 flags_ |= f;
72 }
73
75 constexpr void setFlag(Flag const& f)
76 {
77 flags_ |= f.flags_;
78 }
79
81 constexpr void unsetFlag(const std::uint64_t f)
82 {
83 flags_ &= ~f;
84 }
85
87 constexpr void unsetFlag(Flag const& f)
88 {
89 flags_ &= ~f.flags_;
90 }
91
92 constexpr std::uint64_t flags() const
93 {
94 return flags_;
95 }
96
98 friend Flag operator+(Flag r, Flag const& f)
99 {
100 r.setFlag(f);
101 return r;
102 }
103
105 friend Flag operator-(Flag r, Flag const& f)
106 {
107 r.unsetFlag(f);
108 return r;
109 }
110
112 friend Flag operator|(Flag r, Flag const& f)
113 {
114 r.setFlag(f);
115 return r;
116 }
117
119 friend Flag operator&(Flag r, Flag const& f)
120 {
121 r.flags_ &= f.flags_;
122 return r;
123 }
124
126 constexpr Flag operator&=(Flag const& f)
127 {
128 flags_ &= f.flags_;
129 return *this;
130 }
131
133 friend Flag operator^(Flag r, Flag const& f)
134 {
135 r.flags_ ^= f.flags_;
136 return r;
137 }
138
140 constexpr Flag& operator|=(Flag const& f)
141 {
142 if (this != &f)
143 flags_ |= f.flags_;
144 return *this;
145 }
146
148 constexpr Flag operator~() const
149 {
150 Flag r;
151 r.flags_ = ~flags_;
152 return r;
153 }
154
156 constexpr bool isSet(Flag const& f) const
157 {
158 return ((flags_ & f.flags_) == f.flags_);
159 }
160
162 constexpr bool isUnset(Flag const& f) const
163 {
164 return !isSet(f);
165 }
166
168 constexpr bool isAnySet() const
169 {
170 return (flags_ != 0);
171 }
172
173 protected:
175 std::uint64_t flags_ = 0;
176 };
177
178} // end namespace AMDiS
The Flag class encapsulates flags which represents simple information. Used e.g. while mesh traversal...
Definition: Flag.hpp:14
constexpr Flag & operator|=(Flag const &f)
Sets flags_ to flags_ & f.flags_.
Definition: Flag.hpp:140
std::uint64_t flags_
Internal flag representation.
Definition: Flag.hpp:175
constexpr bool isUnset(Flag const &f) const
Returns !isSet(f)
Definition: Flag.hpp:162
constexpr bool isAnySet() const
Returns true if flags_ != 0.
Definition: Flag.hpp:168
constexpr Flag()=default
Constructs a unset Flag.
constexpr void setFlag(const std::uint64_t f)
Sets flags_ to flags_ | f.
Definition: Flag.hpp:69
friend Flag operator&(Flag r, Flag const &f)
Returns flags_ & f.flags_.
Definition: Flag.hpp:119
constexpr Flag & operator=(Flag const &f)
Assignment operator.
Definition: Flag.hpp:43
constexpr Flag operator~() const
Returns ~flags_.
Definition: Flag.hpp:148
constexpr void unsetFlag(Flag const &f)
Sets flags_ to flags_ & ~f.flags_.
Definition: Flag.hpp:87
constexpr Flag operator&=(Flag const &f)
Sets flags_ to flags_ &= f.flags_.
Definition: Flag.hpp:126
friend Flag operator+(Flag r, Flag const &f)
Returns flags_ | f.flags_.
Definition: Flag.hpp:98
constexpr bool operator!=(Flag const &f) const
Compares two Flags.
Definition: Flag.hpp:37
constexpr void setFlags(Flag const &f)
Set flags_.
Definition: Flag.hpp:63
constexpr Flag(const std::uint64_t f)
Constructs a Flag initialized by f.
Definition: Flag.hpp:20
friend Flag operator|(Flag r, Flag const &f)
Returns flags_ | f.flags_.
Definition: Flag.hpp:112
constexpr Flag(Flag &&)=default
Move constructor.
constexpr bool operator==(Flag const &f) const
Compares two Flags.
Definition: Flag.hpp:31
constexpr void unsetFlag(const std::uint64_t f)
Sets flags_ to flags_ & ~f.
Definition: Flag.hpp:81
friend Flag operator^(Flag r, Flag const &f)
Returns flags_ ^ f.flags_.
Definition: Flag.hpp:133
constexpr void setFlag(Flag const &f)
Sets flags_ to flags_ | f.flags_.
Definition: Flag.hpp:75
constexpr bool isSet(Flag const &f) const
Checks whether all set bits of f.flags_ are set in flags_ too.
Definition: Flag.hpp:156
constexpr void setFlags(const std::uint64_t f)
Set flags_.
Definition: Flag.hpp:57
constexpr Flag(Flag const &)=default
Copy constructor.
friend Flag operator-(Flag r, Flag const &f)
Returns flags_ & ~f.flags_.
Definition: Flag.hpp:105