1
0

refactor: rename flag_enum to cenum.

- rename flag_enum to cenum because it not only provide functions related to flag enum, but also make C++ enum used like C enum.
This commit is contained in:
2025-12-16 21:22:15 +08:00
parent b3ace3d820
commit 8a604ee813
7 changed files with 96 additions and 96 deletions

View File

@@ -59,7 +59,7 @@ FILES
yycc/macro/ptr_size_detector.hpp
yycc/macro/class_copy_move.hpp
yycc/macro/printf_checker.hpp
yycc/flag_enum.hpp
yycc/cenum.hpp
yycc/string.hpp
yycc/string/reinterpret.hpp
yycc/string/op.hpp

View File

@@ -1,10 +1,10 @@
#include "termcolor.hpp"
#include "../flag_enum.hpp"
#include "../cenum.hpp"
#include "../patch/stream.hpp"
#include <stdexcept>
#include <bit>
#define FLAG_ENUM ::yycc::flag_enum
#define CENUM ::yycc::cenum
using namespace std::literals::string_view_literals;
using namespace yycc::patch::stream;
@@ -102,7 +102,7 @@ namespace yycc::carton::termcolor {
}
// Check whether it only has one flag
if (!std::has_single_bit(FLAG_ENUM::integer(attr))) {
if (!std::has_single_bit(CENUM::integer(attr))) {
throw std::invalid_argument("style() only accept single flag attribute");
}
@@ -145,7 +145,7 @@ namespace yycc::carton::termcolor {
* @return The count of single flag.
*/
static size_t count_attribute_flags(Attribute attrs) {
return static_cast<size_t>(std::popcount(FLAG_ENUM::integer(attrs)));
return static_cast<size_t>(std::popcount(CENUM::integer(attrs)));
}
/**
@@ -163,7 +163,7 @@ namespace yycc::carton::termcolor {
*/
static void append_styles(std::u8string& s, Attribute attrs) {
#define CHECK_ATTR(probe) \
if (FLAG_ENUM::has(attrs, probe)) s.append(termcolor::style(probe));
if (CENUM::has(attrs, probe)) s.append(termcolor::style(probe));
if (attrs != Attribute::Default) {
CHECK_ATTR(Attribute::Bold);

View File

@@ -8,7 +8,7 @@
* But it lack essential logic operations which is commonly used by programmer.
* So we create this helper to resolve this issue.
*/
namespace yycc::flag_enum {
namespace yycc::cenum {
// Reference:
// Enum operator overload: https://stackoverflow.com/a/71107019
@@ -204,4 +204,4 @@ namespace yycc::flag_enum {
return static_cast<ut>(e);
}
} // namespace yycc::flag_enum
} // namespace yycc::cenum