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:
AnsiV01
2024-09-12 09:37:31 +02:00
committed by GitHub
parent 7274a2eb47
commit dfc24ad932
7 changed files with 124 additions and 7 deletions
+25
View File
@@ -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.