-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add json traits. Refactor rapid/boost dom parsing (#52)
- Loading branch information
1 parent
d913634
commit d80fa83
Showing
15 changed files
with
550 additions
and
340 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
2 changes: 1 addition & 1 deletion
2
include/tgbm/tools/json_tools/generator_parser/discriminated_api.hpp
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,54 @@ | ||
#pragma once | ||
|
||
#include <concepts> | ||
#include <cstdint> | ||
#include <string_view> | ||
#include <ranges> | ||
|
||
namespace tgbm::json { | ||
template <typename Traits, typename Json = typename Traits::type> | ||
concept json_traits = requires(const Json& json, std::string_view str, std::size_t sz) { | ||
requires std::same_as<typename Traits::type, Json>; | ||
|
||
{ Traits::is_bool(json) } -> std::same_as<bool>; | ||
|
||
{ Traits::is_integer(json) } -> std::same_as<bool>; | ||
|
||
{ Traits::is_uinteger(json) } -> std::same_as<bool>; | ||
|
||
{ Traits::is_floating(json) } -> std::same_as<bool>; | ||
|
||
{ Traits::is_string(json) } -> std::same_as<bool>; | ||
|
||
{ Traits::is_object(json) } -> std::same_as<bool>; | ||
|
||
{ Traits::is_array(json) } -> std::same_as<bool>; | ||
|
||
{ Traits::is_object(json) } -> std::same_as<bool>; | ||
|
||
{ Traits::is_null(json) } -> std::same_as<bool>; | ||
|
||
{ Traits::get_bool(json) } -> std::same_as<bool>; | ||
|
||
{ Traits::on_error() }; | ||
|
||
{ Traits::get_integer(json) } -> std::same_as<std::int64_t>; | ||
|
||
{ Traits::get_uinteger(json) } -> std::same_as<std::uint64_t>; | ||
|
||
{ Traits::get_string(json) } -> std::convertible_to<std::string_view>; | ||
|
||
{ Traits::get_floating(json) } -> std::same_as<double>; | ||
|
||
{ Traits::find_field(json, str) }; | ||
|
||
{ Traits::element_by_index(json, sz) } -> std::same_as<const Json&>; | ||
|
||
{ Traits::size(json) } -> std::same_as<std::size_t>; | ||
|
||
{ Traits::member_range(json) } -> std::ranges::range; | ||
}; | ||
|
||
template <typename T> | ||
struct default_json_traits {}; | ||
} // namespace tgbm::json |
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,9 @@ | ||
#pragma once | ||
|
||
#include <tgbm/tools/json_tools/parse_dom/array.hpp> | ||
#include <tgbm/tools/json_tools/parse_dom/basic.hpp> | ||
#include <tgbm/tools/json_tools/parse_dom/common_api.hpp> | ||
#include <tgbm/tools/json_tools/parse_dom/discriminated_api.hpp> | ||
#include <tgbm/tools/json_tools/parse_dom/fundamental.hpp> | ||
#include <tgbm/tools/json_tools/parse_dom/oneof_field_api_type.hpp> | ||
#include <tgbm/tools/json_tools/parse_dom/optional.hpp> |
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,23 @@ | ||
#pragma once | ||
#include <tgbm/tools/json_tools/parse_dom/basic.hpp> | ||
#include <tgbm/tools/json_tools/json_traits.hpp> | ||
#include <vector> | ||
|
||
namespace tgbm::json::parse_dom { | ||
|
||
template <typename T> | ||
struct parser<std::vector<T>> { | ||
template <typename Json, json::json_traits Traits> | ||
static void parse(const Json& json, std::vector<T>& out) { | ||
if (!Traits::is_array(json)) { | ||
Traits::on_error(); | ||
} | ||
std::size_t size = Traits::size(json); | ||
out.reserve(size); | ||
for (std::size_t i = 0; i < size; i++) { | ||
auto& element_node = Traits::element_by_index(json, i); | ||
parser<T>::template parse<Json, Traits>(element_node, out.emplace_back()); | ||
} | ||
} | ||
}; | ||
} // namespace tgbm::json::parse_dom |
Oops, something went wrong.