![]() |
NDEVR
API Documentation
|
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...
Public Types | |
| enum | NodeType { e_number , e_array , e_bool , e_object , e_node , e_root } |
| Describes the type of data stored by a JSONNode. More... | |
Public Member Functions | |
| JSONNode () | |
| JSONNode (const JSONNode &node) | |
| JSONNode (const String &node, const StringView &json_string) | |
| Creates a JSONNode by parsing a named node from a JSON string. | |
| JSONNode (File &file) | |
| JSONNode (JSONNode &&node) noexcept | |
| JSONNode (Scanner &scan) | |
| ~JSONNode () | |
| Destroys the JSONNode and frees all child nodes. | |
| decltype(auto) | begin () |
| Returns a mutable iterator to the beginning of the children dictionary. | |
| decltype(auto) | begin () const |
| Returns a const iterator to the beginning of the children dictionary. | |
| const Buffer< JSONNode * > & | children () const |
| Returns the ordered list of child node pointers. | |
| JSONNode & | createChildNode (const StringView &child_node, NodeType type) |
| Creates a named child node with the specified type. | |
| JSONNode & | createChildNode (NodeType type=NodeType::e_node) |
| Creates an unnamed child node with the specified type. | |
| decltype(auto) | end () |
| Returns a mutable iterator to the end of the children dictionary. | |
| decltype(auto) | end () const |
| Returns a const iterator to the end of the children dictionary. | |
| const JSONNode & | get (const StringView &child_node) const |
| template<class t_type> | |
| t_type | get (const StringView &child_node, const t_type &default_value) const |
| Gets the value if it exists, otherwise returns the default value. | |
| template<class t_type> | |
| decltype(auto) | getAs () const |
| template<class t_type> | |
| bool | getIfExists (const StringView &child_node, t_type &value) const |
| Retrieves a child value if the node exists, returning whether it was found. | |
| bool | hasNode (const StringView &child_node) const |
| Checks whether a child node with the given name exists. | |
| bool | isEmpty () const |
| const String & | nodeName () const |
| Returns the name of this node. | |
| template<class t_type> | |
| JSONNode & | operator= (const Angle< t_type > &value) |
| Assigns an Angle value to this node, storing it as degrees. | |
| template<class String> | |
| JSONNode & | operator= (const Buffer< String > &buffer) |
| Assigns a Buffer of Strings to this node as a quoted comma-separated array. | |
| template<class String> | |
| JSONNode & | operator= (const Buffer< StringView > &buffer) |
| Assigns a Buffer of StringViews to this node as a quoted comma-separated array. | |
| template<class t_type, class t_allocator> | |
| JSONNode & | operator= (const Buffer< t_type, t_allocator > &buffer) |
| Assigns a typed Buffer to this node as a comma-separated array. | |
| JSONNode & | operator= (const JSONNode &node) |
| A special case of the = operator for nodes. | |
| template<uint01 t_dims, class t_type> | |
| JSONNode & | operator= (const Ray< t_dims, t_type > &buffer) |
| Assigns a Ray value to this node as a comma-separated array. | |
| JSONNode & | operator= (const StringView &value) |
| Assigns a string value to this node, setting the type to e_object. | |
| template<class t_type> | |
| JSONNode & | operator= (const t_type &value) |
| JSONNode & | operator= (const Time &time) |
| template<uint01 t_dims, class t_type> | |
| JSONNode & | operator= (const Vector< t_dims, t_type > &buffer) |
| Assigns a Vector value to this node as a comma-separated array. | |
| template<uint01 t_dims, class t_type> | |
| JSONNode & | operator= (const Vertex< t_dims, t_type > &buffer) |
| Assigns a Vertex value to this node as a comma-separated array. | |
| JSONNode & | operator[] (const StringView &child_node) |
| Returns a mutable reference to the named child node, creating it if it does not exist. | |
| const JSONNode & | operator[] (const StringView &child_node) const |
| JSONNode & | operator[] (const uint04 &child_idx) |
| const JSONNode & | operator[] (const uint04 &child_idx) const |
| Returns a const reference to the child node at the given index. | |
| void | remove (const StringView &child_node) |
| Removes the child node with the given name from this node. | |
| template<class t_type> | |
| void | setOrClearIfDefault (const StringView &child_node, const t_type &value, const t_type &default_value) |
| Sets the value of the child node if value differs from the default value, otherwise clears the child. | |
| uint04 | size () |
| NodeType | type () const |
| void | write (File &file) |
| Writes the JSON structure out to a file with no frills. | |
| void | write (std::ostream &file) |
| Writes the JSON structure to an output stream. | |
| void | write (String &stream) const |
| void | writePretty (File &file) |
| Writes our structure out to a file using tabs and new lines. | |
| void | writePretty (std::ostream &file) |
| Writes the JSON structure to an output stream with human-readable formatting. | |
| 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 | writeValue (String &stream) const |
| Writes only the value portion of this node to the given string stream. | |
Static Public Member Functions | |
| static JSONNode | ParseYAML (Scanner &scan) |
| Parses a YAML document from the given scanner and returns it as a JSONNode tree. | |
Protected Member Functions | |
| JSONNode (const StringView &name) | |
| bool | parseJSON (Scanner &scan) |
| bool | parseJSONContent (char start, Scanner &scan) |
| Parses JSON content starting from the given character. | |
| void | parseYAMLContent (StringView value) |
| Parses a YAML value from a string view and sets this node accordingly. | |
| bool | parseYAMLContent (uint04 indentention, Scanner &scan) |
| void | readArray (Scanner &scan) |
| void | readChildrenNodes (Scanner &scan) |
| void | readData (Scanner &scan) |
| template<uint01 t_dims, class t_type> | |
| void | setVector (const Vector< t_dims, t_type > &buffer) |
| Sets the node value from a Vector, storing it as a comma-separated array string. | |
Static Protected Member Functions | |
| static TranslatedString | BadChildErrorString (const Scanner &scan) |
| Generates a translated error message for a malformed child node. | |
| static void | ConvertFromJSONString (String &string) |
| Unescapes JSON escape sequences in the string back to their original characters. | |
| static void | ConvertToJSONString (String &string) |
| Escapes special characters in the string for JSON output. | |
| static TranslatedString | DuplicateChildErrorString (const StringView &child, const Scanner &scan) |
| Generates a translated error message for a duplicate child node name. | |
| static TranslatedString | UnexpectedCharErrorString (char current_char, const Scanner &scan) |
| Generates a translated error message for an unexpected character during parsing. | |
| static void | WriteTabs (String &stream, uint04 tab_indention) |
Protected Attributes | |
| Dictionary< StringView, JSONNode * > | m_json_children |
| Dictionary of child nodes keyed by name. Empty if the node type is not e_node or e_root. | |
| const String | m_name |
| The name of this node. | |
| Buffer< JSONNode * > | m_sorted_json_children |
| Ordered list of child node pointers preserving insertion order. | |
| NodeType | m_type |
| The type classification of this node. | |
| String | m_value |
| The stored value of this node as a string. | |
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
Definition at line 148 of file JSONParser.h.
| enum JSONNode::NodeType |
Describes the type of data stored by a JSONNode.
Definition at line 155 of file JSONParser.h.
| JSONNode::JSONNode | ( | ) |
Creates a root JSON node
Author: Tyler Parke
Date: 2017-11-19
Referenced by JSONNode(), JSONNode(), createChildNode(), createChildNode(), get(), operator=(), operator=(), operator=(), operator=(), operator=(), operator=(), operator=(), operator=(), operator=(), operator=(), operator=(), operator[](), operator[](), operator[](), operator[](), and ParseYAML().
|
protected |
| JSONNode::JSONNode | ( | const JSONNode & | node | ) |
|
noexcept |
| JSONNode::JSONNode | ( | Scanner & | scan | ) |
| JSONNode::JSONNode | ( | const String & | node, |
| const StringView & | json_string ) |
Creates a JSONNode by parsing a named node from a JSON string.
| [in] | node | The name to assign to this node. |
| [in] | json_string | The JSON string to parse. |
| JSONNode::JSONNode | ( | File & | file | ) |
| JSONNode::~JSONNode | ( | ) |
Destroys the JSONNode and frees all child nodes.
|
staticprotected |
Generates a translated error message for a malformed child node.
| [in] | scan | The scanner providing position context for the error. |
|
inlinenodiscard |
Returns a mutable iterator to the beginning of the children dictionary.
Definition at line 681 of file JSONParser.h.
References m_json_children.
|
inlinenodiscard |
Returns a const iterator to the beginning of the children dictionary.
Definition at line 689 of file JSONParser.h.
References m_json_children.
Returns the ordered list of child node pointers.
Definition at line 392 of file JSONParser.h.
References m_sorted_json_children.
Referenced by IconManager::fromJSON().
|
staticprotected |
Unescapes JSON escape sequences in the string back to their original characters.
| [in] | string | The JSON string to convert in place to its unescaped form. |
|
staticprotected |
Escapes special characters in the string for JSON output.
| [in] | string | The string to convert in place to a JSON-safe representation. |
| JSONNode & JSONNode::createChildNode | ( | const StringView & | child_node, |
| NodeType | type ) |
Creates a named child node with the specified type.
| [in] | child_node | The name for the new child node. |
| [in] | type | The NodeType for the new child node. |
References JSONNode(), and type().
|
inline |
Creates an unnamed child node with the specified type.
Definition at line 462 of file JSONParser.h.
References JSONNode(), createChildNode(), e_node, and type().
Referenced by createChildNode().
|
staticprotected |
Generates a translated error message for a duplicate child node name.
| [in] | child | The name of the duplicate child node. |
| [in] | scan | The scanner providing position context for the error. |
|
inlinenodiscard |
Returns a mutable iterator to the end of the children dictionary.
Definition at line 698 of file JSONParser.h.
References m_json_children.
|
inlinenodiscard |
Returns a const iterator to the end of the children dictionary.
Definition at line 706 of file JSONParser.h.
References m_json_children.
|
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.
Definition at line 330 of file JSONParser.h.
References JSONNode(), and m_json_children.
|
inline |
Returns this object as the type specified.
Author: Tyler Parke
Date: 2017-11-19
Definition at line 315 of file JSONParser.h.
References JSONToStringHelper< t_type >::Convert(), and m_value.
Referenced by Customer::company(), Customer::email(), IconDefinition::fromJSON(), CustomerDevice::osName(), CustomerDevice::serialNumber(), and HardwareCommandQueue< t_type >::setFromJSONInfo().
|
inline |
Retrieves a child value if the node exists, returning whether it was found.
| [in] | child_node | The name of the child node to look up. |
| [in] | value | Reference to store the retrieved value if found. |
Definition at line 444 of file JSONParser.h.
References m_json_children.
|
inline |
Checks whether a child node with the given name exists.
| [in] | child_node | The name of the child node to look for. |
Definition at line 401 of file JSONParser.h.
References m_json_children.
Referenced by HardwareCommandQueue< t_type >::setFromJSONInfo().
|
inlinenodiscard |
Returns true if the node contains no information.
Author: Tyler Parke
Date: 2019-14-12
Definition at line 637 of file JSONParser.h.
References m_json_children, and m_value.
|
inline |
Returns the name of this node.
Definition at line 410 of file JSONParser.h.
References m_name.
Referenced by operator=(), and operator[]().
Assigns an Angle value to this node, storing it as degrees.
| [in] | value | The Angle value to assign. |
Definition at line 517 of file JSONParser.h.
References JSONNode(), e_object, m_type, and m_value.
Assigns a Buffer of Strings to this node as a quoted comma-separated array.
| [in] | buffer | The buffer of strings to assign. |
Definition at line 563 of file JSONParser.h.
References JSONNode(), e_array, m_type, and m_value.
|
inline |
Assigns a Buffer of StringViews to this node as a quoted comma-separated array.
| [in] | buffer | The buffer of string views to assign. |
Definition at line 583 of file JSONParser.h.
References JSONNode(), e_array, m_type, and m_value.
|
inline |
Assigns a typed Buffer to this node as a comma-separated array.
| [in] | buffer | The buffer of values to assign. |
Definition at line 544 of file JSONParser.h.
References JSONNode(), e_array, m_type, and m_value.
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
Definition at line 477 of file JSONParser.h.
References JSONNode(), e_node, e_root, m_json_children, m_sorted_json_children, m_type, m_value, and nodeName().
|
inline |
Assigns a Ray value to this node as a comma-separated array.
| [in] | buffer | The Ray to assign. |
Definition at line 625 of file JSONParser.h.
References JSONNode(), and setVector().
|
inline |
Assigns a string value to this node, setting the type to e_object.
| [in] | value | The string value to assign. |
Definition at line 505 of file JSONParser.h.
References JSONNode(), e_object, m_type, and m_value.
|
inline |
A general case t_type equals. Sets the value internal and predicts the type.
Author: Tyler Parke
Date: 2017-11-19
Definition at line 650 of file JSONParser.h.
References JSONNode(), e_array, e_bool, e_number, e_object, m_type, and m_value.
A special case Time equals. writes in YYYY/MM/DDTHH:mm:ss.fffZ format.
Author: Tyler Parke
Date: 2017-11-19
Definition at line 531 of file JSONParser.h.
References JSONNode(), e_object, Time::getAsString(), m_type, and m_value.
|
inline |
Assigns a Vector value to this node as a comma-separated array.
| [in] | buffer | The Vector to assign. |
Definition at line 603 of file JSONParser.h.
References JSONNode(), and setVector().
|
inline |
Assigns a Vertex value to this node as a comma-separated array.
| [in] | buffer | The Vertex to assign. |
Definition at line 614 of file JSONParser.h.
References JSONNode(), and setVector().
|
inline |
Returns a mutable reference to the named child node, creating it if it does not exist.
| [in] | child_node | The name of the child node to access or create. |
Definition at line 353 of file JSONParser.h.
References JSONNode(), m_json_children, m_sorted_json_children, and nodeName().
|
inline |
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.
Definition at line 344 of file JSONParser.h.
References JSONNode(), and m_json_children.
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.
Definition at line 374 of file JSONParser.h.
References JSONNode(), and m_sorted_json_children.
Returns a const reference to the child node at the given index.
| [in] | child_idx | The index of the child node. |
Definition at line 383 of file JSONParser.h.
References JSONNode(), and m_sorted_json_children.
|
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
|
protected |
Parses JSON content starting from the given character.
| [in] | start | The character that begins this content section. |
| [in] | scan | The scanner to read from. |
Parses a YAML document from the given scanner and returns it as a JSONNode tree.
| [in] | scan | The scanner positioned at the start of the YAML content. |
References JSONNode().
|
protected |
Parses a YAML value from a string view and sets this node accordingly.
| [in] | value | The string view containing the YAML value to parse. |
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
|
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
|
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
|
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
| void JSONNode::remove | ( | const StringView & | child_node | ) |
Removes the child node with the given name from this node.
| [in] | child_node | The name of the child node to remove. |
Referenced by setOrClearIfDefault().
|
inlineprotected |
Sets the node value from a Vector, storing it as a comma-separated array string.
| [in] | buffer | The Vector whose components are written as the node value. |
Definition at line 829 of file JSONParser.h.
References e_array, m_type, and m_value.
Referenced by operator=(), operator=(), and operator=().
|
inline |
Returns the number of children within this node.
Author: Tyler Parke
Date: 2017-11-19
Definition at line 673 of file JSONParser.h.
References cast(), and m_json_children.
| NodeType JSONNode::type | ( | ) | const |
Author: Tyler Parke
Date: 2017-11-19
Referenced by createChildNode(), and createChildNode().
|
staticprotected |
Generates a translated error message for an unexpected character during parsing.
| [in] | current_char | The unexpected character encountered. |
| [in] | scan | The scanner providing position context for the error. |
| void JSONNode::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
| void JSONNode::write | ( | std::ostream & | file | ) |
Writes the JSON structure to an output stream.
| [in] | file | The output stream to write to. |
| 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
| void JSONNode::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
| void JSONNode::writePretty | ( | std::ostream & | file | ) |
Writes the JSON structure to an output stream with human-readable formatting.
| [in] | file | The output stream to write to. |
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
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
| void JSONNode::writeValue | ( | String & | stream | ) | const |
Writes only the value portion of this node to the given string stream.
| [in] | stream | The string to append the value to. |