mirror of
https://github.com/matrix-construct/construct
synced 2024-10-01 13:18:58 +02:00
ircd::json: Inline value constructors.
This commit is contained in:
parent
d61850ecf6
commit
0344a12b40
3 changed files with 188 additions and 165 deletions
|
@ -61,6 +61,7 @@ ircd::json::member::member(const string_view &key,
|
||||||
{}
|
{}
|
||||||
|
|
||||||
template<class V>
|
template<class V>
|
||||||
|
inline __attribute__((always_inline))
|
||||||
ircd::json::member::member(const string_view &key,
|
ircd::json::member::member(const string_view &key,
|
||||||
V&& v)
|
V&& v)
|
||||||
:member
|
:member
|
||||||
|
|
|
@ -145,6 +145,193 @@ ircd::json::value::value()
|
||||||
,floats{false}
|
,floats{false}
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
inline
|
||||||
|
ircd::json::value::value(const nullptr_t &)
|
||||||
|
:value
|
||||||
|
{
|
||||||
|
literal_null, type::LITERAL
|
||||||
|
}
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
ircd::json::value::value(const json::object &sv)
|
||||||
|
:value{sv, OBJECT}
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
ircd::json::value::value(const json::array &sv)
|
||||||
|
:value{sv, ARRAY}
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
ircd::json::value::value(const bool &boolean)
|
||||||
|
:value
|
||||||
|
{
|
||||||
|
boolean? literal_true : literal_false, type::LITERAL
|
||||||
|
}
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
ircd::json::value::value(const uint8_t &integer)
|
||||||
|
:value{int64_t{integer}}
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
ircd::json::value::value(const int8_t &integer)
|
||||||
|
:value{int64_t{integer}}
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
ircd::json::value::value(const uint16_t &integer)
|
||||||
|
:value{int64_t{integer}}
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
ircd::json::value::value(const int16_t &integer)
|
||||||
|
:value{int64_t{integer}}
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
ircd::json::value::value(const uint32_t &integer)
|
||||||
|
:value{int64_t{integer}}
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
ircd::json::value::value(const int32_t &integer)
|
||||||
|
:value{int64_t{integer}}
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
ircd::json::value::value(const int64_t &integer)
|
||||||
|
:integer{integer}
|
||||||
|
,len{0}
|
||||||
|
,type{NUMBER}
|
||||||
|
,serial{false}
|
||||||
|
,alloc{false}
|
||||||
|
,floats{false}
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
ircd::json::value::value(const double &floating)
|
||||||
|
:floating{floating}
|
||||||
|
,len{0}
|
||||||
|
,type{NUMBER}
|
||||||
|
,serial{false}
|
||||||
|
,alloc{false}
|
||||||
|
,floats{true}
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
ircd::json::value::value(const char *const &str)
|
||||||
|
:value{string_view{str}}
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
ircd::json::value::value(const char *const &str,
|
||||||
|
const enum type &type)
|
||||||
|
:value{string_view{str}, type}
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
ircd::json::value::value(const string_view &sv)
|
||||||
|
:value{sv, json::type(sv, strict, std::nothrow)}
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
ircd::json::value::value(const string_view &sv,
|
||||||
|
const enum type &type)
|
||||||
|
:string{sv.data()}
|
||||||
|
,len{sv.size()}
|
||||||
|
,type{type}
|
||||||
|
,serial{type == STRING? surrounds(sv, '"') : true}
|
||||||
|
,alloc{false}
|
||||||
|
,floats{false}
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
ircd::json::value::value(const std::string &s)
|
||||||
|
:value{s, json::type(s, strict, std::nothrow)}
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
ircd::json::value::value(const struct value *const &array,
|
||||||
|
const size_t &len)
|
||||||
|
:array{array}
|
||||||
|
,len{len}
|
||||||
|
,type{ARRAY}
|
||||||
|
,serial{false}
|
||||||
|
,alloc{false}
|
||||||
|
,floats{false}
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
ircd::json::value::value(std::unique_ptr<const struct value[]> &&array,
|
||||||
|
const size_t &len)
|
||||||
|
:array{array.get()}
|
||||||
|
,len{len}
|
||||||
|
,type{ARRAY}
|
||||||
|
,serial{false}
|
||||||
|
,alloc{true}
|
||||||
|
,floats{false}
|
||||||
|
{
|
||||||
|
array.release();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
ircd::json::value::value(const struct member *const &object,
|
||||||
|
const size_t &len)
|
||||||
|
:object{object}
|
||||||
|
,len{len}
|
||||||
|
,type{OBJECT}
|
||||||
|
,serial{false}
|
||||||
|
,alloc{false}
|
||||||
|
,floats{false}
|
||||||
|
{}
|
||||||
|
|
||||||
|
inline
|
||||||
|
ircd::json::value::value(std::unique_ptr<const struct member[]> &&object,
|
||||||
|
const size_t &len)
|
||||||
|
:object{object.get()}
|
||||||
|
,len{len}
|
||||||
|
,type{OBJECT}
|
||||||
|
,serial{false}
|
||||||
|
,alloc{true}
|
||||||
|
,floats{false}
|
||||||
|
{
|
||||||
|
object.release();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
ircd::json::value::value(value &&other)
|
||||||
|
noexcept
|
||||||
|
:integer{other.integer}
|
||||||
|
,len{other.len}
|
||||||
|
,type{other.type}
|
||||||
|
,serial{other.serial}
|
||||||
|
,alloc{other.alloc}
|
||||||
|
,floats{other.floats}
|
||||||
|
{
|
||||||
|
other.alloc = false;
|
||||||
|
}
|
||||||
|
|
||||||
template<size_t N>
|
template<size_t N>
|
||||||
ircd::json::value::value(const char (&str)[N])
|
ircd::json::value::value(const char (&str)[N])
|
||||||
:value{string_view{str, strnlen(str, N)}}
|
:value{string_view{str, strnlen(str, N)}}
|
||||||
|
|
165
ircd/json.cc
165
ircd/json.cc
|
@ -3403,114 +3403,6 @@ ircd::json::type(const value &a)
|
||||||
// value::value
|
// value::value
|
||||||
//
|
//
|
||||||
|
|
||||||
ircd::json::value::value(const nullptr_t &)
|
|
||||||
:value
|
|
||||||
{
|
|
||||||
literal_null, type::LITERAL
|
|
||||||
}
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
ircd::json::value::value(const json::object &sv)
|
|
||||||
:value{sv, OBJECT}
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
ircd::json::value::value(const json::array &sv)
|
|
||||||
:value{sv, ARRAY}
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
ircd::json::value::value(const bool &boolean)
|
|
||||||
:value
|
|
||||||
{
|
|
||||||
boolean? literal_true : literal_false, type::LITERAL
|
|
||||||
}
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
ircd::json::value::value(const uint8_t &integer)
|
|
||||||
:value{int64_t{integer}}
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
ircd::json::value::value(const int8_t &integer)
|
|
||||||
:value{int64_t{integer}}
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
ircd::json::value::value(const uint16_t &integer)
|
|
||||||
:value{int64_t{integer}}
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
ircd::json::value::value(const int16_t &integer)
|
|
||||||
:value{int64_t{integer}}
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
ircd::json::value::value(const uint32_t &integer)
|
|
||||||
:value{int64_t{integer}}
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
ircd::json::value::value(const int32_t &integer)
|
|
||||||
:value{int64_t{integer}}
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
ircd::json::value::value(const int64_t &integer)
|
|
||||||
:integer{integer}
|
|
||||||
,len{0}
|
|
||||||
,type{NUMBER}
|
|
||||||
,serial{false}
|
|
||||||
,alloc{false}
|
|
||||||
,floats{false}
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
ircd::json::value::value(const double &floating)
|
|
||||||
:floating{floating}
|
|
||||||
,len{0}
|
|
||||||
,type{NUMBER}
|
|
||||||
,serial{false}
|
|
||||||
,alloc{false}
|
|
||||||
,floats{true}
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
ircd::json::value::value(const char *const &str)
|
|
||||||
:value{string_view{str}}
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
ircd::json::value::value(const char *const &str,
|
|
||||||
const enum type &type)
|
|
||||||
:value{string_view{str}, type}
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
ircd::json::value::value(const string_view &sv)
|
|
||||||
:value{sv, json::type(sv, strict, std::nothrow)}
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
ircd::json::value::value(const string_view &sv,
|
|
||||||
const enum type &type)
|
|
||||||
:string{sv.data()}
|
|
||||||
,len{sv.size()}
|
|
||||||
,type{type}
|
|
||||||
,serial{type == STRING? surrounds(sv, '"') : true}
|
|
||||||
,alloc{false}
|
|
||||||
,floats{false}
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
ircd::json::value::value(const std::string &s)
|
|
||||||
:value{s, json::type(s, strict, std::nothrow)}
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
ircd::json::value::value(const std::string &s,
|
ircd::json::value::value(const std::string &s,
|
||||||
const enum type &type)
|
const enum type &type)
|
||||||
:string{nullptr}
|
:string{nullptr}
|
||||||
|
@ -3528,51 +3420,6 @@ ircd::json::value::value(const std::string &s,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
ircd::json::value::value(const struct value *const &array,
|
|
||||||
const size_t &len)
|
|
||||||
:array{array}
|
|
||||||
,len{len}
|
|
||||||
,type{ARRAY}
|
|
||||||
,serial{false}
|
|
||||||
,alloc{false}
|
|
||||||
,floats{false}
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
ircd::json::value::value(std::unique_ptr<const struct value[]> &&array,
|
|
||||||
const size_t &len)
|
|
||||||
:array{array.get()}
|
|
||||||
,len{len}
|
|
||||||
,type{ARRAY}
|
|
||||||
,serial{false}
|
|
||||||
,alloc{true}
|
|
||||||
,floats{false}
|
|
||||||
{
|
|
||||||
array.release();
|
|
||||||
}
|
|
||||||
|
|
||||||
ircd::json::value::value(const struct member *const &object,
|
|
||||||
const size_t &len)
|
|
||||||
:object{object}
|
|
||||||
,len{len}
|
|
||||||
,type{OBJECT}
|
|
||||||
,serial{false}
|
|
||||||
,alloc{false}
|
|
||||||
,floats{false}
|
|
||||||
{}
|
|
||||||
|
|
||||||
ircd::json::value::value(std::unique_ptr<const struct member[]> &&object,
|
|
||||||
const size_t &len)
|
|
||||||
:object{object.get()}
|
|
||||||
,len{len}
|
|
||||||
,type{OBJECT}
|
|
||||||
,serial{false}
|
|
||||||
,alloc{true}
|
|
||||||
,floats{false}
|
|
||||||
{
|
|
||||||
object.release();
|
|
||||||
}
|
|
||||||
|
|
||||||
ircd::json::value::value(const json::members &members)
|
ircd::json::value::value(const json::members &members)
|
||||||
:string{nullptr}
|
:string{nullptr}
|
||||||
,len{serialized(members)}
|
,len{serialized(members)}
|
||||||
|
@ -3653,18 +3500,6 @@ ircd::json::value::value(const value &other)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ircd::json::value::value(value &&other)
|
|
||||||
noexcept
|
|
||||||
:integer{other.integer}
|
|
||||||
,len{other.len}
|
|
||||||
,type{other.type}
|
|
||||||
,serial{other.serial}
|
|
||||||
,alloc{other.alloc}
|
|
||||||
,floats{other.floats}
|
|
||||||
{
|
|
||||||
other.alloc = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
ircd::json::value &
|
ircd::json::value &
|
||||||
ircd::json::value::operator=(value &&other)
|
ircd::json::value::operator=(value &&other)
|
||||||
noexcept
|
noexcept
|
||||||
|
|
Loading…
Reference in a new issue