added a new method of implementing a custom parser using a Reflector … (#142)

Co-authored-by: Daedie <daedie@gmail.com>
This commit is contained in:
BjornSAIM
2024-07-07 22:41:31 +02:00
committed by GitHub
co-authored by Daedie
parent 1ff7f762f1
commit 6dadbc2506
4 changed files with 91 additions and 3 deletions
+22 -1
View File
@@ -1,7 +1,28 @@
# Custom parsers
If you absolutely do not want to make any changes to your original classes whatsoever,
you can implement a custom parser using `rfl::parsing::CustomParser`.
You can create a Reflector template specialization for your type:
```cpp
namespace rfl {
template <>
struct Reflector<Person> {
struct ReflType {
std::string first_name;
std::string last_name;
};
static constexpr Person to(const ReflType& v) noexcept {
return {v.first_name, v.last_name};
}
static constexpr ReflType from(const Person& v) {
return {v.first_name, v.last_name};
}
};
}
```
Alternatively, you can implement a custom parser using `rfl::parsing::CustomParser`.
In order to do so, you must do the following: