Orcus
Loading...
Searching...
No Matches
orcus::json::const_node Class Reference

#include <json_document_tree.hpp>

Inheritance diagram for orcus::json::const_node:
orcus::json::node

Public Member Functions

 const_node (const const_node &other)
 const_node (const_node &&rhs)
node_t type () const
size_t child_count () const
std::vector< std::string_view > keys () const
std::string_view key (size_t index) const
bool has_key (std::string_view key) const
const_node child (size_t index) const
const_node child (std::string_view key) const
const_node parent () const
const_node back () const
std::string_view string_value () const
double numeric_value () const
const_nodeoperator= (const const_node &other)
const_nodeoperator= (const_node &&other)
uintptr_t identity () const
const_node_iterator begin () const
const_node_iterator end () const
std::string dump (std::size_t indent) const

Protected Member Functions

 const_node (const document_tree *doc, json_value *jv)
 const_node (std::unique_ptr< impl > &&p)

Protected Attributes

std::unique_ptr< impl > mp_impl

Friends

class document_tree
class const_node_iterator
class subtree

Detailed Description

Each node instance represents a JSON value stored in the document tree. It's immutable.

Member Function Documentation

◆ back()

const_node orcus::json::const_node::back ( ) const

Get the last child node.

Exceptions
orcus::json::document_errorif the node is not of array type or node has no children.
Returns
last child node instance.

◆ begin()

const_node_iterator orcus::json::const_node::begin ( ) const

Get an iterator pointing to the first value of an array if the array is not empty. If the array is empty the iterator equals the end iterator as returned by the end() method.

Exceptions
document_errorIf this method is called on a non-array node.
Returns
Iterator pointing to the first value of an array or the end iterator if the array is empty.

◆ child() [1/2]

const_node orcus::json::const_node::child ( size_t index) const

Get a child node by index.

Parameters
index0-based index of a child node.
Exceptions
orcus::json::document_errorif the node is not one of the object or array types.
std::out_of_rangeif the index is equal to or greater than the number of child nodes that the node has.
Returns
child node instance.

◆ child() [2/2]

const_node orcus::json::const_node::child ( std::string_view key) const

Get a child node by textural key value.

Parameters
keytextural key value to get a child node by.
Exceptions
orcus::json::document_errorif the node is not of the object type, or the node doesn't have the specified key.
Returns
child node instance.

◆ child_count()

size_t orcus::json::const_node::child_count ( ) const

Get the number of child nodes if any.

Returns
number of child nodes.

◆ dump()

std::string orcus::json::const_node::dump ( std::size_t indent) const

Dump the subtree below this node to a string.

Parameters
indentNumber of whitespace characters to use for one indent level. Note that specifying the indent value of 0 will generate output without line breaks.
Returns
a string representation of the subtree with this node as the root node.

◆ end()

const_node_iterator orcus::json::const_node::end ( ) const

Get an end iterator for an array node. Use it in conjunction with an iterator returned by the begin() method.

Exceptions
document_errorIf this method is called on a non-array node.
Returns
End iterator for an array node.

◆ has_key()

bool orcus::json::const_node::has_key ( std::string_view key) const

Query whether or not a particular key exists in a JSON object node.

Parameters
keykey value.
Returns
true if this object node contains the specified key, otherwise false. If this node is not of a JSON object type, false is returned.

◆ identity()

uintptr_t orcus::json::const_node::identity ( ) const

Return an indentifier of the JSON value object that the node represents. The identifier is derived directly from the memory address of the value object.

Returns
identifier of the JSON value object.

◆ key()

std::string_view orcus::json::const_node::key ( size_t index) const

Get the key by index in a JSON object node. This method works only when the preserve object order option is set.

Parameters
index0-based key index.
Exceptions
orcus::json::document_errorif the node is not of the object type.
std::out_of_rangeif the index is equal to or greater than the number of keys stored in the node.
Returns
key value.

◆ keys()

std::vector< std::string_view > orcus::json::const_node::keys ( ) const

Get a list of keys stored in a JSON object node.

Exceptions
orcus::json::document_errorif the node is not of the object type.
Returns
a list of keys.

◆ numeric_value()

double orcus::json::const_node::numeric_value ( ) const

Get the numeric value of a JSON number node.

Exceptions
orcus::json::document_errorif the node is not of the number type.
Returns
numeric value.

◆ parent()

const_node orcus::json::const_node::parent ( ) const

Get the parent node.

Exceptions
orcus::json::document_errorif the node doesn't have a parent node which implies that the node is a root node.
Returns
parent node instance.

◆ string_value()

std::string_view orcus::json::const_node::string_value ( ) const

Get the string value of a JSON string node.

Exceptions
orcus::json::document_errorif the node is not of the string type.
Returns
string value.

◆ type()

node_t orcus::json::const_node::type ( ) const

Get the type of a node.

Returns
node type.