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

◆ get_value()

template<typename T>
ParseResult< T > fl::JsonValue::array_iterator< T >::get_value ( ) const
inlineprivate

Definition at line 1218 of file json.h.

1220 {
1221 if (!m_variant || m_index >= get_size()) {
1222 return ParseResult<T>(Error("Index out of bounds"));
1223 }
1224
1225 if (m_variant->is<JsonArray>()) {
1226 auto ptr = m_variant->ptr<JsonArray>();
1227 if (ptr && m_index < ptr->size() && (*ptr)[m_index]) {
1228 auto& val = *((*ptr)[m_index]);
1229
1230 // Try to convert to T using the JsonValue conversion methods
1231 // Using FastLED type traits instead of std:: ones
1233 auto opt = val.as_bool();
1234 if (opt) {
1235 return ParseResult<T>(*opt);
1236 } else {
1237 return ParseResult<T>(Error("Cannot convert to bool"));
1238 }
1240 auto opt = val.template as_int<T>();
1241 if (opt) {
1242 return ParseResult<T>(*opt);
1243 } else {
1244 return ParseResult<T>(Error("Cannot convert to signed integer"));
1245 }
1247 // For unsigned types, we check that it's integral but not signed
1248 auto opt = val.template as_int<T>();
1249 if (opt) {
1250 return ParseResult<T>(*opt);
1251 } else {
1252 return ParseResult<T>(Error("Cannot convert to unsigned integer"));
1253 }
1255 auto opt = val.template as_float<T>();
1256 if (opt) {
1257 return ParseResult<T>(*opt);
1258 } else {
1259 return ParseResult<T>(Error("Cannot convert to floating point"));
1260 }
1261 }
1262 } else {
1263 return ParseResult<T>(Error("Invalid array access"));
1264 }
1265 }
1266
1267 if (m_variant->is<fl::vector<int16_t>>()) {
1268 auto ptr = m_variant->ptr<fl::vector<int16_t>>();
1269 if (ptr && m_index < ptr->size()) {
1270 return ParseResult<T>(static_cast<T>((*ptr)[m_index]));
1271 } else {
1272 return ParseResult<T>(Error("Index out of bounds in int16_t array"));
1273 }
1274 }
1275
1276 if (m_variant->is<fl::vector<uint8_t>>()) {
1277 auto ptr = m_variant->ptr<fl::vector<uint8_t>>();
1278 if (ptr && m_index < ptr->size()) {
1279 return ParseResult<T>(static_cast<T>((*ptr)[m_index]));
1280 } else {
1281 return ParseResult<T>(Error("Index out of bounds in uint8_t array"));
1282 }
1283 }
1284
1285 if (m_variant->is<fl::vector<float>>()) {
1286 auto ptr = m_variant->ptr<fl::vector<float>>();
1287 if (ptr && m_index < ptr->size()) {
1288 return ParseResult<T>(static_cast<T>((*ptr)[m_index]));
1289 } else {
1290 return ParseResult<T>(Error("Index out of bounds in float array"));
1291 }
1292 }
1293
size_t get_size() const
Definition json.h:1191
size_t size() const
Definition json.h:1478
fl::optional< float > as_float()
Definition json.h:936
fl::optional< int64_t > as_int()
Definition json.h:902

References fl::JsonValue::as_float(), fl::JsonValue::as_int(), get_size(), m_index, m_variant, fl::JsonValue::size(), fl::is_floating_point< T >::value, fl::is_integral< T >::value, fl::is_same< T, U >::value, and fl::is_signed< T >::value.

+ Here is the call graph for this function: