DAW JSON Link
daw_from_json_fwd.h
Go to the documentation of this file.
1// Copyright (c) Darrell Wright
2//
3// Distributed under the Boost Software License, version 1.0. (see accompanying
4// file LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt)
5//
6// Official repository: https://github.com/beached/daw_json_link
7//
8
9#pragma once
10
14#include "impl/version.h"
15
16#include <ciso646>
17#include <string_view>
18
19namespace daw::json {
20 inline namespace DAW_JSON_VER {
33 template<typename JsonMember,
34 typename ParsePolicy = NoCommentSkippingPolicyChecked,
35 bool KnownBounds = false,
36 typename Result = json_details::from_json_result_t<JsonMember>,
37 typename String>
38 [[maybe_unused, nodiscard]] constexpr auto from_json( String &&json_data )
39 -> std::enable_if_t<json_details::is_string_view_like_v<String>, Result>;
40
51 template<typename JsonMember,
52 typename ParsePolicy = NoCommentSkippingPolicyChecked,
53 bool KnownBounds = false,
54 typename Result = json_details::from_json_result_t<JsonMember>,
55 typename String, typename Allocator>
56 [[maybe_unused, nodiscard]] constexpr auto
57 from_json_alloc( String &&json_data, Allocator const &alloc )
58 -> std::enable_if_t<json_details::is_string_view_like_v<String>, Result>;
59
60 /***
61 * Parse a JSONMember from the json_data starting at member_path.
62 * @tparam JsonMember The type of the item being parsed
63 * @param json_data JSON string data
64 * @param member_path A dot separated path of member names, default is the
65 * root. Array indices are specified with square brackets e.g. [5] is the
66 * 6th item
67 * @tparam KnownBounds The bounds of the json_data are known to contain the
68 * whole value
69 * @return A value reified from the JSON data member
70 * @throws daw::json::json_exception
71 */
72 template<typename JsonMember,
73 typename ParsePolicy = NoCommentSkippingPolicyChecked,
74 bool KnownBounds = false,
75 typename Result = json_details::from_json_result_t<JsonMember>,
76 typename String>
77 [[maybe_unused, nodiscard]] constexpr auto
78 from_json( String &&json_data, std::string_view member_path )
79 -> std::enable_if_t<json_details::is_string_view_like_v<String>, Result>;
80
81 /***
82 * Parse a JSONMember from the json_data starting at member_path.
83 * @tparam JsonMember The type of the item being parsed
84 * @param json_data JSON string data
85 * @param member_path A dot separated path of member names, default is the
86 * root. Array indices are specified with square brackets e.g. [5] is the
87 * 6th item
88 * @tparam KnownBounds The bounds of the json_data are known to contain the
89 * whole value
90 * @return A value reified from the JSON data member
91 * @throws daw::json::json_exception
92 */
93 template<typename JsonMember,
94 typename ParsePolicy = NoCommentSkippingPolicyChecked,
95 bool KnownBounds = false,
96 typename Result = json_details::from_json_result_t<JsonMember>,
97 typename String, typename Allocator>
98 [[maybe_unused, nodiscard]] constexpr auto
99 from_json_alloc( String &&json_data, std::string_view member_path,
100 Allocator const &alloc )
101 -> std::enable_if_t<json_details::is_string_view_like_v<String>, Result>;
102
103 /***
104 * Parse a value from a json_value
105 * @tparam JsonMember The type of the item being parsed
106 * @param value JSON data, see basic_json_value
107 * @tparam KnownBounds The bounds of the json_data are known to contain the
108 * whole value
109 * @return A value reified from the JSON data member
110 * @throws daw::json::json_exception
111 */
112 template<typename JsonMember,
113 typename ParsePolicy = NoCommentSkippingPolicyChecked,
114 bool KnownBounds = false,
115 typename Result = json_details::from_json_result_t<JsonMember>,
116 typename ParseState>
117 [[maybe_unused, nodiscard]] inline constexpr Result
118 from_json( basic_json_value<ParseState> value );
119
120 /***
121 * Parse a JSONMember from the json_data starting at member_path.
122 * @param value JSON data, see basic_json_value
123 * @param member_path A dot separated path of member names, default is the
124 * root. Array indices are specified with square brackets e.g. [5] is the
125 * 6th item
126 * @tparam JsonMember The type of the item being parsed
127 * @tparam KnownBounds The bounds of the json_data are known to contain the
128 * whole value
129 * @return A value reified from the JSON data member
130 * @throws daw::json::json_exception
131 */
132 template<typename JsonMember,
133 typename ParsePolicy = NoCommentSkippingPolicyChecked,
134 bool KnownBounds = false,
135 typename Result = json_details::from_json_result_t<JsonMember>,
136 typename ParseState>
137 [[maybe_unused, nodiscard]] constexpr Result
138 from_json( basic_json_value<ParseState> value,
139 std::string_view member_path );
140
156 template<typename JsonElement,
157 typename Container =
158 std::vector<json_details::from_json_result_t<JsonElement>>,
159 typename ParsePolicy = NoCommentSkippingPolicyChecked,
160 typename Constructor = default_constructor<Container>,
161 bool KnownBounds = false, typename String>
162 [[maybe_unused, nodiscard]] constexpr auto
163 from_json_array( String &&json_data, std::string_view member_path = "" )
164 -> std::enable_if_t<json_details::is_string_view_like_v<String>,
165 Container>;
166 } // namespace DAW_JSON_VER
167} // namespace daw::json
constexpr auto from_json_alloc(String &&json_data, Allocator const &alloc) -> std::enable_if_t< json_details::is_string_view_like_v< String >, Result >
Definition: daw_from_json.h:95
constexpr auto from_json_array(String &&json_data, std::string_view member_path) -> std::enable_if_t< json_details::is_string_view_like_v< String >, Container >
Definition: daw_from_json.h:369
constexpr auto from_json(String &&json_data) -> std::enable_if_t< json_details::is_string_view_like_v< String >, Result >
Definition: daw_from_json.h:36
BasicParsePolicy<> NoCommentSkippingPolicyChecked
Definition: daw_json_parse_policy.h:550
Definition: daw_from_json.h:22
#define DAW_JSON_VER
The version string used in namespace definitions. Must be a valid namespace name.
Definition: version.h:16