Apply comments

* Rename intersectMapWith -> mergeMapWith
* Remove macro
* Add r-value ref
This commit is contained in:
TolyaTalamanov 2022-09-16 15:24:13 +00:00
parent eb8883160d
commit ec92f3fefa
2 changed files with 11 additions and 16 deletions

View File

@ -193,7 +193,7 @@ CallParams read<CallParams>(const cv::FileNode& fn) {
template <typename V> template <typename V>
std::map<std::string, V> readMap(const cv::FileNode& fn) { std::map<std::string, V> readMap(const cv::FileNode& fn) {
std::map<std::string, V> map; std::map<std::string, V> map;
for (auto item : fn) { for (auto&& item : fn) {
map.emplace(item.name(), read<V>(item)); map.emplace(item.name(), read<V>(item));
} }
return map; return map;
@ -380,10 +380,14 @@ int main(int argc, char* argv[]) {
builder.addDummy(call_params, read<DummyParams>(node_fn)); builder.addDummy(call_params, read<DummyParams>(node_fn));
} else if (node_type == "Infer") { } else if (node_type == "Infer") {
auto infer_params = read<InferParams>(node_fn); auto infer_params = read<InferParams>(node_fn);
RETHROW_WITH_MSG_IF_FAILED( try {
utils::intersectMapWith(infer_params.config, gconfig), utils::mergeMapWith(infer_params.config, gconfig);
"Failed to combine global and local configs for Infer node: " } catch (std::exception& e) {
+ call_params.name); 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); builder.addInfer(call_params, infer_params);
} else { } else {
throw std::logic_error("Unsupported node type: " + node_type); throw std::logic_error("Unsupported node type: " + node_type);

View File

@ -93,21 +93,12 @@ typename duration_t::rep timestamp() {
return duration_cast<duration_t>(now.time_since_epoch()).count(); return duration_cast<duration_t>(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 <typename K, typename V> template <typename K, typename V>
void intersectMapWith(std::map<K, V>& target, const std::map<K, V>& second) { void mergeMapWith(std::map<K, V>& target, const std::map<K, V>& second) {
for (auto&& item : second) { for (auto&& item : second) {
auto it = target.find(item.first); auto it = target.find(item.first);
if (it != target.end()) { 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); target.insert(item);
} }