|
DNDSR 0.1.0.dev1+gcd065ad
Distributed Numeric Data Structure for CFV
|
Extended enum-to-JSON serialization macro that also exposes allowed string values for JSON Schema generation. More...
Go to the source code of this file.
Classes | |
| struct | DNDS::detail::EnumStringPair< EnumType > |
| A pair of (enum-value, optional string) used to extract allowed values. More... | |
Namespaces | |
| namespace | DNDS |
| the host side operators are provided as implemented | |
| namespace | DNDS::detail |
Macros | |
| #define | DNDS_DEFINE_ENUM_JSON(EnumType_, ...) |
| Define JSON serialization for an enum AND expose its allowed string values. | |
| #define | DNDS_ENUM_ALLOWED_VALUES(EnumType_) _dnds_enum_allowed_values_fn(static_cast<EnumType_ *>(nullptr)) |
| Get the list of allowed string values for an enum type. | |
Functions | |
| template<typename EnumType > | |
| std::vector< std::string > | DNDS::detail::extractEnumStrings (std::initializer_list< EnumStringPair< EnumType > > pairs) |
| Extract non-null string values from a list of enum-string pairs. | |
Extended enum-to-JSON serialization macro that also exposes allowed string values for JSON Schema generation.
The standard NLOHMANN_JSON_SERIALIZE_ENUM macro generates to_json/from_json overloads for an enum, but provides no way to programmatically query the set of allowed string values at runtime. The config schema generator needs this list to produce "enum": ["Roe", "HLLC", ...] entries.
DNDS_DEFINE_ENUM_JSON wraps NLOHMANN_JSON_SERIALIZE_ENUM and additionally generates a free function _dnds_enum_allowed_values_<EnumType>() that returns std::vector<std::string> of the valid string representations.
The companion macro DNDS_ENUM_ALLOWED_VALUES(EnumType) calls this function.
Existing enums using NLOHMANN_JSON_SERIALIZE_ENUM continue to work for serialization. To also get schema enum values, replace with DNDS_DEFINE_ENUM_JSON. Until that replacement, pass allowed values explicitly via DNDS::Config::enum_values({"Roe","HLLC",...}) in the DNDS_FIELD call.
Following the existing DNDSR convention, the first entry in the mapping should map the "unknown/invalid" enum value to nullptr. This entry is skipped when building the allowed-values list for the schema (users should never write null in a config file).
Definition in file ConfigEnum.hpp.
| #define DNDS_DEFINE_ENUM_JSON | ( | EnumType_, | |
| ... | |||
| ) |
Define JSON serialization for an enum AND expose its allowed string values.
Drop-in replacement for NLOHMANN_JSON_SERIALIZE_ENUM that additionally generates a function returning the allowed string values for schema emission.
The variadic arguments are {EnumValue, "string"} pairs, identical to those accepted by NLOHMANN_JSON_SERIALIZE_ENUM. Pairs with nullptr as the string (sentinel/unknown values) are excluded from the allowed-values list.
| EnumType_ | The enum type. |
| ... | Comma-separated {EnumValue, "string_or_nullptr"} pairs. |
Generates:
NLOHMANN_JSON_SERIALIZE_ENUM(EnumType_, ...) — standard serialization.inline std::vector<std::string> _dnds_enum_values_<mangled>() — allowed values. Accessed via DNDS_ENUM_ALLOWED_VALUES(EnumType_). Definition at line 126 of file ConfigEnum.hpp.
| #define DNDS_ENUM_ALLOWED_VALUES | ( | EnumType_ | ) | _dnds_enum_allowed_values_fn(static_cast<EnumType_ *>(nullptr)) |
Get the list of allowed string values for an enum type.
Returns std::vector<std::string>. Only works for enums defined with DNDS_DEFINE_ENUM_JSON. Uses ADL on a dummy pointer argument to find the correct overload of _dnds_enum_allowed_values_fn.
| EnumType_ | The enum type (unquoted). |
Definition at line 145 of file ConfigEnum.hpp.