ECSTASY
All in the name
Loading...
Searching...
No Matches
util::serialization::ANode Class Reference

Serialization node. More...

#include <ANode.hpp>

Inheritance diagram for util::serialization::ANode:
Collaboration diagram for util::serialization::ANode:

Public Member Functions

virtual ~ANode ()=default
 Default destructor.
 
bool isType (Type type) const noexcept override final
 Check if the node type is type.
 
bool isNull () const noexcept override final
 Check if the node type is Type::Null.
 
bool isObject () const noexcept override final
 Check if the node type is Type::Object.
 
bool isArray () const noexcept override final
 Check if the node type is Type::Array.
 
bool isString () const noexcept override final
 Check if the node type is Type::String.
 
bool isInteger () const noexcept override final
 Check if the node type is Type::Integer.
 
bool isFloat () const noexcept override final
 Check if the node type is Type::Float.
 
bool isBoolean () const noexcept override final
 Check if the node type is Type::Boolean.
 
bool isDate () const noexcept override final
 Check if the node type is Type::Date.
 
bool isTime () const noexcept override final
 Check if the node type is Type::Time.
 
bool isDateTime () const noexcept override final
 Check if the node type is Type::DateTime.
 
const IObjectNodeasObject () const override final
 Get the object node value.
 
IObjectNodeasObject () override final
 Get the object node value.
 
std::optional< std::reference_wrapper< const IObjectNode > > tryAsObject () const noexcept override final
 Try to get the node object value.
 
std::optional< std::reference_wrapper< IObjectNode > > tryAsObject () noexcept override final
 Try to get the node object value.
 
const IArrayNodeasArray () const override final
 Get the array node value.
 
IArrayNodeasArray () override final
 Get the array node value.
 
std::optional< std::reference_wrapper< const IArrayNode > > tryAsArray () const noexcept override final
 Try to get the node array value.
 
std::optional< std::reference_wrapper< IArrayNode > > tryAsArray () noexcept override final
 Try to get the node array value.
 
std::string_view asString () const override final
 Get the string node value.
 
int64_t asInteger () const override final
 Get the integer node value.
 
double asFloat () const override final
 Get the float node value.
 
bool asBoolean () const override final
 Get the boolean node value.
 
Date asDate () const override final
 Get the date node value.
 
Time asTime () const override final
 Get the time node value.
 
DateTime asDateTime () const override final
 Get the datetime node value.
 
- Public Member Functions inherited from util::serialization::INode
virtual ~INode ()=default
 Default destructor.
 
virtual Type getType () const noexcept=0
 Types check ///.
 
virtual bool isType (Type type) const noexcept=0
 Check if the node type is type.
 
virtual bool isNull () const noexcept=0
 Check if the node type is Type::Null.
 
virtual bool isObject () const noexcept=0
 Check if the node type is Type::Object.
 
virtual bool isArray () const noexcept=0
 Check if the node type is Type::Array.
 
virtual bool isString () const noexcept=0
 Check if the node type is Type::String.
 
virtual bool isInteger () const noexcept=0
 Check if the node type is Type::Integer.
 
virtual bool isFloat () const noexcept=0
 Check if the node type is Type::Float.
 
virtual bool isBoolean () const noexcept=0
 Check if the node type is Type::Boolean.
 
virtual bool isDate () const noexcept=0
 Check if the node type is Type::Date.
 
virtual bool isTime () const noexcept=0
 Check if the node type is Type::Time.
 
virtual bool isDateTime () const noexcept=0
 Check if the node type is Type::DateTime.
 
virtual const IObjectNodeasObject () const =0
 Value getter ///.
 
virtual IObjectNodeasObject ()=0
 Get the object node value.
 
virtual std::optional< std::reference_wrapper< const IObjectNode > > tryAsObject () const noexcept=0
 Try to get the node object value.
 
virtual std::optional< std::reference_wrapper< IObjectNode > > tryAsObject () noexcept=0
 Try to get the node object value.
 
virtual const IArrayNodeasArray () const =0
 Get the array node value.
 
virtual IArrayNodeasArray ()=0
 Get the array node value.
 
virtual std::optional< std::reference_wrapper< const IArrayNode > > tryAsArray () const noexcept=0
 Try to get the node array value.
 
virtual std::optional< std::reference_wrapper< IArrayNode > > tryAsArray () noexcept=0
 Try to get the node array value.
 
virtual std::string_view asString () const =0
 Get the string node value.
 
virtual std::optional< std::string_viewtryAsString () const noexcept=0
 Try to get the node string value.
 
virtual int64_t asInteger () const =0
 Get the integer node value.
 
