| 45 | ActivationFunctionProviderImpl() = default; |
| 46 | |
| 47 | absl::StatusOr<absl::optional<cel::FunctionOverloadReference>> GetFunction( |
| 48 | const cel::FunctionDescriptor& descriptor, |
| 49 | const cel::ActivationInterface& activation) const override { |
| 50 | std::vector<cel::FunctionOverloadReference> overloads = |
| 51 | activation.FindFunctionOverloads(descriptor.name()); |
| 52 | |
| 53 | absl::optional<cel::FunctionOverloadReference> matching_overload = |
| 54 | absl::nullopt; |
| 55 | |
| 56 | for (const auto& overload : overloads) { |
| 57 | if (overload.descriptor.ShapeMatches(descriptor)) { |
| 58 | if (matching_overload.has_value()) { |
| 59 | return absl::Status(absl::StatusCode::kInvalidArgument, |
| 60 | "Couldn't resolve function."); |
| 61 | } |
| 62 | matching_overload.emplace(overload); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | return matching_overload; |
| 67 | } |
| 68 | }; |
| 69 | |
| 70 | // Create a CelFunctionProvider that just looks up the functions inserted in the |