Skip to content

Commit

Permalink
added some documentation in the code related to custom types (#2146)
Browse files Browse the repository at this point in the history
  • Loading branch information
lemire committed Mar 9, 2024
1 parent 9923d27 commit 87f5f7a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
19 changes: 15 additions & 4 deletions include/simdjson/generic/ondemand/document.h
Expand Up @@ -179,21 +179,23 @@ class document {
* @returns INCORRECT_TYPE If the JSON value is not the given type.
*/
template<typename T> simdjson_inline simdjson_result<T> get() & noexcept {
// Unless the simdjson library provides an inline implementation, calling this method should
// Unless the simdjson library or the user provides an inline implementation, calling this method should
// immediately fail.
static_assert(!sizeof(T), "The get method with given type is not implemented by the simdjson library. "
"The supported types are ondemand::object, ondemand::array, raw_json_string, std::string_view, uint64_t, "
"int64_t, double, and bool. We recommend you use get_double(), get_bool(), get_uint64(), get_int64(), "
" get_object(), get_array(), get_raw_json_string(), or get_string() instead of the get template.");
" get_object(), get_array(), get_raw_json_string(), or get_string() instead of the get template."
" You may also add support for custom types, see our documentation.");
}
/** @overload template<typename T> simdjson_result<T> get() & noexcept */
template<typename T> simdjson_inline simdjson_result<T> get() && noexcept {
// Unless the simdjson library provides an inline implementation, calling this method should
// Unless the simdjson library or the user provides an inline implementation, calling this method should
// immediately fail.
static_assert(!sizeof(T), "The get method with given type is not implemented by the simdjson library. "
"The supported types are ondemand::object, ondemand::array, raw_json_string, std::string_view, uint64_t, "
"int64_t, double, and bool. We recommend you use get_double(), get_bool(), get_uint64(), get_int64(), "
" get_object(), get_array(), get_raw_json_string(), or get_string() instead of the get template.");
" get_object(), get_array(), get_raw_json_string(), or get_string() instead of the get template."
" You may also add support for custom types, see our documentation.");
}

/**
Expand All @@ -212,6 +214,15 @@ class document {
template<typename T> simdjson_inline error_code get(T &out) && noexcept;

#if SIMDJSON_EXCEPTIONS
/**
* Cast this JSON value to an instance of type T. The programmer is responsible for
* providing an implementation of get<T> for the type T, if T is not one of the types
* supported by the library (object, array, raw_json_string, string_view, uint64_t, etc.)
*
* See https://github.com/simdjson/simdjson/blob/master/doc/basics.md#adding-support-for-custom-types
*
* @returns An instance of type T
*/
template <class T>
explicit simdjson_inline operator T() noexcept(false);
/**
Expand Down
10 changes: 7 additions & 3 deletions include/simdjson/generic/ondemand/value.h
Expand Up @@ -36,12 +36,13 @@ class value {
* @returns INCORRECT_TYPE If the JSON value is not the given type.
*/
template<typename T> simdjson_inline simdjson_result<T> get() noexcept {
// Unless the simdjson library provides an inline implementation, calling this method should
// Unless the simdjson library or the user provides an inline implementation, calling this method should
// immediately fail.
static_assert(!sizeof(T), "The get method with given type is not implemented by the simdjson library. "
"The supported types are ondemand::object, ondemand::array, raw_json_string, std::string_view, uint64_t, "
"int64_t, double, and bool. We recommend you use get_double(), get_bool(), get_uint64(), get_int64(), "
" get_object(), get_array(), get_raw_json_string(), or get_string() instead of the get template.");
" get_object(), get_array(), get_raw_json_string(), or get_string() instead of the get template."
" You may also add support for custom types, see our documentation.");
}

/**
Expand Down Expand Up @@ -196,7 +197,10 @@ class value {
#if SIMDJSON_EXCEPTIONS
/**
* Cast this JSON value to an instance of type T. The programmer is responsible for
* providing an implementation of get<T> for the type T.
* providing an implementation of get<T> for the type T, if T is not one of the types
* supported by the library (object, array, raw_json_string, string_view, uint64_t, etc.).
*
* See https://github.com/simdjson/simdjson/blob/master/doc/basics.md#adding-support-for-custom-types
*
* @returns An instance of type T
*/
Expand Down

0 comments on commit 87f5f7a

Please sign in to comment.