17#include <c4/yml/std/map.hpp>
18#include <c4/yml/std/string.hpp>
19#include <c4/yml/common.hpp>
24size_t count_nlines(c4::csubstr
src)
27 size_t n = (
src.len > 0);
29 n += (
src.begins_with(
'\n') ||
src.begins_with(
'\r'));
35c4::yml::Tree makeTree(std::istream &is)
38 throw std::runtime_error(
"invalid input!");
39 std::string s(std::istreambuf_iterator<char>(is), {});
41 auto src = c4::to_csubstr(s.c_str());
42 size_t nlines = count_nlines(
src);
43 c4::yml::Tree
tree(nlines, s.size());
60 inline ryml::Tree &
get()
65 inline const ryml::Tree &
get()
const
86 inline c4::yml::NodeRef &
get()
91 inline const c4::yml::NodeRef &
get()
const
103 os << c4::yml::as_json(
node->get());
115 node->
get() |= c4::yml::MAP;
122 node->
get() |= c4::yml::SEQ;
128 throw std::logic_error(
"Function not yet implemented");
203 return Impl::mkNode(
tree, node->get()[c4::to_csubstr(
tree->incache(k))]);
209 return Impl::mkNode(
tree, node->get()[c4::to_csubstr(
tree->incache(k))]);
215 return node->get().is_container();
221 return node->get().is_map();
227 return node->get().is_seq();
233 std::stringstream ss;
234 ss << node->get().key();
242 std::stringstream ss;
243 ss << node->get().val();
250 return Impl::mkNode(
tree, node->get().append_child());
256 return node->get().has_key();
262 return node->get().has_val();
268 return node->get().has_child(c4::to_csubstr(s.c_str()));
274 return node->get().num_children();
280 return Impl::mkNode(
tree, node->get().child(pos));
286 return Impl::mkNode(
tree, node->get().child(pos));
292void error_cb(
const char *msg,
size_t msg_len, c4::yml::Location ,
void * )
295 if (msg && msg_len > 0) {
296 throw std::runtime_error(msg);
298 throw std::runtime_error(
"error handler invoked without error message");
305 c4::yml::set_callbacks(c4::yml::Callbacks(c4::yml::get_callbacks().m_user_data, c4::yml::get_callbacks().m_allocate,
306 c4::yml::get_callbacks().m_free, &::error_cb));
309bool ok = setcallbacks();
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t np
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t src
JSONNode & get(std::string const &key)
const ryml::Tree & get() const
const c4::yml::NodeRef & get() const
static TRYMLTree::Node & mkNode(TRYMLTree *t, c4::yml::NodeRef node)
Impl(const c4::yml::NodeRef &n)
bool is_map() const override
bool has_key() const override
Node & child(size_t pos) override
const Node & operator>>(std::string &v) const override
void writeYML(std::ostream &) const override
bool is_container() const override
std::string key() const override
Node & set_map() override
Node & operator<<(std::string const &s) override
std::unique_ptr< Impl > node
std::string val() const override
Node & operator[](std::string const &k) override
Node & append_child() override
bool is_seq() const override
Node(TRYMLTree *t, const Impl &other)
bool has_val() const override
bool has_child(std::string const &) const override
void writeJSON(std::ostream &os) const override
size_t num_children() const override
Node & set_seq() override
std::list< std::string > _strcache
Node & incache(const Node &n)
Node & rootnode() override
std::list< Node > _nodecache