MCPcopy Create free account
hub / github.com/FastLED/FastLED / operator[]

Method operator[]

src/fl/stl/json.h:540–566  ·  view source on GitHub ↗

Indexing for fluid chaining

Source from the content-addressed store, hash-verified

538
539 // Indexing for fluid chaining
540 json operator[](size_t idx) FL_NOEXCEPT {
541 if (!mValue) {
542 mValue = fl::make_shared<json_value>(json_array{});
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) {
551 mValue = fl::make_shared<json_value>(fl::move(*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 }
565 return json(nullptr);
566 }
567
568 const json operator[](size_t idx) const FL_NOEXCEPT {
569 if (!mValue) {

Callers 2

FL_TEST_FILEFunction · 0.45
FL_TEST_FILEFunction · 0.45

Calls 8

jsonClass · 0.70
clone_arrayMethod · 0.45
as_arrayMethod · 0.45
sizeMethod · 0.45
push_backMethod · 0.45
is_objectMethod · 0.45
findMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected