API Documentation
Loading...
Searching...
No Matches
JSONNode Class Reference

JavaScript Object Notation or JSON is an open - standard file format that uses human - readable text to transmit data objects consisting of attribute–value pairs and array data types(or any other serializable value). More...

#include <JSONParser.h>

Collaboration diagram for JSONNode:
[legend]

Public Types

enum  NodeType {
  e_number , e_array , e_bool , e_object ,
  e_node , e_root
}
 

Public Member Functions

decltype(auto) begin ()
 
decltype(auto) begin () const
 
const Buffer< JSONNode * > & children () const
 
JSONNodecreateChildNode (const String &child_node, NodeType type)
 
decltype(auto) end ()
 
decltype(auto) end () const
 
const JSONNodeget (const String &child_node) const
 
template<class t_type >
decltype(auto) getAs () const
 
bool hasNode (const String &child_node) const
 
bool isEmpty () const
 
 JSONNode ()
 
 JSONNode (const JSONNode &node)
 
 JSONNode (const String &node, const String &json_string)
 
 JSONNode (File &file)
 
 JSONNode (JSONNode &&node) noexcept
 
 JSONNode (Scanner &scan)
 
const StringnodeName () const
 
template<class t_type >
JSONNodeoperator= (const Angle< t_type > &value)
 
template<class t_type , class t_allocator >
JSONNodeoperator= (const Buffer< t_type, t_allocator > &buffer)
 
JSONNodeoperator= (const JSONNode &node)
 
JSONNodeoperator= (const String &value)
 
template<class t_type >
JSONNodeoperator= (const t_type &value)
 
JSONNodeoperator= (const Time &time)
 
template<uint01 t_dims, class t_type >
JSONNodeoperator= (const Vector< t_dims, t_type > &buffer)
 
JSONNodeoperator[] (const String &child_node)
 
const JSONNodeoperator[] (const String &child_node) const
 
JSONNodeoperator[] (const uint04 &child_idx)
 
const JSONNodeoperator[] (const uint04 &child_idx) const
 
void remove (const String &child_node)
 
uint04 size ()
 
NodeType type () const
 
void write (File &file)
 Writes the JSON structure out to a file with no frills. Same as write(String&) but for files.
 
void write (std::ostream &file)
 
void write (String &stream) const
 
void writePretty (File &file)
 Writes our structure out to a file using tabs and new lines. Same as writePretty(String&) but for files.
 
void writePretty (std::ostream &file)
 
void writePretty (String &stream, const uint04 tab_indention=0) const
 Same as write, but adds tabs and new lines to make it easier to read, though will result in larger file.
 
 ~JSONNode ()
 

Static Public Member Functions

static JSONNode ParseYAML (Scanner &scan)
 

Protected Member Functions

 JSONNode (const String &name)
 
bool parseJSON (Scanner &scan)
 
bool parseJSONContent (char start, Scanner &scan)
 
bool parseYAMLContent (uint04 indentention, Scanner &scan)
 
void readArray (Scanner &scan)
 
void readChildrenNodes (Scanner &scan)
 
void readData (Scanner &scan)
 

Static Protected Member Functions

static TranslatedString BadChildErrorString (const Scanner &scan)
 
static void ConvertFromJSONString (String &string)
 
static void ConvertToJSONString (String &string)
 
static TranslatedString DuplicateChildErrorString (const String &child, const Scanner &scan)
 
static TranslatedString UnexpectedCharErrorString (char current_char, const Scanner &scan)
 
static void WriteTabs (String &stream, uint04 tab_indention)
 

Protected Attributes

Dictionary< String, JSONNode * > m_json_children
 
const String m_name
 
Buffer< JSONNode * > m_sorted_json_children
 
NodeType m_type
 
String m_value
 

Detailed Description

JavaScript Object Notation or JSON is an open - standard file format that uses human - readable text to transmit data objects consisting of attribute–value pairs and array data types(or any other serializable value).


Class: JSONNode

It is a very common data format used for asynchronous browser–server communication, including as a replacement for XML in some AJAX - style systems.

The JSONNode class serves as a container for data and it's children. Includes options to read and write from streams and files.

Author: Tyler Parke

Date: 2017-11-13

Member Enumeration Documentation

◆ NodeType

enum NodeType
Enumerator
e_number 
e_array 
e_bool 
e_object 
e_node 
e_root 

Constructor & Destructor Documentation

◆ JSONNode() [1/7]

JSONNode ( )

Creates a root JSON node

