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

 JSONNode ()
 
 JSONNode (const JSONNode &node)
 
 JSONNode (JSONNode &&node) noexcept
 
 JSONNode (Scanner &scan)
 
 JSONNode (const String &node, const String &json_string)
 
 JSONNode (File &file)
 
 ~JSONNode ()
 
NodeType type () const
 
void write (String &stream) 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 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.
 
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)
 
template<class t_type >
decltype(auto) getAs () const
 
const JSONNodeget (const String &child_node) const
 
const JSONNodeoperator[] (const String &child_node) const
 
JSONNodeoperator[] (const String &child_node)
 
JSONNodeoperator[] (const uint04 &child_idx)
 
const JSONNodeoperator[] (const uint04 &child_idx) const
 
const Buffer< JSONNode * > & children () const
 
bool hasNode (const String &child_node) const
 
const StringnodeName () const
 
void remove (const String &child_node)
 
JSONNodecreateChildNode (const String &child_node, NodeType type)
 
JSONNodeoperator= (const JSONNode &node)
 
JSONNodeoperator= (const String &value)
 
template<class t_type >
JSONNodeoperator= (const Angle< t_type > &value)
 
JSONNodeoperator= (const Time &time)
 
template<class t_type , class t_allocator >
JSONNodeoperator= (const Buffer< t_type, t_allocator > &buffer)
 
template<uint01 t_dims, class t_type >
JSONNodeoperator= (const Vector< t_dims, t_type > &buffer)
 
bool isEmpty () const
 
template<class t_type >
JSONNodeoperator= (const t_type &value)
 
uint04 size ()
 
decltype(auto) begin ()
 
decltype(auto) begin () const
 
decltype(auto) end ()
 
decltype(auto) end () const
 

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 readChildrenNodes (Scanner &scan)
 
void readData (Scanner &scan)
 
void readArray (Scanner &scan)
 

Static Protected Member Functions

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

Protected Attributes

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

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

Fn: JSONNode::JSONNode(const String& name)

Creates a root JSON node

Author: Tyler Parke

Date: 2017-11-19

◆ JSONNode() [2/7]

JSONNode ( const String & name)
protected

Fn: JSONNode::JSONNode(const String& name)

Creates a JSONNode with a given name

Author: Tyler Parke

Date: 2017-11-19

◆ JSONNode() [3/7]

JSONNode ( const JSONNode & node)

Fn: JSONNode::JSONNode(const JSONNode& node)

Very basic copy constructor.

Author: Tyler Parke

Date: 2017-11-19

◆ JSONNode() [4/7]

JSONNode ( JSONNode && node)
noexcept

Fn: JSONNode::JSONNode(const JSONNode&& node)

Very basic move constructor.

Author: Tyler Parke

Date: 2017-11-19

◆ JSONNode() [5/7]

JSONNode ( Scanner & scan)

Fn: JSONNode::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)

Fn: JSONNode::JSONNode(File& scan)

Creates a JSONNode by parsing it from the File.

Author: Tyler Parke

Date: 2017-11-19

◆ ~JSONNode()

~JSONNode ( )

Member Function Documentation

◆ BadChildErrorString()

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

void ConvertFromJSONString ( String & string)
staticprotected

◆ ConvertToJSONString()

void ConvertToJSONString ( String & string)
staticprotected

◆ createChildNode()

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

◆ DuplicateChildErrorString()

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

Fn: const JSONNode& JSONNode::get(const String& child_node) const

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

Fn: void JSONNode::getAs()

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

Fn: bool JSONNode::isEmpty() const

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

Fn: void JSONNode::operator=(const JSONNode& node)

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

Fn: void JSONNode::operator=(const t_type& node)

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

Fn: void JSONNode::operator=(const Time& node)

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

Fn: const JSONNode& 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)

Fn: JSONNode& JSONNode::operator[](const uint04& child_node)

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

Fn: JSONParser::parseJSON(Scanner& scan)

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

JSONNode ParseYAML ( Scanner & scan)
static

◆ parseYAMLContent()

bool parseYAMLContent ( uint04 indentention,
Scanner & scan )
protected

Fn: JSONParser::parseYAML(Scanner& scan)

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

Fn: JSONParser::readArray(Scanner& scan)

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

Fn: JSONParser::readChildrenNodes(Scanner& scan)

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

Fn: JSONParser::readData(Scanner& scan)

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

Fn: void JSONNode::operator=()

Returns the number of children within this node.

Author: Tyler Parke

Date: 2017-11-19

◆ type()

JSONNode::NodeType type ( ) const

Fn: NodeType JSONNode::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()

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.


Fn: void JSONNode::write(File& file)

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

Fn: void JSONNode::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.


Fn: void JSONNode::writePretty(File& file)

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.


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

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

void WriteTabs ( String & stream,
uint04 tab_indention )
staticprotected

Fn: JSONParser::WriteTabs(String& stream, uint04 tab_indention)

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 files: