0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-25 23:14:13 +01:00

ircd::json::stack: Add object::append() convenience.

This commit is contained in:
Jason Volk 2019-01-10 15:22:37 -08:00
parent f1d5b0798e
commit 1198f7bc56
2 changed files with 27 additions and 0 deletions

View file

@ -149,6 +149,9 @@ struct ircd::json::stack::object
size_t mc {0}; ///< members witnessed (monotonic)
public:
template<class... T> void append(const json::tuple<T...> &);
void append(const json::object &);
object(stack &s); ///< Object is top
object(array &pa); ///< Object is value in the array
object(member &pm); ///< Object is value of named member
@ -276,3 +279,17 @@ ircd::json::stack::array::append(const json::tuple<T...> &t)
return size(stringify(buf, t));
});
}
template<class... T>
void
ircd::json::stack::object::append(const json::tuple<T...> &t)
{
for_each(t, [this](const auto &name, const auto &_value)
{
const json::value value(_value);
if(defined(value)) json::stack::member
{
*this, name, value
};
});
}

View file

@ -700,6 +700,16 @@ ircd::json::stack::object::object(array &pa)
s->append("{"_sv);
}
void
ircd::json::stack::object::append(const json::object &object)
{
for(const auto &kv : object)
json::stack::member
{
*this, kv.first, kv.second
};
}
ircd::json::stack::object::~object()
noexcept
{