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

◆ operator[]() [4/4]

json fl::json::operator[] ( size_t idx)
inline

Definition at line 538 of file json.h.

540 {
541 if (!mValue) {
543 }
544 // If we're indexing into a specialized array, convert it to regular json_array first
545 if (mValue->data.is<fl::vector<i16>>() ||
546 mValue->data.is<fl::vector<u8>>() ||
547 mValue->data.is<fl::vector<float>>()) {
548 // Convert to regular json_array (needs a copy/conversion)
549 auto arr = mValue->clone_array();
550 if (arr) {
552 }
553 }
554 // Get pointer directly to avoid copying - fixes silent mutation bug
555 auto arrPtr = mValue->as_array();
556 if (arrPtr) {
557 // Ensure the array is large enough
558 if (idx >= arrPtr->size()) {
559 for (size_t i = arrPtr->size(); i <= idx; i++) {
560 arrPtr->push_back(fl::make_shared<json_value>(nullptr));
561 }
562 }
563 return json((*arrPtr)[idx]);
564 }
json() FL_NOEXCEPT
Definition json.h:134
fl::shared_ptr< json_value > mValue
Definition json.h:130
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

References json(), FL_NOEXCEPT, fl::make_shared(), fl::fl::move(), and mValue.

+ Here is the call graph for this function: