20 #define BOOST_TEST_MODULE ( trajectorypointflags_test )
21 #include "boost/test/unit_test.hpp"
52 template <
typename FlagSet>
55 std::set<typename FlagSet::Flag_t>
const&
defined,
56 std::set<typename FlagSet::Flag_t>
const& set
59 using FlagIndex_t =
typename FlagSet::FlagIndex_t;
60 using Flag_t =
typename FlagSet::Flag_t;
62 for (FlagIndex_t i = 0; i <= flags.capacity(); ++i) {
66 BOOST_TEST_MESSAGE(
" flag #" << i);
68 bool const isFlag = (i < flags.size());
69 bool const isDefined = (defined.count(i) > 0);
70 bool const isSet = (set.count(i) > 0);
72 BOOST_TEST(flags.isFlag(i) == isFlag);
73 BOOST_TEST(flags.isFlag(
flag) == isFlag);
78 BOOST_CHECK_THROW(flags.test(i),
typename FlagSet::OutOfRangeError);
79 BOOST_CHECK_THROW(flags.test(
flag),
typename FlagSet::OutOfRangeError);
82 else if (!isDefined) {
83 BOOST_CHECK_THROW(flags.test(i),
typename FlagSet::FlagNotDefinedError);
85 (flags.test(
flag),
typename FlagSet::FlagNotDefinedError);
88 BOOST_TEST(flags.test(i) == isSet);
89 BOOST_TEST(flags.test(
flag) == isSet);
92 BOOST_TEST(flags.isUndefined(i) == !isDefined);
93 BOOST_TEST(flags.isDefined(i) == isDefined);
94 BOOST_TEST(flags.isUndefined(
flag) == !isDefined);
95 BOOST_TEST(flags.isDefined(
flag) == isDefined);
99 BOOST_TEST(flags.get(i) == isSet);
100 BOOST_TEST(flags.get(
flag) == isSet);
102 BOOST_TEST(flags.isSet(i) == isSet);
103 BOOST_TEST(flags.isUnset(i) == !isSet);
104 BOOST_TEST(flags.isSet(
flag) == isSet);
105 BOOST_TEST(flags.isUnset(
flag) == !isSet);
108 BOOST_TEST(!flags.isSet(i));
109 BOOST_TEST(!flags.isUnset(i));
110 BOOST_TEST(!flags.isSet(
flag));
111 BOOST_TEST(!flags.isUnset(
flag));
126 "Capacity mismatch for util::flags::FlagSet<4U>");
128 "Capacity mismatch for util::flags::FlagSet<8U>");
130 "Capacity mismatch for util::flags::FlagSet<12U>");
132 "Capacity mismatch for util::flags::FlagSet<16U>");
134 "Capacity mismatch for util::flags::FlagSet<32U>");
138 "Capacity mismatch for util::flags::FlagSet<4U>");
140 "Capacity mismatch for util::flags::FlagSet<8U>");
142 "Capacity mismatch for util::flags::FlagSet<12U>");
144 "Capacity mismatch for util::flags::FlagSet<16U>");
146 "Capacity mismatch for util::flags::FlagSet<32U>");
151 constexpr FlagSet_t flags0;
152 static_assert(flags0.size() == 7U,
"Invalid size.");
154 static_assert(!flags0.isDefined(
MyFlags::F0),
"Unexpected flag #0 definition.");
155 static_assert(!flags0.isDefined(
MyFlags::F1),
"Unexpected flag #1 definition.");
156 static_assert(!flags0.isDefined(
MyFlags::F2),
"Unexpected flag #2 definition.");
157 static_assert(!flags0.isDefined(
MyFlags::F3),
"Unexpected flag #3 definition.");
158 static_assert(!flags0.isDefined(
MyFlags::F4),
"Unexpected flag #4 definition.");
159 static_assert(!flags0.isDefined(
MyFlags::F5),
"Unexpected flag #5 definition.");
160 static_assert(!flags0.isDefined(
MyFlags::F6),
"Unexpected flag #6 definition.");
161 static_assert(!flags0.isDefined(
MyFlags::F7),
"Unexpected flag #7 definition.");
162 static_assert(!flags0.isSet(
MyFlags::F0),
"Unexpected flag #0 value.");
163 static_assert(!flags0.isSet(
MyFlags::F1),
"Unexpected flag #1 value.");
164 static_assert(!flags0.isSet(
MyFlags::F2),
"Unexpected flag #2 value.");
165 static_assert(!flags0.isSet(
MyFlags::F3),
"Unexpected flag #3 value.");
166 static_assert(!flags0.isSet(
MyFlags::F4),
"Unexpected flag #4 value.");
167 static_assert(!flags0.isSet(
MyFlags::F5),
"Unexpected flag #5 value.");
168 static_assert(!flags0.isSet(
MyFlags::F6),
"Unexpected flag #6 value.");
169 static_assert(!flags0.isSet(
MyFlags::F7),
"Unexpected flag #7 value.");
170 static_assert(!flags0.isUnset(
MyFlags::F0),
"Unexpected flag #0 value.");
171 static_assert(!flags0.isUnset(
MyFlags::F1),
"Unexpected flag #1 value.");
172 static_assert(!flags0.isUnset(
MyFlags::F2),
"Unexpected flag #2 value.");
173 static_assert(!flags0.isUnset(
MyFlags::F3),
"Unexpected flag #3 value.");
174 static_assert(!flags0.isUnset(
MyFlags::F4),
"Unexpected flag #4 value.");
175 static_assert(!flags0.isUnset(
MyFlags::F5),
"Unexpected flag #5 value.");
176 static_assert(!flags0.isUnset(
MyFlags::F6),
"Unexpected flag #6 value.");
177 static_assert(!flags0.isUnset(
MyFlags::F7),
"Unexpected flag #7 value.");
180 static_assert(flags1.size() == 7U,
"Invalid size.");
182 static_assert(!flags1.isDefined(
MyFlags::F0),
"Unexpected flag #0 definition.");
183 static_assert(!flags1.isDefined(
MyFlags::F1),
"Unexpected flag #1 definition.");
184 static_assert(!flags1.isDefined(
MyFlags::F2),
"Unexpected flag #2 definition.");
185 static_assert(!flags1.isDefined(
MyFlags::F3),
"Unexpected flag #3 definition.");
186 static_assert(!flags1.isDefined(
MyFlags::F4),
"Unexpected flag #4 definition.");
187 static_assert(!flags1.isDefined(
MyFlags::F5),
"Unexpected flag #5 definition.");
188 static_assert( flags1.isDefined(
MyFlags::F6),
"Unexpected flag #6 definition.");
189 static_assert( flags1.isDefined(
MyFlags::F7),
"Unexpected flag #7 definition.");
190 static_assert(!flags1.isSet(
MyFlags::F0),
"Unexpected flag #0 value.");
191 static_assert(!flags1.isSet(
MyFlags::F1),
"Unexpected flag #1 value.");
192 static_assert(!flags1.isSet(
MyFlags::F2),
"Unexpected flag #2 value.");
193 static_assert(!flags1.isSet(
MyFlags::F3),
"Unexpected flag #3 value.");
194 static_assert(!flags1.isSet(
MyFlags::F4),
"Unexpected flag #4 value.");
195 static_assert(!flags1.isSet(
MyFlags::F5),
"Unexpected flag #5 value.");
196 static_assert( flags1.isSet(
MyFlags::F6),
"Unexpected flag #6 value.");
197 static_assert( flags1.isSet(
MyFlags::F7),
"Unexpected flag #7 value.");
198 static_assert(!flags1.isUnset(
MyFlags::F0),
"Unexpected flag #0 value.");
199 static_assert(!flags1.isUnset(
MyFlags::F1),
"Unexpected flag #1 value.");
200 static_assert(!flags1.isUnset(
MyFlags::F2),
"Unexpected flag #2 value.");
201 static_assert(!flags1.isUnset(
MyFlags::F3),
"Unexpected flag #3 value.");
202 static_assert(!flags1.isUnset(
MyFlags::F4),
"Unexpected flag #4 value.");
203 static_assert(!flags1.isUnset(
MyFlags::F5),
"Unexpected flag #5 value.");
204 static_assert(!flags1.isUnset(
MyFlags::F6),
"Unexpected flag #6 value.");
205 static_assert(!flags1.isUnset(
MyFlags::F7),
"Unexpected flag #7 value.");
215 using Flag_t = FlagSet_t::Flag_t;
226 BOOST_TEST_MESSAGE(
"Default construction");
228 std::cout <<
" => " << flags << std::endl;
231 BOOST_TEST_MESSAGE(
"Single bit set");
235 std::cout <<
" => " << flags << std::endl;
238 BOOST_TEST_MESSAGE(
"Two more bits set (one set again)");
246 std::cout <<
" => " << flags << std::endl;
249 BOOST_TEST_MESSAGE(
"Bits set from a list of bits to set");
250 flags.rangeSet(indices.begin(), indices.end());
251 std::for_each(indices.begin(), indices.end(),
255 (indices.begin(), indices.end(), [&set](
auto flag){ set.insert(
flag); });
256 std::cout <<
" => " << flags << std::endl;
259 BOOST_TEST_MESSAGE(
"Undefine bits");
264 std::cout <<
" => " << flags << std::endl;
267 BOOST_TEST_MESSAGE(
"Unset bits");
271 std::cout <<
" => " << flags << std::endl;
274 BOOST_TEST_MESSAGE(
"Unset bit range");
275 flags.rangeUnset(indices.begin(), indices.end());
276 std::for_each(indices.begin(), indices.end(),
279 std::for_each(indices.begin(), indices.end(),
280 [&set](
auto flag){ set.erase(
flag); }
282 std::cout <<
" => " << flags << std::endl;
332 BOOST_TEST( flags.match (flags.mask()));
333 BOOST_TEST(!flags.match (flags.mask() -
MyFlags::F6));
334 BOOST_TEST(!flags.match (flags.mask() +
MyFlags::F5));
335 BOOST_TEST(!flags.match (flags.mask() +
MyFlags::F6));
337 BOOST_TEST( flags.anySet (flags.mask()));
338 BOOST_TEST( flags.anySet (flags.mask() -
MyFlags::F6));
339 BOOST_TEST( flags.anySet (flags.mask() +
MyFlags::F5));
340 BOOST_TEST( flags.anySet (flags.mask() +
MyFlags::F6));
342 BOOST_TEST(!flags.noneSet(flags.mask()));
343 BOOST_TEST(!flags.noneSet(flags.mask() -
MyFlags::F6));
344 BOOST_TEST(!flags.noneSet(flags.mask() +
MyFlags::F5));
345 BOOST_TEST(!flags.noneSet(flags.mask() +
MyFlags::F6));
356 constexpr MyMask_t DefaultMask [[maybe_unused]] (MyMask_t::fromValues, 0x0300U);
366 constexpr MyMask_t DefaultMask [[maybe_unused]] (MyMask_t::fromValues, 0x0300U, 0x0200U);
386 constexpr Mask_t maskA(Mask_t::fromValues, 0b011
'011'011, 0b001
'001'001);
387 constexpr Mask_t maskB(Mask_t::fromValues, 0b000
'111'111, 0b000
'000'111);
388 constexpr Mask_t::Bits_t bitsB (0b000
'000'111);
393 constexpr Mask_t maskMAB(Mask_t::fromValues, 0b011
'111'111, 0b001
'000'111);
394 static_assert(Mask_t::mergeIntoMask(maskA, maskB) == maskMAB,
395 "mergeIntoMask(Mask_t, Mask_t) failure");
397 (maskA + maskB == maskMAB,
"maskA + maskB failure");
399 constexpr Mask_t maskMBA(Mask_t::fromValues, 0b011
'111'111, 0b001
'001'101);
400 static_assert(Mask_t::mergeIntoMask(maskB, maskA) == maskMBA,
401 "mergeIntoMask(Mask_t, Mask_t) failure");
403 (maskB + maskA == maskMBA,
"maskB + maskA failure");
408 constexpr Mask_t maskMAbB(Mask_t::fromValues, 0b011
'011'111, 0b001
'001'111);
409 static_assert(Mask_t::mergeIntoMask(maskA, bitsB) == maskMAbB,
410 "mergeIntoMask(Mask_t, Bits_t) failure");
412 (maskA + bitsB == maskMAbB,
"maskA + bitsB failure");
414 constexpr Mask_t maskMbBA(Mask_t::fromValues, 0b011
'011'111, 0b001
'001'101);
415 static_assert(bitsB + maskA == maskMbBA,
"bitsB + maskA failure");
420 constexpr Mask_t maskCAB(Mask_t::fromValues, 0b011
'111'111, 0b001
'001'111);
421 static_assert(Mask_t::combineWithMask(maskA, maskB) == maskCAB,
422 "combineWithMask(Mask_t, Mask_t) failure");
424 ((maskA | maskB) == maskCAB,
"maskA | maskB failure");
426 constexpr Mask_t maskCBA(Mask_t::fromValues, 0b011
'111'111, 0b001
'001'111);
427 static_assert(Mask_t::combineWithMask(maskB, maskA) == maskCBA,
428 "combineWithMask(Mask_t, Mask_t) failure");
430 ((maskB | maskA) == maskCBA,
"maskB | maskA failure");
435 constexpr Mask_t maskCAbB(Mask_t::fromValues, 0b011
'011'111, 0b001
'001'111);
436 static_assert(Mask_t::combineWithMask(maskA, bitsB) == maskCAbB,
437 "combineWithMask(Mask_t, Bits_t) failure");
439 ((maskA | bitsB) == maskCAbB,
"maskA | bitsB failure");
441 constexpr Mask_t maskCbBA(Mask_t::fromValues, 0b011
'011'111, 0b001
'001'111);
443 ((bitsB | maskA) == maskCbBA,
"bitsB | maskA failure");
448 constexpr Mask_t maskIAB(Mask_t::fromValues, 0b011
'111'111, 0b001
'000'101);
449 static_assert(Mask_t::intersectWithMask(maskA, maskB) == maskIAB,
450 "intersectWithMask(Mask_t, Mask_t) failure");
451 static_assert((maskA & maskB) == maskIAB,
"maskA & maskB failure");
453 constexpr Mask_t maskIBA(Mask_t::fromValues, 0b011
'111'111, 0b001
'000'101);
454 static_assert(Mask_t::intersectWithMask(maskB, maskA) == maskIBA,
455 "intersectWithMask(Mask_t, Mask_t) failure");
456 static_assert((maskB & maskA) == maskIBA,
"maskB & maskA failure");
461 constexpr Mask_t maskIAbB(Mask_t::fromValues, 0b011
'011'111, 0b001
'001'101);
462 static_assert(Mask_t::intersectWithMask(maskA, bitsB) == maskIAbB,
463 "intersectWithMask(Mask_t, Bits_t) failure");
465 ((maskA & bitsB) == maskIAbB,
"maskA & bitsB failure");
467 constexpr Mask_t maskIbBA(Mask_t::fromValues, 0b011
'011'111, 0b001
'001'101);
468 static_assert((bitsB & maskA) == maskIbBA,
"bitsB & maskA failure");
473 constexpr Mask_t maskUAB(Mask_t::fromValues, 0b011
'111'111, 0b001
'001'000);
474 static_assert(Mask_t::unsetMask(maskA, maskB) == maskUAB,
475 "unsetMask(Mask_t, Mask_t) failure");
476 static_assert((maskA - maskB) == maskUAB,
"maskA - maskB failure");
478 constexpr Mask_t maskUBA(Mask_t::fromValues, 0b011
'111'111, 0b000
'000'110);
479 static_assert(Mask_t::unsetMask(maskB, maskA) == maskUBA,
480 "unsetMask(Mask_t, Mask_t) failure");
481 static_assert((maskB - maskA) == maskUBA,
"maskB - maskA failure");
486 constexpr Mask_t maskUAbB(Mask_t::fromValues, 0b011
'011'111, 0b001
'001'000);
487 static_assert(Mask_t::unsetMask(maskA, bitsB) == maskUAbB,
488 "unsetMask(Mask_t, Bits_t) failure");
489 static_assert((maskA - bitsB) == maskUAbB,
"maskA - bitsB failure");
491 constexpr Mask_t maskUbBA(Mask_t::fromValues, 0b011
'011'111, 0b000
'000'110);
492 static_assert((bitsB - maskA) == maskUbBA,
"bitsB - maskA failure");
497 constexpr Mask_t maskNA(Mask_t::fromValues, 0b011
'011'011, 0b010
'010'010);
499 (Mask_t::negateMask(maskA) == maskNA,
"negateMask(Mask_t) failure");
500 static_assert(~maskA == maskNA,
"~mask failure");
505 constexpr Mask_t maskNbB(Mask_t::fromValues, 0b000
'000'111, 0b000
'000'000);
507 (Mask_t::negateMask(bitsB) == maskNbB,
"negateMask(Bits_t) failure");
513 constexpr Mask_t maskbB(Mask_t::fromValues, 0b000
'000'111, 0b000
'000'111);
514 static_assert(+maskA == maskA,
"+mask failure");
515 static_assert(+bitsB == maskbB,
"+bits failure");
520 static_assert(maskA + (-bitsB) == maskA - bitsB,
"-bits failure");
534 std::cout <<
"Testing Set()/Unset() on " << mask << std::endl;
536 BOOST_TEST(!mask.isDefined(0));
537 BOOST_TEST( mask.isDefined(1));
538 BOOST_TEST( mask.isDefined(2));
539 BOOST_TEST(!mask.isDefined(3));
541 BOOST_TEST(!mask.isSet(0));
542 BOOST_TEST( mask.isSet(1));
543 BOOST_TEST(!mask.isSet(2));
544 BOOST_TEST(!mask.isSet(3));
546 BOOST_TEST(!mask.isUnset(0));
547 BOOST_TEST(!mask.isUnset(1));
548 BOOST_TEST( mask.isUnset(2));
549 BOOST_TEST(!mask.isUnset(3));
void BitMaskDocTest_ConstructorFromValues1()
constexpr MyFlag_t F8[[gnu::unused]]
then echo unknown compiler flag
Type identifying a flag. Operations are implemented as free functions.
A class containing a set of flags.
void BitMaskDocTest_ConstructorFromValues2()
A class containing a set of flags.
constexpr mask_t< EnumType > mask(EnumType bit, OtherBits...otherBits)
Returns a mask with all specified bits set.
constexpr BitMask< Storage > Set(Flag_t< Storage > flag)
Returns a bit mask which sets the specified flag.
void BitMaskCombineTests()
constexpr std::array< std::size_t, geo::vect::dimension< Vector >)> indices()
Returns a sequence of indices valid for a vector of the specified type.
then echo echo For and will not be changed by echo further linking echo echo B echo The symbol is in the uninitialized data multiple common symbols may appear with the echo same name If the symbol is defined the common echo symbols are treated as undefined references For more echo details on common see the discussion of warn common echo in *Note Linker see the discussion of warn common echo in *Note Linker such as a global int variable echo as opposed to a large global array echo echo I echo The symbol is an indirect reference to another symbol This echo is a GNU extension to the a out object file format which is echo rarely used echo echo N echo The symbol is a debugging symbol echo echo R echo The symbol is in a read only data section echo echo S echo The symbol is in an uninitialized data section for small echo objects echo echo T echo The symbol is in the the normal defined echo symbol is used with no error When a weak undefined symbol echo is linked and the symbol is not defined
void CheckFlags(FlagSet const &flags, std::set< typename FlagSet::Flag_t > const &defined, std::set< typename FlagSet::Flag_t > const &set)
constexpr BitMask< Storage > Unset(Flag_t< Storage > flag)
Returns a bit mask which unsets the specified flag.
BEGIN_PROLOG could also be cout