virtual std::optional< int64_t > tryAsInteger () const noexcept=0
 Try to get the node integer value.
 
virtual double asFloat () const =0
 Get the float node value.
 
virtual std::optional< double > tryAsFloat () const noexcept=0
 Try to get the node float value.
 
virtual bool asBoolean () const =0
 Get the boolean node value.
 
virtual std::optional< bool > tryAsBoolean () const noexcept=0
 Try to get the node boolean value.
 
virtual Date asDate () const =0
 Get the date node value.
 
virtual std::optional< DatetryAsDate () const noexcept=0
 Try to get the node date value.
 
virtual Time asTime () const =0
 Get the time node value.
 
virtual std::optional< TimetryAsTime () const noexcept=0
 Try to get the node time value.
 
virtual DateTime asDateTime () const =0
 Get the datetime node value.
 
virtual std::optional< DateTimetryAsDateTime () const noexcept=0
 Try to get the node datetime value.
 

Additional Inherited Members

- Public Types inherited from util::serialization::INode
enum class  Type {
  Unknown = -1 , Null , Object , Array ,
  String , Integer , Float , Boolean ,
  Date , Time , DateTime , Count
}
 Available node types. More...
 
using Date = std::chrono::year_month_day
 Type::Date underlying type.
 
using Time = std::chrono::nanoseconds
 Type::Time underlying type.
 
using DateTime = std::chrono::high_resolution_clock::time_point
 Type::DateTime underlying type.
 

Detailed Description

Serialization node.

Can be any type of INode::Type.

Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-12-08)

Definition at line 25 of file ANode.hpp.

Constructor & Destructor Documentation

◆ ~ANode()

virtual util::serialization::ANode::~ANode ( )
virtualdefault

Default destructor.

Member Function Documentation

◆ asArray() [1/2]

const IArrayNode & util::serialization::ANode::asArray ( ) const
finaloverridevirtual

Get the array node value.

Returns
IArrayNode& node value.
Exceptions
std::runtime_errorIf the node is the node type is not Type::Array.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-12-08)

Implements util::serialization::INode.

Definition at line 99 of file ANode.cpp.

100 {
101 return const_cast<ANode &>(*this).asArray();
102 }

◆ asArray() [2/2]

IArrayNode & util::serialization::ANode::asArray ( )
finaloverridevirtual

Get the array node value.

Returns
IArrayNode& node value.
Exceptions
std::runtime_errorIf the node is the node type is not Type::Array.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-12-08)

Implements util::serialization::INode.

Definition at line 104 of file ANode.cpp.

105 {
106 if (!isArray()) [[unlikely]]
107 throw std::runtime_error("Node is not an Array Node.");
108 return dynamic_cast<IArrayNode &>(*this);
109 }
bool isArray() const noexcept override final
Check if the node type is Type::Array.
Definition ANode.cpp:33

◆ asBoolean()

bool util::serialization::ANode::asBoolean ( ) const
finaloverridevirtual

Get the boolean node value.

Returns
bool node value.
Exceptions
std::bad_optional_castIf the node is the node type is not Type::Boolean.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-12-08)

Implements util::serialization::INode.

Definition at line 140 of file ANode.cpp.

141 {
142 return tryAsBoolean().value();
143 }
virtual std::optional< bool > tryAsBoolean() const noexcept=0
Try to get the node boolean value.

◆ asDate()

INode::Date util::serialization::ANode::asDate ( ) const
finaloverridevirtual

Get the date node value.

Returns
Date node value.
Exceptions
std::bad_optional_castIf the node is the node type is not Type::Date.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-12-08)

Implements util::serialization::INode.

Definition at line 145 of file ANode.cpp.

146 {
147 return tryAsDate().value();
148 }
virtual std::optional< Date > tryAsDate() const noexcept=0
Try to get the node date value.

◆ asDateTime()

INode::DateTime util::serialization::ANode::asDateTime ( ) const
finaloverridevirtual

Get the datetime node value.

Returns
DateTime node value.
Exceptions
std::bad_optional_castIf the node is the node type is not Type::DateTime.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-12-08)

Implements util::serialization::INode.

Definition at line 155 of file ANode.cpp.

156 {
157 return tryAsDateTime().value();
158 }
virtual std::optional< DateTime > tryAsDateTime() const noexcept=0
Try to get the node datetime value.

◆ asFloat()

double util::serialization::ANode::asFloat ( ) const
finaloverridevirtual

Get the float node value.

Returns
double node value.
Exceptions
std::bad_optional_castIf the node is the node type is not Type::Float.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-12-08)

