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

Toml Object node. More...

#include <TomlObjectNode.hpp>

Inheritance diagram for util::serialization::TomlObjectNode:
Collaboration diagram for util::serialization::TomlObjectNode:

Public Member Functions

 TomlObjectNode ()=default
 Default constructor.
 
 TomlObjectNode (const toml::table &table)
 Construct a new Toml Object Node.
 
NodeCView get (std::string_view key) const override final
 Get the node matching key if existing.
 
NodeView get (std::string_view key) override final
 Get the node matching key if existing.
 
NodeCView tryGet (std::string_view key) const noexcept override final
 Get the node matching key.
 
NodeView tryGet (std::string_view key) noexcept override final
 Get the node matching key.
 
bool insert (std::string_view key, const INode &value) override final
 Try to insert a new node at key.
 
bool insertOrAssign (std::string_view key, const INode &value) override final
 Try to insert a new node at key or replace the existing one.
 
void erase (std::string_view key) override final
 Erase the node identified by key.
 
void clear () noexcept override final
 Remove all the internal nodes.
 
bool empty () const noexcept override final
 Check if the object is empty.
 
size_t size () const noexcept override final
 Get the number of node in this.
 
bool contains (std::string_view key) const noexcept override final
 Check if key match a node.
 
const_iterator cbegin () const noexcept override final
 Get the start iterator of the internal nodes.
 
const_iterator begin () const noexcept override final
 Get the start iterator of the internal nodes.
 
iterator begin () noexcept override final
 Get the start iterator of the internal nodes.
 
const_iterator cend () const noexcept override final
 Get the end iterator of the internal nodes.
 
const_iterator end () const noexcept override final
 Get the end iterator of the internal nodes.
 
iterator end () noexcept override final
 Get the end iterator of the internal nodes.
 
- Public Member Functions inherited from util::serialization::TomlNode< toml::table >
 TomlNode () noexcept(std::is_nothrow_default_constructible_v< toml::table >)=default
 Default constructor.
 
 TomlNode (const toml::table &node) noexcept(std::is_nothrow_copy_constructible_v< toml::table >)
 Construct a new Toml Node from a toml::node derived class object.
 
 TomlNode (Args &&...args) noexcept(std::is_nothrow_constructible_v< toml::table, 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.
 
- Public Member Functions inherited from util::serialization::IObjectNode
virtual ~IObjectNode ()=default
 Default destructor.
 
virtual NodeCView get (std::string_view key) const =0
 Get the node matching key if existing.
 
virtual NodeView get (std::string_view key)=0
 Get the node matching key if existing.
 
virtual NodeCView tryGet (std::string_view key) const noexcept=0
 Get the node matching key.
 
virtual NodeView tryGet (std::string_view key) noexcept=0
 Get the node matching key.
 
virtual bool insert (std::string_view key, const INode &value)=0
 Try to insert a new node at key.
 
virtual bool insertOrAssign (std::string_view key, const INode &value)=0
 Try to insert a new node at key or replace the existing one.
 
virtual void erase (std::string_view key)=0
 Erase the node identified by key.
 
virtual void clear ()=0
 Remove all the internal nodes.
 
virtual bool empty () const noexcept=0
 Check if the object is empty.
 
virtual size_t size () const noexcept=0
 Get the number of node in this.
 
virtual bool contains (std::string_view key) const noexcept=0
 Check if key match a node.
 
virtual const_iterator cbegin () const noexcept=0
 Get the start iterator of the internal nodes.
 
virtual const_iterator begin () const noexcept=0
 Get the start iterator of the internal nodes.
 
virtual iterator begin () noexcept=0
 Get the start iterator of the internal nodes.
 
virtual const_iterator cend () const noexcept=0
 Get the end iterator of the internal nodes.
 
virtual const_iterator end () const noexcept=0
 Get the end iterator of the internal nodes.
 
virtual iterator end () noexcept=0
 Get the end iterator of the internal nodes.
 

Private Attributes

std::map< std::string, NodePtr, std::less<> > _nodes
 Internal nodes map.
 

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.
 
- Public Types inherited from util::serialization::IObjectNode
using iterator = ObjectIterator< false >
 Object iterator type.
 
using const_iterator = ObjectIterator< true >
 Object const iterator type.
 
- Protected Types inherited from util::serialization::IObjectNode
template<bool isConst>
using ObjectIterator = PolymorphicIterator< std::pair< std::string, std::conditional_t< isConst, NodeCView, NodeView > > >
 Abstract Array Iterator.
 
- Protected Attributes inherited from util::serialization::TomlNode< toml::table >
toml::table _node
 Inner node.
 

Detailed Description

Toml Object node.

Contains nodes in an map.

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 26 of file TomlObjectNode.hpp.

Constructor & Destructor Documentation

◆ TomlObjectNode() [1/2]

util::serialization::TomlObjectNode::TomlObjectNode ( )
default

Default constructor.

◆ TomlObjectNode() [2/2]

util::serialization::TomlObjectNode::TomlObjectNode ( const toml::table table)

Construct a new Toml Object Node.

Parameters
[in]tableToml table.
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-13)

Definition at line 18 of file TomlObjectNode.cpp.

19 {
20 for (auto &node : table)
21 _nodes.insert({std::string(node.first.str()), TomlNodeFactory::get().createFromToml(node.second)});
22 }
static TomlNodeFactory & get() noexcept
Retrieve the TomlNodeFactory singleton instance.
NodePtr createFromToml(const toml::node &node)
Create a node from a toml::node object.
std::map< std::string, NodePtr, std::less<> > _nodes
Internal nodes map.
bool insert(std::string_view key, const INode &value) override final
Try to insert a new node at key.

Member Function Documentation

◆ begin() [1/2]

TomlObjectNode::const_iterator util::serialization::TomlObjectNode::begin ( ) const
finaloverridevirtualnoexcept

Get the start iterator of the internal nodes.

Returns
iterator Iterator to the first 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-08)

Implements util::serialization::IObjectNode.

Definition at line 117 of file TomlObjectNode.cpp.

118 {
119 return cbegin();
120 }
const_iterator cbegin() const noexcept override final
Get the start iterator of the internal nodes.

◆ begin() [2/2]

TomlObjectNode::iterator util::serialization::TomlObjectNode::begin ( )
finaloverridevirtualnoexcept

Get the start iterator of the internal nodes.

Returns
iterator Iterator to the first 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-08)

Implements util::serialization::IObjectNode.

Definition at line 122 of file TomlObjectNode.cpp.

123 {
124 return _nodes.begin();
125 }

◆ cbegin()

TomlObjectNode::const_iterator util::serialization::TomlObjectNode::cbegin ( ) const
finaloverridevirtualnoexcept

Get the start iterator of the internal nodes.

Returns
const_iterator Iterator to the first 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-08)

Implements util::serialization::IObjectNode.

Definition at line 112 of file TomlObjectNode.cpp.

113 {
114 return _nodes.cbegin();
115 }

◆ cend()

TomlObjectNode::const_iterator util::serialization::TomlObjectNode::cend ( ) const
finaloverridevirtualnoexcept

Get the end iterator of the internal nodes.

Warning
This iterator is never valid.
Returns
const_iterator Iterator to the last node + 1.
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::IObjectNode.

Definition at line 127 of file TomlObjectNode.cpp.

128 {
129 return _nodes.cend();
130 }

◆ clear()

void util::serialization::TomlObjectNode::clear ( )
finaloverridevirtualnoexcept

Remove all the internal nodes.

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::IObjectNode.

Definition at line 92 of file TomlObjectNode.cpp.

93 {
94 _nodes.clear();
95 }

◆ contains()

bool util::serialization::TomlObjectNode::contains ( std::string_view  key) const
finaloverridevirtualnoexcept

Check if key match a node.

Parameters
[in]keyEvaluated key.
Returns
bool Whether there is a node associated to key.
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::IObjectNode.

Definition at line 107 of file TomlObjectNode.cpp.

108 {
109 return _nodes.find(key) != _nodes.end();
110 }

◆ empty()

bool util::serialization::TomlObjectNode::empty ( ) const
finaloverridevirtualnoexcept

Check if the object is empty.

Returns
bool True if this doesn't contains any 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-08)

Implements util::serialization::IObjectNode.

Definition at line 97 of file TomlObjectNode.cpp.

98 {
99 return _nodes.empty();
100 }

◆ end() [1/2]

TomlObjectNode::const_iterator util::serialization::TomlObjectNode::end ( ) const
finaloverridevirtualnoexcept

Get the end iterator of the internal nodes.

Warning
This iterator is never valid.
Returns
iterator Iterator to the last node + 1.
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::IObjectNode.

Definition at line 132 of file TomlObjectNode.cpp.

133 {
134 return cend();
135 }
const_iterator cend() const noexcept override final
Get the end iterator of the internal nodes.

◆ end() [2/2]

TomlObjectNode::iterator util::serialization::TomlObjectNode::end ( )
finaloverridevirtualnoexcept

Get the end iterator of the internal nodes.

Warning
This iterator is never valid.
Returns
iterator Iterator to the last node + 1.
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::IObjectNode.

Definition at line 137 of file TomlObjectNode.cpp.

138 {
139 return _nodes.end();
140 }

◆ erase()

void util::serialization::TomlObjectNode::erase ( std::string_view  key)
finaloverridevirtual

Erase the node identified by key.

Parameters
[in]keyNode's key.
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::IObjectNode.

Definition at line 84 of file TomlObjectNode.cpp.

