MCPcopy Create free account
hub / github.com/AllentDan/LibtorchTutorials / json_pointer top

Function json_pointer top

lesson6-Segmentation/json.hpp:11554–11924  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11552{
11553template<typename BasicJsonType>
11554class json_pointer
11555{
11556 // allow basic_json to access private members
11557 NLOHMANN_BASIC_JSON_TPL_DECLARATION
11558 friend class basic_json;
11559
11560 public:
11561 /*!
11562 @brief create JSON pointer
11563
11564 Create a JSON pointer according to the syntax described in
11565 [Section 3 of RFC6901](https://tools.ietf.org/html/rfc6901#section-3).
11566
11567 @param[in] s string representing the JSON pointer; if omitted, the empty
11568 string is assumed which references the whole JSON value
11569
11570 @throw parse_error.107 if the given JSON pointer @a s is nonempty and does
11571 not begin with a slash (`/`); see example below
11572
11573 @throw parse_error.108 if a tilde (`~`) in the given JSON pointer @a s is
11574 not followed by `0` (representing `~`) or `1` (representing `/`); see
11575 example below
11576
11577 @liveexample{The example shows the construction several valid JSON pointers
11578 as well as the exceptional behavior.,json_pointer}
11579
11580 @since version 2.0.0
11581 */
11582 explicit json_pointer(const std::string& s = "")
11583 : reference_tokens(split(s))
11584 {}
11585
11586 /*!
11587 @brief return a string representation of the JSON pointer
11588
11589 @invariant For each JSON pointer `ptr`, it holds:
11590 @code {.cpp}
11591 ptr == json_pointer(ptr.to_string());
11592 @endcode
11593
11594 @return a string representation of the JSON pointer
11595
11596 @liveexample{The example shows the result of `to_string`.,json_pointer__to_string}
11597
11598 @since version 2.0.0
11599 */
11600 std::string to_string() const
11601 {
11602 return std::accumulate(reference_tokens.begin(), reference_tokens.end(),
11603 std::string{},
11604 [](const std::string & a, const std::string & b)
11605 {
11606 return a + "/" + escape(b);
11607 });
11608 }
11609
11610 /// @copydoc to_string()
11611 operator std::string() const

Callers

nothing calls this directly

Calls 2

emptyFunction · 0.85
createFunction · 0.85

Tested by

no test coverage detected