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

Toml Array node. More...

#include <TomlArrayNode.hpp>

Inheritance diagram for util::serialization::TomlArrayNode:
Collaboration diagram for util::serialization::TomlArrayNode:

Public Member Functions

 TomlArrayNode ()=default
 Default constructor.
 
 TomlArrayNode (const toml::array &array)
 Construct a new Toml Array Node.
 
NodeCView get (Index index) const override final
 Get the node at index if existing.
 
NodeView get (Index index) override final
 Get the node at index if existing.
 
NodeCView tryGet (Index index) const noexcept override final
 Get the node at index.
 
NodeView tryGet (Index index) noexcept override final
 Get the node at index.
 
void pushBack (const INode &node) override final
 Push a new node at the end of the array.
 
void insert (Index index, const INode &node) override final
 Insert a node at the given index.
 
void replace (Index index, const INode &node) override final
 Replace a node at the given index.
 
void popBack () override final
 Delete the last array node.
 
void erase (Index index) override final
 Delete the node at index.
 
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.
 
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::array >
 TomlNode () noexcept(std::is_nothrow_default_constructible_v< toml::array >)=default
 Default constructor.
 
 TomlNode (const toml::array &node) noexcept(std::is_nothrow_copy_constructible_v< toml::array >)
 Construct a new Toml Node from a toml::node derived class object.
 
 TomlNode (Args &&...args) noexcept(std::is_nothrow_constructible_v< toml::array, 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::IArrayNode
virtual ~IArrayNode ()=default
 Default destructor.
 
virtual NodeCView get (Index index) const =0
 Get the node at index if existing.
 
virtual NodeView get (Index index)=0
 Get the node at index if existing.
 
virtual NodeCView tryGet (Index index) const noexcept=0
 Get the node at index.
 
virtual NodeView tryGet (Index index) noexcept=0
 Get the node at index.
 
virtual void pushBack (const INode &node)=0
 Push a new node at the end of the array.
 
virtual void insert (Index index, const INode &node)=0
 Insert a node at the given index.
 
virtual void replace (Index index, const INode &node)=0
 Replace a node at the given index.
 
virtual void popBack ()=0
 Delete the last array node.
 
virtual void erase (Index index)=0
 Delete the node at index.
 
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 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::vector< NodePtr_nodes
 Array nodes.
 

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::IArrayNode
using Index = size_t
 Array index type.
 
using iterator = ArrayIterator< false >
 Array iterator type.
 
using const_iterator = ArrayIterator< true >
 Array const iterator type.
 
- Protected Types inherited from util::serialization::IArrayNode
template<bool isConst>
using ArrayIterator = PolymorphicIterator< std::conditional_t< isConst, NodeCView, NodeView > >
 Array Iterator.
 
- Protected Attributes inherited from util::serialization::TomlNode< toml::array >
toml::array _node
 Inner node.
 

Detailed Description

Toml Array node.

Contains nodes in an 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)

Definition at line 26 of file TomlArrayNode.hpp.

Constructor & Destructor Documentation

◆ TomlArrayNode() [1/2]

util::serialization::TomlArrayNode::TomlArrayNode ( )
default

Default constructor.

◆ TomlArrayNode() [2/2]

util::serialization::TomlArrayNode::TomlArrayNode ( const toml::array array)

Construct a new Toml Array Node.

Parameters
[in]arrayToml 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-13)

Definition at line 18 of file TomlArrayNode.cpp.

19 {
20 for (auto &node : array)
21 _nodes.push_back(TomlNodeFactory::get().createFromToml(node));
22 }
NodeCView get(Index index) const override final
Get the node at index if existing.
std::vector< NodePtr > _nodes
Array nodes.

Member Function Documentation

◆ begin() [1/2]

TomlArrayNode::const_iterator util::serialization::TomlArrayNode::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::IArrayNode.

Definition at line 102 of file TomlArrayNode.cpp.

103 {
104 return cbegin();
105 }
const_iterator cbegin() const noexcept override final
Get the start iterator of the internal nodes.

◆ begin() [2/2]

TomlArrayNode::iterator util::serialization::TomlArrayNode::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::IArrayNode.

Definition at line 107 of file TomlArrayNode.cpp.

108 {
109 return _nodes.begin();
110 }

◆ cbegin()

TomlArrayNode::const_iterator util::serialization::TomlArrayNode::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::IArrayNode.

Definition at line 97 of file TomlArrayNode.cpp.

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

◆ cend()

TomlArrayNode::const_iterator util::serialization::TomlArrayNode::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::IArrayNode.

Definition at line 112 of file TomlArrayNode.cpp.

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

◆ clear()

void util::serialization::TomlArrayNode::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::IArrayNode.

Definition at line 82 of file TomlArrayNode.cpp.

83 {
84 _nodes.clear();
85 }

◆ empty()

bool util::serialization::TomlArrayNode::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::IArrayNode.

Definition at line 87 of file TomlArrayNode.cpp.

88 {
89 return _nodes.empty();
90 }

◆ end() [1/2]

TomlArrayNode::const_iterator util::serialization::TomlArrayNode::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::IArrayNode.

Definition at line 117 of file TomlArrayNode.cpp.

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

