mirror of
https://github.com/nlohmann/json.git
synced 2025-07-29 23:01:16 +03:00
📝 added documentation
This commit is contained in:
@ -82,7 +82,9 @@ class json_pointer
|
||||
*/
|
||||
json_pointer& operator/=(const json_pointer& ptr)
|
||||
{
|
||||
reference_tokens.insert(reference_tokens.end(), ptr.reference_tokens.begin(), ptr.reference_tokens.end());
|
||||
reference_tokens.insert(reference_tokens.end(),
|
||||
ptr.reference_tokens.begin(),
|
||||
ptr.reference_tokens.end());
|
||||
return *this;
|
||||
}
|
||||
|
||||
@ -102,7 +104,8 @@ class json_pointer
|
||||
/*!
|
||||
@brief create a new JSON pointer by appending the right JSON pointer at the end of the left JSON pointer
|
||||
*/
|
||||
friend json_pointer operator/(const json_pointer& left_ptr, const json_pointer& right_ptr)
|
||||
friend json_pointer operator/(const json_pointer& left_ptr,
|
||||
const json_pointer& right_ptr)
|
||||
{
|
||||
return json_pointer(left_ptr) /= right_ptr;
|
||||
}
|
||||
@ -124,7 +127,17 @@ class json_pointer
|
||||
}
|
||||
|
||||
/*!
|
||||
@brief create a new JSON pointer that is the parent of this JSON pointer
|
||||
@brief returns the parent of this JSON pointer
|
||||
|
||||
@return parent of this JSON pointer; in case this JSON pointer is the root,
|
||||
the root itself is returned
|
||||
|
||||
@complexity Constant.
|
||||
|
||||
@liveexample{The example shows the result of `parent_pointer` for different
|
||||
JSON Pointers.,json_pointer__parent_pointer}
|
||||
|
||||
@since version 3.6.0
|
||||
*/
|
||||
json_pointer parent_pointer() const
|
||||
{
|
||||
@ -138,27 +151,6 @@ class json_pointer
|
||||
return res;
|
||||
}
|
||||
|
||||
/*!
|
||||
@param[in] s reference token to be converted into an array index
|
||||
|
||||
@return integer representation of @a s
|
||||
|
||||
@throw out_of_range.404 if string @a s could not be converted to an integer
|
||||
*/
|
||||
static int array_index(const std::string& s)
|
||||
{
|
||||
std::size_t processed_chars = 0;
|
||||
const int res = std::stoi(s, &processed_chars);
|
||||
|
||||
// check if the string was completely read
|
||||
if (JSON_UNLIKELY(processed_chars != s.size()))
|
||||
{
|
||||
JSON_THROW(detail::out_of_range::create(404, "unresolved reference token '" + s + "'"));
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/*!
|
||||
@brief remove and return last reference token
|
||||
@throw out_of_range.405 if JSON pointer has no parent
|
||||
@ -177,6 +169,15 @@ class json_pointer
|
||||
|
||||
/*!
|
||||
@brief append an unescaped token at the end of the reference pointer
|
||||
|
||||
@param[in] token token to add
|
||||
|
||||
@complexity Amortized constant.
|
||||
|
||||
@liveexample{The example shows the result of `push_back` for different
|
||||
JSON Pointers.,json_pointer__push_back}
|
||||
|
||||
@since version 0.6.0
|
||||
*/
|
||||
void push_back(const std::string& token)
|
||||
{
|
||||
@ -189,13 +190,47 @@ class json_pointer
|
||||
reference_tokens.push_back(std::move(token));
|
||||
}
|
||||
|
||||
/// return whether pointer points to the root document
|
||||
/*!
|
||||
@brief return whether pointer points to the root document
|
||||
|
||||
@return true iff the JSON pointer points to the root document
|
||||
|
||||
@complexity Constant.
|
||||
|
||||
@exceptionsafety No-throw guarantee: this function never throws exceptions.
|
||||
|
||||
@liveexample{The example shows the result of `empty` for different JSON
|
||||
Pointers.,json_pointer__empty}
|
||||
|
||||
@since version 3.6.0
|
||||
*/
|
||||
bool empty() const noexcept
|
||||
{
|
||||
return reference_tokens.empty();
|
||||
}
|
||||
|
||||
private:
|
||||
/*!
|
||||
@param[in] s reference token to be converted into an array index
|
||||
|
||||
@return integer representation of @a s
|
||||
|
||||
@throw out_of_range.404 if string @a s could not be converted to an integer
|
||||
*/
|
||||
static int array_index(const std::string& s)
|
||||
{
|
||||
std::size_t processed_chars = 0;
|
||||
const int res = std::stoi(s, &processed_chars);
|
||||
|
||||
// check if the string was completely read
|
||||
if (JSON_UNLIKELY(processed_chars != s.size()))
|
||||
{
|
||||
JSON_THROW(detail::out_of_range::create(404, "unresolved reference token '" + s + "'"));
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
json_pointer top() const
|
||||
{
|
||||
if (JSON_UNLIKELY(empty()))
|
||||
|
Reference in New Issue
Block a user