ECSTASY
All in the name
Loading...
Searching...
No Matches
util::serialization::TomlNode< N > Class Template Reference

Serialization node. More...

#include <TomlNode.hpp>

Inheritance diagram for util::serialization::TomlNode< N >:
Collaboration diagram for util::serialization::TomlNode< N >:

Public Member Functions

 TomlNode () noexcept(std::is_nothrow_default_constructible_v< N >)=default
 Default constructor.
 
 TomlNode (const N &node) noexcept(std::is_nothrow_copy_constructible_v< N >)
 Construct a new Toml Node from a toml::node derived class object.
 
template<typename... Args>
 TomlNode (Args &&...args) noexcept(std::is_nothrow_constructible_v< N, Args... >)
 Construct a new Toml Node from a node data.
 
constexpr INode::Type getType () const noexcept override final
 Types check ///.
 
std::optional< std::string_viewtryAsString () const noexcept override final
 Try to get the node string value.
 
std::optional< int64_t > tryAsInteger () const noexcept override final
 Try to get the node integer value.
 
std::optional< double > tryAsFloat () const noexcept override final
 Try to get the node float value.
 
std::optional< bool > tryAsBoolean () const noexcept override final
 Try to get the node boolean value.
 
std::optional< DatetryAsDate () const noexcept override final
 Try to get the node date value.
 
std::optional< TimetryAsTime () const noexcept override final
 Try to get the node time value.
 
std::optional< DateTimetryAsDateTime () const noexcept override final
 Try to get the node datetime value.
 
- Public Member Functions inherited from util::serialization::ANode
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.
 

Protected Attributes

_node
 Inner node.
 

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

template<typename N>
requires std::derived_from<N, toml::node> && std::copy_constructible<N>
class util::serialization::TomlNode< N >

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 29 of file TomlNode.hpp.

Constructor & Destructor Documentation

◆ TomlNode() [1/3]

template<typename N >
util::serialization::TomlNode< N >::TomlNode ( ) const
defaultnoexcept

Default constructor.

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

◆ TomlNode() [2/3]

template<typename N >
util::serialization::TomlNode< N >::TomlNode ( const N &  node)
inlinenoexcept

Construct a new Toml Node from a toml::node derived class object.

Parameters
[in]nodeInner node.
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-12)

Definition at line 47 of file TomlNode.hpp.

47 : _node(node)
48 {
49 }

◆ TomlNode() [3/3]

template<typename N >
template<typename... Args>
util::serialization::TomlNode< N >::TomlNode ( Args &&...  args)
inlinenoexcept

Construct a new Toml Node from a node data.

Template Parameters
ArgsTypes of the internal node constructor.
Parameters
[in]argsArguments to forward to the internal node constructor.
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-12)

Definition at line 62 of file TomlNode.hpp.

63 : _node(std::forward<Args &&>(args)...)
64 {
65 }

Member Function Documentation

◆ getType()

template<typename N >
constexpr INode::Type util::serialization::TomlNode< N >::getType ( ) const
inlineconstexprfinaloverridevirtualnoexcept

Types check ///.

Get the node type.

Returns
Type Node 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 68 of file TomlNode.hpp.

69 {
70 if constexpr (std::same_as<toml::table, N>)
72 else if constexpr (std::same_as<toml::array, N>)
73 return INode::Type::Array;
74 else if constexpr (std::same_as<toml::value<std::string>, N>)
76 else if constexpr (std::same_as<toml::value<int64_t>, N>)
78 else if constexpr (std::same_as<toml::value<double>, N>)
79 return INode::Type::Float;
80 else if constexpr (std::same_as<toml::value<bool>, N>)
82 else if constexpr (std::same_as<toml::value<toml::date>, N>)
83 return INode::Type::Date;
84 else if constexpr (std::same_as<toml::value<toml::time>, N>)
85 return INode::Type::Time;
86 else if constexpr (std::same_as<toml::value<toml::date_time>, N>)
88 else
90 }
@ Float
Floating point number node.
@ Boolean
Boolean value node.
@ Array
Node containing multiple unnamed nodes. (similar to a std::vector<string>)
@ Object
Node containing multiple named nodes. (similar to a std::map<string, INode>)
@ DateTime
DateTime node. (Timestamp)
@ Integer
Integer number node.

