FastLED 3.10.8
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 1248 of file types.h.

1248 {
1249 if (!mVariant || mIndex >= get_size()) {
1250 return parse_result<T>(task::Error("Index out of bounds"));
1251 }
1252
1253 if (mVariant->is<json_array>()) {
1254 auto ptr = mVariant->ptr<json_array>();
1255 if (ptr && mIndex < ptr->size() && (*ptr)[mIndex]) {
1256 auto& val = *((*ptr)[mIndex]);
1257
1258 // Try to convert to T using the json_value conversion methods
1259 // Using FastLED type traits instead of std:: ones
1261 auto opt = val.as_bool();
1262 if (opt) {
1263 return parse_result<T>(*opt);
1264 } else {
1265 return parse_result<T>(task::Error("Cannot convert to bool"));
1266 }
1268 auto opt = val.template as_int<T>();
1269 if (opt) {
1270 return parse_result<T>(*opt);
1271 } else {
1272 return parse_result<T>(task::Error("Cannot convert to signed integer"));
1273 }
1275 // For unsigned types, we check that it's integral but not signed
1276 auto opt = val.template as_int<T>();
1277 if (opt) {
1278 return parse_result<T>(*opt);
1279 } else {
1280 return parse_result<T>(task::Error("Cannot convert to unsigned integer"));
1281 }
1283 auto opt = val.template as_float<T>();
1284 if (opt) {
1285 return parse_result<T>(*opt);
1286 } else {
1287 return parse_result<T>(task::Error("Cannot convert to floating point"));
1288 }
1289 }
1290 } else {
1291 return parse_result<T>(task::Error("Invalid array access"));
1292 }
1293 }
1294
1295 if (mVariant->is<fl::vector<i16>>()) {
1296 auto ptr = mVariant->ptr<fl::vector<i16>>();
1297 if (ptr && mIndex < ptr->size()) {
1298 return parse_result<T>(static_cast<T>((*ptr)[mIndex]));
1299 } else {
1300 return parse_result<T>(task::Error("Index out of bounds in i16 array"));
1301 }
1302 }
1303
1304 if (mVariant->is<fl::vector<u8>>()) {
1305 auto ptr = mVariant->ptr<fl::vector<u8>>();
1306 if (ptr && mIndex < ptr->size()) {
1307 return parse_result<T>(static_cast<T>((*ptr)[mIndex]));
1308 } else {
1309 return parse_result<T>(task::Error("Index out of bounds in u8 array"));
1310 }
1311 }
1312
1313 if (mVariant->is<fl::vector<float>>()) {
1314 auto ptr = mVariant->ptr<fl::vector<float>>();
1315 if (ptr && mIndex < ptr->size()) {
1316 return parse_result<T>(static_cast<T>((*ptr)[mIndex]));
1317 } else {
1318 return parse_result<T>(task::Error("Index out of bounds in float array"));
1319 }
1320 }
1321
1322 return parse_result<T>(task::Error("Unknown array type"));
1323 }
size_t get_size() const FL_NO_EXCEPT
Definition types.h:1221
fl::optional< i64 > as_int() FL_NO_EXCEPT
Definition types.h:964
size_t size() const FL_NO_EXCEPT
Definition types.h:1508
fl::optional< float > as_float() FL_NO_EXCEPT
Definition types.h:998

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

Referenced by operator*().

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