141template<
typename IntType = i64>
152 template<
typename T = IntType>
159 template<
typename T = IntType>
166 template<
typename T = IntType>
174 template<
typename T = IntType>
186 FL_ERROR(
"JSON integer overflow: value " <<
value <<
" does not fit in target type (range: "
187 << min_val <<
" to " << max_val <<
"), truncating");
205 template<
typename T = IntType>
216 bool isValidInt =
true;
217 fl::size startPos = 0;
220 if (str.length() > 0 && (str[0] ==
'+' || str[0] ==
'-')) {
225 for (fl::size i = startPos; i < str.length(); i++) {
233 if (isValidInt && str.length() > 0) {
235 result =
static_cast<IntType
>(parsed);
272 if (
value >
static_cast<float>(2147483647)) {
274 }
else if (
value <
static_cast<float>(-2147483648.0f)) {
275 result =
static_cast<i64>(-2147483648LL);
292 bool isValidInt =
true;
293 fl::size startPos = 0;
296 if (str.length() > 0 && (str[0] ==
'+' || str[0] ==
'-')) {
301 for (fl::size i = startPos; i < str.length(); i++) {
309 if (isValidInt && str.length() > 0) {
367 for (fl::size i = 0; i < lower.
length(); i++) {
372 if (lower ==
"true" || lower ==
"1" || lower ==
"yes" || lower ==
"on") {
378 if (lower ==
"false" || lower ==
"0" || lower ==
"no" || lower ==
"off") {
393template<
typename FloatType =
double>
408 template<
typename T = FloatType>
415 template<
typename T = FloatType>
428 if (
value > 2147483647LL) {
429 result =
static_cast<FloatType
>(2147483647);
430 }
else if (
value < -2147483648LL) {
431 result =
static_cast<FloatType
>(-2147483648);
433 result =
static_cast<FloatType
>(
static_cast<fl::i32
>(
value));
440 result =
static_cast<FloatType
>(
value ? 1.0f : 0.0f);
447 bool isValidFloat =
true;
448 bool hasDecimal =
false;
449 fl::size startPos = 0;
452 if (str.length() > 0 && (str[0] ==
'+' || str[0] ==
'-')) {
457 for (fl::size i = startPos; i < str.length(); i++) {
462 isValidFloat =
false;
466 }
else if (!
fl::isdigit(c) && c !=
'e' && c !=
'E') {
467 isValidFloat =
false;
473 if (isValidFloat && str.length() > 0) {
476 bool isSimpleDecimal =
true;
477 for (fl::size i = startPos; i < str.length(); i++) {
480 isSimpleDecimal =
false;
485 if (isSimpleDecimal) {
488 result =
static_cast<FloatType
>(parsed);
492 result =
static_cast<FloatType
>(parsed);
527 if (
value > 2147483647LL) {
528 result =
static_cast<double>(2147483647);
529 }
else if (
value < -2147483648LL) {
530 result =
static_cast<double>(-2147483648);
532 result =
static_cast<double>(
static_cast<fl::i32
>(
value));
544 bool isValidFloat =
true;
545 bool hasDecimal =
false;
546 fl::size startPos = 0;
549 if (str.length() > 0 && (str[0] ==
'+' || str[0] ==
'-')) {
554 for (fl::size i = startPos; i < str.length(); i++) {
559 isValidFloat =
false;
563 }
else if (!
fl::isdigit(c) && c !=
'e' && c !=
'E') {
564 isValidFloat =
false;
570 if (isValidFloat && str.length() > 0) {
573 bool isSimpleDecimal =
true;
574 for (fl::size i = startPos; i < str.length(); i++) {
577 isSimpleDecimal =
false;
582 if (isSimpleDecimal) {
585 result =
static_cast<double>(parsed);
589 result =
static_cast<double>(parsed);
670template<
typename T>
struct NumericExtractVisitor;
671template<
typename T>
struct CopyToVisitor;
672template<
typename T,
typename OutputIt>
struct CopyToOutputIteratorVisitor;
781 data =
static_cast<float>(d);
821 template<
typename Visitor>
826 template<
typename Visitor>
838 return data.is<
bool>();
846 return data.is<
float>();
849 return data.is<
float>();
946 template<
typename IntType>
973 template<
typename FloatType>
1008 data.visit(visitor);
1019 data.visit(visitor);
1023 template<
typename IntType>
1031 data.visit(visitor);
1039 template<
typename FloatType>
1047 data.visit(visitor);
1058 data.visit(visitor);
1074 for (
const auto& item : *audioPtr) {
1082 for (
const auto& item : *bytePtr) {
1090 for (
const auto& item : *floatPtr) {
1105 template<
typename T>
1108 data.visit(visitor);
1115 template<
typename T,
typename OutputIt>
1118 data.visit(visitor);
1123 template<
typename Container>
1125 using T =
typename Container::value_type;
1127 data.visit(visitor);
1132 template<
typename T>
1134 auto ptr =
data.ptr<T>();
1138 template<
typename T>
1140 auto ptr =
data.ptr<T>();
1184 template<
typename T>
1197 return ptr ? ptr->size() : 0;
1202 return ptr ? ptr->
size() : 0;
1207 return ptr ? ptr->
size() : 0;
1212 return ptr ? ptr->
size() : 0;
1227 auto& val = *((*ptr)[
mIndex]);
1232 auto opt = val.as_bool();
1325 template<
typename T>
1333 template<
typename T>
1341 template<
typename T>
1349 template<
typename T>
1371 if (idx >= arr.size()) {
1373 for (
size_t i = arr.size(); i <= idx; i++) {
1391 auto &jsonArr = *ptr;
1392 if (idx >= jsonArr.size()) {
1394 for (
size_t i = jsonArr.size(); i <= idx; i++) {
1399 return *jsonArr[idx];
1410 if (obj.find(key) == obj.end()) {
1418 template<
typename T>
1421 data.visit(visitor);
1426 template<
typename T>
1429 data.visit(visitor);
1438 return ptr && idx < ptr->size();
1444 return ptr && idx < ptr->
size();
1448 return ptr && idx < ptr->
size();
1452 return ptr && idx < ptr->
size();
1460 return ptr && ptr->find(key) != ptr->end();
1467 for (
auto it =
begin(); it !=
end(); ++it) {
1468 auto keyValue = *it;
1469 result.push_back(keyValue.first);
1481 data.visit(visitor);
1529 return mIter != other.mIter;
1533 return mIter == other.mIter;
1585 return mIter != other.mIter;
1589 return mIter == other.mIter;
1616 template<
typename U>
1640 template<
typename U>
1650 size_t n = (arr.size() <
dst.size()) ? arr.size() :
dst.size();
1651 for (
size_t i = 0; i < n; ++i) {
1652 const auto& elem = arr[i];
1653 if (!elem) {
dst[i] = T(0);
continue; }
1655 elem->data.visit(nv);
1670 template<
typename ElemT>
1672 size_t n = (vec.size() <
dst.size()) ? vec.size() :
dst.size();
1673 for (
size_t i = 0; i < n; ++i) {
1674 dst[i] =
static_cast<T
>(vec[i]);
1682template<
typename T,
typename OutputIt>
1689 template<
typename U>
1699 for (
size_t i = 0; i < arr.size(); ++i) {
1700 const auto& elem = arr[i];
1703 elem->data.visit(nv);
1719 template<
typename ElemT>
1721 for (
size_t i = 0; i < vec.size(); ++i) {
1722 *
out =
static_cast<T
>(vec[i]);
Back insert iterator - an output iterator that inserts elements at the end of a container.
fl::size length() const FL_NOEXCEPT
typename vector_type::iterator iterator
typename vector_type::const_iterator const_iterator
array_iterator(variant_t *variant, size_t index) FL_NOEXCEPT
size_t get_size() const FL_NOEXCEPT
array_iterator & operator++() FL_NOEXCEPT
bool operator!=(const array_iterator &other) const FL_NOEXCEPT
parse_result< T > operator*() const FL_NOEXCEPT
bool operator==(const array_iterator &other) const FL_NOEXCEPT
parse_result< T > get_value() const FL_NOEXCEPT
array_iterator() FL_NOEXCEPT
array_iterator operator++(int) FL_NOEXCEPT
typename json_value::variant_t variant_t
fl::forward_iterator_tag iterator_category
static const_iterator from_object_iterator(const iterator &other) FL_NOEXCEPT
KeyValue operator*() const FL_NOEXCEPT
static const_iterator from_iterator(json_object::const_iterator iter) FL_NOEXCEPT
json_object::const_iterator mIter
bool operator==(const const_iterator &other) const FL_NOEXCEPT
const_iterator & operator++() FL_NOEXCEPT
const_iterator operator++(int) FL_NOEXCEPT
const_iterator(json_object::const_iterator iter) FL_NOEXCEPT
bool operator!=(const const_iterator &other) const FL_NOEXCEPT
json_object::iterator get_iter() const FL_NOEXCEPT
KeyValue operator*() const FL_NOEXCEPT
bool operator!=(const iterator &other) const FL_NOEXCEPT
json_object::iterator mIter
iterator & operator++() FL_NOEXCEPT
iterator operator++(int) FL_NOEXCEPT
fl::forward_iterator_tag iterator_category
bool operator==(const iterator &other) const FL_NOEXCEPT
iterator(json_object::iterator iter) FL_NOEXCEPT
fl::size size() const FL_NOEXCEPT
Centralized logging categories for FastLED hardware interfaces and subsystems.
constexpr T && forward(typename remove_reference< T >::type &t) FL_NOEXCEPT
decltype(nullptr) nullptr_t
constexpr remove_reference< T >::type && move(T &&t) FL_NOEXCEPT
string to_string(T value) FL_NOEXCEPT
char tolower(char c) FL_NOEXCEPT
Convert character to lowercase.
constexpr int type_rank< T >::value
bool isdigit(char c) FL_NOEXCEPT
Check if character is a decimal digit (0-9)
int parseInt(const char *str, fl::size len)
Parse an integer from a character buffer.
json_object & get_empty_json_obj()
shared_ptr< T > make_shared(Args &&... args) FL_NOEXCEPT
fl::vector< fl::shared_ptr< json_value > > json_array
expected< T, E > result
Alias for expected (Rust-style naming)
json_value & get_null_json_value()
constexpr nullopt_t nullopt
fl::flat_map< fl::string, fl::shared_ptr< json_value >, fl::StringFastLess > json_object
float parseFloat(const char *str, fl::size len)
Parse a floating point number from a character buffer.
Base definition for an LED controller.
Promise-based fluent API for FastLED - standalone async primitives.
void accept(const U &value) FL_NOEXCEPT
void operator()(const fl::string &str) FL_NOEXCEPT
void operator()(const double &value) FL_NOEXCEPT
void operator()(const float &value) FL_NOEXCEPT
fl::optional< bool > result
void operator()(const T &) FL_NOEXCEPT
void operator()(const i64 &value) FL_NOEXCEPT
void operator()(const bool &value) FL_NOEXCEPT
void operator()(const fl::vector< u8 > &v) FL_NOEXCEPT
void operator()(const json_object &) FL_NOEXCEPT
void operator()(const i64 &) FL_NOEXCEPT
void operator()(const fl::vector< i16 > &v) FL_NOEXCEPT
void operator()(const fl::nullptr_t &) FL_NOEXCEPT
void operator()(const fl::vector< float > &v) FL_NOEXCEPT
void accept(const U &value) FL_NOEXCEPT
void operator()(const json_array &arr) FL_NOEXCEPT
void write_vec(const fl::vector< ElemT > &vec) FL_NOEXCEPT
CopyToOutputIteratorVisitor(OutputIt o) FL_NOEXCEPT
void operator()(const fl::string &) FL_NOEXCEPT
void operator()(const float &) FL_NOEXCEPT
void operator()(const bool &) FL_NOEXCEPT
void operator()(const fl::vector< i16 > &v) FL_NOEXCEPT
void operator()(const fl::vector< float > &v) FL_NOEXCEPT
void operator()(const bool &) FL_NOEXCEPT
void copy_vec(const fl::vector< ElemT > &vec) FL_NOEXCEPT
void operator()(const float &) FL_NOEXCEPT
void operator()(const json_object &) FL_NOEXCEPT
void operator()(const json_array &arr) FL_NOEXCEPT
void operator()(const fl::string &) FL_NOEXCEPT
void operator()(const fl::nullptr_t &) FL_NOEXCEPT
void operator()(const fl::vector< u8 > &v) FL_NOEXCEPT
void accept(const U &value) FL_NOEXCEPT
void operator()(const i64 &) FL_NOEXCEPT
CopyToVisitor(fl::span< T > d) FL_NOEXCEPT
void operator()(const fl::nullptr_t &) FL_NOEXCEPT
void operator()(const fl::string &) FL_NOEXCEPT
void operator()(const json_array &arr) FL_NOEXCEPT
void operator()(const bool &) FL_NOEXCEPT
void operator()(const float &) FL_NOEXCEPT
void operator()(const fl::vector< u8 > &vec) FL_NOEXCEPT
void operator()(const fl::vector< i16 > &vec) FL_NOEXCEPT
void operator()(const i64 &) FL_NOEXCEPT
void accept(const U &value) FL_NOEXCEPT
void operator()(const json_object &obj) FL_NOEXCEPT
void operator()(const fl::vector< float > &vec) FL_NOEXCEPT
void operator()(const bool &value) FL_NOEXCEPT
void operator()(const i64 &value) FL_NOEXCEPT
void accept(const U &value) FL_NOEXCEPT
void operator()(const fl::string &value) FL_NOEXCEPT
void operator()(const double &value) FL_NOEXCEPT
void operator()(const T &) FL_NOEXCEPT
void operator()(const float &value) FL_NOEXCEPT
fl::optional< fl::string > result
void operator()(const fl::nullptr_t &) FL_NOEXCEPT
fl::enable_if< fl::is_floating_point< T >::value &&fl::is_integral< U >::value, void >::type operator()(const U &value) FL_NOEXCEPT
fl::enable_if< fl::is_integral< T >::value &&fl::is_integral< U >::value, void >::type operator()(const U &value) FL_NOEXCEPT
void accept(const U &value) FL_NOEXCEPT
fl::enable_if< fl::is_floating_point< T >::value &&fl::is_floating_point< U >::value &&!fl::is_same< T, U >::value, void >::type operator()(const U &value) FL_NOEXCEPT
fl::enable_if< fl::is_integral< T >::value &&fl::is_floating_point< U >::value, void >::type operator()(const U &value) FL_NOEXCEPT
default_value_visitor(const T &fb) FL_NOEXCEPT
void operator()(const T &value) FL_NOEXCEPT
void operator()(const fl::nullptr_t &)
fl::enable_if<!(fl::is_integral< T >::value &&fl::is_integral< U >::value) FL_NOEXCEPT &&!(fl::is_integral< T >::value &&fl::is_floating_point< U >::value)&&!(fl::is_floating_point< T >::value &&fl::is_integral< U >::value)&&!(fl::is_floating_point< T >::value &&fl::is_floating_point< U >::value &&!fl::is_same< T, U >::value), void >::type operator()(const U &)
void operator()(const fl::string &str) FL_NOEXCEPT
void operator()(const bool &value) FL_NOEXCEPT
void accept(const U &value) FL_NOEXCEPT
void operator()(const i64 &value) FL_NOEXCEPT
fl::optional< double > result
void operator()(const double &value) FL_NOEXCEPT
void operator()(const T &) FL_NOEXCEPT
void operator()(const float &value) FL_NOEXCEPT
void accept(const U &value) FL_NOEXCEPT
void operator()(const bool &value) FL_NOEXCEPT
void operator()(const fl::string &str) FL_NOEXCEPT
void operator()(const i64 &value) FL_NOEXCEPT
void operator()(const FloatType &value) FL_NOEXCEPT
fl::optional< FloatType > result
void operator()(const T &) FL_NOEXCEPT
fl::enable_if<!fl::is_same< T, double >::value, void >::type operator()(const double &value) FL_NOEXCEPT
fl::enable_if<!fl::is_same< T, float >::value, void >::type operator()(const float &value) FL_NOEXCEPT
fl::optional< i64 > result
void operator()(const double &value) FL_NOEXCEPT
void operator()(const T &) FL_NOEXCEPT
void operator()(const float &value) FL_NOEXCEPT
void operator()(const bool &value) FL_NOEXCEPT
void accept(const U &value) FL_NOEXCEPT
void operator()(const i64 &value) FL_NOEXCEPT
void operator()(const fl::string &str) FL_NOEXCEPT
fl::enable_if< fl::is_same< T, i64 >::value, void >::type operator()(const i64 &value) FL_NOEXCEPT
void operator()(const T &) FL_NOEXCEPT
void accept(const U &value) FL_NOEXCEPT
void operator()(const bool &value) FL_NOEXCEPT
void operator()(const float &value) FL_NOEXCEPT
void operator()(const fl::string &str) FL_NOEXCEPT
fl::enable_if< fl::is_same< T, double >::value, void >::type operator()(const double &value) FL_NOEXCEPT
fl::optional< IntType > result
fl::enable_if<!fl::is_same< T, i64 >::value, void >::type operator()(const i64 &value) FL_NOEXCEPT
fl::enable_if<!fl::is_same< T, double >::value, void >::type operator()(const double &value) FL_NOEXCEPT
fl::enable_if<!fl::is_same< T, i64 >::value &&!fl::is_same< T, double >::value, void >::type operator()(const IntType &value) FL_NOEXCEPT
void operator()(const fl::vector< u8 > &) FL_NOEXCEPT
void operator()(const fl::vector< i16 > &) FL_NOEXCEPT
void operator()(const json_array &) FL_NOEXCEPT
void operator()(const fl::vector< float > &) FL_NOEXCEPT
void accept(const T &value) FL_NOEXCEPT
void operator()(const T &) FL_NOEXCEPT
const json_value & second
KeyValue(const fl::string &key, const fl::shared_ptr< json_value > &value_ptr) FL_NOEXCEPT
KeyValue(const fl::string &key, const fl::shared_ptr< json_value > &value_ptr) FL_NOEXCEPT
json_value & operator=(i64 i) FL_NOEXCEPT
fl::optional< json_object > clone_object() const FL_NOEXCEPT
fl::optional< fl::string > as_string() FL_NOEXCEPT
const_iterator end() const FL_NOEXCEPT
fl::optional< bool > as_bool() FL_NOEXCEPT
json_value & operator[](const fl::string &key) FL_NOEXCEPT
fl::optional< FloatType > as_float() FL_NOEXCEPT
json_value(const fl::vector< i16 > &audio) FL_NOEXCEPT
json_value(const json_array &a) FL_NOEXCEPT
fl::vector< fl::string > get_object_keys() const FL_NOEXCEPT
fl::optional< T > get() const FL_NOEXCEPT
fl::optional< float > as_float() const FL_NOEXCEPT
friend const_iterator end(const json_value &v) FL_NOEXCEPT
json_value & operator=(json_value &&other) FL_NOEXCEPT
fl::optional< fl::string > as_string() const FL_NOEXCEPT
size_t copy_to_output_iterator(fl::back_insert_iterator< Container > out) const FL_NOEXCEPT
size_t size() const FL_NOEXCEPT
fl::string to_string() const FL_NOEXCEPT
array_iterator< T > begin_array() const FL_NOEXCEPT
array_iterator< T > end_array() FL_NOEXCEPT
fl::optional< i64 > as_int() const FL_NOEXCEPT
T operator|(const T &fallback) const FL_NOEXCEPT
json_array * as_array() FL_NOEXCEPT
friend struct SerializerVisitor
bool is_double() const FL_NOEXCEPT
bool is_int() const FL_NOEXCEPT
const_iterator begin() const FL_NOEXCEPT
friend iterator begin(json_value &v) FL_NOEXCEPT
fl::optional< bool > as_bool() const FL_NOEXCEPT
bool is_floats() const FL_NOEXCEPT
json_value & operator=(float f) FL_NOEXCEPT
auto visit(Visitor &&visitor) FL_NOEXCEPT -> decltype(visitor(fl::nullptr_t{}))
const json_array * as_array() const FL_NOEXCEPT
fl::enable_if<!fl::is_same< typenamefl::remove_cv< typenamefl::remove_reference< T >::type >::type, json_value >::value, json_value & >::type operator=(T &&value) FL_NOEXCEPT
bool is_audio() const FL_NOEXCEPT
json_value(fl::vector< u8 > &&bytes) FL_NOEXCEPT
fl::optional< double > as_double() const FL_NOEXCEPT
json_value & operator=(const json_value &other) FL_NOEXCEPT
json_value(unsigned int i) FL_NOEXCEPT
json_value(const fl::vector< u8 > &bytes) FL_NOEXCEPT
bool contains(const fl::string &key) const FL_NOEXCEPT
json_value & operator=(fl::string s) FL_NOEXCEPT
bool contains(size_t idx) const FL_NOEXCEPT
json_value(fl::vector< float > &&floats) FL_NOEXCEPT
static bool parse2_validate_only(const fl::string &txt) FL_NOEXCEPT
json_value(const json_value &other) FL_NOEXCEPT
size_t copy_to_output_iterator(OutputIt out) const FL_NOEXCEPT
static fl::shared_ptr< json_value > from_char(char c) FL_NOEXCEPT
json_value::iterator iterator
json_value(const fl::vector< float > &floats) FL_NOEXCEPT
json_value & operator=(bool b) FL_NOEXCEPT
json_value & operator=(fl::vector< float > floats) FL_NOEXCEPT
json_value & operator=(fl::nullptr_t) FL_NOEXCEPT
array_iterator< T > end_array() const FL_NOEXCEPT
fl::optional< FloatType > as_float() const FL_NOEXCEPT
fl::optional< i64 > as_int() FL_NOEXCEPT
const json_object * as_object() const FL_NOEXCEPT
bool is_null() const FL_NOEXCEPT
json_object * as_object() FL_NOEXCEPT
json_value(int i) FL_NOEXCEPT
fl::optional< json_array > clone_array() const FL_NOEXCEPT
bool is_object() const FL_NOEXCEPT
bool is_string() const FL_NOEXCEPT
json_value(const json_object &o) FL_NOEXCEPT
json_value(fl::vector< i16 > &&audio) FL_NOEXCEPT
json_value & operator=(json_array a) FL_NOEXCEPT
json_value(const fl::string &s) FL_NOEXCEPT
static fl::shared_ptr< json_value > parse2(const fl::string &txt) FL_NOEXCEPT
fl::vector< fl::string > keys() const FL_NOEXCEPT
json_value & operator=(fl::vector< i16 > audio) FL_NOEXCEPT
fl::optional< IntType > as_int() FL_NOEXCEPT
fl::optional< IntType > as_int() const FL_NOEXCEPT
json_value(fl::nullptr_t) FL_NOEXCEPT
fl::variant< fl::nullptr_t, bool, i64, float, fl::string, json_array, json_object, fl::vector< i16 >, fl::vector< u8 >, fl::vector< float > > variant_t
bool is_bytes() const FL_NOEXCEPT
bool is_generic_array() const FL_NOEXCEPT
fl::optional< T > get() FL_NOEXCEPT
array_iterator< T > begin_array() FL_NOEXCEPT
bool is_number() const FL_NOEXCEPT
friend iterator end(json_value &v) FL_NOEXCEPT
json_value(i64 i) FL_NOEXCEPT
friend const_iterator begin(const json_value &v) FL_NOEXCEPT
auto visit(Visitor &&visitor) const FL_NOEXCEPT -> decltype(visitor(fl::nullptr_t{}))
bool is_float() const FL_NOEXCEPT
iterator begin() FL_NOEXCEPT
iterator end() FL_NOEXCEPT
size_t copy_to(fl::span< T > out) const FL_NOEXCEPT
json_value(float f) FL_NOEXCEPT
json_value & operator[](size_t idx) FL_NOEXCEPT
bool is_array() const FL_NOEXCEPT
json_value & operator=(fl::vector< u8 > bytes) FL_NOEXCEPT
T as_or(const T &fallback) const FL_NOEXCEPT
json_value & operator=(double d) FL_NOEXCEPT
json_value(bool b) FL_NOEXCEPT
fl::optional< float > as_float() FL_NOEXCEPT
bool is_bool() const FL_NOEXCEPT
static constexpr T min() FL_NOEXCEPT
static constexpr T max() FL_NOEXCEPT
const T & get_value() const FL_NOEXCEPT
bool has_error() const FL_NOEXCEPT
parse_result(const task::Error &err) FL_NOEXCEPT
parse_result(const T &val) FL_NOEXCEPT
const task::Error & get_error() const FL_NOEXCEPT