◆ end() [2/2]

TomlArrayNode::iterator util::serialization::TomlArrayNode::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::IArrayNode.

Definition at line 122 of file TomlArrayNode.cpp.

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

◆ erase()

void util::serialization::TomlArrayNode::erase ( Index  index)
finaloverridevirtual

Delete the node at index.

Parameters
[in]indexIndex of the node to erase.
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::IArrayNode.

Definition at line 76 of file TomlArrayNode.cpp.

77 {
78 if (index <= size())
79 _nodes.erase(_nodes.cbegin() + static_cast<long>(index));
80 }
size_t size() const noexcept override final
Get the number of node in this.

◆ get() [1/2]

NodeCView util::serialization::TomlArrayNode::get ( Index  index) const
finaloverridevirtual

Get the node at index if existing.

Parameters
[in]indexThe node's index.
Returns
NodeCView A weak pointer to the requested node.
Exceptions
std::out_of_rangeIf the index is out of bounds.
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::IArrayNode.

Definition at line 29 of file TomlArrayNode.cpp.

30 {
31 return _nodes.at(index);
32 }

◆ get() [2/2]

NodeView util::serialization::TomlArrayNode::get ( Index  index)
finaloverridevirtual

Get the node at index if existing.

Parameters
[in]indexThe node's index.
Returns
NodeCView A weak pointer to the requested node.
Exceptions
std::out_of_rangeIf the index is out of bounds.
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::IArrayNode.

Definition at line 24 of file TomlArrayNode.cpp.

25 {
26 return _nodes.at(index);
27 }

◆ insert()

void util::serialization::TomlArrayNode::insert ( Index  index,
const INode node 
)
finaloverridevirtual

Insert a node at the given index.

Note
All elements after (greater index) index will be moved one index further.
Parameters
[in]indexIndex of the new node.
[in]nodeNode to insert.
Exceptions
std::out_of_rangeIf index is greater than the current size().
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::IArrayNode.

Definition at line 55 of file TomlArrayNode.cpp.

56 {
57 if (index > size()) [[unlikely]]
58 throw std::out_of_range("Index out of bounds.");
59
60 _nodes.insert(_nodes.cbegin() + static_cast<long>(index), TomlNodeFactory::get().create(node));
61 }
static TomlNodeFactory & get() noexcept
Retrieve the TomlNodeFactory singleton instance.
NodePtr create(INode::Type type) override final
Construct an empty node from its type.

◆ popBack()

void util::serialization::TomlArrayNode::popBack ( )
finaloverridevirtual

Delete the last array node.

Note
Does nothing if the array is empty().
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::IArrayNode.

Definition at line 71 of file TomlArrayNode.cpp.

72 {
73 _nodes.pop_back();
74 }

◆ pushBack()

void util::serialization::TomlArrayNode::pushBack ( const INode node)
finaloverridevirtual

Push a new node at the end of the array.

Parameters
[in]nodeNode to push.
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::IArrayNode.

Definition at line 50 of file TomlArrayNode.cpp.

51 {
52 insert(size(), node);
53 }
void insert(Index index, const INode &node) override final
Insert a node at the given index.

◆ replace()

void util::serialization::TomlArrayNode::replace ( Index  index,
const INode node 
)
finaloverridevirtual

Replace a node at the given index.

Note
Other indexes are not changed.
Parameters
[in]indexIndex of the node.
[in]nodeNew node value.
Exceptions
std::out_of_rangeIf index is greater than or equal the current size().
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::IArrayNode.

Definition at line 63 of file TomlArrayNode.cpp.

64 {
65 if (index >= size()) [[unlikely]]
66 throw std::out_of_range("Index out of bounds.");
67
68 _nodes.at(index) = TomlNodeFactory::get().create(node);
69 }

◆ size()

size_t util::serialization::TomlArrayNode::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::IArrayNode.

Definition at line 92 of file TomlArrayNode.cpp.

93 {
94 return _nodes.size();
95 }

◆ tryGet() [1/2]

NodeCView util::serialization::TomlArrayNode::tryGet ( Index  index) const
finaloverridevirtualnoexcept

Get the node at index.

Parameters
[in]indexThe node's index.
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::IArrayNode.

Definition at line 42 of file TomlArrayNode.cpp.

43 {
44 if (index >= size())
45 return NodeCView();
46
47 return _nodes.at(index);
48 }
std::weak_ptr< const INode > NodeCView
Non owning pointer to const node.
Definition INode.hpp:459

◆ tryGet() [2/2]

NodeView util::serialization::TomlArrayNode::tryGet ( Index  index)
finaloverridevirtualnoexcept

Get the node at index.

Parameters
[in]indexThe node's index.
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::IArrayNode.

Definition at line 34 of file TomlArrayNode.cpp.

35 {
36 if (index >= size())
37 return NodeView();
38
39 return _nodes.at(index);
40 }
std::weak_ptr< INode > NodeView
Non owning pointer to node.
Definition INode.hpp:457

Member Data Documentation

◆ _nodes

std::vector<NodePtr> util::serialization::TomlArrayNode::_nodes
private

Array nodes.

Definition at line 97 of file TomlArrayNode.hpp.


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