34#include <NDEVR/Scanner.h>
35#include <NDEVR/String.h>
36#include <NDEVR/Buffer.h>
37#include <NDEVR/Dictionary.h>
38#include <NDEVR/Vertex.h>
39#include <NDEVR/StringView.h>
40#include <NDEVR/Time.h>
48 template<
class t_type>
59 return value.
getAs<t_type>();
65 template<
class t_type>
115 if (value.contains(
'.'))
116 return Time(value,
false,
"YYYY/MM/DDTHH:mm:ss.fffZ");
117 else if (value.contains(
'T'))
118 return Time(value,
false,
"YYYY/MM/DDTHH:mm:ss");
125 lib_assert(
IsValid(time_val),
"Could not parse time value");
150 static const uint04 s_number_of_decimals = 10;
314 template<
class t_type>
362 return *iter.value();
417 template<
class t_type>
420 if (AreSame(value, default_value))
423 (*
this)[child_node] = value;
428 template<
class t_type>
433 return iter.value()->getAs<t_type>();
435 return default_value;
443 template<
class t_type>
449 value = iter.value()->getAs<t_type>();
516 template<
class t_type>
520 m_value.setFrom(value.template as<DEGREES>());
543 template<
class t_type,
class t_allocator>
549 for (
uint01 i = 1; i < buffer.size(); i++)
562 template<
class String>
569 for (
uint01 i = 1; i < buffer.size(); i++)
582 template<
class String>
589 for (
uint01 i = 1; i < buffer.size(); i++)
602 template<u
int01 t_dims,
class t_type>
613 template<u
int01 t_dims,
class t_type>
624 template<u
int01 t_dims,
class t_type>
649 template<
class t_type>
681 [[nodiscard]]
decltype(
auto)
begin()
689 [[nodiscard]]
decltype(
auto)
begin()
const
698 [[nodiscard]]
decltype(
auto)
end()
706 [[nodiscard]]
decltype(
auto)
end()
const
828 template<u
int01 t_dims,
class t_type>
834 for (
uint01 i = 1; i < t_dims; i++)
Stores an angle in an optimized internal format with support for efficient trigonometric operations.
The equivelent of std::vector but with a bit more control.
A hash-based key-value store, useful for quick associative lookups.
Logic for reading or writing to a file as well as navigating filesystems or other common file operati...
String m_value
The stored value of this node as a string.
JSONNode & operator=(const StringView &value)
Assigns a string value to this node, setting the type to e_object.
void setVector(const Vector< t_dims, t_type > &buffer)
Sets the node value from a Vector, storing it as a comma-separated array string.
JSONNode & createChildNode(NodeType type=NodeType::e_node)
Creates an unnamed child node with the specified type.
decltype(auto) begin()
Returns a mutable iterator to the beginning of the children dictionary.
JSONNode(const StringView &name)
decltype(auto) getAs() const
const Buffer< JSONNode * > & children() const
Returns the ordered list of child node pointers.
void readChildrenNodes(Scanner &scan)
static TranslatedString BadChildErrorString(const Scanner &scan)
Generates a translated error message for a malformed child node.
bool hasNode(const StringView &child_node) const
Checks whether a child node with the given name exists.
NodeType m_type
The type classification of this node.
JSONNode & operator=(const Buffer< StringView > &buffer)
Assigns a Buffer of StringViews to this node as a quoted comma-separated array.
void write(String &stream) const
const JSONNode & get(const StringView &child_node) const
decltype(auto) end() const
Returns a const iterator to the end of the children dictionary.
JSONNode & operator=(const Buffer< t_type, t_allocator > &buffer)
Assigns a typed Buffer to this node as a comma-separated array.
bool parseJSON(Scanner &scan)
t_type get(const StringView &child_node, const t_type &default_value) const
Gets the value if it exists, otherwise returns the default value.
JSONNode(const JSONNode &node)
JSONNode(JSONNode &&node) noexcept
bool parseJSONContent(char start, Scanner &scan)
Parses JSON content starting from the given character.
JSONNode & operator=(const JSONNode &node)
A special case of the = operator for nodes.
JSONNode & operator=(const Vertex< t_dims, t_type > &buffer)
Assigns a Vertex value to this node as a comma-separated array.
const String m_name
The name of this node.
void writePretty(File &file)
Writes our structure out to a file using tabs and new lines.
void readData(Scanner &scan)
Buffer< JSONNode * > m_sorted_json_children
Ordered list of child node pointers preserving insertion order.
void parseYAMLContent(StringView value)
Parses a YAML value from a string view and sets this node accordingly.
JSONNode & operator=(const Vector< t_dims, t_type > &buffer)
Assigns a Vector value to this node as a comma-separated array.
static TranslatedString DuplicateChildErrorString(const StringView &child, const Scanner &scan)
Generates a translated error message for a duplicate child node name.
bool parseYAMLContent(uint04 indentention, Scanner &scan)
JSONNode & createChildNode(const StringView &child_node, NodeType type)
Creates a named child node with the specified type.
void readArray(Scanner &scan)
JSONNode & operator=(const t_type &value)
static JSONNode ParseYAML(Scanner &scan)
Parses a YAML document from the given scanner and returns it as a JSONNode tree.
const JSONNode & operator[](const uint04 &child_idx) const
Returns a const reference to the child node at the given index.
static void ConvertToJSONString(String &string)
Escapes special characters in the string for JSON output.
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.
JSONNode & operator=(const Buffer< String > &buffer)
Assigns a Buffer of Strings to this node as a quoted comma-separated array.
JSONNode(const String &node, const StringView &json_string)
Creates a JSONNode by parsing a named node from a JSON string.
~JSONNode()
Destroys the JSONNode and frees all child nodes.
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.
JSONNode & operator=(const Ray< t_dims, t_type > &buffer)
Assigns a Ray value to this node as a comma-separated array.
void remove(const StringView &child_node)
Removes the child node with the given name from this node.
JSONNode & operator=(const Time &time)
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 fi...
decltype(auto) begin() const
Returns a const iterator to the beginning of the children dictionary.
JSONNode & operator[](const StringView &child_node)
Returns a mutable reference to the named child node, creating it if it does not exist.
static void ConvertFromJSONString(String &string)
Unescapes JSON escape sequences in the string back to their original characters.
const String & nodeName() const
Returns the name of this node.
JSONNode & operator[](const uint04 &child_idx)
void write(File &file)
Writes the JSON structure out to a file with no frills.
decltype(auto) end()
Returns a mutable iterator to the end of the children dictionary.
JSONNode & operator=(const Angle< t_type > &value)
Assigns an Angle value to this node, storing it as degrees.
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)
void writeValue(String &stream) const
Writes only the value portion of this node to the given string stream.
void write(std::ostream &file)
Writes the JSON structure to an output stream.
NodeType
Describes the type of data stored by a JSONNode.
@ e_number
Stores a number (may be integer or floating point).
@ e_root
Is a root node, meaning it has no parent.
@ e_node
Is a node storing a number of children JSON nodes.
@ e_object
Stores an object with data that is not a number type.
@ e_array
Stores an array of values.
@ e_bool
Stores a boolean true/false.
bool getIfExists(const StringView &child_node, t_type &value) const
Retrieves a child value if the node exists, returning whether it was found.
const JSONNode & operator[](const StringView &child_node) const
static Angle< t_type > Convert(const String &value)
Converts a JSON string to an Angle by interpreting the value as degrees.
static StringView Convert(const String &value)
Converts a JSON string value to a StringView without transformation.
static Time Convert(const String &value)
Template specialization for time, as the format for time in JSON is not entirely specified,...
Helper template for converting a JSON string value to a specific type.
static t_type Convert(const String &value)
Converts a JSON string representation to the target type.
Contains methods for easily reading objects in an ascii stream using set deliminators and line logic.
The core String View class for the NDEVR API.
t_type getAs() const
Converts a string into an object.
The core String class for the NDEVR API.
StringView substr(uint04 start) const
Creates a substring from a given start position, to the end of the string.
uint04 indexOf(const StringView &sub_string, bool ignore_case=false, uint04 start_index=0) const
Given a substring specified by the input, returns the first index of that string, if it exists.
decltype(auto) getAs() const
Converts a string into an object.
Represents a timestamp with utilities for manipulation and conversion.
StringAllocatingView getAsString(bool get_local_time, const StringView &format_string) const
Converts the timestamp to a string representation.
Any text displayed to the user should be defined as a TranslatedString which allows the program to lo...
A fixed-size array with N dimensions used as the basis for geometric and mathematical types.
A point in N-dimensional space, used primarily for spatial location information.
The primary namespace for the NDEVR SDK.
static constexpr bool IsValid(const Angle< t_type > &value)
Checks whether the given Angle holds a valid value.
uint64_t uint08
-Defines an alias representing an 8 byte, unsigned integer
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
double fltp08
Defines an alias representing an 8 byte floating-point number.
@ DEGREES
Angle measured in degrees (0 to 360 for a full circle).
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
constexpr t_to cast(const Angle< t_from > &value)
Casts an Angle from one backing type to another.
Information about the object.