34#include <NDEVR/Scanner.h>
35#include <NDEVR/String.h>
36#include <NDEVR/Buffer.h>
37#include <NDEVR/Dictionary.h>
38#include <NDEVR/Time.h>
41 class TranslatedString;
61 static const uint04 s_number_of_decimals = 10;
200 template<
class t_type>
203 return JSONToStringHelper<t_type>::Convert(m_value);
218 return *m_json_children[child_node];
247 return m_sorted_json_children;
251 return m_json_children.hasKey(child_node);
272 if (node.
m_type == e_root)
276 for (
const auto& iter : m_sorted_json_children)
280 m_sorted_json_children.clear();
281 m_json_children.clear();
284 m_sorted_json_children.add(
new JSONNode(*iter));
285 if (!m_json_children.hasKey(iter->nodeName()))
286 m_json_children.add(iter->nodeName(), m_sorted_json_children.last());
298 template<
class t_type>
302 m_value =
String(value.template as<DEGREES>());
316 m_value = time.
toString(
false,
"YYYY/MM/DDTHH:mm:ss.fffZ");;
320 template<
class t_type,
class t_allocator>
328 template<u
int01 t_dims,
class t_type>
345 return m_value.size() == 0 && m_json_children.size() == 0;
355 template<
class t_type>
381 return cast<uint04>(m_json_children.size());
384 [[nodiscard]]
decltype(
auto)
begin()
386 return m_json_children.begin();
388 [[nodiscard]]
decltype(
auto)
begin()
const
390 return m_json_children.begin();
393 [[nodiscard]]
decltype(
auto)
end()
395 return m_json_children.end();
397 [[nodiscard]]
decltype(
auto)
end()
const
399 return m_json_children.end();
500 template<
class t_type>
501 class JSONToStringHelper
504 static t_type Convert(
const String& value)
506 return value.
getAs<t_type>();
509 template<
class t_type>
510 class JSONToStringHelper<
Angle<t_type>>
519 class JSONToStringHelper<String>
522 static const String& Convert(
const String& value)
528 class JSONToStringHelper<Time>
539 static Time Convert(
const String& value)
543 if (value.contains(
'.'))
544 return Time(value,
false,
"YYYY/MM/DDTHH:mm:ss.fffZ");
545 else if (value.contains(
'T'))
546 return Time(value,
false,
"YYYY/MM/DDTHH:mm:ss");
547 uint04 sub_value = value.indexOf(
"Date(");
550 return Time(value.substr(sub_value + 5).getAs<uint08>() * Time::SECOND);
552 Time time_val = value.getAs<Time>();
#define lib_assert(expression, message)
Definition LibAssert.h:61
The primary angle storage class for this API. Stores an angle in an optimized format.
Definition StringStream.h:540
The equivelent of std::vector but with a bit more control. The basic array unit of the library.
Definition Buffer.hpp:56
A hash-based key-value store, useful for quick associative lookups. Key features include:
Definition Dictionary.h:61
Logic for reading or writing to a file as well as navigating filesystems.
Definition File.h:48
JavaScript Object Notation or JSON is an open - standard file format that uses human - readable text ...
Definition JSONParser.h:60
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...
bool parseJSON(Scanner &scan)
Buffer< JSONNode * > m_sorted_json_children
Definition JSONParser.h:494
void write(String &stream) const
JSONNode & operator[](const uint04 &child_idx)
void writePretty(File &file)
Writes our structure out to a file using tabs and new lines. Same as writePretty(String&) but for fil...
bool parseJSONContent(char start, Scanner &scan)
void remove(const String &child_node)
JSONNode(const String &node, const String &json_string)
static void ConvertFromJSONString(String &string)
JSONNode(const JSONNode &node)
JSONNode & operator=(const t_type &value)
Definition JSONParser.h:356
void writePretty(std::ostream &file)
void write(File &file)
Writes the JSON structure out to a file with no frills. Same as write(String&) but for files.
JSONNode & operator=(const String &value)
Definition JSONParser.h:292
static TranslatedString DuplicateChildErrorString(const String &child, const Scanner &scan)
JSONNode & createChildNode(const String &child_node, NodeType type)
const JSONNode & operator[](const String &child_node) const
JSONNode & operator=(const Buffer< t_type, t_allocator > &buffer)
Definition JSONParser.h:321
Dictionary< String, JSONNode * > m_json_children
Definition JSONParser.h:495
const String m_name
Definition JSONParser.h:496
JSONNode & operator=(const Time &time)
Definition JSONParser.h:313
decltype(auto) end()
Definition JSONParser.h:393
JSONNode & operator=(const JSONNode &node)
Definition JSONParser.h:269
static TranslatedString BadChildErrorString(const Scanner &scan)
JSONNode & operator[](const String &child_node)
String m_value
Definition JSONParser.h:497
JSONNode(const String &name)
void write(std::ostream &file)
static void WriteTabs(String &stream, uint04 tab_indention)
decltype(auto) getAs() const
Definition JSONParser.h:201
uint04 size()
Definition JSONParser.h:379
JSONNode & operator=(const Vector< t_dims, t_type > &buffer)
Definition JSONParser.h:329
bool hasNode(const String &child_node) const
Definition JSONParser.h:249
decltype(auto) begin()
Definition JSONParser.h:384
const String & nodeName() const
Definition JSONParser.h:254
const JSONNode & get(const String &child_node) const
Definition JSONParser.h:216
bool parseYAMLContent(uint04 indentention, Scanner &scan)
void readData(Scanner &scan)
static JSONNode ParseYAML(Scanner &scan)
static TranslatedString UnexpectedCharErrorString(char current_char, const Scanner &scan)
const JSONNode & operator[](const uint04 &child_idx) const
NodeType
Definition JSONParser.h:64
decltype(auto) begin() const
Definition JSONParser.h:388
JSONNode(JSONNode &&node) noexcept
bool isEmpty() const
Definition JSONParser.h:343
JSONNode & operator=(const Angle< t_type > &value)
Definition JSONParser.h:299
NodeType m_type
Definition JSONParser.h:498
void readArray(Scanner &scan)
void readChildrenNodes(Scanner &scan)
decltype(auto) end() const
Definition JSONParser.h:397
const Buffer< JSONNode * > & children() const
Definition JSONParser.h:245
static void ConvertToJSONString(String &string)
Contains methods for easily reading objects in an ascii stream.
Definition Scanner.h:45
The core String class for the NDEVR API.
Definition String.h:69
t_type getAs() const
Converts a string into an object. To use this function an object must have overwritten StringStream<t...
Definition String.h:143
Represents a timestamp with utilities for manipulation and conversion.
Definition Time.h:54
String toString(bool get_local_time, const String &format_string) const
Converts the timestamp to a string representation. https://ndevr.org/time-patterns/.
Any text displayed to the user should be defined as a TranslatedString which allows the program to lo...
Definition TranslatedString.h:13
A fixed-size array with better performance compared to dynamic containers.
Definition Vector.hpp:60
constexpr bool IsInvalid(const t_type &value)
Query if 'value' is valid or invalid. Invalid values should return invalid if used for calculations o...
Definition BaseFunctions.hpp:170
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:96
double fltp08
Defines an alias representing an 8 byte floating-point number.
Definition BaseValues.hpp:149
Information about the object.
Definition ObjectInfo.h:54