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

◆ operator[]() [4/4]

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

Definition at line 699 of file json.h.

701 {
702 if (!mValue) {
704 }
705 // FastLED#3588: make_shared may degrade to empty under OOM.
706 if (!mValue) { return json(nullptr); }
707 // If we're indexing into a specialized array, convert it to regular json_array first
708 if (mValue->data.is<fl::vector<i16>>() ||
709 mValue->data.is<fl::vector<u8>>() ||
710 mValue->data.is<fl::vector<float>>()) {
711 // Convert to regular json_array (needs a copy/conversion)
712 auto arr = mValue->clone_array();
713 if (arr) {
715 }
716 }
717 // Get pointer directly to avoid copying - fixes silent mutation bug
718 auto arrPtr = mValue->as_array();
719 if (arrPtr) {
720 // Ensure the array is large enough
721 if (idx >= arrPtr->size()) {
722 for (size_t i = arrPtr->size(); i <= idx; i++) {
723 arrPtr->push_back(fl::make_shared<json_value>(nullptr));
724 }
725 }
726 return json((*arrPtr)[idx]);
727 }
fl::shared_ptr< json_value > mValue
Definition json.h:263
json() FL_NO_EXCEPT
Definition json.h:267
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
fl::vector< fl::shared_ptr< json_value > > json_array
Definition types.h:54

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

+ Here is the call graph for this function: