2018-02-04 03:22:01 +01: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.
|
2017-09-08 12:08:29 +02:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#define HAVE_IRCD_JSON_MEMBER_H
|
|
|
|
|
|
|
|
namespace ircd::json
|
|
|
|
{
|
|
|
|
struct member;
|
2019-03-29 04:15:22 +01:00
|
|
|
using members = std::initializer_list<const member>;
|
2019-01-22 20:42:50 +01:00
|
|
|
|
|
|
|
bool operator==(const member &a, const member &b);
|
|
|
|
bool operator==(const member &a, const string_view &b);
|
|
|
|
bool operator!=(const member &a, const member &b);
|
|
|
|
bool operator!=(const member &a, const string_view &b);
|
|
|
|
bool operator<(const member &a, const member &b);
|
|
|
|
bool operator<(const member &a, const string_view &b);
|
2017-09-08 12:08:29 +02:00
|
|
|
|
2018-03-21 20:29:16 +01:00
|
|
|
bool sorted(const member *const &begin, const member *const &end);
|
2019-01-22 20:42:50 +01:00
|
|
|
|
2017-09-08 16:47:07 +02:00
|
|
|
size_t serialized(const member *const &begin, const member *const &end);
|
2019-01-22 20:42:50 +01:00
|
|
|
size_t serialized(const members &);
|
|
|
|
size_t serialized(const member &);
|
|
|
|
|
2017-09-08 16:47:07 +02:00
|
|
|
string_view stringify(mutable_buffer &, const member *const &begin, const member *const &end);
|
2019-01-22 20:42:50 +01:00
|
|
|
string_view stringify(mutable_buffer &, const members &);
|
|
|
|
string_view stringify(mutable_buffer &, const member &);
|
|
|
|
|
|
|
|
std::ostream &operator<<(std::ostream &, const member &);
|
2017-09-08 12:08:29 +02:00
|
|
|
}
|
|
|
|
|
2017-09-14 20:30:06 +02:00
|
|
|
/// A pair of json::value representing state for a member of an object.
|
|
|
|
///
|
|
|
|
/// This is slightly heavier than object::member as that only deals with
|
|
|
|
/// a pair of strings while the value here holds more diverse native state.
|
2017-09-12 18:37:44 +02:00
|
|
|
///
|
2017-09-08 12:08:29 +02:00
|
|
|
struct ircd::json::member
|
|
|
|
:std::pair<value, value>
|
|
|
|
{
|
|
|
|
explicit member(const string_view &k);
|
|
|
|
explicit member(const object::member &m);
|
2020-02-07 22:55:19 +01:00
|
|
|
template<class K, class V> member(K&&, V&&);
|
|
|
|
template<class K> member(K&&, value);
|
2017-09-08 12:08:29 +02:00
|
|
|
member() = default;
|
|
|
|
};
|
|
|
|
|
2020-02-07 22:55:19 +01:00
|
|
|
template<class K,
|
|
|
|
class V>
|
2019-07-15 04:12:46 +02:00
|
|
|
inline __attribute__((always_inline))
|
2020-02-07 22:55:19 +01:00
|
|
|
ircd::json::member::member(K&& k,
|
2017-09-08 12:08:29 +02:00
|
|
|
V&& v)
|
2020-02-07 22:55:19 +01:00
|
|
|
:std::pair<value, value>
|
|
|
|
{
|
|
|
|
value { std::forward<K>(k), json::STRING }, value { std::forward<V>(v) }
|
|
|
|
}
|
|
|
|
{}
|
|
|
|
|
|
|
|
template<class K>
|
|
|
|
inline __attribute__((always_inline))
|
|
|
|
ircd::json::member::member(K&& k,
|
|
|
|
value v)
|
|
|
|
:std::pair<value, value>
|
2017-09-08 12:08:29 +02:00
|
|
|
{
|
2020-02-07 22:55:19 +01:00
|
|
|
value { std::forward<K>(k), json::STRING }, std::move(v)
|
2017-09-08 12:08:29 +02:00
|
|
|
}
|
|
|
|
{}
|
|
|
|
|
|
|
|
inline
|
|
|
|
ircd::json::member::member(const object::member &m)
|
2019-03-29 04:15:22 +01:00
|
|
|
:member
|
2017-09-08 12:08:29 +02:00
|
|
|
{
|
2019-04-25 04:52:56 +02:00
|
|
|
m.first, value { m.second }
|
2017-09-08 12:08:29 +02:00
|
|
|
}
|
|
|
|
{}
|
|
|
|
|
|
|
|
inline
|
|
|
|
ircd::json::member::member(const string_view &k)
|
2019-03-29 04:15:22 +01:00
|
|
|
:member
|
2017-09-08 12:08:29 +02:00
|
|
|
{
|
2019-03-29 04:15:22 +01:00
|
|
|
k, value{}
|
2017-09-08 12:08:29 +02:00
|
|
|
}
|
|
|
|
{}
|