From 696b0e29e4d5e9c37a188901d3bdd651a6e9c904 Mon Sep 17 00:00:00 2001 From: Daniel Lemire Date: Tue, 23 Jun 2020 10:47:32 -0400 Subject: [PATCH] Fixing issue 961 --- doc/basics.md | 3 +-- include/simdjson/dom/element.h | 16 ++++++++-------- include/simdjson/inline/element.h | 28 ++++++++++++++-------------- tests/cast_tester.h | 16 ++++++++-------- 4 files changed, 31 insertions(+), 32 deletions(-) diff --git a/doc/basics.md b/doc/basics.md index 35ea7a1b..c4e765b1 100644 --- a/doc/basics.md +++ b/doc/basics.md @@ -77,8 +77,7 @@ Once you have an element, you can navigate it with idiomatic C++ iterators, oper * **Extracting Values:** You can cast a JSON element to a native type: `double(element)` or `double x = json_element`. This works for double, uint64_t, int64_t, bool, - dom::object and dom::array. An exception is thrown if the cast is not possible. You can also use is<*typename*>() to test if it is a - given type, or use the `type()` method: e.g., `element.type() == dom::element_type::DOUBLE`. Instead of casting, you can use get<*typename*>() to get the value: casts and get<*typename*>() can be used interchangeably. You can use a variant usage of get<*typename*>() with error codes to avoid exceptions: e.g., + dom::object and dom::array. An exception is thrown if the cast is not possible. You can also use is<*typename*>() to test if it is a given type, or use the equivalent without templates (`is_uint64()`, `is_uint64()`, `is_number()`, `is_double()`, , `is_bool()`, `is_integer()`, `is_string()`, `is_array()`, `is_object()`) or use the `type()` method: e.g., `element.type() == dom::element_type::DOUBLE`. Instead of casting, you can use get<*typename*>() to get the value: casts and get<*typename*>() can be used interchangeably. You can also use equivalent functions without templates: e.g., `get_string()`, `get_int64()`, `get_uint64()`, `get_double()` and `get_bool()`. You can use a variant usage of get<*typename*>() with error codes to avoid exceptions: e.g., ```c++ simdjson::error_code error; simdjson::padded_string numberstring = "1.2"_padded; // our JSON input ("1.2") diff --git a/include/simdjson/dom/element.h b/include/simdjson/dom/element.h index ea84d4f0..db8c993a 100644 --- a/include/simdjson/dom/element.h +++ b/include/simdjson/dom/element.h @@ -90,7 +90,7 @@ public: * Returns INCORRECT_TYPE if the JSON element is not an integer, or NUMBER_OUT_OF_RANGE * if it is negative. */ - inline simdjson_result get_int64_t() const noexcept; + inline simdjson_result get_int64() const noexcept; /** * Cast this element to an unsigned integer. * @@ -100,7 +100,7 @@ public: * Returns INCORRECT_TYPE if the JSON element is not an integer, or NUMBER_OUT_OF_RANGE * if it is too large. */ - inline simdjson_result get_uint64_t() const noexcept; + inline simdjson_result get_uint64() const noexcept; /** * Cast this element to an double floating-point. * @@ -143,13 +143,13 @@ public: * * Equivalent to is(). */ - inline bool is_int64_t() const noexcept; + inline bool is_int64() const noexcept; /** * Whether this element is a json number that fits in an unsigned 64-bit integer. * * Equivalent to is(). */ - inline bool is_uint64_t() const noexcept; + inline bool is_uint64() const noexcept; /** * Whether this element is a json number that fits in a double. * @@ -484,16 +484,16 @@ public: really_inline simdjson_result get_object() const noexcept; really_inline simdjson_result get_c_str() const noexcept; really_inline simdjson_result get_string() const noexcept; - really_inline simdjson_result get_int64_t() const noexcept; - really_inline simdjson_result get_uint64_t() const noexcept; + really_inline simdjson_result get_int64() const noexcept; + really_inline simdjson_result get_uint64() const noexcept; really_inline simdjson_result get_double() const noexcept; really_inline simdjson_result get_bool() const noexcept; really_inline simdjson_result is_array() const noexcept; really_inline simdjson_result is_object() const noexcept; really_inline simdjson_result is_string() const noexcept; - really_inline simdjson_result is_int64_t() const noexcept; - really_inline simdjson_result is_uint64_t() const noexcept; + really_inline simdjson_result is_int64() const noexcept; + really_inline simdjson_result is_uint64() const noexcept; really_inline simdjson_result is_double() const noexcept; really_inline simdjson_result is_bool() const noexcept; really_inline simdjson_result is_null() const noexcept; diff --git a/include/simdjson/inline/element.h b/include/simdjson/inline/element.h index 690f40ff..121c8f5e 100644 --- a/include/simdjson/inline/element.h +++ b/include/simdjson/inline/element.h @@ -55,13 +55,13 @@ really_inline simdjson_result simdjson_result::g if (error()) { return error(); } return first.get_string(); } -really_inline simdjson_result simdjson_result::get_int64_t() const noexcept { +really_inline simdjson_result simdjson_result::get_int64() const noexcept { if (error()) { return error(); } - return first.get_int64_t(); + return first.get_int64(); } -really_inline simdjson_result simdjson_result::get_uint64_t() const noexcept { +really_inline simdjson_result simdjson_result::get_uint64() const noexcept { if (error()) { return error(); } - return first.get_uint64_t(); + return first.get_uint64(); } really_inline simdjson_result simdjson_result::get_double() const noexcept { if (error()) { return error(); } @@ -84,13 +84,13 @@ really_inline simdjson_result simdjson_result::is_string() c if (error()) { return error(); } return first.is_string(); } -really_inline simdjson_result simdjson_result::is_int64_t() const noexcept { +really_inline simdjson_result simdjson_result::is_int64() const noexcept { if (error()) { return error(); } - return first.is_int64_t(); + return first.is_int64(); } -really_inline simdjson_result simdjson_result::is_uint64_t() const noexcept { +really_inline simdjson_result simdjson_result::is_uint64() const noexcept { if (error()) { return error(); } - return first.is_uint64_t(); + return first.is_uint64(); } really_inline simdjson_result simdjson_result::is_double() const noexcept { if (error()) { return error(); } @@ -207,7 +207,7 @@ inline simdjson_result element::get_string() const noexcept { return INCORRECT_TYPE; } } -inline simdjson_result element::get_uint64_t() const noexcept { +inline simdjson_result element::get_uint64() const noexcept { if(unlikely(!tape.is_uint64())) { // branch rarely taken if(tape.is_int64()) { int64_t result = tape.next_tape_value(); @@ -220,7 +220,7 @@ inline simdjson_result element::get_uint64_t() const noexcept { } return tape.next_tape_value(); } -inline simdjson_result element::get_int64_t() const noexcept { +inline simdjson_result element::get_int64() const noexcept { if(unlikely(!tape.is_int64())) { // branch rarely taken if(tape.is_uint64()) { uint64_t result = tape.next_tape_value(); @@ -293,16 +293,16 @@ template<> inline simdjson_result element::get() const noexcept { template<> inline simdjson_result element::get() const noexcept { return get_object(); } template<> inline simdjson_result element::get() const noexcept { return get_c_str(); } template<> inline simdjson_result element::get() const noexcept { return get_string(); } -template<> inline simdjson_result element::get() const noexcept { return get_int64_t(); } -template<> inline simdjson_result element::get() const noexcept { return get_uint64_t(); } +template<> inline simdjson_result element::get() const noexcept { return get_int64(); } +template<> inline simdjson_result element::get() const noexcept { return get_uint64(); } template<> inline simdjson_result element::get() const noexcept { return get_double(); } template<> inline simdjson_result element::get() const noexcept { return get_bool(); } inline bool element::is_array() const noexcept { return is(); } inline bool element::is_object() const noexcept { return is(); } inline bool element::is_string() const noexcept { return is(); } -inline bool element::is_int64_t() const noexcept { return is(); } -inline bool element::is_uint64_t() const noexcept { return is(); } +inline bool element::is_int64() const noexcept { return is(); } +inline bool element::is_uint64() const noexcept { return is(); } inline bool element::is_double() const noexcept { return is(); } inline bool element::is_bool() const noexcept { return is(); } diff --git a/tests/cast_tester.h b/tests/cast_tester.h index 59cdc948..b8598b39 100644 --- a/tests/cast_tester.h +++ b/tests/cast_tester.h @@ -229,8 +229,8 @@ template<> simdjson_result cast_tester::named_get(element element) template<> simdjson_result cast_tester::named_get(element element) { return element.get_object(); } template<> simdjson_result cast_tester::named_get(element element) { return element.get_c_str(); } template<> simdjson_result cast_tester::named_get(element element) { return element.get_string(); } -template<> simdjson_result cast_tester::named_get(element element) { return element.get_uint64_t(); } -template<> simdjson_result cast_tester::named_get(element element) { return element.get_int64_t(); } +template<> simdjson_result cast_tester::named_get(element element) { return element.get_uint64(); } +template<> simdjson_result cast_tester::named_get(element element) { return element.get_int64(); } template<> simdjson_result cast_tester::named_get(element element) { return element.get_double(); } template<> simdjson_result cast_tester::named_get(element element) { return element.get_bool(); } @@ -238,8 +238,8 @@ template<> simdjson_result cast_tester::named_get(simdjson_result< template<> simdjson_result cast_tester::named_get(simdjson_result element) { return element.get_object(); } template<> simdjson_result cast_tester::named_get(simdjson_result element) { return element.get_c_str(); } template<> simdjson_result cast_tester::named_get(simdjson_result element) { return element.get_string(); } -template<> simdjson_result cast_tester::named_get(simdjson_result element) { return element.get_uint64_t(); } -template<> simdjson_result cast_tester::named_get(simdjson_result element) { return element.get_int64_t(); } +template<> simdjson_result cast_tester::named_get(simdjson_result element) { return element.get_uint64(); } +template<> simdjson_result cast_tester::named_get(simdjson_result element) { return element.get_int64(); } template<> simdjson_result cast_tester::named_get(simdjson_result element) { return element.get_double(); } template<> simdjson_result cast_tester::named_get(simdjson_result element) { return element.get_bool(); } @@ -247,8 +247,8 @@ template<> bool cast_tester::named_is(element element) { return element.i template<> bool cast_tester::named_is(element element) { return element.is_object(); } template<> bool cast_tester::named_is(element element) { return element.is_string(); } template<> bool cast_tester::named_is(element element) { return element.is_string(); } -template<> bool cast_tester::named_is(element element) { return element.is_uint64_t(); } -template<> bool cast_tester::named_is(element element) { return element.is_int64_t(); } +template<> bool cast_tester::named_is(element element) { return element.is_uint64(); } +template<> bool cast_tester::named_is(element element) { return element.is_int64(); } template<> bool cast_tester::named_is(element element) { return element.is_double(); } template<> bool cast_tester::named_is(element element) { return element.is_bool(); } @@ -256,8 +256,8 @@ template<> simdjson_result cast_tester::named_is(simdjson_result simdjson_result cast_tester::named_is(simdjson_result element) { return element.is_object(); } template<> simdjson_result cast_tester::named_is(simdjson_result element) { return element.is_string(); } template<> simdjson_result cast_tester::named_is(simdjson_result element) { return element.is_string(); } -template<> simdjson_result cast_tester::named_is(simdjson_result element) { return element.is_uint64_t(); } -template<> simdjson_result cast_tester::named_is(simdjson_result element) { return element.is_int64_t(); } +template<> simdjson_result cast_tester::named_is(simdjson_result element) { return element.is_uint64(); } +template<> simdjson_result cast_tester::named_is(simdjson_result element) { return element.is_int64(); } template<> simdjson_result cast_tester::named_is(simdjson_result element) { return element.is_double(); } template<> simdjson_result cast_tester::named_is(simdjson_result element) { return element.is_bool(); }