xentara-utils v1.2.1
Xentara utilities library
Loading...
Searching...
No Matches
xentara::utils::json::decoder::Document Class Referencefinal

A JSON document. More...

#include <json/decoder/Document.hpp>

+ Inheritance diagram for xentara::utils::json::decoder::Document:

Public Member Functions

 Document (std::reference_wrapper< io::InputStream< char > > stream)
 Constructor.
 
auto read () -> Value
 Reads the root element of the document.
 
auto readAsObject () -> Object
 Reads the root element of the document as a JSON object.
 
auto readAsArray () -> Array
 Reads the root element of the document as a JSON array.
 
auto description () const -> std::string
 Retuns a descption of the stream used to read the document.
 
auto lineNumber () const -> std::uint_least32_t
 Gets the current line number.
 
auto location () const -> Location
 Gets the current location.
 
auto location (std::uint_least32_t lineNumber) const -> Location
 Gets an arbitrary location within the document.
 

Detailed Description

A JSON document.

Objects of this class can be moved, but not copied.

Constructor & Destructor Documentation

◆ Document()

xentara::utils::json::decoder::Document::Document ( std::reference_wrapper< io::InputStream< char > >  stream)
explicit

Constructor.

Parameters
streamThe stream to read the document from. The stream must contain the document encoded as UTF-8 data.

Member Function Documentation

◆ description()

auto xentara::utils::json::decoder::Document::description ( ) const -> std::string

Retuns a descption of the stream used to read the document.

Returns
The description of the stream

◆ lineNumber()

auto xentara::utils::json::decoder::Document::lineNumber ( ) const -> std::uint_least32_t

Gets the current line number.

Returns
The line number

◆ location() [1/2]

auto xentara::utils::json::decoder::Document::location ( ) const -> Location

Gets the current location.

Returns
A location object for the current line number

◆ location() [2/2]

auto xentara::utils::json::decoder::Document::location ( std::uint_least32_t  lineNumber) const -> Location

Gets an arbitrary location within the document.

Parameters
lineNumberThe line number
Returns
A location object for the given line number

◆ read()

auto xentara::utils::json::decoder::Document::read ( ) -> Value

Reads the root element of the document.

This function loads the root element of the document. The root element is usually a JSON object, but can theoretically be any type of value.

Exceptions
SyntaxErrorThe stream does not contain a valid JSON element
std::runtime_errorAn error occured reading from the stream
Returns
The root element

◆ readAsArray()

auto xentara::utils::json::decoder::Document::readAsArray ( ) -> Array

Reads the root element of the document as a JSON array.

This function loads the root element of the document and tries to interpret it as a JSON array.

Exceptions
SyntaxErrorThe stream does not contain a valid JSON element
std::runtime_errorAn error occured reading from the stream
Returns
The root element

◆ readAsObject()

auto xentara::utils::json::decoder::Document::readAsObject ( ) -> Object

Reads the root element of the document as a JSON object.

This function loads the root element of the document and tries to interpret it as a JSON object.

Exceptions
SyntaxErrorThe stream does not contain a valid JSON element
std::runtime_errorAn error occured reading from the stream
Returns
The root element