描述辅助
公共头文件: #include "brookesia/lib_utils/describe_helpers.hpp"
概述
describe_helpers 基于 Boost.Describe 和 Boost.JSON 提供“对象描述 + 序列化/反序列化” 能力,降低结构体、枚举与复杂类型的配置编解码成本。
特性
支持枚举与结构体成员反射(描述名称、成员列表、枚举值等)
支持常见类型 JSON 序列化/反序列化:字符串、数值、布尔、容器、可选值等
覆盖 variant、optional、map、vector 等复合类型检测与处理
提供调试友好的描述输出能力,便于日志与配置排查
API 参考
Header File
Classes
-
class DescribeFormatManager
Singleton that stores the global default
DescribeOutputFormat.Public Functions
-
inline void set_format(const DescribeOutputFormat &fmt)
Set the process-wide default output format.
- 参数
fmt – New global format.
-
inline const DescribeOutputFormat &get_format() const
Get the current process-wide default output format.
- 返回
Reference to the active global format.
-
inline void reset_to_default()
Restore the built-in default output format.
Public Static Functions
-
static inline DescribeFormatManager &instance()
Get the singleton instance.
- 返回
Reference to the global format manager.
-
inline void set_format(const DescribeOutputFormat &fmt)
Macros
-
BROOKESIA_DESCRIBE_STRUCT(C, Bases, Members)
Register a struct with Boost.Describe reflection.
-
BROOKESIA_DESCRIBE_ENUM(C, ...)
Register an enum with Boost.Describe reflection.
-
BROOKESIA_DESCRIBE_ENUM_TO_STR(value)
Convert a described enum value to a string.
-
BROOKESIA_DESCRIBE_ENUM_TO_NUM(value)
Convert an enum value to its underlying integer value.
-
BROOKESIA_DESCRIBE_NUM_TO_ENUM(number, ret_value)
Convert an integer value to a described enum value.
-
BROOKESIA_DESCRIBE_STR_TO_ENUM(str, ret_value)
Convert an enumerator name to a described enum value.
-
BROOKESIA_DESCRIBE_TO_JSON(value)
Convert a supported value to
boost::json::value.
-
BROOKESIA_DESCRIBE_FROM_JSON(json_value, ret_value)
Convert a
boost::json::valueto a supported C++ value.
-
BROOKESIA_DESCRIBE_JSON_SERIALIZE(value)
Serialize a supported value to JSON text.
-
BROOKESIA_DESCRIBE_JSON_DESERIALIZE(str, ret_value)
Deserialize JSON text into a supported C++ value.
-
BROOKESIA_DESCRIBE_FORMAT_VERBOSE
Verbose multi-line formatting preset.
-
BROOKESIA_DESCRIBE_FORMAT_JSON
JSON-like formatting preset.
-
BROOKESIA_DESCRIBE_FORMAT_COMPACT
Compact single-line formatting preset.
-
BROOKESIA_DESCRIBE_FORMAT_DEFAULT
Default human-readable formatting preset.
-
BROOKESIA_DESCRIBE_FORMAT_PYTHON
Python-dict-inspired formatting preset.
-
BROOKESIA_DESCRIBE_FORMAT_CPP
C++ designated-initializer-inspired formatting preset.
-
BROOKESIA_DESCRIBE_SET_GLOBAL_FORMAT(fmt)
Set the global default string formatting preset.
-
BROOKESIA_DESCRIBE_GET_GLOBAL_FORMAT()
Get the global default string formatting preset.
-
BROOKESIA_DESCRIBE_RESET_GLOBAL_FORMAT()
Reset the global default string formatting preset.
-
BROOKESIA_DESCRIBE_TO_STR(value)
Convert a supported value to a string with the global default format.
-
BROOKESIA_DESCRIBE_TO_STR_WITH_FMT(value, fmt)
Convert a supported value to a string with an explicit format preset.