@@ -35,16 +35,143 @@ enum class element_type {
3535 * References an element in a JSON document, representing a JSON null, boolean, string, number,
3636 * array or object.
3737 */
38- class element : protected internal ::tape_ref {
38+ class element {
3939public:
4040 /* * Create a new, invalid element. */
4141 really_inline element () noexcept ;
4242
4343 /* * The type of this element. */
4444 really_inline element_type type () const noexcept ;
4545
46- /* * Whether this element is a json `null`. */
47- really_inline bool is_null () const noexcept ;
46+ /* *
47+ * Cast this element to an array.
48+ *
49+ * Equivalent to get<array>().
50+ *
51+ * @returns An object that can be used to iterate the array, or:
52+ * INCORRECT_TYPE if the JSON element is not an array.
53+ */
54+ inline simdjson_result<array> get_array () const noexcept ;
55+ /* *
56+ * Cast this element to an object.
57+ *
58+ * Equivalent to get<object>().
59+ *
60+ * @returns An object that can be used to look up or iterate the object's fields, or:
61+ * INCORRECT_TYPE if the JSON element is not an object.
62+ */
63+ inline simdjson_result<object> get_object () const noexcept ;
64+ /* *
65+ * Cast this element to a string.
66+ *
67+ * Equivalent to get<const char *>().
68+ *
69+ * @returns An pointer to a null-terminated string. This string is stored in the parser and will
70+ * be invalidated the next time it parses a document or when it is destroyed.
71+ * Returns INCORRECT_TYPE if the JSON element is not a string.
72+ */
73+ inline simdjson_result<const char *> get_c_str () const noexcept ;
74+ /* *
75+ * Cast this element to a string.
76+ *
77+ * Equivalent to get<std::string_view>().
78+ *
79+ * @returns A string. The string is stored in the parser and will be invalidated the next time it
80+ * parses a document or when it is destroyed.
81+ * Returns INCORRECT_TYPE if the JSON element is not a string.
82+ */
83+ inline simdjson_result<std::string_view> get_string () const noexcept ;
84+ /* *
85+ * Cast this element to a signed integer.
86+ *
87+ * Equivalent to get<int64_t>().
88+ *
89+ * @returns A signed 64-bit integer.
90+ * Returns INCORRECT_TYPE if the JSON element is not an integer, or NUMBER_OUT_OF_RANGE
91+ * if it is negative.
92+ */
93+ inline simdjson_result<int64_t > get_int64_t () const noexcept ;
94+ /* *
95+ * Cast this element to an unsigned integer.
96+ *
97+ * Equivalent to get<uint64_t>().
98+ *
99+ * @returns An unsigned 64-bit integer.
100+ * Returns INCORRECT_TYPE if the JSON element is not an integer, or NUMBER_OUT_OF_RANGE
101+ * if it is too large.
102+ */
103+ inline simdjson_result<uint64_t > get_uint64_t () const noexcept ;
104+ /* *
105+ * Cast this element to an double floating-point.
106+ *
107+ * Equivalent to get<double>().
108+ *
109+ * @returns A double value.
110+ * Returns INCORRECT_TYPE if the JSON element is not a number.
111+ */
112+ inline simdjson_result<double > get_double () const noexcept ;
113+ /* *
114+ * Cast this element to a bool.
115+ *
116+ * Equivalent to get<bool>().
117+ *
118+ * @returns A bool value.
119+ * Returns INCORRECT_TYPE if the JSON element is not a boolean.
120+ */
121+ inline simdjson_result<bool > get_bool () const noexcept ;
122+
123+ /* *
124+ * Whether this element is a json array.
125+ *
126+ * Equivalent to is<array>().
127+ */
128+ inline bool is_array () const noexcept ;
129+ /* *
130+ * Whether this element is a json object.
131+ *
132+ * Equivalent to is<object>().
133+ */
134+ inline bool is_object () const noexcept ;
135+ /* *
136+ * Whether this element is a json string.
137+ *
138+ * Equivalent to is<std::string_view>() or is<const char *>().
139+ */
140+ inline bool is_string () const noexcept ;
141+ /* *
142+ * Whether this element is a json number that fits in a signed 64-bit integer.
143+ *
144+ * Equivalent to is<int64_t>().
145+ */
146+ inline bool is_int64_t () const noexcept ;
147+ /* *
148+ * Whether this element is a json number that fits in an unsigned 64-bit integer.
149+ *
150+ * Equivalent to is<uint64_t>().
151+ */
152+ inline bool is_uint64_t () const noexcept ;
153+ /* *
154+ * Whether this element is a json number that fits in a double.
155+ *
156+ * Equivalent to is<double>().
157+ */
158+ inline bool is_double () const noexcept ;
159+ /* *
160+ * Whether this element is a json number.
161+ *
162+ * Both integers and floating points will return true.
163+ */
164+ inline bool is_number () const noexcept ;
165+ /* *
166+ * Whether this element is a json `true` or `false`.
167+ *
168+ * Equivalent to is<bool>().
169+ */
170+ inline bool is_bool () const noexcept ;
171+ /* *
172+ * Whether this element is a json `null`.
173+ */
174+ inline bool is_null () const noexcept ;
48175
49176 /* *
50177 * Tell whether the value can be cast to provided type (T).
@@ -249,7 +376,8 @@ class element : protected internal::tape_ref {
249376 inline bool dump_raw_tape (std::ostream &out) const noexcept ;
250377
251378private:
252- really_inline element (const document *doc, size_t json_index) noexcept ;
379+ really_inline element (const internal::tape_ref &tape) noexcept ;
380+ internal::tape_ref tape;
253381 friend class document ;
254382 friend class object ;
255383 friend class array ;
@@ -289,12 +417,29 @@ struct simdjson_result<dom::element> : public internal::simdjson_result_base<dom
289417 really_inline simdjson_result (error_code error) noexcept ; // /< @private
290418
291419 inline simdjson_result<dom::element_type> type () const noexcept ;
292- inline simdjson_result<bool > is_null () const noexcept ;
293420 template <typename T>
294421 inline simdjson_result<bool > is () const noexcept ;
295422 template <typename T>
296423 inline simdjson_result<T> get () const noexcept ;
297424
425+ inline simdjson_result<dom::array> get_array () const noexcept ;
426+ inline simdjson_result<dom::object> get_object () const noexcept ;
427+ inline simdjson_result<const char *> get_c_str () const noexcept ;
428+ inline simdjson_result<std::string_view> get_string () const noexcept ;
429+ inline simdjson_result<int64_t > get_int64_t () const noexcept ;
430+ inline simdjson_result<uint64_t > get_uint64_t () const noexcept ;
431+ inline simdjson_result<double > get_double () const noexcept ;
432+ inline simdjson_result<bool > get_bool () const noexcept ;
433+
434+ inline simdjson_result<bool > is_array () const noexcept ;
435+ inline simdjson_result<bool > is_object () const noexcept ;
436+ inline simdjson_result<bool > is_string () const noexcept ;
437+ inline simdjson_result<bool > is_int64_t () const noexcept ;
438+ inline simdjson_result<bool > is_uint64_t () const noexcept ;
439+ inline simdjson_result<bool > is_double () const noexcept ;
440+ inline simdjson_result<bool > is_bool () const noexcept ;
441+ inline simdjson_result<bool > is_null () const noexcept ;
442+
298443 inline simdjson_result<dom::element> operator [](const std::string_view &key) const noexcept ;
299444 inline simdjson_result<dom::element> operator [](const char *key) const noexcept ;
300445 inline simdjson_result<dom::element> at (const std::string_view &json_pointer) const noexcept ;
0 commit comments