mirror of
https://github.com/matrix-construct/construct
synced 2025-01-13 16:33:53 +01:00
ircd::json: Split strung into file.
This commit is contained in:
parent
f245fc74c0
commit
d3493e5901
3 changed files with 84 additions and 43 deletions
|
@ -49,18 +49,6 @@ namespace ircd::json
|
|||
template<class... T> size_t print(const mutable_buffer &buf, T&&... t);
|
||||
}
|
||||
|
||||
/// Convenience template to allocate std::string and print() arguments to it.
|
||||
struct ircd::json::strung
|
||||
:std::string
|
||||
{
|
||||
explicit operator json::object() const;
|
||||
explicit operator json::array() const;
|
||||
|
||||
template<class... T> strung(T&&... t);
|
||||
strung(strung &&s) noexcept: std::string{std::move(s)} {}
|
||||
strung(const strung &s): std::string{s} {}
|
||||
};
|
||||
|
||||
#include "util.h"
|
||||
#include "array.h"
|
||||
#include "object.h"
|
||||
|
@ -68,6 +56,7 @@ struct ircd::json::strung
|
|||
#include "value.h"
|
||||
#include "member.h"
|
||||
#include "iov.h"
|
||||
#include "strung.h"
|
||||
#include "tuple/tuple.h"
|
||||
#include "stack.h"
|
||||
|
||||
|
@ -146,34 +135,3 @@ ircd::json::print(const mutable_buffer &buf,
|
|||
valid_output(sv, size(sv)); // no size expectation check
|
||||
return sv.size();
|
||||
}
|
||||
|
||||
template<class... T>
|
||||
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)...)
|
||||
};
|
||||
|
||||
valid_output(sv, ircd::size(out));
|
||||
return sv;
|
||||
})
|
||||
}{}
|
||||
|
||||
inline ircd::json::strung::operator
|
||||
json::array()
|
||||
const
|
||||
{
|
||||
return string_view{*this};
|
||||
}
|
||||
|
||||
inline ircd::json::strung::operator
|
||||
json::object()
|
||||
const
|
||||
{
|
||||
return string_view{*this};
|
||||
}
|
||||
|
|
64
include/ircd/json/strung.h
Normal file
64
include/ircd/json/strung.h
Normal file
|
@ -0,0 +1,64 @@
|
|||
// 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);
|
||||
};
|
||||
|
||||
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>
|
||||
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)...)
|
||||
};
|
||||
|
||||
valid_output(sv, ircd::size(out));
|
||||
return sv;
|
||||
})
|
||||
}
|
||||
{}
|
19
ircd/json.cc
19
ircd/json.cc
|
@ -1204,6 +1204,25 @@ ircd::json::iov::defaults::defaults(iov &iov,
|
|||
{
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// json/strung.h
|
||||
//
|
||||
|
||||
ircd::json::strung::operator
|
||||
json::array()
|
||||
const
|
||||
{
|
||||
return string_view{*this};
|
||||
}
|
||||
|
||||
ircd::json::strung::operator
|
||||
json::object()
|
||||
const
|
||||
{
|
||||
return string_view{*this};
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// json/vector.h
|
||||
|
|
Loading…
Reference in a new issue