From ec92f3fefa8421a65f64ab11a942252057483683 Mon Sep 17 00:00:00 2001 From: TolyaTalamanov Date: Fri, 16 Sep 2022 15:24:13 +0000 Subject: [PATCH] Apply comments * Rename intersectMapWith -> mergeMapWith * Remove macro * Add r-value ref --- modules/gapi/samples/pipeline_modeling_tool.cpp | 14 +++++++++----- modules/gapi/samples/pipeline_modeling_tool/utils.hpp | 13 ++----------- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/modules/gapi/samples/pipeline_modeling_tool.cpp b/modules/gapi/samples/pipeline_modeling_tool.cpp index a10cb5f..bacd174 100644 --- a/modules/gapi/samples/pipeline_modeling_tool.cpp +++ b/modules/gapi/samples/pipeline_modeling_tool.cpp @@ -193,7 +193,7 @@ CallParams read(const cv::FileNode& fn) { template std::map readMap(const cv::FileNode& fn) { std::map map; - for (auto item : fn) { + for (auto&& item : fn) { map.emplace(item.name(), read(item)); } return map; @@ -380,10 +380,14 @@ int main(int argc, char* argv[]) { builder.addDummy(call_params, read(node_fn)); } else if (node_type == "Infer") { auto infer_params = read(node_fn); - RETHROW_WITH_MSG_IF_FAILED( - utils::intersectMapWith(infer_params.config, gconfig), - "Failed to combine global and local configs for Infer node: " - + call_params.name); + try { + utils::mergeMapWith(infer_params.config, gconfig); + } catch (std::exception& e) { + std::stringstream ss; + ss << "Failed to merge global and local config for Infer node: " + << call_params.name << std::endl << e.what(); + throw std::logic_error(ss.str()); + } builder.addInfer(call_params, infer_params); } else { throw std::logic_error("Unsupported node type: " + node_type); diff --git a/modules/gapi/samples/pipeline_modeling_tool/utils.hpp b/modules/gapi/samples/pipeline_modeling_tool/utils.hpp index c8f0101..a5be323 100644 --- a/modules/gapi/samples/pipeline_modeling_tool/utils.hpp +++ b/modules/gapi/samples/pipeline_modeling_tool/utils.hpp @@ -93,21 +93,12 @@ typename duration_t::rep timestamp() { return duration_cast(now.time_since_epoch()).count(); } -#define RETHROW_WITH_MSG_IF_FAILED(expr, msg) \ - try { \ - expr; \ - } catch (const std::exception& e) { \ - std::stringstream ss; \ - ss << msg << "\n caused by: " << e.what(); \ - throw std::logic_error(ss.str()); \ - } \ - template -void intersectMapWith(std::map& target, const std::map& second) { +void mergeMapWith(std::map& target, const std::map& second) { for (auto&& item : second) { auto it = target.find(item.first); if (it != target.end()) { - throw std::logic_error("Met already existing key: " + item.first); + throw std::logic_error("Error: key: " + it->first + " is already in target map"); } target.insert(item); } -- 2.7.4