Orcus
Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
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< pstringkeys () const
 
pstring key (size_t index) const
 
bool has_key (const pstring &key) const
 
const_node child (size_t index) const
 
const_node child (const pstring &key) const
 
const_node parent () const
 
const_node back () const
 
pstring string_value () const
 
double numeric_value () const
 
const_nodeoperator= (const const_node &other)
 
uintptr_t identity () const
 
const_node_iterator begin () const
 
const_node_iterator end () 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
 

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.

◆ child() [1/2]

const_node orcus::json::const_node::child ( const pstring 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() [2/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_count()

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

Get the number of child nodes if any.

Returns
number of child nodes.

◆ has_key()

bool orcus::json::const_node::has_key ( const pstring 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()

pstring 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<pstring> 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()

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