simdjson  3.11.0
Ridiculously Fast JSON
object.h
1 #ifndef SIMDJSON_GENERIC_ONDEMAND_OBJECT_H
2 
3 #ifndef SIMDJSON_CONDITIONAL_INCLUDE
4 #define SIMDJSON_GENERIC_ONDEMAND_OBJECT_H
5 #include "simdjson/generic/ondemand/base.h"
6 #include "simdjson/generic/implementation_simdjson_result_base.h"
7 #include "simdjson/generic/ondemand/value_iterator.h"
8 #endif // SIMDJSON_CONDITIONAL_INCLUDE
9 
10 namespace simdjson {
11 namespace SIMDJSON_IMPLEMENTATION {
12 namespace ondemand {
13 
17 class object {
18 public:
24  simdjson_inline object() noexcept = default;
25 
26  simdjson_inline simdjson_result<object_iterator> begin() noexcept;
27  simdjson_inline simdjson_result<object_iterator> end() noexcept;
64  simdjson_inline simdjson_result<value> find_field(std::string_view key) & noexcept;
66  simdjson_inline simdjson_result<value> find_field(std::string_view key) && noexcept;
67 
103  simdjson_inline simdjson_result<value> find_field_unordered(std::string_view key) & noexcept;
105  simdjson_inline simdjson_result<value> find_field_unordered(std::string_view key) && noexcept;
107  simdjson_inline simdjson_result<value> operator[](std::string_view key) & noexcept;
109  simdjson_inline simdjson_result<value> operator[](std::string_view key) && noexcept;
110 
145  inline simdjson_result<value> at_pointer(std::string_view json_pointer) noexcept;
146 
158  inline simdjson_result<value> at_path(std::string_view json_path) noexcept;
159 
169  inline simdjson_result<bool> reset() & noexcept;
179  inline simdjson_result<bool> is_empty() & noexcept;
197  simdjson_inline simdjson_result<size_t> count_fields() & noexcept;
203  simdjson_inline simdjson_result<std::string_view> raw_json() noexcept;
204 
205 protected:
209  simdjson_inline error_code consume() noexcept;
210  static simdjson_inline simdjson_result<object> start(value_iterator &iter) noexcept;
211  static simdjson_inline simdjson_result<object> start_root(value_iterator &iter) noexcept;
212  static simdjson_inline simdjson_result<object> started(value_iterator &iter) noexcept;
213  static simdjson_inline object resume(const value_iterator &iter) noexcept;
214  simdjson_inline object(const value_iterator &iter) noexcept;
215 
216  simdjson_warn_unused simdjson_inline error_code find_field_raw(const std::string_view key) noexcept;
217 
218  value_iterator iter{};
219 
220  friend class value;
221  friend class document;
222  friend struct simdjson_result<object>;
223 };
224 
225 } // namespace ondemand
226 } // namespace SIMDJSON_IMPLEMENTATION
227 } // namespace simdjson
228 
229 namespace simdjson {
230 
231 template<>
232 struct simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::object> : public SIMDJSON_IMPLEMENTATION::implementation_simdjson_result_base<SIMDJSON_IMPLEMENTATION::ondemand::object> {
233 public:
235  simdjson_inline simdjson_result(error_code error) noexcept;
236  simdjson_inline simdjson_result() noexcept = default;
237 
240  simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> find_field(std::string_view key) & noexcept;
241  simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> find_field(std::string_view key) && noexcept;
242  simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> find_field_unordered(std::string_view key) & noexcept;
243  simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> find_field_unordered(std::string_view key) && noexcept;
244  simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> operator[](std::string_view key) & noexcept;
245  simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> operator[](std::string_view key) && noexcept;
246  simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> at_pointer(std::string_view json_pointer) noexcept;
247  simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> at_path(std::string_view json_path) noexcept;
248 
249  inline simdjson_result<bool> reset() noexcept;
250  inline simdjson_result<bool> is_empty() noexcept;
251  inline simdjson_result<size_t> count_fields() & noexcept;
252  inline simdjson_result<std::string_view> raw_json() noexcept;
253 
254 };
255 
256 } // namespace simdjson
257 
258 #endif // SIMDJSON_GENERIC_ONDEMAND_OBJECT_H
A forward-only JSON object field iterator.
Definition: object.h:17
simdjson_inline object() noexcept=default
Create a new invalid object.
simdjson_inline simdjson_result< value > find_field_unordered(std::string_view key) &noexcept
Look up a field by name on an object, without regard to key order.
Definition: object-inl.h:18
simdjson_inline simdjson_result< std::string_view > raw_json() noexcept
Consumes the object and returns a string_view instance corresponding to the object as represented in ...
Definition: object-inl.h:95
simdjson_inline simdjson_result< value > find_field(std::string_view key) &noexcept
Look up a field by name on an object (order-sensitive).
Definition: object-inl.h:42
simdjson_result< bool > is_empty() &noexcept
This method scans the beginning of the object and checks whether the object is empty.
Definition: object-inl.h:187
simdjson_inline error_code consume() noexcept
Go to the end of the object, no matter where you are right now.
Definition: object-inl.h:69
simdjson_result< bool > reset() &noexcept
Reset the iterator so that we are pointing back at the beginning of the object.
Definition: object-inl.h:194
simdjson_result< value > at_path(std::string_view json_path) noexcept
Get the value associated with the given JSONPath expression.
Definition: object-inl.h:167
simdjson_result< value > at_pointer(std::string_view json_pointer) noexcept
Get the value associated with the given JSON pointer.
Definition: object-inl.h:127
simdjson_inline simdjson_result< size_t > count_fields() &noexcept
This method scans the object and counts the number of key-value pairs.
Definition: object-inl.h:175
An ephemeral JSON value returned during iteration.
Definition: value.h:21
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:215
simdjson_inline error_code error() const noexcept
The error.
Definition: error-inl.h:131
simdjson_inline T & value() &noexcept(false)
Get the result value.