FastLED 3.10.8
Loading...
Searching...
No Matches

◆ operator[]() [2/2]

json_value & fl::json_value::operator[] ( size_t idx)
inline

Definition at line 1393 of file types.h.

1393 {
1394 if (!is_array()) data = json_array{};
1395 // Handle regular json_array
1396 if (data.is<json_array>()) {
1397 auto ptr = data.ptr<json_array>();
1398 if (!ptr) return get_null_json_value(); // Handle error case
1399 auto &arr = *ptr;
1400 if (idx >= arr.size()) {
1401 // Resize array and fill with null values
1402 for (size_t i = arr.size(); i <= idx; i++) {
1403 arr.push_back(fl::make_shared<json_value>());
1404 }
1405 }
1406 if (idx >= arr.size()) return get_null_json_value(); // Handle error case
1407 return *arr[idx];
1408 }
1409 // For packed arrays, we need to convert them to regular arrays first
1410 // This is needed for compatibility with existing code that expects json_array
1411 if (data.is<fl::vector<i16>>() ||
1412 data.is<fl::vector<u8>>() ||
1413 data.is<fl::vector<float>>()) {
1414 // Convert to regular json_array (needs a copy/conversion)
1415 auto arr = clone_array();
1416 if (arr) {
1417 data = fl::move(*arr);
1418 auto ptr = data.ptr<json_array>();
1419 if (!ptr) return get_null_json_value();
1420 auto &jsonArr = *ptr;
1421 if (idx >= jsonArr.size()) {
1422 // Resize array and fill with null values
1423 for (size_t i = jsonArr.size(); i <= idx; i++) {
1424 jsonArr.push_back(fl::make_shared<json_value>());
1425 }
1426 }
1427 if (idx >= jsonArr.size()) return get_null_json_value();
1428 return *jsonArr[idx];
1429 }
1430 }
1431 return get_null_json_value();
1432 }
constexpr remove_reference< T >::type && move(T &&t) FL_NO_EXCEPT
Definition move.h:30
shared_ptr< T > make_shared(Args &&... args) FL_NO_EXCEPT
Definition shared_ptr.h:423
json_value & get_null_json_value() FL_NO_EXCEPT
Definition json.cpp.hpp:64
fl::vector< fl::shared_ptr< json_value > > json_array
Definition types.h:54
fl::optional< json_array > clone_array() const FL_NO_EXCEPT
Definition types.h:1096
variant_t data
Definition types.h:760
bool is_array() const FL_NO_EXCEPT
Definition types.h:919

References json_value(), clone_array(), data, fl::FL_NO_EXCEPT, fl::get_null_json_value(), is_array(), fl::adl_barrier::make_shared(), and fl::adl_barrier::move().

+ Here is the call graph for this function: