A utility function to traverse a pipeline model and invoke a handler. If the model is not a pipeline, it simply invokes the handler with the model. If the model is a pipeline, it invokes the handler with each sub model first, and then with the pipeline model. The traversal stops if the handler returns `true`.
| 63 | /// |
| 64 | /// The traversal stops if the handler returns `true`. |
| 65 | static bool walkModelAndPipeline(const Specification::Model &model, |
| 66 | std::function<bool(const Specification::Model& m)> handler) { |
| 67 | switch (model.Type_case()) { |
| 68 | case Specification::Model::kPipeline: |
| 69 | for (auto &m : model.pipeline().models()) { |
| 70 | if (walkModelAndPipeline(m, handler)) { |
| 71 | return true; |
| 72 | } |
| 73 | } |
| 74 | break; |
| 75 | case Specification::Model::kPipelineRegressor: |
| 76 | for (auto &m : model.pipelineregressor().pipeline().models()) { |
| 77 | if (walkModelAndPipeline(m, handler)) { |
| 78 | return true; |
| 79 | } |
| 80 | } |
| 81 | break; |
| 82 | case Specification::Model::kPipelineClassifier: |
| 83 | for (auto &m : model.pipelineclassifier().pipeline().models()) { |
| 84 | if (walkModelAndPipeline(m, handler)) { |
| 85 | return true; |
| 86 | } |
| 87 | } |
| 88 | break; |
| 89 | default: |
| 90 | break; |
| 91 | } |
| 92 | if (handler(model)) { |
| 93 | return true; |
| 94 | } |
| 95 | return false; |
| 96 | } |
| 97 | |
| 98 | /// A utility function to invoke a handler with input, output, and |
| 99 | /// state feature description. |
no outgoing calls
no test coverage detected