Orcus
Public Member Functions | Friends | List of all members
orcus::json::detail::node Class Reference

#include <json_document_tree.hpp>

Public Member Functions

 node (const node &other)
 
 node (node &&rhs)
 
node_t type () const
 
size_t child_count () const
 
std::vector< pstringkeys () const
 
pstring key (size_t index) const
 
node child (size_t index) const
 
node child (const pstring &key) const
 
node parent () const
 
pstring string_value () const
 
double numeric_value () const
 
nodeoperator= (const node &other)
 
uintptr_t identity () const
 

Friends

class ::orcus::json_document_tree
 

Detailed Description

Each node instance represents a JSON value object stored in the document tree.

Member Function Documentation

node orcus::json::detail::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.
node orcus::json::detail::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.
size_t orcus::json::detail::node::child_count ( ) const

Get the number of child nodes if any.

Returns
number of child nodes.
uintptr_t orcus::json::detail::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.
pstring orcus::json::detail::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.
std::vector<pstring> orcus::json::detail::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.
double orcus::json::detail::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.
node orcus::json::detail::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.
pstring orcus::json::detail::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.
node_t orcus::json::detail::node::type ( ) const

Get the type of a node.

Returns
node type.