Implements util::serialization::INode.

Definition at line 135 of file ANode.cpp.

136 {
137 return tryAsFloat().value();
138 }
virtual std::optional< double > tryAsFloat() const noexcept=0
Try to get the node float value.

◆ asInteger()

int64_t util::serialization::ANode::asInteger ( ) const
finaloverridevirtual

Get the integer node value.

Returns
int node value.
Exceptions
std::bad_optional_castIf the node is the node type is not Type::Integer.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-12-08)

Implements util::serialization::INode.

Definition at line 130 of file ANode.cpp.

131 {
132 return tryAsInteger().value();
133 }
virtual std::optional< int64_t > tryAsInteger() const noexcept=0
Try to get the node integer value.

◆ asObject() [1/2]

const IObjectNode & util::serialization::ANode::asObject ( ) const
finaloverridevirtual

Get the object node value.

Returns
IObjectNode& node value.
Exceptions
std::runtime_errorIf the node is the node type is not Type::Object.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-12-08)

Implements util::serialization::INode.

Definition at line 73 of file ANode.cpp.

74 {
75 return const_cast<ANode &>(*this).asObject();
76 }

◆ asObject() [2/2]

IObjectNode & util::serialization::ANode::asObject ( )
finaloverridevirtual

Get the object node value.

Returns
IObjectNode& node value.
Exceptions
std::runtime_errorIf the node is the node type is not Type::Object.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-12-08)

Implements util::serialization::INode.

Definition at line 78 of file ANode.cpp.

79 {
80 if (!isObject()) [[unlikely]]
81 throw std::runtime_error("Node is not an Object Node.");
82 return dynamic_cast<IObjectNode &>(*this);
83 }
bool isObject() const noexcept override final
Check if the node type is Type::Object.
Definition ANode.cpp:28

◆ asString()

std::string_view util::serialization::ANode::asString ( ) const
finaloverridevirtual

Get the string node value.

Returns
std::string_view node value.
Exceptions
std::bad_optional_castIf the node is the node type is not Type::String.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-12-08)

Implements util::serialization::INode.

Definition at line 125 of file ANode.cpp.

126 {
127 return tryAsString().value();
128 }
virtual std::optional< std::string_view > tryAsString() const noexcept=0
Try to get the node string value.

◆ asTime()

INode::Time util::serialization::ANode::asTime ( ) const
finaloverridevirtual

Get the time node value.

Returns
Time node value.
Exceptions
std::bad_optional_castIf the node is the node type is not Type::Time.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-12-08)

Implements util::serialization::INode.

Definition at line 150 of file ANode.cpp.

151 {
152 return tryAsTime().value();
153 }
virtual std::optional< Time > tryAsTime() const noexcept=0
Try to get the node time value.

◆ isArray()

bool util::serialization::ANode::isArray ( ) const
finaloverridevirtualnoexcept

Check if the node type is Type::Array.

Returns
bool Whether the node type is Type::Array.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-12-08)

Implements util::serialization::INode.

Definition at line 33 of file ANode.cpp.

34 {
35 return isType(Type::Array);
36 }
bool isType(Type type) const noexcept override final
Check if the node type is type.
Definition ANode.cpp:18
@ Array
Node containing multiple unnamed nodes. (similar to a std::vector<string>)

◆ isBoolean()

bool util::serialization::ANode::isBoolean ( ) const
finaloverridevirtualnoexcept

Check if the node type is Type::Boolean.

Returns
bool Whether the node type is Type::Boolean.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-12-08)

Implements util::serialization::INode.

Definition at line 53 of file ANode.cpp.

54 {
55 return isType(Type::Boolean);
56 }
@ Boolean
Boolean value node.

◆ isDate()

bool util::serialization::ANode::isDate ( ) const
finaloverridevirtualnoexcept

Check if the node type is Type::Date.

Returns
bool Whether the node type is Type::Date.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-12-08)

Implements util::serialization::INode.

Definition at line 58 of file ANode.cpp.

59 {
60 return isType(Type::Date);
61 }

◆ isDateTime()

bool util::serialization::ANode::isDateTime ( ) const
finaloverridevirtualnoexcept

Check if the node type is Type::DateTime.

Returns
bool Whether the node type is Type::DateTime.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-12-08)

Implements util::serialization::INode.

Definition at line 68 of file ANode.cpp.

69 {
70 return isType(Type::DateTime);
71 }
@ DateTime
DateTime node. (Timestamp)

◆ isFloat()

bool util::serialization::ANode::isFloat ( ) const
finaloverridevirtualnoexcept

Check if the node type is Type::Float.

