-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
43ebb0b
commit 1eed713
Showing
11 changed files
with
162 additions
and
17 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
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
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
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,18 @@ | ||
#ifndef RFL_NOOPTIONALS_HPP_ | ||
#define RFL_NOOPTIONALS_HPP_ | ||
|
||
namespace rfl { | ||
|
||
/// This is a "fake" processor - it doesn't do much in itself, but its | ||
/// inclusion instructs the parsers to require the inclusion of all fields. | ||
struct NoOptionals { | ||
public: | ||
template <class StructType> | ||
static auto process(auto&& _named_tuple) { | ||
return _named_tuple; | ||
} | ||
}; | ||
|
||
} // namespace rfl | ||
|
||
#endif |
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
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,29 @@ | ||
#ifndef RFL_INTERNAL_ISNOOPTIONALS_HPP_ | ||
#define RFL_INTERNAL_ISNOOPTIONALS_HPP_ | ||
|
||
#include <tuple> | ||
#include <type_traits> | ||
#include <utility> | ||
|
||
#include "../NoOptionals.hpp" | ||
|
||
namespace rfl { | ||
namespace internal { | ||
|
||
template <class T> | ||
class is_no_optionals; | ||
|
||
template <class T> | ||
class is_no_optionals : public std::false_type {}; | ||
|
||
template <> | ||
class is_no_optionals<NoOptionals> : public std::true_type {}; | ||
|
||
template <class T> | ||
constexpr bool is_no_optionals_v = | ||
is_no_optionals<std::remove_cvref_t<std::remove_pointer_t<T>>>::value; | ||
|
||
} // namespace internal | ||
} // namespace rfl | ||
|
||
#endif |
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
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
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
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 <iostream> | ||
#include <rfl.hpp> | ||
#include <rfl/json.hpp> | ||
#include <source_location> | ||
#include <string> | ||
#include <vector> | ||
|
||
#include "write_and_read.hpp" | ||
|
||
namespace test_no_optionals { | ||
|
||
struct Person { | ||
rfl::Rename<"firstName", std::string> first_name; | ||
rfl::Rename<"lastName", std::string> last_name = "Simpson"; | ||
rfl::Rename<"children", std::optional<std::vector<Person>>> children; | ||
}; | ||
|
||
TEST(json, test_no_optionals) { | ||
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<rfl::NoOptionals>( | ||
homer, | ||
R"({"firstName":"Homer","lastName":"Simpson","children":[{"firstName":"Bart","lastName":"Simpson","children":null},{"firstName":"Lisa","lastName":"Simpson","children":null},{"firstName":"Maggie","lastName":"Simpson","children":null}]})"); | ||
} | ||
} // namespace test_no_optionals |
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