0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-07-01 00:08:22 +02:00

ircd::json: Inline value constructors.

This commit is contained in:
Jason Volk 2019-07-14 19:12:46 -07:00
parent d61850ecf6
commit 0344a12b40
3 changed files with 188 additions and 165 deletions

View file

@ -61,6 +61,7 @@ ircd::json::member::member(const string_view &key,
{}
template<class V>
inline __attribute__((always_inline))
ircd::json::member::member(const string_view &key,
V&& v)
:member

View file

@ -145,6 +145,193 @@ ircd::json::value::value()
,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>
ircd::json::value::value(const char (&str)[N])
:value{string_view{str, strnlen(str, N)}}

View file

@ -3403,114 +3403,6 @@ ircd::json::type(const value &a)
// 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,
const enum type &type)
: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)
:string{nullptr}
,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::operator=(value &&other)
noexcept