mirror of
https://github.com/matrix-construct/construct
synced 2024-10-02 13:48:53 +02:00
ircd::json: Allow multiple attributes to the printer; simplify printer stack.
This commit is contained in:
parent
42a22a6c79
commit
89ca9c9b24
1 changed files with 38 additions and 37 deletions
73
ircd/json.cc
73
ircd/json.cc
|
@ -39,7 +39,6 @@ namespace ircd::json
|
||||||
using karma::long_;
|
using karma::long_;
|
||||||
using karma::double_;
|
using karma::double_;
|
||||||
using karma::bool_;
|
using karma::bool_;
|
||||||
using karma::maxwidth;
|
|
||||||
using karma::eps;
|
using karma::eps;
|
||||||
using karma::attr_cast;
|
using karma::attr_cast;
|
||||||
|
|
||||||
|
@ -282,18 +281,12 @@ const ircd::json::parser;
|
||||||
struct ircd::json::printer
|
struct ircd::json::printer
|
||||||
:output<char *>
|
:output<char *>
|
||||||
{
|
{
|
||||||
template<class generator,
|
template<class gen,
|
||||||
class attribute>
|
class... attr>
|
||||||
bool operator()(char *&out, char *const &stop, generator&& gen, attribute&& a) const;
|
bool operator()(mutable_buffer &out, gen&&, attr&&...) const;
|
||||||
|
|
||||||
template<class generator>
|
template<class gen>
|
||||||
bool operator()(char *&out, char *const &stop, generator&& gen) const;
|
bool operator()(mutable_buffer &out, gen&&) const;
|
||||||
|
|
||||||
template<class... args>
|
|
||||||
bool operator()(mutable_buffer &out, args&&... a) const
|
|
||||||
{
|
|
||||||
return operator()(begin(out), end(out), std::forward<args>(a)...);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<class it_a,
|
template<class it_a,
|
||||||
class it_b,
|
class it_b,
|
||||||
|
@ -309,56 +302,64 @@ struct ircd::json::ostreamer
|
||||||
const ircd::json::ostreamer;
|
const ircd::json::ostreamer;
|
||||||
|
|
||||||
template<class gen,
|
template<class gen,
|
||||||
class attr>
|
class... attr>
|
||||||
bool
|
bool
|
||||||
ircd::json::printer::operator()(char *&out,
|
ircd::json::printer::operator()(mutable_buffer &out,
|
||||||
char *const &stop,
|
|
||||||
gen&& g,
|
gen&& g,
|
||||||
attr&& a)
|
attr&&... a)
|
||||||
const
|
const
|
||||||
{
|
{
|
||||||
const auto throws{[&out, &stop]
|
const auto maxwidth
|
||||||
{
|
{
|
||||||
throw print_error
|
karma::maxwidth(size(out))
|
||||||
{
|
|
||||||
"Failed to print attribute '%s' generator '%s' (%zd bytes in buffer)",
|
|
||||||
demangle<decltype(a)>(),
|
|
||||||
demangle<decltype(g)>(),
|
|
||||||
size_t(stop - out)
|
|
||||||
};
|
};
|
||||||
}};
|
|
||||||
|
|
||||||
const auto gg
|
const auto gg
|
||||||
{
|
{
|
||||||
maxwidth(size_t(stop - out))[std::forward<gen>(g)] | eps[throws]
|
maxwidth[std::forward<gen>(g)]
|
||||||
};
|
};
|
||||||
|
|
||||||
return karma::generate(out, gg, std::forward<attr>(a));
|
const auto throws{[&out]
|
||||||
|
{
|
||||||
|
throw print_error
|
||||||
|
{
|
||||||
|
"Failed to print attributes '%s' generator '%s' (%zd bytes in buffer)",
|
||||||
|
demangle<decltype(a)...>(),
|
||||||
|
demangle<decltype(g)>(),
|
||||||
|
size(out)
|
||||||
|
};
|
||||||
|
}};
|
||||||
|
|
||||||
|
return karma::generate(begin(out), gg | eps[throws], std::forward<attr>(a)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class gen>
|
template<class gen>
|
||||||
bool
|
bool
|
||||||
ircd::json::printer::operator()(char *&out,
|
ircd::json::printer::operator()(mutable_buffer &out,
|
||||||
char *const &stop,
|
|
||||||
gen&& g)
|
gen&& g)
|
||||||
const
|
const
|
||||||
{
|
{
|
||||||
const auto throws{[&out, &stop]
|
const auto maxwidth
|
||||||
|
{
|
||||||
|
karma::maxwidth(size(out))
|
||||||
|
};
|
||||||
|
|
||||||
|
const auto gg
|
||||||
|
{
|
||||||
|
maxwidth[std::forward<gen>(g)]
|
||||||
|
};
|
||||||
|
|
||||||
|
const auto throws{[&out]
|
||||||
{
|
{
|
||||||
throw print_error
|
throw print_error
|
||||||
{
|
{
|
||||||
"Failed to print generator '%s' (%zd bytes in buffer)",
|
"Failed to print generator '%s' (%zd bytes in buffer)",
|
||||||
demangle<decltype(g)>(),
|
demangle<decltype(g)>(),
|
||||||
size_t(stop - out)
|
size(out)
|
||||||
};
|
};
|
||||||
}};
|
}};
|
||||||
|
|
||||||
const auto gg
|
return karma::generate(begin(out), gg | eps[throws]);
|
||||||
{
|
|
||||||
maxwidth(size_t(stop - out))[std::forward<gen>(g)] | eps[throws]
|
|
||||||
};
|
|
||||||
|
|
||||||
return karma::generate(out, gg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class it_a,
|
template<class it_a,
|
||||||
|
|
Loading…
Reference in a new issue