85 {
86 auto it = _nodes.find(key);
87
88 if (it != _nodes.end())
89 _nodes.erase(it);
90 }

◆ get() [1/2]

NodeCView util::serialization::TomlObjectNode::get ( std::string_view  key) const
finaloverridevirtual

Get the node matching key if existing.

Parameters
[in]keyThe node's key.
Returns
NodeCView A weak pointer to the requested node.
Exceptions
std::out_of_rangeIf the key doesn't exists.
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::IObjectNode.

Definition at line 33 of file TomlObjectNode.cpp.

34 {
35 auto it = _nodes.find(key);
36 if (it == _nodes.end()) [[unlikely]]
37 throw std::out_of_range(std::string("Key '") + std::string(key) + "' no found in Toml Object.");
38
39 return it->second;
40 }

◆ get() [2/2]

NodeView util::serialization::TomlObjectNode::get ( std::string_view  key)
finaloverridevirtual

Get the node matching key if existing.

Parameters
[in]keyThe node's key.
Returns
NodeCView A weak pointer to the requested node.
Exceptions
std::out_of_rangeIf the key doesn't exists.
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::IObjectNode.

Definition at line 24 of file TomlObjectNode.cpp.

25 {
26 auto it = _nodes.find(key);
27 if (it == _nodes.end()) [[unlikely]]
28 throw std::out_of_range(std::string("Key '") + std::string(key) + "' no found in Toml Object.");
29
30 return it->second;
31 }

◆ insert()

bool util::serialization::TomlObjectNode::insert ( std::string_view  key,
const INode value 
)
finaloverridevirtual

Try to insert a new node at key.

Warning
If the key is already used, this method will fail. Use insertOrAssign() instead.
Parameters
[in]keyNew node key.
[in]valueNew node.
Returns
bool Whether the node was inserted or not.
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::IObjectNode.

Definition at line 60 of file TomlObjectNode.cpp.

61 {
62 auto it = _nodes.find(key);
63
64 if (it != _nodes.end())
65 return false;
66
67 _nodes.insert({std::string(key), TomlNodeFactory::get().create(node)});
68 return true;
69 }
NodePtr create(INode::Type type) override final
Construct an empty node from its type.

◆ insertOrAssign()

bool util::serialization::TomlObjectNode::insertOrAssign ( std::string_view  key,
const INode value 
)
finaloverridevirtual

Try to insert a new node at key or replace the existing one.

Parameters
[in]keyNew node key.
[in]valueNew node.
Returns
bool Whether the node was inserted. It is false if it was assigned.
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::IObjectNode.

Definition at line 71 of file TomlObjectNode.cpp.

72 {
73 auto it = _nodes.find(key);
74 NodePtr nodePtr = TomlNodeFactory::get().create(node);
75
76 if (it != _nodes.end()) {
77 it->second = nodePtr;
78 return false;
79 } else
80 _nodes.insert({std::string(key), TomlNodeFactory::get().create(node)});
81 return true;
82 }
std::shared_ptr< INode > NodePtr
Pointer to node.
Definition INode.hpp:452

◆ size()

size_t util::serialization::TomlObjectNode::size ( ) const
finaloverridevirtualnoexcept

Get the number of node in this.

Returns
size_t Number of node contained in this.
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::IObjectNode.

Definition at line 102 of file TomlObjectNode.cpp.

103 {
104 return _nodes.size();
105 }

◆ tryGet() [1/2]

NodeCView util::serialization::TomlObjectNode::tryGet ( std::string_view  key) const
finaloverridevirtualnoexcept

Get the node matching key.

Parameters
[in]keyThe node's key.
Returns
NodeCView A weak pointer to the requested node if it exists.
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::IObjectNode.

Definition at line 51 of file TomlObjectNode.cpp.

52 {
53 auto it = _nodes.find(key);
54 if (it == _nodes.end())
55 return NodeCView();
56
57 return it->second;
58 }
std::weak_ptr< const INode > NodeCView
Non owning pointer to const node.
Definition INode.hpp:459

◆ tryGet() [2/2]

NodeView util::serialization::TomlObjectNode::tryGet ( std::string_view  key)
finaloverridevirtualnoexcept

Get the node matching key.

Parameters
[in]keyThe node's key.
Returns
NodeCView A weak pointer to the requested node if it exists.
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::IObjectNode.

Definition at line 42 of file TomlObjectNode.cpp.

43 {
44 auto it = _nodes.find(key);
45 if (it == _nodes.end())
46 return NodeView();
47
48 return it->second;
49 }
std::weak_ptr< INode > NodeView
Non owning pointer to node.
Definition INode.hpp:457

Member Data Documentation

◆ _nodes

std::map<std::string, NodePtr, std::less<> > util::serialization::TomlObjectNode::_nodes
private

Internal nodes map.

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 (2024-10-18)

Definition at line 99 of file TomlObjectNode.hpp.


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