ECSTASY
All in the name
Loading...
Searching...
No Matches
TomlArrayNode.cpp
Go to the documentation of this file.
1
11
12#include "TomlArrayNode.hpp"
13#include "TomlConversion.hpp"
14#include "TomlNodeFactory.hpp"
15
16namespace util::serialization
17{
19 {
20 for (auto &node : array)
22 }
23
25 {
26 return _nodes.at(index);
27 }
28
30 {
31 return _nodes.at(index);
32 }
33
35 {
36 if (index >= size())
37 return NodeView();
38
39 return _nodes.at(index);
40 }
41
43 {
44 if (index >= size())
45 return NodeCView();
46
47 return _nodes.at(index);
48 }
49
51 {
52 insert(size(), node);
53 }
54
55 void TomlArrayNode::insert(Index index, const INode &node)
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 }
62
63 void TomlArrayNode::replace(Index index, const INode &node)
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 }
70
72 {
73 _nodes.pop_back();
74 }
75
77 {
78 if (index <= size())
79 _nodes.erase(_nodes.cbegin() + static_cast<long>(index));
80 }
81
82 void TomlArrayNode::clear() noexcept
83 {
84 _nodes.clear();
85 }
86
87 bool TomlArrayNode::empty() const noexcept
88 {
89 return _nodes.empty();
90 }
91
92 size_t TomlArrayNode::size() const noexcept
93 {
94 return _nodes.size();
95 }
96
98 {
99 return _nodes.cbegin();
100 }
101
103 {
104 return cbegin();
105 }
106
108 {
109 return _nodes.begin();
110 }
111
113 {
114 return _nodes.cend();
115 }
116
118 {
119 return cend();
120 }
121
123 {
124 return _nodes.end();
125 }
126
127} // namespace util::serialization
Toml array node.
Toml conversion interface.
Toml node factory declaration.
size_t Index
Array index type.
Serialization node.
Definition INode.hpp:32
Polymorphism iterator for value T.
void popBack() override final
Delete the last array node.
NodeCView tryGet(Index index) const noexcept override final
Get the node at index.
NodeCView get(Index index) const override final
Get the node at index if existing.
const_iterator begin() const noexcept override final
Get the start iterator of the internal nodes.
const_iterator end() const noexcept override final
Get the end iterator of the internal nodes.
const_iterator cend() const noexcept override final
Get the end iterator of the internal nodes.
void erase(Index index) override final
Delete the node at index.
void replace(Index index, const INode &node) override final
Replace a node at the given index.
void clear() noexcept override final
Remove all the internal nodes.
void pushBack(const INode &node) override final
Push a new node at the end of the array.
std::vector< NodePtr > _nodes
Array nodes.
bool empty() const noexcept override final
Check if the object is empty.
TomlArrayNode()=default
Default constructor.
void insert(Index index, const INode &node) override final
Insert a node at the given index.
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.
static TomlNodeFactory & get() noexcept
Retrieve the TomlNodeFactory singleton instance.
NodePtr createFromToml(const toml::node &node)
Create a node from a toml::node object.
NodePtr create(INode::Type type) override final
Construct an empty node from its type.
std::weak_ptr< const INode > NodeCView
Non owning pointer to const node.
Definition INode.hpp:459
std::weak_ptr< INode > NodeView
Non owning pointer to node.
Definition INode.hpp:457