9#if !TOML_IMPLEMENTATION
10#error This is an implementation-only header.
21#if TOML_LIFETIME_HOOKS
28#if TOML_LIFETIME_HOOKS
34 table::table(
const impl::table_init_pair* b,
const impl::table_init_pair* e) {
35#if TOML_LIFETIME_HOOKS
49 map_.insert_or_assign(std::move(b->key), std::move(b->value));
55 : node(other), inline_{other.inline_} {
56 for (
auto&& [k, v] : other.map_) map_.emplace_hint(map_.end(), k, impl::make_node(*v));
58#if TOML_LIFETIME_HOOKS
65 : node(std::move(other)), map_{std::move(other.map_)}, inline_{other.inline_} {
66#if TOML_LIFETIME_HOOKS
76 for (
auto&& [k, v] : rhs.map_) map_.emplace_hint(map_.end(), k, impl::make_node(*v));
77 inline_ = rhs.inline_;
85 node::operator=(std::move(rhs));
86 map_ = std::move(rhs.map_);
87 inline_ = rhs.inline_;
95 if (map_.empty())
return false;
97 if (ntype == node_type::none) ntype = map_.
cbegin()->second->type();
99 for (
auto&& [k, v] : map_) {
101 if (v->type() != ntype)
return false;
114 if (ntype == node_type::none) ntype = map_.cbegin()->second->type();
115 for (
const auto& [k, v] : map_) {
117 if (v->type() != ntype) {
118 first_nonmatch = v.get();
130 first_nonmatch = fnm;
136 node*
table::get(std::string_view key)
noexcept {
137 if (
auto it = map_.find(key); it != map_.end())
return it->second.get();
145#if TOML_COMPILER_HAS_EXCEPTIONS
150 err.append(
"' not found in table"sv);
151 throw std::out_of_range{err};
165 table::map_iterator table::get_lower_bound(std::string_view key)
noexcept {
166 return map_.lower_bound(key);
172 return iterator{map_.find(key)};
178 return const_iterator{map_.find(key)};
182 table::map_iterator
table::erase(const_map_iterator pos)
noexcept {
183 return map_.erase(pos);
187 table::map_iterator
table::erase(const_map_iterator begin, const_map_iterator end)
noexcept {
188 return map_.erase(begin, end);
193 if (
auto it = map_.find(key); it != map_.end()) {
202 if (map_.empty())
return *
this;
204 for (
auto it = map_.begin(); it != map_.end();) {
205 if (
auto arr = it->second->as_array()) {
206 if (recursive) arr->
prune(
true);
212 }
else if (
auto tbl = it->second->as_table()) {
213 if (recursive) tbl->prune(
true);
232 table::map_iterator table::insert_with_hint(const_iterator hint, key && k, impl::node_ptr && v) {
233 return map_.emplace_hint(const_map_iterator{hint}, std::move(k), std::move(v));
239 if (&lhs == &rhs)
return true;
240 if (lhs.map_.
size() != rhs.map_.
size())
return false;
242 for (
auto l = lhs.map_.
begin(), r = rhs.map_.
begin(), e = lhs.map_.
end(); l != e; l++, r++) {
243 if (l->first != r->first)
return false;
245 const auto lhs_type = l->second->type();
246 const node& rhs_ = *r->second;
247 const auto rhs_type = rhs_.type();
248 if (lhs_type != rhs_type)
return false;
250 const bool equal = l->second->visit([&](
const auto& lhs_)
noexcept {
251 return lhs_ == *
reinterpret_cast<std::remove_reference_t<decltype(lhs_)
>*>(&rhs_);
253 if (!equal)
return false;
A TOML table.
Definition table.hpp:220
TOML_EXPORTED_MEMBER_FUNCTION table & prune(bool recursive=true) &noexcept
Removes empty child arrays and tables.
KeyType && key
Definition table.hpp:1469
TOML_NODISCARD TOML_EXPORTED_MEMBER_FUNCTION node & at(std::string_view key)
Gets a reference to the element at a specific key, throwing std::out_of_range if none existed.
TOML_NODISCARD_CTOR TOML_EXPORTED_MEMBER_FUNCTION table() noexcept
Default constructor.
TOML_PURE_GETTER TOML_EXPORTED_MEMBER_FUNCTION node * get(std::string_view key) noexcept
Gets the node at a specific key.
toml::const_table_iterator const_iterator
A BidirectionalIterator for iterating over const key-value pairs in a toml::table.
Definition table.hpp:793
TOML_EXPORTED_MEMBER_FUNCTION void clear() noexcept
Removes all key-value pairs from the table.
toml::table_iterator iterator
A BidirectionalIterator for iterating over key-value pairs in a toml::table.
Definition table.hpp:790
TOML_PURE_GETTER TOML_EXPORTED_MEMBER_FUNCTION bool is_homogeneous(node_type ntype) const noexcept final
TOML_EXPORTED_MEMBER_FUNCTION table & operator=(const table &)
Copy-assignment operator.
TOML_PURE_INLINE_GETTER iterator begin() noexcept
Returns an iterator to the first key-value pair.
Definition table.hpp:797
TOML_EXPORTED_MEMBER_FUNCTION ~table() noexcept
TOML_PURE_GETTER TOML_EXPORTED_MEMBER_FUNCTION iterator find(std::string_view key) noexcept
Gets an iterator to the node at a specific key.
TOML_PURE_INLINE_GETTER const_iterator cbegin() const noexcept
Returns an iterator to the first key-value pair.
Definition table.hpp:811
TOML_PURE_INLINE_GETTER iterator end() noexcept
Returns an iterator to one-past-the-last key-value pair.
Definition table.hpp:818
iterator erase(iterator pos) noexcept
Removes the specified key-value pair from the table.
Definition table.hpp:1295
TOML_PURE_INLINE_GETTER size_t size() const noexcept
Returns the number of key-value pairs in the table.
Definition table.hpp:1119
#define TOML_CALLCONV
Calling convention to apply to exported free/static functions. \detail Not defined by default (let th...
Definition preprocessor.hpp:1134
#define TOML_ASSERT_ASSUME(expr)
Definition preprocessor.hpp:1190
#define TOML_UNUSED(...)
Definition preprocessor.hpp:603
#define TOML_UNLIKELY(...)
Definition preprocessor.hpp:538
#define TOML_EXTERNAL_LINKAGE
Definition preprocessor.hpp:1339
#define TOML_PURE_GETTER
Definition preprocessor.hpp:474
#define TOML_NAMESPACE_END
Definition preprocessor.hpp:1320
TOML_NAMESPACE_START
Definition table.inl:18