MCPcopy Create free account
hub / github.com/cel-expr/cel-cpp / operator[]

Method operator[]

tools/flatbuffers_backed_impl.cc:105–131  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

103 }
104
105 absl::optional<CelValue> operator[](CelValue cel_key) const override {
106 if (!cel_key.IsString()) {
107 return CreateErrorValue(
108 arena_, absl::InvalidArgumentError(
109 absl::StrCat("Invalid map key type: '",
110 CelValue::TypeName(cel_key.type()), "'")));
111 }
112 const absl::string_view key = cel_key.StringOrDie().value();
113 const auto it = std::lower_bound(
114 list_->begin(), list_->end(), key,
115 [this](const flatbuffers::Table* t, const absl::string_view key) {
116 auto value = flatbuffers::GetFieldS(*t, index_);
117 auto sv = value ? absl::string_view(value->c_str(), value->size())
118 : absl::string_view();
119 return sv < key;
120 });
121 if (it != list_->end()) {
122 auto value = flatbuffers::GetFieldS(**it, index_);
123 auto sv = value ? absl::string_view(value->c_str(), value->size())
124 : absl::string_view();
125 if (sv == key) {
126 return CelValue::CreateMap(google::protobuf::Arena::Create<FlatBuffersMapImpl>(
127 arena_, **it, schema_, object_, arena_));
128 }
129 }
130 return absl::nullopt;
131 }
132
133 absl::StatusOr<const CelList*> ListKeys() const override { return &keys_; }
134

Callers

nothing calls this directly

Calls 9

CreateErrorValueFunction · 0.85
typeMethod · 0.80
StringOrDieMethod · 0.80
CreateMapFunction · 0.50
IsStringMethod · 0.45
valueMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected