0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-02 18:18:56 +02:00

ircd::json: Object semantics for json::stack classes.

This commit is contained in:
Jason Volk 2018-04-10 13:33:26 -07:00
parent d457a26022
commit 102ef2cb47
2 changed files with 62 additions and 6 deletions

View file

@ -69,6 +69,8 @@ struct ircd::json::stack
void clear();
stack(const mutable_buffer &, flush_callback = {});
stack(stack &&) noexcept;
stack(const stack &) = delete;
~stack() noexcept;
};
@ -98,10 +100,11 @@ struct ircd::json::stack::object
size_t mc {0}; ///< members witnessed (monotonic)
public:
object() = default;
object(stack &s); ///< Object is top
object(array &pa); ///< Object is value in the array
object(member &pm); ///< Object is value of named member
object(object &&) noexcept;
object(const object &) = delete;
~object() noexcept;
};
@ -128,10 +131,11 @@ struct ircd::json::stack::array
template<class... T> void append(const json::tuple<T...> &);
void append(const json::value &);
array() = default;
array(stack &s); ///< Array is top
array(array &pa); ///< Array is value in the array
array(member &pm); ///< Array is value of the named member
array(const array &) = delete;
array(array &&) noexcept;
~array() noexcept;
};
@ -158,10 +162,11 @@ struct ircd::json::stack::member
template<class... T> void append(const json::tuple<T...> &);
void append(const json::value &);
member() = default;
member(object &po, const string_view &name);
member(object &po, const string_view &name, const json::value &v);
template<class... T> member(object &po, const string_view &name, const json::tuple<T...> &t);
member(const member &) = delete;
member(member &&) noexcept;
~member() noexcept;
};

View file

@ -422,6 +422,17 @@ ircd::json::stack::stack(const mutable_buffer &buf,
{
}
ircd::json::stack::stack(stack &&other)
noexcept
:buf{std::move(other.buf)}
,flusher{std::move(other.flusher)}
,co{std::move(other.co)}
,ca{std::move(other.ca)}
{
other.co = nullptr;
other.ca = nullptr;
}
ircd::json::stack::~stack()
noexcept
{
@ -516,6 +527,17 @@ const
// object
//
ircd::json::stack::object::object(object &&other)
noexcept
:s{std::move(other.s)}
,pm{std::move(other.pm)}
,pa{std::move(other.pa)}
,cm{std::move(other.cm)}
,mc{std::move(other.mc)}
{
other.s = nullptr;
}
ircd::json::stack::object::object(stack &s)
:s{&s}
{
@ -553,7 +575,9 @@ ircd::json::stack::object::object(array &pa)
ircd::json::stack::object::~object()
noexcept
{
assert(s);
if(!s)
return; // std::move()'ed away
assert(cm == nullptr);
s->printer(json::printer.object_end);
@ -587,6 +611,18 @@ noexcept
// array
//
ircd::json::stack::array::array(array &&other)
noexcept
:s{std::move(other.s)}
,pm{std::move(other.pm)}
,pa{std::move(other.pa)}
,co{std::move(other.co)}
,ca{std::move(other.ca)}
,vc{std::move(other.vc)}
{
other.s = nullptr;
}
ircd::json::stack::array::array(stack &s)
:s{&s}
{
@ -624,7 +660,9 @@ ircd::json::stack::array::array(array &pa)
ircd::json::stack::array::~array()
noexcept
{
assert(s);
if(!s)
return; // std::move()'ed away
assert(co == nullptr);
assert(ca == nullptr);
s->printer(json::printer.array_end);
@ -688,6 +726,17 @@ ircd::json::stack::array::_post_append()
// member
//
ircd::json::stack::member::member(member &&other)
noexcept
:s{std::move(other.s)}
,po{std::move(other.po)}
,name{std::move(other.name)}
,co{std::move(other.co)}
,ca{std::move(other.ca)}
{
other.s = nullptr;
}
ircd::json::stack::member::member(object &po,
const string_view &name)
:s{po.s}
@ -714,7 +763,9 @@ ircd::json::stack::member::member(object &po,
ircd::json::stack::member::~member()
noexcept
{
assert(s);
if(!s)
return; // std::move()'ed away
assert(co == nullptr);
assert(ca == nullptr);
assert(po);