Returns
bool Whether the node type is Type::Float.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-12-08)

Implements util::serialization::INode.

Definition at line 48 of file ANode.cpp.

49 {
50 return isType(Type::Float);
51 }
@ Float
Floating point number node.

◆ isInteger()

bool util::serialization::ANode::isInteger ( ) const
finaloverridevirtualnoexcept

Check if the node type is Type::Integer.

Returns
bool Whether the node type is Type::Integer.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-12-08)

Implements util::serialization::INode.

Definition at line 43 of file ANode.cpp.

44 {
45 return isType(Type::Integer);
46 }
@ Integer
Integer number node.

◆ isNull()

bool util::serialization::ANode::isNull ( ) const
finaloverridevirtualnoexcept

Check if the node type is Type::Null.

Returns
bool Whether the node type is Type::Null.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-12-08)

Implements util::serialization::INode.

Definition at line 23 of file ANode.cpp.

24 {
25 return isType(Type::Null);
26 }
@ Null
Null node (none/null).

◆ isObject()

bool util::serialization::ANode::isObject ( ) const
finaloverridevirtualnoexcept

Check if the node type is Type::Object.

Returns
bool Whether the node type is Type::Object.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-12-08)

Implements util::serialization::INode.

Definition at line 28 of file ANode.cpp.

29 {
30 return isType(Type::Object);
31 }
@ Object
Node containing multiple named nodes. (similar to a std::map<string, INode>)

◆ isString()

bool util::serialization::ANode::isString ( ) const
finaloverridevirtualnoexcept

Check if the node type is Type::String.

Returns
bool Whether the node type is Type::String.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-12-08)

Implements util::serialization::INode.

Definition at line 38 of file ANode.cpp.

39 {
40 return isType(Type::String);
41 }

◆ isTime()

bool util::serialization::ANode::isTime ( ) const
finaloverridevirtualnoexcept

Check if the node type is Type::Time.

Returns
bool Whether the node type is Type::Time.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-12-08)

Implements util::serialization::INode.

Definition at line 63 of file ANode.cpp.

64 {
65 return isType(Type::Time);
66 }

◆ isType()

bool util::serialization::ANode::isType ( Type  type) const
finaloverridevirtualnoexcept

Check if the node type is type.

Returns
bool Whether the node type is type.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-12-08)

Implements util::serialization::INode.

Definition at line 18 of file ANode.cpp.

19 {
20 return getType() == type;
21 }
virtual Type getType() const noexcept=0
Types check ///.

◆ tryAsArray() [1/2]

std::optional< std::reference_wrapper< const IArrayNode > > util::serialization::ANode::tryAsArray ( ) const
finaloverridevirtualnoexcept

Try to get the node array value.

Returns
std::optional<IArrayNode &> Filled with the node string if the type is Type::Array, empty otherwise.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-12-08)

Implements util::serialization::INode.

Definition at line 111 of file ANode.cpp.

112 {
113 if (isArray())
114 return dynamic_cast<const IArrayNode &>(*this);
116 }

◆ tryAsArray() [2/2]

std::optional< std::reference_wrapper< IArrayNode > > util::serialization::ANode::tryAsArray ( )
finaloverridevirtualnoexcept

Try to get the node array value.

Returns
std::optional<IArrayNode &> Filled with the node string if the type is Type::Array, empty otherwise.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-12-08)

Implements util::serialization::INode.

Definition at line 118 of file ANode.cpp.

119 {
120 if (isArray())
121 return dynamic_cast<IArrayNode &>(*this);
123 }

◆ tryAsObject() [1/2]

std::optional< std::reference_wrapper< const IObjectNode > > util::serialization::ANode::tryAsObject ( ) const
finaloverridevirtualnoexcept

Try to get the node object value.

Returns
std::optional<IObjectNode &> Filled with the node string if the type is Type::Object, empty otherwise.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-12-08)

Implements util::serialization::INode.

Definition at line 85 of file ANode.cpp.

86 {
87 if (isObject())
88 return dynamic_cast<const IObjectNode &>(*this);
90 }

◆ tryAsObject() [2/2]

std::optional< std::reference_wrapper< IObjectNode > > util::serialization::ANode::tryAsObject ( )
finaloverridevirtualnoexcept

Try to get the node object value.

Returns
std::optional<IObjectNode &> Filled with the node string if the type is Type::Object, empty otherwise.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-12-08)

Implements util::serialization::INode.

Definition at line 92 of file ANode.cpp.

93 {
94 if (isObject())
95 return dynamic_cast<IObjectNode &>(*this);
97 }

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