84#ifndef GNC_KVP_FRAME_TYPE
85#define GNC_KVP_FRAME_TYPE
87#include "kvp-value.hpp"
94using Path = std::vector<std::string>;
95using KvpEntry = std::pair <std::vector <std::string>, KvpValue*>;
115 bool operator()(
const char * one,
const char * two)
const
117 auto ret = std::strcmp(one, two) < 0;
121 using map_type = std::map<const char *, KvpValue*, cstring_comparer>;
159 KvpValue* set(Path path, KvpValue* newvalue) noexcept;
171 KvpValue*
set_path(Path path, KvpValue* newvalue) noexcept;
182 std::
string to_string(std::
string const &) const noexcept;
188 std::vector<std::
string>
get_keys() const noexcept;
194 KvpValue*
get_slot(Path keys) noexcept;
200 template <typename func_type, typename data_type>
203 template <typename func_type>
210 template <typename func_type, typename data_type>
213 template <typename func_type>
220 std::vector <KvpEntry>
226 bool empty() const noexcept {
return m_valuemap.empty(); }
229 map_type::iterator begin() {
return m_valuemap.begin(); }
230 map_type::iterator end() {
return m_valuemap.end(); }
235 KvpFrame * get_child_frame_or_nullptr (Path
const &)
noexcept;
236 KvpFrame * get_child_frame_or_create (Path
const &)
noexcept;
237 void flatten_kvp_impl(std::vector <std::string>, std::vector <KvpEntry> &)
const noexcept;
238 KvpValue * set_impl (std::string
const &, KvpValue *)
noexcept;
241template<
typename func_type,
typename data_type>
242void KvpFrame::for_each_slot_prefix(std::string
const & prefix,
243 func_type
const & func, data_type & data)
const noexcept
245 std::for_each (m_valuemap.begin(), m_valuemap.end(),
246 [&prefix,&func,&data](
const KvpFrameImpl::map_type::value_type & a)
249 if (strncmp(a.first, prefix.c_str(), prefix.size()) == 0)
250 func (&a.first[prefix.size()], a.second, data);
255template <
typename func_type>
256void KvpFrame::for_each_slot_temp(func_type
const & func)
const noexcept
258 std::for_each (m_valuemap.begin(), m_valuemap.end(),
259 [&func](
const KvpFrameImpl::map_type::value_type & a)
261 func (a.first, a.second);
266template <
typename func_type,
typename data_type>
267void KvpFrame::for_each_slot_temp(func_type
const & func, data_type & data)
const noexcept
269 std::for_each (m_valuemap.begin(), m_valuemap.end(),
270 [&func,&data](
const KvpFrameImpl::map_type::value_type & a)
272 func (a.first, a.second, data);
std::vector< std::string > get_keys() const noexcept
Report the keys in the immediate frame.
~KvpFrameImpl() noexcept
Perform a deep delete.
std::vector< KvpEntry > flatten_kvp(void) const noexcept
Returns all keys and values of this frame recursively, flattening the frame-containing values.
std::string to_string() const noexcept
Make a string representation of the frame.
void for_each_slot_prefix(std::string const &prefix, func_type const &, data_type &) const noexcept
Like for_each_slot, but doesn't traverse nested values.
bool empty() const noexcept
Test for emptiness.
KvpValue * get_slot(Path keys) noexcept
Get the value for the tail of the path or nullptr if it doesn't exist.
friend int compare(const KvpFrameImpl &, const KvpFrameImpl &) noexcept
If the first KvpFrameImpl has an item that the second does not, 1 is returned.
KvpValue * set_path(Path path, KvpValue *newvalue) noexcept
Set the value with the key in a subframe following the keys in path, replacing and returning the old ...
void for_each_slot_temp(func_type const &, data_type &) const noexcept
The function should be of the form: <anything> func (char const *, KvpValue *, data_type &); Do not p...