Author: Tyler Parke

Date: 2017-11-19

◆ JSONNode() [2/7]

JSONNode ( const String & name)
protected

Creates a JSONNode with a given name

Author: Tyler Parke

Date: 2017-11-19

◆ JSONNode() [3/7]

JSONNode ( const JSONNode & node)

Very basic copy constructor.

Author: Tyler Parke

Date: 2017-11-19

◆ JSONNode() [4/7]

JSONNode ( JSONNode && node)
noexcept

Very basic move constructor.

Author: Tyler Parke

Date: 2017-11-19

◆ JSONNode() [5/7]

JSONNode ( Scanner & scan)

Creates a JSONNode by parsing it from the scanner. Scanner should be at the start of the file or stream just before the opening '{'

Author: Tyler Parke

Date: 2017-11-19

◆ JSONNode() [6/7]

JSONNode ( const String & node,
const String & json_string )

◆ JSONNode() [7/7]

JSONNode ( File & file)

Creates a JSONNode by parsing it from the File.

Author: Tyler Parke

Date: 2017-11-19

◆ ~JSONNode()

~JSONNode ( )

Member Function Documentation

◆ BadChildErrorString()

static TranslatedString BadChildErrorString ( const Scanner & scan)
staticprotected

◆ begin() [1/2]

decltype(auto) begin ( )
inlinenodiscard

◆ begin() [2/2]

decltype(auto) begin ( ) const
inlinenodiscard

◆ children()

const Buffer< JSONNode * > & children ( ) const
inline

◆ ConvertFromJSONString()

static void ConvertFromJSONString ( String & string)
staticprotected

◆ ConvertToJSONString()

static void ConvertToJSONString ( String & string)
staticprotected

◆ createChildNode()

JSONNode & createChildNode ( const String & child_node,
NodeType type )

◆ DuplicateChildErrorString()

static TranslatedString DuplicateChildErrorString ( const String & child,
const Scanner & scan )
staticprotected

◆ end() [1/2]

decltype(auto) end ( )
inlinenodiscard

◆ end() [2/2]

decltype(auto) end ( ) const
inlinenodiscard

◆ get()

const JSONNode & get ( const String & child_node) const
inline

returns the child, if it exists. Is read only. Same as (*this)[child_node]

Author: Tyler Parke

Date: 2017-11-19

Parameters: child_node - The name of the node you want to return. Must be an existing child node.

◆ getAs()

template<class t_type >
decltype(auto) getAs ( ) const
inline

Returns this object as the type specified.

Author: Tyler Parke

Date: 2017-11-19

◆ hasNode()

bool hasNode ( const String & child_node) const
inline

◆ isEmpty()

bool isEmpty ( ) const
inlinenodiscard

Returns true if the node contains no information.

Author: Tyler Parke

Date: 2019-14-12

◆ nodeName()

const String & nodeName ( ) const
inline

◆ operator=() [1/7]

template<class t_type >
JSONNode & operator= ( const Angle< t_type > & value)
inline

◆ operator=() [2/7]

template<class t_type , class t_allocator >
JSONNode & operator= ( const Buffer< t_type, t_allocator > & buffer)
inline

◆ operator=() [3/7]

JSONNode & operator= ( const JSONNode & node)
inline

A special case of the = operator for nodes. Note that this will not set the name of the node, but set the contents equal to that of another

Author: Tyler Parke

Date: 2017-11-19

◆ operator=() [4/7]

JSONNode & operator= ( const String & value)
inline

◆ operator=() [5/7]

template<class t_type >
JSONNode & operator= ( const t_type & value)
inline

A general case t_type equals. Sets the value internal and predicts the type.

Author: Tyler Parke

Date: 2017-11-19

◆ operator=() [6/7]

JSONNode & operator= ( const Time & time)
inline

A special case Time equals. writes in YYYY/MM/DDTHH:mm:ss.fffZ format.

Author: Tyler Parke

Date: 2017-11-19

◆ operator=() [7/7]

template<uint01 t_dims, class t_type >
JSONNode & operator= ( const Vector< t_dims, t_type > & buffer)
inline

◆ operator[]() [1/4]

JSONNode & operator[] ( const String & child_node)

◆ operator[]() [2/4]

const JSONNode & operator[] ( const String & child_node) const

returns the child, if it exists. Is read only. Same as get

Author: Tyler Parke

Date: 2017-11-19

Parameters: child_node - The name of the node you want to return. Must be an existing child node.

