2#include <score/serialization/JSONVisitor.hpp>
4#include <ossia/math/safe_math.hpp>
26template <
typename Obj, std::
size_t N>
29 if(
auto v = obj.tryGet(key); v && v->obj.IsString())
37template <
typename Obj, std::
size_t N>
38bool parseJsonField(
const Obj& obj,
const char (&key)[N],
bool& out)
40 if(
auto v = obj.tryGet(key); v && v->obj.IsBool())
42 out = v->obj.GetBool();
53 if(!ossia::safe_isfinite(d))
55 if constexpr(!std::is_floating_point_v<T>)
57 if(d <
double(std::numeric_limits<long long>::min())
58 || d > double(std::numeric_limits<long long>::max()))
60 out =
static_cast<T
>(
static_cast<long long>(d));
64 out =
static_cast<T
>(d);
69template <
typename Obj, std::
size_t N,
typename T>
71 (std::is_arithmetic_v<T> || std::is_enum_v<T>) && !std::is_same_v<T, bool>)
74 auto v = obj.tryGet(key);
75 if(!v || !v->obj.IsNumber())
78 if constexpr(std::is_floating_point_v<T>)
80 out =
static_cast<T
>(v->obj.GetDouble());
83 else if constexpr(std::is_integral_v<T> && std::is_unsigned_v<T>)
87 out =
static_cast<T
>(v->obj.GetUint64());
92 out =
static_cast<T
>(v->obj.GetInt64());
100 out =
static_cast<T
>(v->obj.GetInt64());
103 if(v->obj.IsUint64())
105 const auto u = v->obj.GetUint64();
106 if(u > uint64_t(std::numeric_limits<long long>::max()))
108 out =
static_cast<T
>(
static_cast<long long>(u));
115template <
typename Obj, std::
size_t N>
116bool parseJsonField(
const Obj& obj,
const char (&key)[N], QSize& out)
118 auto v = obj.tryGet(key);
119 if(!v || !v->obj.IsArray())
121 const auto& arr = v->obj.GetArray();
122 if(arr.Size() < 2 || !arr[0].IsNumber() || !arr[1].IsNumber())
Base toolkit upon which the software is built.
Definition Application.cpp:117
bool parseJsonNumber(double d, T &out) noexcept
Definition JSONParse.hpp:51
bool parseJsonField(const Obj &obj, const char(&key)[N], QString &out)
Read one field of a JSON object, or leave out alone.
Definition JSONParse.hpp:27