mirror of
https://codeberg.org/DawnMagnet/reflect-cpp
synced 2026-12-03 16:56:17 +08:00
rfl::UnderlyingEnums (#186)
* First part * Plural * Update rfl.hpp * Documentation * Update rfl.hpp * Update processors.md * underlying_enums test * Update Parser_default.hpp * Fix typo in test
This commit is contained in:
@@ -34,7 +34,9 @@ The resulting JSON string looks like this:
|
||||
reflect-cpp currently supports the following processors:
|
||||
|
||||
- `rfl::AddStructName`
|
||||
- `rfl::NoFieldNames`
|
||||
- `rfl::NoOptionals`
|
||||
- `rfl::UnderlyingEnums`
|
||||
- `rfl::SnakeCaseToCamelCase`
|
||||
- `rfl::SnakeCaseToPascalCase`
|
||||
|
||||
@@ -117,6 +119,29 @@ leaving out the field `town`. However, if you want to require the field
|
||||
rfl::json::read<Person, rfl::NoOptionals>(json_string);
|
||||
```
|
||||
|
||||
### `rfl::UnderlyingEnums`
|
||||
|
||||
By passing the processor `rfl::UnderlyingEnums`, fields of the enum type will be written and read as integers
|
||||
|
||||
```cpp
|
||||
enum class Color { red, green, blue, yellow };
|
||||
|
||||
struct Circle {
|
||||
float radius;
|
||||
Color color;
|
||||
};
|
||||
|
||||
const auto circle = Circle{.radius = 2.0, .color = Color::green};
|
||||
|
||||
rfl::json::write<rfl::UnderlyingEnums>(circle);
|
||||
```
|
||||
|
||||
The resulting JSON string looks like this:
|
||||
|
||||
```json
|
||||
{"radius":2.0,"color":1}
|
||||
```
|
||||
|
||||
### `rfl::SnakeCaseToCamelCase`
|
||||
|
||||
Please refer to the example above.
|
||||
|
||||
Reference in New Issue
Block a user