You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+44-19Lines changed: 44 additions & 19 deletions
Original file line number
Diff line number
Diff line change
@@ -23,20 +23,22 @@ Design principles for reflect-cpp include:
23
23
- Simple extendability to custom classes
24
24
- Standard C++ only, no compiler-specific macros
25
25
26
-
## Why do we need this?
27
-
28
-
Suppose your C++ program has complex data structures it needs to save and load. Or maybe it needs to interact with some kind of external API. If you do this the traditional way, you will have a lot of boilerplate code. This is annoying and error-prone.
26
+
## Serialization formats
29
27
30
-
reflect-cpp is not just a reflection library, it is for **serialization, deserialization and validation** through reflection.
28
+
reflect-cpp provides a unified reflection-based interface across different serialization formats. It is deliberately designed in a very modular way, using [concepts](https://en.cppreference.com/w/cpp/language/constraints), to make it as easy as possible to interface various C or C++ libraries related to serialization. Refer to the [documentation](https://github.com/getml/reflect-cpp/tree/main/docs) for details.
31
29
32
-
That means that you can encode your requirements about the input data in the type system and have them validated upfront. This is why the library also includes algebraic data types like tagged unions and numerous validation routines. Having your requirements encoded in the type system is the most reliable way of ensuring they are met. If your requirements are not met, the user of your software gets a very clear error message. Encoding your requirements in the type system also makes it a lot easier for anyone reading your code.
30
+
The following table lists the serialization formats currently supported by reflect-cpp and the underlying libraries used:
33
31
34
-
This increases user experience and developer experience, it makes your code safer (fewer bugs) and more secure (less prone to malicious attacks).
32
+
| Format | Library | Version | License | Remarks |
auto homer2 = rfl::yaml::read<Person>(yaml_string).value();
81
+
```
82
+
83
+
The resulting YAML string looks like this:
84
+
85
+
```yaml
86
+
first_name: Homer
87
+
last_name: Simpson
88
+
age: 45
89
+
```
90
+
69
91
## More Comprehensive Example
70
92
71
93
```cpp
@@ -361,19 +383,20 @@ In addition, it supports the following custom containers:
361
383
362
384
Finally, it is very easy to extend full support to your own classes, refer to the [documentation](https://github.com/getml/reflect-cpp/tree/main/docs) for details.
363
385
364
-
## Serialization formats
386
+
## Why do we need this?
365
387
366
-
reflect-cpp is deliberately designed in a very modular way, using [concepts](https://en.cppreference.com/w/cpp/language/constraints), to make it as easy as possible to interface C or C++ libraries for various serialization formats. Refer to the [documentation](https://github.com/getml/reflect-cpp/tree/main/docs) for details. PRs related to serialization formats are welcome.
388
+
Suppose your C++ program has complex data structures it needs to save and load. Or maybe it needs to interact with some kind of external API. If you do this the traditional way, you will have a lot of boilerplate code. This is annoying and error-prone.
367
389
368
-
The following table lists the serialization formats currently supported by reflect-cpp and the underlying libraries used:
390
+
reflect-cpp is not just a reflection library, it is for **serialization, deserialization and validation** through reflection.
369
391
370
-
| Format | Library | Version | License | Remarks |
| XML | [pugixml](https://github.com/zeux/pugixml) | >= 1.14 | MIT | |
392
+
That means that you can encode your requirements about the input data in the type system and have them validated upfront. This is why the library also includes algebraic data types like tagged unions and numerous validation routines. Having your requirements encoded in the type system is the most reliable way of ensuring they are met. If your requirements are not met, the user of your software gets a very clear error message. Encoding your requirements in the type system also makes it a lot easier for anyone reading your code.
375
393
376
-
Please also refer to the *vcpkg.json* in this repository.
394
+
This increases user experience and developer experience, it makes your code safer (fewer bugs) and more secure (less prone to malicious attacks).
395
+
396
+
For a more in-depth theoretical discussions of these topics, the following books are warmly recommended:
397
+
398
+
- *Category Theory for Programmers* by Bartosz Milewski (https://github.com/hmemcpy/milewski-ctfp-pdf/releases)
399
+
- *Domain Modeling Made Functional* by Scott Wlaschin
377
400
378
401
## Documentation
379
402
@@ -427,6 +450,7 @@ add_subdirectory(reflect-cpp) # Add this project as a subdirectory
427
450
428
451
set(REFLECTCPP_FLEXBUFFERS ON) # Optional
429
452
set(REFLECTCPP_XML ON) # Optional
453
+
set(REFLECTCPP_YAML ON) # Optional
430
454
431
455
target_link_libraries(your_project PRIVATE reflectcpp) # Link against the library
432
456
```
@@ -470,7 +494,7 @@ git submodule update --init
470
494
./vcpkg/bootstrap-vcpkg.bat # Windows
471
495
# You may be prompted to install additional dependencies.
6.1) [Supporting your own format](https://github.com/getml/reflect-cpp/blob/main/docs/supporting_your_own_format.md) - For supporting your own serialization and deserialization formats.
0 commit comments