Make simdjson_result<element>.is() return bool
This commit is contained in:
parent
eef1171944
commit
2d84b6f6d9
|
@ -455,7 +455,7 @@ public:
|
|||
|
||||
really_inline simdjson_result<dom::element_type> type() const noexcept;
|
||||
template<typename T>
|
||||
really_inline simdjson_result<bool> is() const noexcept;
|
||||
really_inline bool is() const noexcept;
|
||||
template<typename T>
|
||||
really_inline simdjson_result<T> get() const noexcept;
|
||||
template<typename T>
|
||||
|
@ -470,14 +470,14 @@ public:
|
|||
really_inline simdjson_result<double> get_double() const noexcept;
|
||||
really_inline simdjson_result<bool> get_bool() const noexcept;
|
||||
|
||||
really_inline simdjson_result<bool> is_array() const noexcept;
|
||||
really_inline simdjson_result<bool> is_object() const noexcept;
|
||||
really_inline simdjson_result<bool> is_string() const noexcept;
|
||||
really_inline simdjson_result<bool> is_int64_t() const noexcept;
|
||||
really_inline simdjson_result<bool> is_uint64_t() const noexcept;
|
||||
really_inline simdjson_result<bool> is_double() const noexcept;
|
||||
really_inline simdjson_result<bool> is_bool() const noexcept;
|
||||
really_inline simdjson_result<bool> is_null() const noexcept;
|
||||
really_inline bool is_array() const noexcept;
|
||||
really_inline bool is_object() const noexcept;
|
||||
really_inline bool is_string() const noexcept;
|
||||
really_inline bool is_int64_t() const noexcept;
|
||||
really_inline bool is_uint64_t() const noexcept;
|
||||
really_inline bool is_double() const noexcept;
|
||||
really_inline bool is_bool() const noexcept;
|
||||
really_inline bool is_null() const noexcept;
|
||||
|
||||
really_inline simdjson_result<dom::element> operator[](const std::string_view &key) const noexcept;
|
||||
really_inline simdjson_result<dom::element> operator[](const char *key) const noexcept;
|
||||
|
|
|
@ -24,9 +24,8 @@ inline simdjson_result<dom::element_type> simdjson_result<dom::element>::type()
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
really_inline simdjson_result<bool> simdjson_result<dom::element>::is() const noexcept {
|
||||
if (error()) { return error(); }
|
||||
return first.is<T>();
|
||||
really_inline bool simdjson_result<dom::element>::is() const noexcept {
|
||||
return !error() && first.is<T>();
|
||||
}
|
||||
template<typename T>
|
||||
really_inline simdjson_result<T> simdjson_result<dom::element>::get() const noexcept {
|
||||
|
@ -72,38 +71,30 @@ really_inline simdjson_result<bool> simdjson_result<dom::element>::get_bool() co
|
|||
return first.get_bool();
|
||||
}
|
||||
|
||||
really_inline simdjson_result<bool> simdjson_result<dom::element>::is_array() const noexcept {
|
||||
if (error()) { return error(); }
|
||||
return first.is_array();
|
||||
really_inline bool simdjson_result<dom::element>::is_array() const noexcept {
|
||||
return !error() && first.is_array();
|
||||
}
|
||||
really_inline simdjson_result<bool> simdjson_result<dom::element>::is_object() const noexcept {
|
||||
if (error()) { return error(); }
|
||||
return first.is_object();
|
||||
really_inline bool simdjson_result<dom::element>::is_object() const noexcept {
|
||||
return !error() && first.is_object();
|
||||
}
|
||||
really_inline simdjson_result<bool> simdjson_result<dom::element>::is_string() const noexcept {
|
||||
if (error()) { return error(); }
|
||||
return first.is_string();
|
||||
really_inline bool simdjson_result<dom::element>::is_string() const noexcept {
|
||||
return !error() && first.is_string();
|
||||
}
|
||||
really_inline simdjson_result<bool> simdjson_result<dom::element>::is_int64_t() const noexcept {
|
||||
if (error()) { return error(); }
|
||||
return first.is_int64_t();
|
||||
really_inline bool simdjson_result<dom::element>::is_int64_t() const noexcept {
|
||||
return !error() && first.is_int64_t();
|
||||
}
|
||||
really_inline simdjson_result<bool> simdjson_result<dom::element>::is_uint64_t() const noexcept {
|
||||
if (error()) { return error(); }
|
||||
return first.is_uint64_t();
|
||||
really_inline bool simdjson_result<dom::element>::is_uint64_t() const noexcept {
|
||||
return !error() && first.is_uint64_t();
|
||||
}
|
||||
really_inline simdjson_result<bool> simdjson_result<dom::element>::is_double() const noexcept {
|
||||
if (error()) { return error(); }
|
||||
return first.is_double();
|
||||
really_inline bool simdjson_result<dom::element>::is_double() const noexcept {
|
||||
return !error() && first.is_double();
|
||||
}
|
||||
really_inline simdjson_result<bool> simdjson_result<dom::element>::is_bool() const noexcept {
|
||||
if (error()) { return error(); }
|
||||
return first.is_bool();
|
||||
really_inline bool simdjson_result<dom::element>::is_bool() const noexcept {
|
||||
return !error() && first.is_bool();
|
||||
}
|
||||
|
||||
really_inline simdjson_result<bool> simdjson_result<dom::element>::is_null() const noexcept {
|
||||
if (error()) { return error(); }
|
||||
return first.is_null();
|
||||
really_inline bool simdjson_result<dom::element>::is_null() const noexcept {
|
||||
return !error() && first.is_null();
|
||||
}
|
||||
|
||||
really_inline simdjson_result<dom::element> simdjson_result<dom::element>::operator[](const std::string_view &key) const noexcept {
|
||||
|
|
|
@ -1503,27 +1503,9 @@ namespace type_tests {
|
|||
std::cout << " test_is_null() expecting " << expected_is_null << std::endl;
|
||||
// Grab the element out and check success
|
||||
dom::element element = result.first;
|
||||
bool actual_is_null;
|
||||
auto error = result.is_null().get(actual_is_null);
|
||||
ASSERT_SUCCESS(error);
|
||||
ASSERT_EQUAL(actual_is_null, expected_is_null);
|
||||
ASSERT_EQUAL(result.is_null(), expected_is_null);
|
||||
|
||||
actual_is_null = element.is_null();
|
||||
ASSERT_EQUAL(actual_is_null, expected_is_null);
|
||||
|
||||
#if SIMDJSON_EXCEPTIONS
|
||||
|
||||
try {
|
||||
|
||||
actual_is_null = result.is_null();
|
||||
ASSERT_EQUAL(actual_is_null, expected_is_null);
|
||||
|
||||
} catch(simdjson_error &e) {
|
||||
std::cerr << e.error() << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
#endif // SIMDJSON_EXCEPTIONS
|
||||
ASSERT_EQUAL(element.is_null(), expected_is_null);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -40,7 +40,6 @@ public:
|
|||
|
||||
bool test_is(element element, bool expected);
|
||||
bool test_is(simdjson_result<element> element, bool expected);
|
||||
bool test_is_error(simdjson_result<element> element, error_code expected_error);
|
||||
|
||||
bool test_named_get(element element, T expected = {});
|
||||
bool test_named_get(simdjson_result<element> element, T expected = {});
|
||||
|
@ -49,13 +48,12 @@ public:
|
|||
|
||||
bool test_named_is(element element, bool expected);
|
||||
bool test_named_is(simdjson_result<element> element, bool expected);
|
||||
bool test_named_is_error(simdjson_result<element> element, error_code expected_error);
|
||||
|
||||
private:
|
||||
simdjson_result<T> named_get(element element);
|
||||
simdjson_result<T> named_get(simdjson_result<element> element);
|
||||
bool named_is(element element);
|
||||
simdjson_result<bool> named_is(simdjson_result<element> element);
|
||||
bool named_is(simdjson_result<element> element);
|
||||
bool assert_equal(const T& expected, const T& actual);
|
||||
};
|
||||
|
||||
|
@ -206,16 +204,7 @@ bool cast_tester<T>::test_is(element element, bool expected) {
|
|||
|
||||
template<typename T>
|
||||
bool cast_tester<T>::test_is(simdjson_result<element> element, bool expected) {
|
||||
bool actual;
|
||||
ASSERT_SUCCESS(element.is<T>().get(actual));
|
||||
ASSERT_EQUAL(actual, expected);
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool cast_tester<T>::test_is_error(simdjson_result<element> element, error_code expected_error) {
|
||||
UNUSED bool actual;
|
||||
ASSERT_EQUAL(element.is<T>().get(actual), expected_error);
|
||||
ASSERT_EQUAL(element.is<T>(), expected);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -227,16 +216,7 @@ bool cast_tester<T>::test_named_is(element element, bool expected) {
|
|||
|
||||
template<typename T>
|
||||
bool cast_tester<T>::test_named_is(simdjson_result<element> element, bool expected) {
|
||||
bool actual;
|
||||
ASSERT_SUCCESS(named_is(element).get(actual));
|
||||
ASSERT_EQUAL(actual, expected);
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool cast_tester<T>::test_named_is_error(simdjson_result<element> element, error_code expected_error) {
|
||||
bool actual;
|
||||
ASSERT_EQUAL(named_is(element).get(actual), expected_error);
|
||||
ASSERT_EQUAL(named_is(element), expected);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -267,14 +247,14 @@ template<> bool cast_tester<int64_t>::named_is(element element) { return element
|
|||
template<> bool cast_tester<double>::named_is(element element) { return element.is_double(); }
|
||||
template<> bool cast_tester<bool>::named_is(element element) { return element.is_bool(); }
|
||||
|
||||
template<> simdjson_result<bool> cast_tester<array>::named_is(simdjson_result<element> element) { return element.is_array(); }
|
||||
template<> simdjson_result<bool> cast_tester<object>::named_is(simdjson_result<element> element) { return element.is_object(); }
|
||||
template<> simdjson_result<bool> cast_tester<const char *>::named_is(simdjson_result<element> element) { return element.is_string(); }
|
||||
template<> simdjson_result<bool> cast_tester<std::string_view>::named_is(simdjson_result<element> element) { return element.is_string(); }
|
||||
template<> simdjson_result<bool> cast_tester<uint64_t>::named_is(simdjson_result<element> element) { return element.is_uint64_t(); }
|
||||
template<> simdjson_result<bool> cast_tester<int64_t>::named_is(simdjson_result<element> element) { return element.is_int64_t(); }
|
||||
template<> simdjson_result<bool> cast_tester<double>::named_is(simdjson_result<element> element) { return element.is_double(); }
|
||||
template<> simdjson_result<bool> cast_tester<bool>::named_is(simdjson_result<element> element) { return element.is_bool(); }
|
||||
template<> bool cast_tester<array>::named_is(simdjson_result<element> element) { return element.is_array(); }
|
||||
template<> bool cast_tester<object>::named_is(simdjson_result<element> element) { return element.is_object(); }
|
||||
template<> bool cast_tester<const char *>::named_is(simdjson_result<element> element) { return element.is_string(); }
|
||||
template<> bool cast_tester<std::string_view>::named_is(simdjson_result<element> element) { return element.is_string(); }
|
||||
template<> bool cast_tester<uint64_t>::named_is(simdjson_result<element> element) { return element.is_uint64_t(); }
|
||||
template<> bool cast_tester<int64_t>::named_is(simdjson_result<element> element) { return element.is_int64_t(); }
|
||||
template<> bool cast_tester<double>::named_is(simdjson_result<element> element) { return element.is_double(); }
|
||||
template<> bool cast_tester<bool>::named_is(simdjson_result<element> element) { return element.is_bool(); }
|
||||
|
||||
template<typename T> bool cast_tester<T>::assert_equal(const T& expected, const T& actual) {
|
||||
ASSERT_EQUAL(expected, actual);
|
||||
|
|
Loading…
Reference in New Issue