134template <
typename T,
typename =
void>
139 static_cast<void>(T::INT_BITS),
140 static_cast<void>(T::FRAC_BITS),
141 static_cast<void>(fl::declval<const T&>().raw()),
142 static_cast<void>(T::from_raw(fl::declval<const T&>().raw())),
148 return static_cast<u32
>(
value);
153 const u64 half =
u64(1) << (shift - 1);
154 const u64 mask = (
u64(1) << shift) - 1;
155 const u64 truncated =
value >> shift;
157 const bool round_up = remainder > half || (remainder == half && (truncated & 1));
158 return static_cast<u32
>(truncated + (round_up ? 1 : 0));
163 if (magnitude == 0) {
168 int exponent = top_bit + binary_exp;
169 if (exponent > 127) {
170 return sign | 0x7F800000u;
173 if (exponent >= -126) {
174 const int shift = top_bit - 23;
179 significand =
static_cast<u32
>(magnitude << -shift);
181 if (significand >= 0x01000000u) {
184 if (exponent > 127) {
185 return sign | 0x7F800000u;
188 return sign | (
static_cast<u32
>(exponent + 127) << 23) |
189 (significand & 0x007FFFFFu);
192 const int subnormal_shift = -(binary_exp + 149);
194 if (subnormal_shift > 0) {
197 const int left_shift = -subnormal_shift;
198 if (left_shift >= 64 || magnitude > (
u64(-1) >> left_shift)) {
199 return sign | 0x7F800000u;
201 const u64 shifted = magnitude << left_shift;
202 mantissa = shifted > 0x007FFFFFu ? 0x00800000u :
static_cast<u32
>(shifted);
204 if (mantissa >= 0x00800000u) {
205 return sign | 0x00800000u;
207 return sign | mantissa;
211 const u32
sign = raw < 0 ? 0x80000000u : 0u;
212 const u64 magnitude = raw < 0
213 ?
static_cast<u64>(-(raw + 1)) + 1u
214 :
static_cast<u64>(raw);
219 const bool negative = (bits & 0x80000000u) != 0;
220 const u32 exp_bits = (bits >> 23) & 0xFFu;
221 const u32 mantissa_bits = bits & 0x007FFFFFu;
222 if (exp_bits == 0xFFu) {
226 u64 significand = mantissa_bits;
229 significand |= 0x00800000u;
230 exponent =
static_cast<int>(exp_bits) - 127;
233 const int shift = exponent + frac_bits - 23;
236 if (shift >= 63 || significand > (
u64(0x7FFFFFFFFFFFFFFF) >> shift)) {
239 magnitude = significand << shift;
243 if ((!negative && magnitude >
u64(0x7FFFFFFFFFFFFFFF)) ||
244 (negative && magnitude > (
u64(0x7FFFFFFFFFFFFFFF) + 1u))) {
248 ? (magnitude == (
u64(0x7FFFFFFFFFFFFFFF) + 1u)
249 ?
static_cast<i64>(0x8000000000000000ull)
250 : -
static_cast<i64>(magnitude))
251 : static_cast<
i64>(magnitude);
255template <
typename FP>
276 template <typename FP, typename fl::enable_if<detail::is_fl_fixed_point<FP>::value,
int>
::type = 0>
297 for (
const auto& item : vec) {
319 if (
this != &other) {
326 if (
this != &other) {
353 template <typename FP, typename fl::enable_if<detail::is_fl_fixed_point<FP>::value,
int>
::type = 0>
372 if (!
mValue) {
return *
this; }
375 for (
const auto& item : vec) {
405 template<
typename IntType>
413 return mValue->as_float();
418 return mValue->as_double();
421 template<
typename FloatType>
427 template <
typename FP>
431 if (
auto raw =
mValue->data.template ptr<i64>()) {
432 return FP::from_raw(
static_cast<decltype(FP().raw())
>(*raw));
434 if (
auto f =
mValue->data.template ptr<float>()) {
440 return FP::from_raw(
static_cast<decltype(FP().raw())
>(raw));
447 return mValue->as_string();
468 template<
typename T,
typename OutputIt>
474 template<
typename Container>
476 return mValue ?
mValue->copy_to_output_iterator(out) : 0;
531 return mValue->as_string();
538 return mValue->clone_array();
545 auto ptr =
mValue->as_object();
656 if (!
mValue)
return typename json_value::template array_iterator<T>();
662 if (!
mValue)
return typename json_value::template array_iterator<T>();
668 if (!
mValue)
return typename json_value::template array_iterator<T>();
674 if (!
mValue)
return typename json_value::template array_iterator<T>();
688 for (
auto it =
begin(); it !=
end(); ++it) {
690 result.push_back(keyValue.first);
712 auto arr =
mValue->clone_array();
718 auto arrPtr =
mValue->as_array();
721 if (idx >= arrPtr->size()) {
722 for (
size_t i = arrPtr->size(); i <= idx; i++) {
726 return json((*arrPtr)[idx]);
728 return json(
nullptr);
733 return json(
nullptr);
736 auto arrPtr =
mValue->as_array();
738 if (idx < arrPtr->
size()) {
739 return json((*arrPtr)[idx]);
741 return json(
nullptr);
744 if (
auto p =
mValue->data.ptr<fl::vector<i16>>()) {
745 if (idx < p->
size())
return json(
static_cast<i64>((*p)[idx]));
746 }
else if (
auto p =
mValue->data.ptr<fl::vector<u8>>()) {
747 if (idx < p->
size())
return json(
static_cast<i64>((*p)[idx]));
748 }
else if (
auto p =
mValue->data.ptr<fl::vector<float>>()) {
749 if (idx < p->
size())
return json((*p)[idx]);
751 return json(
nullptr);
764 if (objPtr->find(key) == objPtr->end()) {
768 return json((*objPtr)[key]);
772 return json(
nullptr);
777 return json(
nullptr);
783 if (!objPtr)
return json(
nullptr);
784 auto it = objPtr->find(key);
785 if (it != objPtr->end()) {
786 return json(it->second);
788 return json(
nullptr);
807 if (!
mValue)
return fallback;
808 return (*
mValue) | fallback;
851 return json(
nullptr);
883 (*objPtr)[key] =
value.mValue;
896 template <typename FP, typename fl::enable_if<detail::is_fl_fixed_point<FP>::value,
int>
::type = 0>
900 template<typename T, typename = fl::enable_if_t<fl::is_same<T, char>::value>>
905 template<
typename IntType>
932 auto arr =
mValue->clone_array();
941 ptr->push_back(
value.mValue);
Back insert iterator - an output iterator that inserts elements at the end of a container.
static const_iterator from_iterator(json_object::const_iterator iter) FL_NO_EXCEPT
static const_iterator from_object_iterator(const iterator &other) FL_NO_EXCEPT
void set_value(const fl::shared_ptr< json_value > &value) FL_NO_EXCEPT
static fl::string normalizeJsonString(const char *jsonStr) FL_NO_EXCEPT
bool is_object() const FL_NO_EXCEPT
friend json_value::const_iterator begin(const json &j) FL_NO_EXCEPT
T operator|(const T &fallback) const FL_NO_EXCEPT
fl::string to_string_native_public() const FL_NO_EXCEPT
fl::string to_string() const FL_NO_EXCEPT
size_t copy_to(fl::span< T > out) const FL_NO_EXCEPT
fl::enable_if< detail::is_fl_fixed_point< FP >::value, fl::optional< FP > >::type as_fixed_point() const FL_NO_EXCEPT
size_t size() const FL_NO_EXCEPT
T as_or(const T &fallback) const FL_NO_EXCEPT
fl::optional< fl::string > as_string() const FL_NO_EXCEPT
fl::shared_ptr< json_value > mValue
const json_object * as_object() const FL_NO_EXCEPT
fl::optional< i64 > as_int() const FL_NO_EXCEPT
json(double d) FL_NO_EXCEPT
bool is_generic_array() const FL_NO_EXCEPT
void set(const fl::string &key, const char *value) FL_NO_EXCEPT
fl::vector< fl::string > getObjectKeys() const FL_NO_EXCEPT
void set(const fl::string &key, const json &value) FL_NO_EXCEPT
static json createObject() FL_NO_EXCEPT
bool is_int() const FL_NO_EXCEPT
json(json_object o) FL_NO_EXCEPT
void set(const fl::string &key, double value) FL_NO_EXCEPT
T value() const FL_NO_EXCEPT
json & operator=(const json &other) FL_NO_EXCEPT
static json create_array() FL_NO_EXCEPT
json_value::iterator begin() FL_NO_EXCEPT
json operator[](size_t idx) FL_NO_EXCEPT
void set(const fl::string &key, T value) FL_NO_EXCEPT
fl::enable_if< fl::is_integral< T >::value &&!fl::is_same< T, bool >::value, T >::type get_default_value() const FL_NO_EXCEPT
fl::optional< json_object > clone_object() const FL_NO_EXCEPT
fl::vector< fl::string > get_object_keys() const FL_NO_EXCEPT
static json createArray() FL_NO_EXCEPT
bool is_number() const FL_NO_EXCEPT
bool has_value() const FL_NO_EXCEPT
bool is_floats() const FL_NO_EXCEPT
json_value::template array_iterator< T > end_array() FL_NO_EXCEPT
fl::string serialize() const FL_NO_EXCEPT
fl::optional< float > as_float() const FL_NO_EXCEPT
fl::enable_if< fl::is_integral< T >::value &&!fl::is_same< T, bool >::value, fl::optional< T > >::type as_impl() const FL_NO_EXCEPT
fl::optional< T > try_as() const FL_NO_EXCEPT
fl::string to_string_native() const FL_NO_EXCEPT
fl::vector< fl::string > keys() const FL_NO_EXCEPT
bool is_array() const FL_NO_EXCEPT
json(bool b) FL_NO_EXCEPT
bool is_null() const FL_NO_EXCEPT
size_t get_size() const FL_NO_EXCEPT
static json create_object() FL_NO_EXCEPT
void set(const fl::string &key, FP value) FL_NO_EXCEPT
fl::optional< bool > as_bool() const FL_NO_EXCEPT
const json_array * as_array() const FL_NO_EXCEPT
void push_back(const json &value) FL_NO_EXCEPT
void set(const fl::string &key, float value) FL_NO_EXCEPT
static fl::string normalize_json_string(const char *jsonStr) FL_NO_EXCEPT
json_value::iterator end() FL_NO_EXCEPT
json(const fl::shared_ptr< json_value > &value) FL_NO_EXCEPT
const json_value * internal_value() const FL_NO_EXCEPT
json(json_array a) FL_NO_EXCEPT
bool contains(size_t idx) const FL_NO_EXCEPT
static json from_char(char c) FL_NO_EXCEPT
bool is_double() const FL_NO_EXCEPT
size_t getSize() const FL_NO_EXCEPT
json(float f) FL_NO_EXCEPT
json(const char *s) FL_NO_EXCEPT
static json parse(const fl::string &txt) FL_NO_EXCEPT
static json fromValue(const json_value &value) FL_NO_EXCEPT
bool is_float() const FL_NO_EXCEPT
bool is_bool() const FL_NO_EXCEPT
bool is_bytes() const FL_NO_EXCEPT
fl::optional< T > as() const FL_NO_EXCEPT
bool is_string() const FL_NO_EXCEPT
void set(const fl::string &key, i64 value) FL_NO_EXCEPT
friend json_value::const_iterator end(const json &j) FL_NO_EXCEPT
static json object() FL_NO_EXCEPT
fl::optional< double > as_double() const FL_NO_EXCEPT
fl::optional< json_array > clone_array() const FL_NO_EXCEPT
bool is_audio() const FL_NO_EXCEPT
static json array() FL_NO_EXCEPT
size_t copy_to_output_iterator(OutputIt out) const FL_NO_EXCEPT
json_value::template array_iterator< T > begin_array() FL_NO_EXCEPT
constexpr remove_reference< T >::type && move(T &&t) FL_NO_EXCEPT
shared_ptr< T > make_shared(Args &&... args) FL_NO_EXCEPT
bool fixed_raw_from_ieee754_bits(u32 bits, int frac_bits, i64 *out) FL_NO_EXCEPT
u32 ieee754_bits_from_fixed_raw(i64 raw, int frac_bits) FL_NO_EXCEPT
u32 ieee754_bits_from_scaled_u64(u32 sign, u64 magnitude, int binary_exp) FL_NO_EXCEPT
u32 round_shift_right_u64(u64 value, int shift) FL_NO_EXCEPT
float fixed_point_to_float(FP value) FL_NO_EXCEPT
int json_floor_log2_u64(u64 value) FL_NO_EXCEPT
float json_double_to_float(double value) FL_NO_EXCEPT
Compile-time linker keep-alive hook for a single fl::Bus.
decltype(nullptr) nullptr_t
back_insert_iterator< Container > back_inserter(Container &c) FL_NO_EXCEPT
Helper function to create a back_insert_iterator.
u8 u8 fract8 blur_amount FL_NO_EXCEPT
volatile size_t g_json_stack_base
constexpr int type_rank< T >::value
volatile size_t g_json_max_stack_depth
integral_constant< bool, false > false_type
fl::vector< fl::shared_ptr< json_value > > json_array
expected< T, E > result
Alias for expected (Rust-style naming)
constexpr nullopt_t nullopt
To bit_cast(const From &from) FL_NO_EXCEPT
fl::flat_map< fl::string, fl::shared_ptr< json_value >, fl::StringFastLess > json_object
constexpr enable_if< is_fixed_point< T >::value, int >::type sign(T x) FL_NO_EXCEPT
integral_constant< bool, true > true_type
Base definition for an LED controller.
Portable compile-time assertion wrapper.
static fl::shared_ptr< json_value > parse2(const fl::string &txt) FL_NO_EXCEPT
json_value::iterator iterator
json_value::const_iterator const_iterator