◆ operator[]() [3/4]

JSONNode & operator[] ( const uint04 & child_idx)

Returns the child, if it exists.

Author: Tyler Parke

Date: 2017-11-19

Parameters: child_idx - The index of the node you want to return.

◆ operator[]() [4/4]

const JSONNode & operator[] ( const uint04 & child_idx) const

◆ parseJSON()

bool parseJSON ( Scanner & scan)
protected

Reads in the next JSON item and adds it to this node's children

Parameters: scan - The object tasked with reading in our data. Shold be just past the second '"' at the end of the node's title at this point.

Author: Tyler Parke

Date: 2017-11-19

Returns
true if there is an adjacent child next to this one, false if end of stream or no additional children.

◆ parseJSONContent()

bool parseJSONContent ( char start,
Scanner & scan )
protected

◆ ParseYAML()

static JSONNode ParseYAML ( Scanner & scan)
static

◆ parseYAMLContent()

bool parseYAMLContent ( uint04 indentention,
Scanner & scan )
protected

Reads in the next YAML item and adds it to this node's children

Parameters: scan - The object tasked with reading in our data. Shold be just past the second '"' at the end of the node's title at this point.

Author: Tyler Parke

Date: 2024-07-08

Returns
true if there is an adjacent child next to this one, false if end of stream or no additional children.

◆ readArray()

void readArray ( Scanner & scan)
protected

Reads in an array of items for this child.

Parameters: scan - The object tasked with reading in our data. Shold be just past the first '[' specifying the beginning of the array

Author: Tyler Parke

Date: 2017-11-19

◆ readChildrenNodes()

void readChildrenNodes ( Scanner & scan)
protected

Reads in all of the children nodes for this node and adds them to the children list

Parameters: scan - The object tasked with reading in our data. Shold be just before the first '"' specifying the title

Author: Tyler Parke

Date: 2017-11-19

◆ readData()

void readData ( Scanner & scan)
protected

Reads in a single object type for this child.

Parameters: scan - The object tasked with reading in our data. Shold be just past the first '"' specifying the data

Author: Tyler Parke

Date: 2017-11-19

◆ remove()

void remove ( const String & child_node)

◆ size()

uint04 size ( )
inline

Returns the number of children within this node.

Author: Tyler Parke

Date: 2017-11-19

◆ type()

NodeType type ( ) const

Author: Tyler Parke

Date: 2017-11-19

Returns
The type of the node which will give a hint as to how the contents should be written to a file, or interpretted by the program

◆ UnexpectedCharErrorString()

static TranslatedString UnexpectedCharErrorString ( char current_char,
const Scanner & scan )
staticprotected

◆ write() [1/3]

void write ( File & file)

Writes the JSON structure out to a file with no frills. Same as write(String&) but for files.


Author: Tyler Parke

Date: 2017-11-19

Parameters: file - The file where you want the JSON node to be written

◆ write() [2/3]

void write ( std::ostream & file)

◆ write() [3/3]

void write ( String & stream) const

A no frills write routine. Useful for writing to a file.

Author: Tyler Parke

Date: 2017-11-19

Parameters: stream - The stream where you want the JSON node to be written

◆ writePretty() [1/3]

void writePretty ( File & file)

Writes our structure out to a file using tabs and new lines. Same as writePretty(String&) but for files.


Author: Tyler Parke

Date: 2017-11-19

Parameters: file - The file where you want the JSON node to be written

◆ writePretty() [2/3]

void writePretty ( std::ostream & file)

◆ writePretty() [3/3]

void writePretty ( String & stream,
const uint04 tab_indention = 0 ) const

Same as write, but adds tabs and new lines to make it easier to read, though will result in larger file.


Author: Tyler Parke

Date: 2017-11-19

Parameters: stream - The stream where you want the JSON node to be written tab_indention - The number of tabs to place before writing data

◆ WriteTabs()

static void WriteTabs ( String & stream,
uint04 tab_indention )
staticprotected

Writes tabs to the file

Parameters: stream - Where to append the tabs tab_indention - The number of tabs to write

Author: Tyler Parke

Date: 2017-11-19

Member Data Documentation

◆ m_json_children

Dictionary<String, JSONNode*> m_json_children
protected

◆ m_name

const String m_name
protected

◆ m_sorted_json_children

Buffer<JSONNode*> m_sorted_json_children
protected

◆ m_type

NodeType m_type
protected

◆ m_value

String m_value
protected

The documentation for this class was generated from the following file: