15 #include <nlohmann/json.hpp>
16 #include <immer/array.hpp>
17 #include <immer/flex_vector.hpp>
18 #include <immer/map.hpp>
19 #include <boost/hana/type.hpp>
20 #include <lager/util.hpp>
38 [](
auto t) -> decltype((
void)std::declval<
typename decltype(t)::type>().empty()) {});
40 struct AddToJsonIfNeededT
43 static void call(
json &j, std::string name, T &&arg) {
44 using Type = std::decay_t<T>;
47 j[name] = std::forward<T>(arg);
50 j[name] = std::forward<T>(arg);
56 struct AddToJsonIfNeededT<
std::optional<U>>
59 static void call(
json &j, std::string name, T &&arg) {
60 if (arg.has_value()) {
61 j[name] = std::forward<T>(arg).value();
67 struct AddToJsonIfNeededT<JsonWrap>
70 static void call(
json &j, std::string name, T &&arg) {
71 if (!arg.get().is_null()) {
72 j[name] = std::forward<T>(arg).get();
82 detail::AddToJsonIfNeededT<std::decay_t<T>>::call(j, name, std::forward<T>(arg));
89 std::enable_if_t<!std::is_same_v<std::decay_t<MapT>,
json>
90 && !std::is_same_v<std::decay_t<MapT>, JsonWrap>,
int> = 0>
93 for (
auto kv : std::forward<MapT>(arg)) {
101 for (
auto kv : arg.items()) {
109 using namespace std::string_literals;
112 using Variant = std::variant<std::string, JsonWrap, Null>;
119 constexpr
operator T()
const {
136 typename std::add_lvalue_reference<T>::type
declref() noexcept;
141 template <
class T,
class V>
142 struct adl_serializer<immer::map<T, V>> {
144 if constexpr (std::is_same_v<T, std::string>) {
146 for (
auto [k, v] : map) {
151 for (
auto [k, v] : map) {
159 immer::map<T, V> ret;
160 if constexpr (std::is_same_v<T, std::string>) {
161 for (
const auto &[k, v] : j.items()) {
162 ret = std::move(ret).set(k, v);
165 for (std::size_t i = 0; i < j.size(); i += 2) {
166 ret = std::move(ret).set(j[i], j[i+1]);
174 struct adl_serializer<immer::array<T>> {
178 j.push_back(
json(i));
185 for (
const auto &i : j) {
186 ret = std::move(ret).push_back(i);
194 struct adl_serializer<immer::flex_vector<T>> {
198 j.push_back(
json(i));
203 immer::flex_vector<T> ret;
205 for (
const auto &i : j) {
206 ret = std::move(ret).push_back(i.get<T>());
216 std::visit(lager::visitor{
217 [&j](std::string i) { j = i; },
225 var = j.get<std::string>();
226 }
else if (j.is_null()) {
Definition: jsonwrap.hpp:23
constexpr auto hasEmptyMethod
Definition: types.hpp:37
std::add_lvalue_reference< T >::type declref() noexcept
Definition: location.hpp:10
std::variant< std::string, JsonWrap, Null > Variant
Definition: types.hpp:112
void addToJsonIfNeeded(json &j, std::string name, T &&arg)
Definition: types.hpp:80
void addPropertyMapToJson(json &j, MapT &&arg)
Definition: types.hpp:91
nlohmann::json json
Definition: jsonwrap.hpp:20
std::string Bytes
Definition: types.hpp:27
constexpr detail::DefaultValT DEFVAL
Definition: types.hpp:125
Status
Definition: types.hpp:30
@ FAIL
Definition: types.hpp:31
@ SUCC
Definition: types.hpp:32
RoomMembership
Definition: types.hpp:128
@ Join
Definition: types.hpp:129
@ Leave
Definition: types.hpp:129
@ Invite
Definition: types.hpp:129
immer::flex_vector< Event > EventList
Definition: types.hpp:107
Definition: location.hpp:27
Definition: clientutil.hpp:217
Definition: types.hpp:111
static void to_json(json &j, const Kazv::Variant &var)
Definition: types.hpp:215
static void from_json(const json &j, Kazv::Variant &var)
Definition: types.hpp:223
static void from_json(const json &j, immer::array< T > &a)
Definition: types.hpp:182
static void to_json(json &j, immer::array< T > arr)
Definition: types.hpp:175
static void from_json(const json &j, immer::flex_vector< T > &a)
Definition: types.hpp:202
static void to_json(json &j, immer::flex_vector< T > arr)
Definition: types.hpp:195
static void from_json(const json &j, immer::map< T, V > &m)
Definition: types.hpp:158
static void to_json(json &j, immer::map< T, V > map)
Definition: types.hpp:143