-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
04aa71c
commit 571ea68
Showing
59 changed files
with
1,335 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include "test_array.hpp" | ||
|
||
#include <array> | ||
#include <iostream> | ||
#include <memory> | ||
#include <rfl/yaml.hpp> | ||
#include <source_location> | ||
#include <string> | ||
|
||
// Make sure things still compile when | ||
// rfl.hpp is included after rfl/yaml.hpp. | ||
#include <rfl.hpp> | ||
|
||
#include "write_and_read.hpp" | ||
|
||
namespace test_array { | ||
|
||
struct Person { | ||
rfl::Rename<"firstName", std::string> first_name; | ||
rfl::Rename<"lastName", std::string> last_name = "Simpson"; | ||
std::unique_ptr<std::array<Person, 3>> children = nullptr; | ||
}; | ||
|
||
void test() { | ||
std::cout << std::source_location::current().function_name() << std::endl; | ||
|
||
auto bart = Person{.first_name = "Bart"}; | ||
|
||
auto lisa = Person{.first_name = "Lisa"}; | ||
|
||
auto maggie = Person{.first_name = "Maggie"}; | ||
|
||
const auto homer = Person{ | ||
.first_name = "Homer", | ||
.children = std::make_unique<std::array<Person, 3>>(std::array<Person, 3>{ | ||
std::move(bart), std::move(lisa), std::move(maggie)})}; | ||
|
||
write_and_read(homer); | ||
} | ||
} // namespace test_array |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
namespace test_array{ | ||
void test(); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#include "test_box.hpp" | ||
|
||
#include <cassert> | ||
#include <iostream> | ||
#include <rfl.hpp> | ||
#include <rfl/json.hpp> | ||
#include <source_location> | ||
#include <string> | ||
#include <vector> | ||
|
||
#include "write_and_read.hpp" | ||
|
||
namespace test_box { | ||
|
||
struct DecisionTree { | ||
struct Leaf { | ||
using Tag = rfl::Literal<"Leaf">; | ||
double value; | ||
}; | ||
|
||
struct Node { | ||
using Tag = rfl::Literal<"Node">; | ||
rfl::Rename<"criticalValue", double> critical_value; | ||
rfl::Box<DecisionTree> lesser; | ||
rfl::Box<DecisionTree> greater; | ||
}; | ||
|
||
using LeafOrNode = rfl::TaggedUnion<"type", Leaf, Node>; | ||
|
||
rfl::Field<"leafOrNode", LeafOrNode> leaf_or_node; | ||
}; | ||
|
||
void test() { | ||
std::cout << std::source_location::current().function_name() << std::endl; | ||
|
||
auto leaf1 = DecisionTree::Leaf{.value = 3.0}; | ||
|
||
auto leaf2 = DecisionTree::Leaf{.value = 5.0}; | ||
|
||
auto node = DecisionTree::Node{ | ||
.critical_value = 10.0, | ||
.lesser = rfl::make_box<DecisionTree>(DecisionTree{leaf1}), | ||
.greater = rfl::make_box<DecisionTree>(DecisionTree{leaf2})}; | ||
|
||
const DecisionTree tree{.leaf_or_node = std::move(node)}; | ||
|
||
write_and_read(tree); | ||
|
||
} | ||
} // namespace test_box |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
namespace test_box{ | ||
void test(); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include "test_custom_class1.hpp" | ||
|
||
#include <cassert> | ||
#include <iostream> | ||
#include <rfl.hpp> | ||
#include <rfl/json.hpp> | ||
#include <source_location> | ||
#include <string> | ||
#include <vector> | ||
|
||
#include "write_and_read.hpp" | ||
|
||
namespace test_custom_class1 { | ||
|
||
struct Person { | ||
struct PersonImpl { | ||
rfl::Rename<"firstName", std::string> first_name; | ||
rfl::Rename<"lastName", std::string> last_name = "Simpson"; | ||
std::vector<Person> children; | ||
}; | ||
|
||
using ReflectionType = PersonImpl; | ||
|
||
Person(const PersonImpl& _impl) : impl(_impl) {} | ||
|
||
Person(const std::string& _first_name) | ||
: impl(PersonImpl{.first_name = _first_name}) {} | ||
|
||
const ReflectionType& reflection() const { return impl; }; | ||
|
||
private: | ||
PersonImpl impl; | ||
}; | ||
|
||
void test() { | ||
std::cout << std::source_location::current().function_name() << std::endl; | ||
|
||
const auto bart = Person("Bart"); | ||
|
||
write_and_read(bart); | ||
} | ||
} // namespace test_custom_class1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
namespace test_custom_class1{ | ||
void test(); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#include "test_custom_class3.hpp" | ||
|
||
#include <cassert> | ||
#include <iostream> | ||
#include <rfl.hpp> | ||
#include <rfl/json.hpp> | ||
#include <source_location> | ||
#include <string> | ||
#include <vector> | ||
|
||
#include "write_and_read.hpp" | ||
|
||
namespace test_custom_class3 { | ||
|
||
struct Person { | ||
Person(const std::string& _first_name, const std::string& _last_name, | ||
const int _age) | ||
: first_name_(_first_name), last_name_(_last_name), age_(_age) {} | ||
|
||
const auto& first_name() const { return first_name_; } | ||
|
||
const auto& last_name() const { return last_name_; } | ||
|
||
auto age() const { return age_; } | ||
|
||
private: | ||
std::string first_name_; | ||
std::string last_name_; | ||
int age_; | ||
}; | ||
|
||
struct PersonImpl { | ||
rfl::Rename<"firstName", std::string> first_name; | ||
rfl::Rename<"lastName", std::string> last_name; | ||
int age; | ||
|
||
static PersonImpl from_class(const Person& _p) noexcept { | ||
return PersonImpl{.first_name = _p.first_name(), | ||
.last_name = _p.last_name(), | ||
.age = _p.age()}; | ||
} | ||
|
||
Person to_class() const { return Person(first_name(), last_name(), age); } | ||
}; | ||
} // namespace test_custom_class3 | ||
|
||
namespace rfl { | ||
namespace parsing { | ||
|
||
template <class ReaderType, class WriterType> | ||
struct Parser<ReaderType, WriterType, test_custom_class3::Person> | ||
: public CustomParser<ReaderType, WriterType, test_custom_class3::Person, | ||
test_custom_class3::PersonImpl> {}; | ||
|
||
} // namespace parsing | ||
} // namespace rfl | ||
|
||
namespace test_custom_class3 { | ||
|
||
void test() { | ||
std::cout << std::source_location::current().function_name() << std::endl; | ||
|
||
const auto bart = Person("Bart", "Simpson", 10); | ||
|
||
write_and_read(bart); | ||
} | ||
|
||
} // namespace test_custom_class3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
namespace test_custom_class3{ | ||
void test(); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#include "test_custom_class4.hpp" | ||
|
||
#include <cassert> | ||
#include <iostream> | ||
#include <rfl.hpp> | ||
#include <rfl/json.hpp> | ||
#include <source_location> | ||
#include <string> | ||
#include <vector> | ||
|
||
#include "write_and_read.hpp" | ||
|
||
namespace test_custom_class4 { | ||
|
||
struct Person { | ||
Person(const std::string& _first_name, | ||
const rfl::Box<std::string>& _last_name, int _age) | ||
: first_name_(_first_name), | ||
last_name_(rfl::make_box<std::string>(*_last_name)), | ||
age_(_age) {} | ||
|
||
const auto& first_name() const { return first_name_; } | ||
|
||
const auto& last_name() const { return last_name_; } | ||
|
||
auto age() const { return age_; } | ||
|
||
private: | ||
std::string first_name_; | ||
rfl::Box<std::string> last_name_; | ||
int age_; | ||
}; | ||
|
||
struct PersonImpl { | ||
rfl::Field<"firstName", std::string> first_name; | ||
rfl::Field<"lastName", rfl::Box<std::string>> last_name; | ||
rfl::Field<"age", int> age; | ||
|
||
static PersonImpl from_class(const Person& _p) noexcept { | ||
return PersonImpl{.first_name = _p.first_name(), | ||
.last_name = rfl::make_box<std::string>(*_p.last_name()), | ||
.age = _p.age()}; | ||
} | ||
}; | ||
|
||
} // namespace test_custom_class4 | ||
|
||
namespace rfl { | ||
namespace parsing { | ||
|
||
template <class ReaderType, class WriterType> | ||
struct Parser<ReaderType, WriterType, test_custom_class4::Person> | ||
: public CustomParser<ReaderType, WriterType, test_custom_class4::Person, | ||
test_custom_class4::PersonImpl> {}; | ||
|
||
} // namespace parsing | ||
} // namespace rfl | ||
|
||
namespace test_custom_class4 { | ||
|
||
void test() { | ||
std::cout << std::source_location::current().function_name() << std::endl; | ||
|
||
const auto bart = test_custom_class4::Person( | ||
"Bart", rfl::make_box<std::string>("Simpson"), 10); | ||
|
||
write_and_read(bart); | ||
} | ||
} // namespace test_custom_class4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
namespace test_custom_class4{ | ||
void test(); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#include "test_default_values.hpp" | ||
|
||
#include <cassert> | ||
#include <iostream> | ||
#include <rfl.hpp> | ||
#include <source_location> | ||
#include <string> | ||
#include <vector> | ||
|
||
#include "write_and_read.hpp" | ||
|
||
namespace test_default_values { | ||
|
||
struct Person { | ||
rfl::Rename<"firstName", std::string> first_name; | ||
rfl::Rename<"lastName", std::string> last_name = "Simpson"; | ||
std::vector<Person> children; | ||
}; | ||
|
||
void test() { | ||
std::cout << std::source_location::current().function_name() << std::endl; | ||
|
||
const auto bart = Person{.first_name = "Bart"}; | ||
const auto lisa = Person{.first_name = "Lisa"}; | ||
const auto maggie = Person{.first_name = "Maggie"}; | ||
const auto homer = | ||
Person{.first_name = "Homer", | ||
.children = std::vector<Person>({bart, lisa, maggie})}; | ||
|
||
write_and_read(homer); | ||
} | ||
} // namespace test_default_values |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
namespace test_default_values{ | ||
void test(); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#include "test_deque.hpp" | ||
|
||
#include <iostream> | ||
#include <rfl.hpp> | ||
#include <source_location> | ||
#include <string> | ||
#include <vector> | ||
|
||
#include "write_and_read.hpp" | ||
|
||
namespace test_deque { | ||
|
||
struct Person { | ||
rfl::Rename<"firstName", std::string> first_name; | ||
rfl::Rename<"lastName", std::string> last_name = "Simpson"; | ||
std::unique_ptr<std::deque<Person>> children; | ||
}; | ||
|
||
void test() { | ||
std::cout << std::source_location::current().function_name() << std::endl; | ||
|
||
auto children = std::make_unique<std::deque<Person>>(); | ||
children->emplace_back(Person{.first_name = "Bart"}); | ||
children->emplace_back(Person{.first_name = "Lisa"}); | ||
children->emplace_back(Person{.first_name = "Maggie"}); | ||
|
||
const auto homer = | ||
Person{.first_name = "Homer", .children = std::move(children)}; | ||
|
||
write_and_read(homer); | ||
|
||
} | ||
} // namespace test_deque |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
namespace test_deque{ | ||
void test(); | ||
} | ||
|
Oops, something went wrong.