flags: add flags_keep_unmutable + test
When moving we want to maintain _some_ flags; add a function making that convenient.
This commit is contained in:
@ -150,6 +150,18 @@ test_flags_filter()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[[maybe_unused]] static void
|
||||||
|
test_flags_keep_unmutable()
|
||||||
|
{
|
||||||
|
static_assert(flags_keep_unmutable((Flags::Seen|Flags::Passed),
|
||||||
|
(Flags::Flagged|Flags::Draft),
|
||||||
|
Flags::Replied) ==
|
||||||
|
(Flags::Flagged|Flags::Draft));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef BUILD_TESTS
|
#ifdef BUILD_TESTS
|
||||||
int
|
int
|
||||||
main(int argc, char* argv[])
|
main(int argc, char* argv[])
|
||||||
@ -164,6 +176,8 @@ main(int argc, char* argv[])
|
|||||||
test_flags_from_delta_expr);
|
test_flags_from_delta_expr);
|
||||||
g_test_add_func("/message/flags/flags-filter",
|
g_test_add_func("/message/flags/flags-filter",
|
||||||
test_flags_filter);
|
test_flags_filter);
|
||||||
|
g_test_add_func("/message/flags/flags-keep-unmutable",
|
||||||
|
test_flags_keep_unmutable);
|
||||||
|
|
||||||
return g_test_run();
|
return g_test_run();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -338,6 +338,28 @@ flags_filter(Flags flags, MessageFlagCategory cat)
|
|||||||
return flags;
|
return flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return flags, where flags = new_flags but with unmutable_flag in the
|
||||||
|
* result the same as in old_flags
|
||||||
|
*
|
||||||
|
* @param old_flags
|
||||||
|
* @param new_flags
|
||||||
|
* @param unmutable_flag
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
constexpr Flags
|
||||||
|
flags_keep_unmutable(Flags old_flags, Flags new_flags, Flags unmutable_flag)
|
||||||
|
{
|
||||||
|
if (any_of(old_flags & unmutable_flag))
|
||||||
|
return new_flags | unmutable_flag;
|
||||||
|
else
|
||||||
|
return new_flags & ~unmutable_flag;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a string representation of flags
|
* Get a string representation of flags
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user