FastLED 3.9.15
Loading...
Searching...
No Matches

◆ get_value()

template<typename T>
parse_result< T > fl::json_value::array_iterator< T >::get_value ( ) const
inlineprivate

Definition at line 1219 of file types.h.

1219 {
1220 if (!mVariant || mIndex >= get_size()) {
1221 return parse_result<T>(task::Error("Index out of bounds"));
1222 }
1223
1224 if (mVariant->is<json_array>()) {
1225 auto ptr = mVariant->ptr<json_array>();
1226 if (ptr && mIndex < ptr->size() && (*ptr)[mIndex]) {
1227 auto& val = *((*ptr)[mIndex]);
1228
1229 // Try to convert to T using the json_value conversion methods
1230 // Using FastLED type traits instead of std:: ones
1232 auto opt = val.as_bool();
1233 if (opt) {
1234 return parse_result<T>(*opt);
1235 } else {
1236 return parse_result<T>(task::Error("Cannot convert to bool"));
1237 }
1239 auto opt = val.template as_int<T>();
1240 if (opt) {
1241 return parse_result<T>(*opt);
1242 } else {
1243 return parse_result<T>(task::Error("Cannot convert to signed integer"));
1244 }
1246 // For unsigned types, we check that it's integral but not signed
1247 auto opt = val.template as_int<T>();
1248 if (opt) {
1249 return parse_result<T>(*opt);
1250 } else {
1251 return parse_result<T>(task::Error("Cannot convert to unsigned integer"));
1252 }
1254 auto opt = val.template as_float<T>();
1255 if (opt) {
1256 return parse_result<T>(*opt);
1257 } else {
1258 return parse_result<T>(task::Error("Cannot convert to floating point"));
1259 }
1260 }
1261 } else {
1262 return parse_result<T>(task::Error("Invalid array access"));
1263 }
1264 }
1265
1266 if (mVariant->is<fl::vector<i16>>()) {
1267 auto ptr = mVariant->ptr<fl::vector<i16>>();
1268 if (ptr && mIndex < ptr->size()) {
1269 return parse_result<T>(static_cast<T>((*ptr)[mIndex]));
1270 } else {
1271 return parse_result<T>(task::Error("Index out of bounds in i16 array"));
1272 }
1273 }
1274
1275 if (mVariant->is<fl::vector<u8>>()) {
1276 auto ptr = mVariant->ptr<fl::vector<u8>>();
1277 if (ptr && mIndex < ptr->size()) {
1278 return parse_result<T>(static_cast<T>((*ptr)[mIndex]));
1279 } else {
1280 return parse_result<T>(task::Error("Index out of bounds in u8 array"));
1281 }
1282 }
1283
1284 if (mVariant->is<fl::vector<float>>()) {
1285 auto ptr = mVariant->ptr<fl::vector<float>>();
1286 if (ptr && mIndex < ptr->size()) {
1287 return parse_result<T>(static_cast<T>((*ptr)[mIndex]));
1288 } else {
1289 return parse_result<T>(task::Error("Index out of bounds in float array"));
1290 }
1291 }
1292
1293 return parse_result<T>(task::Error("Unknown array type"));
1294 }
size_t get_size() const FL_NOEXCEPT
Definition types.h:1192
size_t size() const FL_NOEXCEPT
Definition types.h:1479
fl::optional< i64 > as_int() FL_NOEXCEPT
Definition types.h:935
fl::optional< float > as_float() FL_NOEXCEPT
Definition types.h:969

References fl::json_value::as_float(), fl::json_value::as_int(), FL_NOEXCEPT, get_size(), mIndex, mVariant, fl::json_value::size(), fl::fl::is_floating_point< T >::value, fl::fl::is_integral< T >::value, fl::fl::is_same< T, U >::value, and fl::fl::is_signed< T >::value.

Referenced by operator*().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: