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

◆ operator[]() [2/2]

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

Definition at line 1364 of file types.h.

1364 {
1365 if (!is_array()) data = json_array{};
1366 // Handle regular json_array
1367 if (data.is<json_array>()) {
1368 auto ptr = data.ptr<json_array>();
1369 if (!ptr) return get_null_json_value(); // Handle error case
1370 auto &arr = *ptr;
1371 if (idx >= arr.size()) {
1372 // Resize array and fill with null values
1373 for (size_t i = arr.size(); i <= idx; i++) {
1374 arr.push_back(fl::make_shared<json_value>());
1375 }
1376 }
1377 if (idx >= arr.size()) return get_null_json_value(); // Handle error case
1378 return *arr[idx];
1379 }
1380 // For packed arrays, we need to convert them to regular arrays first
1381 // This is needed for compatibility with existing code that expects json_array
1382 if (data.is<fl::vector<i16>>() ||
1383 data.is<fl::vector<u8>>() ||
1384 data.is<fl::vector<float>>()) {
1385 // Convert to regular json_array (needs a copy/conversion)
1386 auto arr = clone_array();
1387 if (arr) {
1388 data = fl::move(*arr);
1389 auto ptr = data.ptr<json_array>();
1390 if (!ptr) return get_null_json_value();
1391 auto &jsonArr = *ptr;
1392 if (idx >= jsonArr.size()) {
1393 // Resize array and fill with null values
1394 for (size_t i = jsonArr.size(); i <= idx; i++) {
1395 jsonArr.push_back(fl::make_shared<json_value>());
1396 }
1397 }
1398 if (idx >= jsonArr.size()) return get_null_json_value();
1399 return *jsonArr[idx];
1400 }
1401 }
1402 return get_null_json_value();
1403 }
constexpr remove_reference< T >::type && move(T &&t) FL_NOEXCEPT
Definition s16x16x4.h:28
shared_ptr< T > make_shared(Args &&... args) FL_NOEXCEPT
Definition shared_ptr.h:414
fl::vector< fl::shared_ptr< json_value > > json_array
Definition types.h:33
json_value & get_null_json_value()
Definition json.cpp.hpp:64
variant_t data
Definition types.h:700
fl::optional< json_array > clone_array() const FL_NOEXCEPT
Definition types.h:1067
bool is_array() const FL_NOEXCEPT
Definition types.h:894

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

+ Here is the call graph for this function: