Skip to content

feat(enums): add rfl::TransformEnumNames processors - #235

Open
clockblocker wants to merge 1 commit into
enum-string-viewfrom
queue/feat-transform-enum-names
Open

clockblocker wants to merge 1 commit into
enum-string-viewfrom
queue/feat-transform-enum-names

Conversation

@clockblocker

@clockblocker clockblocker commented Dec 2, 2026 •

Copy link
Copy Markdown
Owner

AI-authored below this line.

Addresses munich-data-engineering/reflect-cpp#731

Stacked on: #76 (enum-string-view)

Problem

reflect-cpp provides casing processors for struct fields, but not for enum values.

Codebases with snake_case or PascalCase C++ enums and kebab-case or lowercase wire formats have to maintain manual rfl::Reflector switch tables.

enum class CostModel { t_count, two_qubit_gate_count, gate_count };
struct Config { CostModel cost_model; };

const auto json = rfl::json::write<rfl::EnumSnakeCaseToKebabCase>(
    Config{.cost_model = CostModel::two_qubit_gate_count});
// {"cost_model":"two-qubit-gate-count"}

const auto cfg = rfl::json::read<Config, rfl::EnumSnakeCaseToKebabCase>(json).value();

Summary

  • Adds six built-in enum casing aliases (snake_case to kebab/camel/Pascal, camelCase to snake, lower, and upper) across read, write, bitmasks, enum_to_string, string_to_enum, and JSON Schema.
  • Caches transformed tables per enum and processor, allocates nothing for untransformed enums, and compiles transforms out-of-line.

OSS consumers

Consumer Location Pain point solved
NVIDIA/cuda-quantum TargetConfigYamlAdapters.h#L27-L75 Maintains 4 manual rfl::Reflector switch tables for snake_case to kebab-case YAML enums.
openmoq/moqx ParsedConfig.h#L291 Duplicates QuicStack as an rfl::Literal plus switch mapper for snake_case wire names.
munich-data-engineering/sqlgen sqlite/to_sql.cpp#L338-L340 Manually uppercases rfl::enum_to_string across SQL backends.
games-on-whales/wolf api/openapi.cpp#L92 Manually lowercases HTTP method enum strings after rfl::enum_to_string.
For Agents

…neering#731)

Adds opt-in whole-enum wire-name casing transform processors
(`rfl::TransformEnumNames<...>` plus aliases `EnumSnakeCaseToKebabCase`,
`EnumSnakeCaseToCamelCase`, `EnumSnakeCaseToPascalCase`,
`EnumCamelCaseToSnakeCase`, `EnumToLowerCase`, `EnumToUpperCase`) across read,
write, `rfl::enum_to_string`, `rfl::string_to_enum`, and JSON Schema generation.
Resolved wire-name tables are cached once per `(EnumType, EnumNameTransform)`.

Parent: depends on `feat(enums): accept std::string_view in rfl::string_to_enum (munich-data-engineering#565)`
(open upstream PR munich-data-engineering#802). Per-enum overrides/trait (`rfl::EnumNames<E>`, #106)
is split into a separate child commit on top of this processor seam.

Judge polish applied:
- Moves non-template `apply_enum_name_transform` out-of-line into
  `src/rfl/TransformEnumNames.cpp` (`RFL_API`, wired via `src/reflectcpp.cpp`).
- Places `enum_name_transform_v` in `include/rfl/internal/enum_name_transform_v.hpp`
  (mirroring `enum_names_only_v.hpp` with `std::remove_pointer_t`).
- Adds `EnumCamelCaseToSnakeCase` for parity with `rfl::CamelCaseToSnakeCase` (munich-data-engineering#588).
- Accepts variadic `class... Ps` on `rfl::enum_to_string` and `rfl::string_to_enum`,
  strips `std::remove_cvref_t<EnumType>`, and guards `config::enum_descriptions`
  so untransformed enums avoid static heap caches.

Refs: munich-data-engineering#731
(Maintainer: "My first instinct would be a processor, but I need to give it some thought.")
Downstream receipts:
- NVIDIA/cuda-quantum maintains 4 hand-written `rfl::Reflector<E>` switch tables
  for `snake_case` -> `kebab-case` YAML enums:
  https://github.com/NVIDIA/cuda-quantum/blob/81ef20d9d4a1e0912a6dbc68637ece017e8fd324/cudaq/lib/Target/Yaml/TargetConfigYamlAdapters.h#L27-L75
  https://github.com/NVIDIA/cuda-quantum/blob/81ef20d9d4a1e0912a6dbc68637ece017e8fd324/cudaq/lib/Target/Yaml/v2/QuakeUnmappedProfileYaml.h#L16-L53
- openmoq/moqx duplicates `enum class QuicStack` as `rfl::Literal` + switch mapper:
  https://github.com/openmoq/moqx/blob/60bab7f13925acbaf578670223e660d71e891547/src/config/loader/ParsedConfig.h#L291
- munich-data-engineering/sqlgen post-processes `enum_to_string` across all 4 SQL backends:
  https://github.com/munich-data-engineering/sqlgen/blob/265b0a174b661c5905b874f97b064aecb4cded70/src/sqlgen/sqlite/to_sql.cpp#L338-L340
- games-on-whales/wolf lowercases `enum_to_string`:
  https://github.com/games-on-whales/wolf/blob/ac2461f68feda41fdc7a7c8e812b9ab4b80520b7/src/moonlight-server/api/openapi.cpp#L92
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant