MCPcopy Create free account
hub / github.com/cel-expr/cel-cpp / ValueAsInt32

Function ValueAsInt32

common/values/parsed_map_field_value.cc:190–207  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

188namespace {
189
190absl::optional<int32_t> ValueAsInt32(const Value& value) {
191 if (auto int_value = value.AsInt();
192 int_value &&
193 int_value->NativeValue() >= std::numeric_limits<int32_t>::min() &&
194 int_value->NativeValue() <= std::numeric_limits<int32_t>::max()) {
195 return static_cast<int32_t>(int_value->NativeValue());
196 } else if (auto uint_value = value.AsUint();
197 uint_value &&
198 uint_value->NativeValue() <= std::numeric_limits<int32_t>::max()) {
199 return static_cast<int32_t>(uint_value->NativeValue());
200 } else if (auto double_value = value.AsDouble();
201 double_value &&
202 static_cast<double>(static_cast<int32_t>(
203 double_value->NativeValue())) == double_value->NativeValue()) {
204 return static_cast<int32_t>(double_value->NativeValue());
205 }
206 return absl::nullopt;
207}
208
209absl::optional<int64_t> ValueAsInt64(const Value& value) {
210 if (auto int_value = value.AsInt(); int_value) {

Callers 1

ValueToProtoMapKeyFunction · 0.85

Calls 4

AsIntMethod · 0.45
NativeValueMethod · 0.45
AsUintMethod · 0.45
AsDoubleMethod · 0.45

Tested by

no test coverage detected