ECSTASY
All in the name
Loading...
Searching...
No Matches
TomlObjectNode.cpp
Go to the documentation of this file.
1
11
12#include "TomlObjectNode.hpp"
13#include "TomlConversion.hpp"
14#include "TomlNodeFactory.hpp"
15
16namespace util::serialization
17{
19 {
20 for (auto &node : table)
21 _nodes.insert({std::string(node.first.str()), TomlNodeFactory::get().createFromToml(node.second)});
22 }
23
24 NodeView TomlObjectNode::get(std::string_view key)
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 }
32
33 NodeCView TomlObjectNode::get(std::string_view key) const
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 }
41
42 NodeView TomlObjectNode::tryGet(std::string_view key) noexcept
43 {
44 auto it = _nodes.find(key);
45 if (it == _nodes.end())
46 return NodeView();
47
48 return it->second;
49 }
50
51 NodeCView TomlObjectNode::tryGet(std::string_view key) const noexcept
52 {
53 auto it = _nodes.find(key);
54 if (it == _nodes.end())
55 return NodeCView();
56
57 return it->second;
58 }
59
60 bool TomlObjectNode::insert(std::string_view key, const INode &node)
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 }
70
71 bool TomlObjectNode::insertOrAssign(std::string_view key, const INode &node)
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 }
83
84 void TomlObjectNode::erase(std::string_view key)
85 {
86 auto it = _nodes.find(key);
87
88 if (it != _nodes.end())
89 _nodes.erase(it);
90 }
91
92 void TomlObjectNode::clear() noexcept
93 {
94 _nodes.clear();
95 }
96
97 bool TomlObjectNode::empty() const noexcept
98 {
99 return _nodes.empty();
100 }
101
102 size_t TomlObjectNode::size() const noexcept
103 {
104 return _nodes.size();
105 }
106
107 bool TomlObjectNode::contains(std::string_view key) const noexcept
108 {
109 return _nodes.find(key) != _nodes.end();
110 }
111
112 TomlObjectNode::const_iterator TomlObjectNode::cbegin() const noexcept
113 {
114 return _nodes.cbegin();
115 }
116
117 TomlObjectNode::const_iterator TomlObjectNode::begin() const noexcept
118 {
119 return cbegin();
120 }
121
122 TomlObjectNode::iterator TomlObjectNode::begin() noexcept
123 {
124 return _nodes.begin();
125 }
126
127 TomlObjectNode::const_iterator TomlObjectNode::cend() const noexcept
128 {
129 return _nodes.cend();
130 }
131
132 TomlObjectNode::const_iterator TomlObjectNode::end() const noexcept
133 {
134 return cend();
135 }
136
137 TomlObjectNode::iterator TomlObjectNode::end() noexcept
138 {
139 return _nodes.end();
140 }
141
142} // namespace util::serialization
Toml conversion interface.
Toml node factory declaration.
Toml object node declaration.
Serialization node.
Definition INode.hpp:32
Polymorphism iterator for value T.
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.
TomlObjectNode()=default
Default constructor.