const_node

Defined in header: <orcus/json_document_tree.hpp>

class const_node

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

Subclassed by orcus::json::node

Public Functions

const_node()
const_node(const const_node &other)
const_node(const_node &&rhs)
~const_node()
node_t type() const

Get the type of a node.

Returns:

node type.

size_t child_count() const

Get the number of child nodes if any.

Returns:

number of child nodes.

std::vector<std::string_view> keys() const

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

Throws:

orcus::json::document_error – if the node is not of the object type.

Returns:

a list of keys.

std::string_view 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:

index – 0-based key index.

Throws:
  • orcus::json::document_error – if the node is not of the object type.

  • std::out_of_range – if the index is equal to or greater than the number of keys stored in the node.

Returns:

key value.

bool has_key(std::string_view key) const

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

Parameters:

key – key 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.

const_node child(size_t index) const

Get a child node by index.

Parameters:

index – 0-based index of a child node.

Throws:
  • orcus::json::document_error – if the node is not one of the object or array types.

  • std::out_of_range – if the index is equal to or greater than the number of child nodes that the node has.

Returns:

child node instance.

const_node child(std::string_view key) const

Get a child node by textural key value.

Parameters:

key – textural key value to get a child node by.

Throws:

orcus::json::document_error – if the node is not of the object type, or the node doesn’t have the specified key.

Returns:

child node instance.

const_node parent() const

Get the parent node.

Throws:

orcus::json::document_error – if the node doesn’t have a parent node which implies that the node is a root node.

Returns:

parent node instance.

const_node back() const

Get the last child node.

Throws:

orcus::json::document_error – if the node is not of array type or node has no children.

Returns:

last child node instance.

std::string_view string_value() const

Get the string value of a JSON string node.

Throws:

orcus::json::document_error – if the node is not of the string type.

Returns:

string value.

double numeric_value() const

Get the numeric value of a JSON number node.

Throws:

orcus::json::document_error – if the node is not of the number type.

Returns:

numeric value.

const_node &operator=(const const_node &other)
const_node &operator=(const_node &&other)
uintptr_t 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.

const_node_iterator 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.

Throws:

document_error – If 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.

const_node_iterator end() const

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

Throws:

document_error – If this method is called on a non-array node.

Returns:

End iterator for an array node.

std::string dump(std::size_t indent) const

Dump the subtree below this node to a string.

Parameters:

indent – Number 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.