◆ tryAsBoolean()

template<typename N >
std::optional< bool > util::serialization::TomlNode< N >::tryAsBoolean ( ) const
inlinefinaloverridevirtualnoexcept

Try to get the node boolean value.

Returns
std::optional<bool> Filled with the node boolean if the type is Type::Boolean, 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 120 of file TomlNode.hpp.

121 {
122 if constexpr (std::same_as<toml::value<bool>, N>)
123 return _node.get();
124 else
125 return std::optional<bool>();
126 }

◆ tryAsDate()

template<typename N >
std::optional< Date > util::serialization::TomlNode< N >::tryAsDate ( ) const
inlinefinaloverridevirtualnoexcept

Try to get the node date value.

Returns
std::optional<Date> Filled with the node date if the type is Type::Date, 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 129 of file TomlNode.hpp.

130 {
131 if constexpr (std::same_as<toml::value<toml::date>, N>)
132 return TomlConversion::fromToml(_node.get());
133 else
134 return std::optional<Date>();
135 }
static INode::Date fromToml(const toml::date &date) noexcept
Convert a toml::date to a INode::Date.

◆ tryAsDateTime()

template<typename N >
std::optional< DateTime > util::serialization::TomlNode< N >::tryAsDateTime ( ) const
inlinefinaloverridevirtualnoexcept

Try to get the node datetime value.

Returns
std::optional<DateTime> Filled with the node datetime if the type is Type::DateTime, 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 147 of file TomlNode.hpp.

148 {
149 if constexpr (std::same_as<toml::value<toml::date_time>, N>)
150 return TomlConversion::fromToml(_node.get());
151 else
153 }

◆ tryAsFloat()

template<typename N >
std::optional< double > util::serialization::TomlNode< N >::tryAsFloat ( ) const
inlinefinaloverridevirtualnoexcept

Try to get the node float value.

Returns
std::optional<double> Filled with the node float if the type is Type::Float, 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 TomlNode.hpp.

112 {
113 if constexpr (std::same_as<toml::value<double>, N>)
114 return _node.get();
115 else
116 return std::optional<double>();
117 }

◆ tryAsInteger()

template<typename N >
std::optional< int64_t > util::serialization::TomlNode< N >::tryAsInteger ( ) const
inlinefinaloverridevirtualnoexcept

Try to get the node integer value.

Returns
std::optional<int64_t> Filled with the node integer if the type is Type::Integer, 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 102 of file TomlNode.hpp.

103 {
104 if constexpr (std::same_as<toml::value<int64_t>, N>)
105 return _node.get();
106 else
107 return std::optional<int64_t>();
108 }

◆ tryAsString()

template<typename N >
std::optional< std::string_view > util::serialization::TomlNode< N >::tryAsString ( ) const
inlinefinaloverridevirtualnoexcept

Try to get the node string value.

Returns
std::optional<std::string_view> Filled with the node string if the type is Type::String, 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 93 of file TomlNode.hpp.

94 {
95 if constexpr (std::same_as<toml::value<std::string>, N>)
96 return _node.get();
97 else
99 }

◆ tryAsTime()

template<typename N >
std::optional< Time > util::serialization::TomlNode< N >::tryAsTime ( ) const
inlinefinaloverridevirtualnoexcept

Try to get the node time value.

Returns
std::optional<Time> Filled with the node time if the type is Type::Time, 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 138 of file TomlNode.hpp.

139 {
140 if constexpr (std::same_as<toml::value<toml::time>, N>)
141 return TomlConversion::fromToml(_node.get());
142 else
143 return std::optional<Time>();
144 }

Member Data Documentation

◆ _node

template<typename N >
N util::serialization::TomlNode< N >::_node
protected

Inner node.

Definition at line 157 of file TomlNode.hpp.


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