2018-09-06 03:33:46 +02:00
|
|
|
// Matrix Construct
|
|
|
|
//
|
|
|
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
|
|
|
// Copyright (C) 2016-2018 Jason Volk <jason@zemos.net>
|
|
|
|
//
|
|
|
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice is present in all copies. The
|
|
|
|
// full license for this software is available in the LICENSE file.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#define HAVE_IRCD_JSON_STRUNG_H
|
|
|
|
|
|
|
|
namespace ircd::json
|
|
|
|
{
|
|
|
|
struct strung;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Interface around an allocated std::string of JSON. This is not a
|
|
|
|
/// json::string type; it is a full JSON which will stringify the
|
|
|
|
/// constructor arguments into the std::string's buffer as a convenience
|
|
|
|
/// to reduce boilerplate when the user has no interest in buffering the
|
|
|
|
/// stringify() calls another way.
|
|
|
|
///
|
|
|
|
struct ircd::json::strung
|
|
|
|
:std::string
|
|
|
|
{
|
|
|
|
explicit operator json::object() const;
|
|
|
|
explicit operator json::array() const;
|
|
|
|
|
|
|
|
strung() = default;
|
|
|
|
template<class... T> strung(T&&... t);
|
|
|
|
strung(strung &&s) noexcept;
|
|
|
|
strung(const strung &s);
|
2018-09-06 04:36:52 +02:00
|
|
|
strung &operator=(strung &&) = default;
|
|
|
|
strung &operator=(const strung &) = default;
|
2018-09-06 03:33:46 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
inline
|
|
|
|
ircd::json::strung::strung(strung &&s)
|
|
|
|
noexcept
|
|
|
|
:std::string{std::move(s)}
|
|
|
|
{}
|
|
|
|
|
|
|
|
inline
|
|
|
|
ircd::json::strung::strung(const strung &s)
|
|
|
|
:std::string{s}
|
|
|
|
{}
|
|
|
|
|
|
|
|
template<class... T>
|
2020-08-05 11:18:56 +02:00
|
|
|
inline
|
2018-09-06 03:33:46 +02:00
|
|
|
ircd::json::strung::strung(T&&... t)
|
|
|
|
:std::string
|
|
|
|
{
|
|
|
|
util::string(serialized(std::forward<T>(t)...), [&t...]
|
|
|
|
(const mutable_buffer &out)
|
|
|
|
{
|
|
|
|
const auto sv
|
|
|
|
{
|
|
|
|
stringify(mutable_buffer{out}, std::forward<T>(t)...)
|
|
|
|
};
|
|
|
|
|
2020-05-21 18:17:13 +02:00
|
|
|
debug_valid_output(sv, ircd::size(out));
|
2018-09-06 03:33:46 +02:00
|
|
|
return sv;
|
|
|
|
})
|
|
|
|
}
|
|
|
|
{}
|