提交 161c74a9 编写于 作者: N Niels

some cleanup

上级 6297631e
...@@ -760,6 +760,7 @@ class basic_json ...@@ -760,6 +760,7 @@ class basic_json
}; };
std::unique_ptr<T, decltype(deleter)> object(alloc.allocate(1), deleter); std::unique_ptr<T, decltype(deleter)> object(alloc.allocate(1), deleter);
alloc.construct(object.get(), std::forward<Args>(args)...); alloc.construct(object.get(), std::forward<Args>(args)...);
assert(object.get() != nullptr);
return object.release(); return object.release();
} }
...@@ -4597,6 +4598,10 @@ class basic_json ...@@ -4597,6 +4598,10 @@ class basic_json
object | result of function `object_t::empty()` object | result of function `object_t::empty()`
array | result of function `array_t::empty()` array | result of function `array_t::empty()`
@note This function does not return whether a string stored as JSON value
is empty - it returns whether the JSON container itself is empty which is
false in the case of a string.
@complexity Constant, as long as @ref array_t and @ref object_t satisfy @complexity Constant, as long as @ref array_t and @ref object_t satisfy
the Container concept; that is, their `empty()` functions have constant the Container concept; that is, their `empty()` functions have constant
complexity. complexity.
...@@ -4626,12 +4631,14 @@ class basic_json ...@@ -4626,12 +4631,14 @@ class basic_json
case value_t::array: case value_t::array:
{ {
// delegate call to array_t::empty()
assert(m_value.array != nullptr); assert(m_value.array != nullptr);
return m_value.array->empty(); return m_value.array->empty();
} }
case value_t::object: case value_t::object:
{ {
// delegate call to object_t::empty()
assert(m_value.object != nullptr); assert(m_value.object != nullptr);
return m_value.object->empty(); return m_value.object->empty();
} }
...@@ -4660,6 +4667,10 @@ class basic_json ...@@ -4660,6 +4667,10 @@ class basic_json
object | result of function object_t::size() object | result of function object_t::size()
array | result of function array_t::size() array | result of function array_t::size()
@note This function does not return the length of a string stored as JSON
value - it returns the number of elements in the JSON value which is 1 in
the case of a string.
@complexity Constant, as long as @ref array_t and @ref object_t satisfy @complexity Constant, as long as @ref array_t and @ref object_t satisfy
the Container concept; that is, their size() functions have constant the Container concept; that is, their size() functions have constant
complexity. complexity.
...@@ -4690,12 +4701,14 @@ class basic_json ...@@ -4690,12 +4701,14 @@ class basic_json
case value_t::array: case value_t::array:
{ {
// delegate call to array_t::size()
assert(m_value.array != nullptr); assert(m_value.array != nullptr);
return m_value.array->size(); return m_value.array->size();
} }
case value_t::object: case value_t::object:
{ {
// delegate call to object_t::size()
assert(m_value.object != nullptr); assert(m_value.object != nullptr);
return m_value.object->size(); return m_value.object->size();
} }
...@@ -4750,12 +4763,14 @@ class basic_json ...@@ -4750,12 +4763,14 @@ class basic_json
{ {
case value_t::array: case value_t::array:
{ {
// delegate call to array_t::max_size()
assert(m_value.array != nullptr); assert(m_value.array != nullptr);
return m_value.array->max_size(); return m_value.array->max_size();
} }
case value_t::object: case value_t::object:
{ {
// delegate call to object_t::max_size()
assert(m_value.object != nullptr); assert(m_value.object != nullptr);
return m_value.object->max_size(); return m_value.object->max_size();
} }
...@@ -5844,14 +5859,14 @@ class basic_json ...@@ -5844,14 +5859,14 @@ class basic_json
// string->float->string, string->double->string or string->long // string->float->string, string->double->string or string->long
// double->string; to be safe, we read this value from // double->string; to be safe, we read this value from
// std::numeric_limits<number_float_t>::digits10 // std::numeric_limits<number_float_t>::digits10
const auto old_preicison = o.precision(std::numeric_limits<double>::digits10); const auto old_precision = o.precision(std::numeric_limits<double>::digits10);
// do the actual serialization // do the actual serialization
j.dump(o, pretty_print, static_cast<unsigned int>(indentation)); j.dump(o, pretty_print, static_cast<unsigned int>(indentation));
// reset locale and precision // reset locale and precision
o.imbue(old_locale); o.imbue(old_locale);
o.precision(old_preicison); o.precision(old_precision);
return o; return o;
} }
......
...@@ -760,6 +760,7 @@ class basic_json ...@@ -760,6 +760,7 @@ class basic_json
}; };
std::unique_ptr<T, decltype(deleter)> object(alloc.allocate(1), deleter); std::unique_ptr<T, decltype(deleter)> object(alloc.allocate(1), deleter);
alloc.construct(object.get(), std::forward<Args>(args)...); alloc.construct(object.get(), std::forward<Args>(args)...);
assert(object.get() != nullptr);
return object.release(); return object.release();
} }
...@@ -4597,6 +4598,10 @@ class basic_json ...@@ -4597,6 +4598,10 @@ class basic_json
object | result of function `object_t::empty()` object | result of function `object_t::empty()`
array | result of function `array_t::empty()` array | result of function `array_t::empty()`
@note This function does not return whether a string stored as JSON value
is empty - it returns whether the JSON container itself is empty which is
false in the case of a string.
@complexity Constant, as long as @ref array_t and @ref object_t satisfy @complexity Constant, as long as @ref array_t and @ref object_t satisfy
the Container concept; that is, their `empty()` functions have constant the Container concept; that is, their `empty()` functions have constant
complexity. complexity.
...@@ -4626,12 +4631,14 @@ class basic_json ...@@ -4626,12 +4631,14 @@ class basic_json
case value_t::array: case value_t::array:
{ {
// delegate call to array_t::empty()
assert(m_value.array != nullptr); assert(m_value.array != nullptr);
return m_value.array->empty(); return m_value.array->empty();
} }
case value_t::object: case value_t::object:
{ {
// delegate call to object_t::empty()
assert(m_value.object != nullptr); assert(m_value.object != nullptr);
return m_value.object->empty(); return m_value.object->empty();
} }
...@@ -4660,6 +4667,10 @@ class basic_json ...@@ -4660,6 +4667,10 @@ class basic_json
object | result of function object_t::size() object | result of function object_t::size()
array | result of function array_t::size() array | result of function array_t::size()
@note This function does not return the length of a string stored as JSON
value - it returns the number of elements in the JSON value which is 1 in
the case of a string.
@complexity Constant, as long as @ref array_t and @ref object_t satisfy @complexity Constant, as long as @ref array_t and @ref object_t satisfy
the Container concept; that is, their size() functions have constant the Container concept; that is, their size() functions have constant
complexity. complexity.
...@@ -4690,12 +4701,14 @@ class basic_json ...@@ -4690,12 +4701,14 @@ class basic_json
case value_t::array: case value_t::array:
{ {
// delegate call to array_t::size()
assert(m_value.array != nullptr); assert(m_value.array != nullptr);
return m_value.array->size(); return m_value.array->size();
} }
case value_t::object: case value_t::object:
{ {
// delegate call to object_t::size()
assert(m_value.object != nullptr); assert(m_value.object != nullptr);
return m_value.object->size(); return m_value.object->size();
} }
...@@ -4750,12 +4763,14 @@ class basic_json ...@@ -4750,12 +4763,14 @@ class basic_json
{ {
case value_t::array: case value_t::array:
{ {
// delegate call to array_t::max_size()
assert(m_value.array != nullptr); assert(m_value.array != nullptr);
return m_value.array->max_size(); return m_value.array->max_size();
} }
case value_t::object: case value_t::object:
{ {
// delegate call to object_t::max_size()
assert(m_value.object != nullptr); assert(m_value.object != nullptr);
return m_value.object->max_size(); return m_value.object->max_size();
} }
...@@ -5844,14 +5859,14 @@ class basic_json ...@@ -5844,14 +5859,14 @@ class basic_json
// string->float->string, string->double->string or string->long // string->float->string, string->double->string or string->long
// double->string; to be safe, we read this value from // double->string; to be safe, we read this value from
// std::numeric_limits<number_float_t>::digits10 // std::numeric_limits<number_float_t>::digits10
const auto old_preicison = o.precision(std::numeric_limits<double>::digits10); const auto old_precision = o.precision(std::numeric_limits<double>::digits10);
// do the actual serialization // do the actual serialization
j.dump(o, pretty_print, static_cast<unsigned int>(indentation)); j.dump(o, pretty_print, static_cast<unsigned int>(indentation));
// reset locale and precision // reset locale and precision
o.imbue(old_locale); o.imbue(old_locale);
o.precision(old_preicison); o.precision(old_precision);
return o; return o;
} }
...@@ -9560,7 +9575,7 @@ struct hash<nlohmann::json> ...@@ -9560,7 +9575,7 @@ struct hash<nlohmann::json>
@brief user-defined string literal for JSON values @brief user-defined string literal for JSON values
This operator implements a user-defined string literal for JSON objects. It This operator implements a user-defined string literal for JSON objects. It
can be used by adding \p "_json" to a string literal and returns a JSON object can be used by adding `"_json"` to a string literal and returns a JSON object
if no parse error occurred. if no parse error occurred.
@param[in] s a string representation of a JSON object @param[in] s a string representation of a JSON object
...@@ -9576,6 +9591,13 @@ inline nlohmann::json operator "" _json(const char* s, std::size_t) ...@@ -9576,6 +9591,13 @@ inline nlohmann::json operator "" _json(const char* s, std::size_t)
/*! /*!
@brief user-defined string literal for JSON pointer @brief user-defined string literal for JSON pointer
This operator implements a user-defined string literal for JSON Pointers. It
can be used by adding `"_json"` to a string literal and returns a JSON pointer
object if no parse error occurred.
@param[in] s a string representation of a JSON Pointer
@return a JSON pointer object
@since version 2.0.0 @since version 2.0.0
*/ */
inline nlohmann::json::json_pointer operator "" _json_pointer(const char* s, std::size_t) inline nlohmann::json::json_pointer operator "" _json_pointer(const char* s, std::size_t)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册