simdjson  3.3.0
Ridiculously Fast JSON
field-inl.h
1 #ifndef SIMDJSON_GENERIC_ONDEMAND_FIELD_INL_H
2 
3 #ifndef SIMDJSON_CONDITIONAL_INCLUDE
4 #define SIMDJSON_GENERIC_ONDEMAND_FIELD_INL_H
5 #include "simdjson/generic/ondemand/base.h"
6 #include "simdjson/generic/ondemand/field.h"
7 #include "simdjson/generic/ondemand/value-inl.h"
8 #include "simdjson/generic/ondemand/value_iterator-inl.h"
9 #endif // SIMDJSON_CONDITIONAL_INCLUDE
10 
11 namespace simdjson {
12 namespace SIMDJSON_IMPLEMENTATION {
13 namespace ondemand {
14 
15 // clang 6 doesn't think the default constructor can be noexcept, so we make it explicit
16 simdjson_inline field::field() noexcept : std::pair<raw_json_string, ondemand::value>() {}
17 
18 simdjson_inline field::field(raw_json_string key, ondemand::value &&value) noexcept
19  : std::pair<raw_json_string, ondemand::value>(key, std::forward<ondemand::value>(value))
20 {
21 }
22 
23 simdjson_inline simdjson_result<field> field::start(value_iterator &parent_iter) noexcept {
24  raw_json_string key;
25  SIMDJSON_TRY( parent_iter.field_key().get(key) );
26  SIMDJSON_TRY( parent_iter.field_value() );
27  return field::start(parent_iter, key);
28 }
29 
30 simdjson_inline simdjson_result<field> field::start(const value_iterator &parent_iter, raw_json_string key) noexcept {
31  return field(key, parent_iter.child());
32 }
33 
34 simdjson_inline simdjson_warn_unused simdjson_result<std::string_view> field::unescaped_key(bool allow_replacement) noexcept {
35  SIMDJSON_ASSUME(first.buf != nullptr); // We would like to call .alive() but Visual Studio won't let us.
36  simdjson_result<std::string_view> answer = first.unescape(second.iter.json_iter(), allow_replacement);
37  first.consume();
38  return answer;
39 }
40 
41 simdjson_inline raw_json_string field::key() const noexcept {
42  SIMDJSON_ASSUME(first.buf != nullptr); // We would like to call .alive() by Visual Studio won't let us.
43  return first;
44 }
45 
46 simdjson_inline value &field::value() & noexcept {
47  return second;
48 }
49 
50 simdjson_inline value field::value() && noexcept {
51  return std::forward<field>(*this).second;
52 }
53 
54 } // namespace ondemand
55 } // namespace SIMDJSON_IMPLEMENTATION
56 } // namespace simdjson
57 
58 namespace simdjson {
59 
60 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::field>::simdjson_result(
61  SIMDJSON_IMPLEMENTATION::ondemand::field &&value
62 ) noexcept :
63  implementation_simdjson_result_base<SIMDJSON_IMPLEMENTATION::ondemand::field>(
64  std::forward<SIMDJSON_IMPLEMENTATION::ondemand::field>(value)
65  )
66 {
67 }
68 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::field>::simdjson_result(
69  error_code error
70 ) noexcept :
71  implementation_simdjson_result_base<SIMDJSON_IMPLEMENTATION::ondemand::field>(error)
72 {
73 }
74 
75 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::raw_json_string> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::field>::key() noexcept {
76  if (error()) { return error(); }
77  return first.key();
78 }
79 simdjson_inline simdjson_result<std::string_view> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::field>::unescaped_key(bool allow_replacement) noexcept {
80  if (error()) { return error(); }
81  return first.unescaped_key(allow_replacement);
82 }
83 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::field>::value() noexcept {
84  if (error()) { return error(); }
85  return std::move(first.value());
86 }
87 
88 } // namespace simdjson
89 
90 #endif // SIMDJSON_GENERIC_ONDEMAND_FIELD_INL_H
simdjson_inline raw_json_string key() const noexcept
Get the key as a raw_json_string.
Definition: field-inl.h:41
simdjson_inline simdjson_warn_unused simdjson_result< std::string_view > unescaped_key(bool allow_replacement) noexcept
Get the key as a string_view (for higher speed, consider raw_key).
Definition: field-inl.h:34
simdjson_inline field() noexcept
Create a new invalid field.
Definition: field-inl.h:16
simdjson_inline ondemand::value & value() &noexcept
Get the field value.
Definition: field-inl.h:46
A string escaped per JSON rules, terminated with quote (").
An ephemeral JSON value returned during iteration.
Definition: value.h:18
The top level simdjson namespace, containing everything the library provides.
Definition: base.h:8
error_code
All possible errors returned by simdjson.
Definition: error.h:19
The result of a simdjson operation that could fail.
Definition: error.h:207
simdjson_inline error_code error() const noexcept
The error.
Definition: error-inl.h:131
simdjson_inline T & value() &noexcept(false)
Get the result value.