From e08c9cafca6e5cb5eee9abbc3aff316934b65200 Mon Sep 17 00:00:00 2001 From: benjamindev Date: Fri, 7 Aug 2020 07:36:40 +0000 Subject: [PATCH] Added a more compact name type lookup. We might need to validate the combinations as sum maybe not supported. --- .../PyDP/pydp_lib/algorithm_builder.hpp | 35 +++++-------------- 1 file changed, 9 insertions(+), 26 deletions(-) diff --git a/src/bindings/PyDP/pydp_lib/algorithm_builder.hpp b/src/bindings/PyDP/pydp_lib/algorithm_builder.hpp index c76b1d83..a4b74005 100644 --- a/src/bindings/PyDP/pydp_lib/algorithm_builder.hpp +++ b/src/bindings/PyDP/pydp_lib/algorithm_builder.hpp @@ -49,34 +49,17 @@ class AlgorithmBuilder { .ValueOrDie(); } + std::map type_to_name = {{typeid(double), "Double"}, + {typeid(int), "Int"}}; + std::map algorithm_to_name = { + {typeid(dp::BoundedMean), "BoundedMean"}, + {typeid(dp::BoundedSum), "BoundedSum"}, + {typeid(dp::BoundedStandardDeviation), "BoundedStandardDeviation"}, + {typeid(dp::BoundedVariance), "BoundedVariance"}}; + std::string get_algorithm_name() { // Set the suffix string - std::string suffix = ""; - // TODO: Change to mapping function - if (typeid(T) == typeid(int)) { - suffix = "Int"; - } else if (typeid(T) == typeid(double)) { - suffix = "Double"; - } else { - throw std::runtime_error("Binding error - Only int and double types supported"); - } - - // Set the algorithm name string - std::string name = ""; - // TODO: Change to mapping function - if (typeid(Algorithm) == typeid(dp::BoundedMean)) { - name = "BoundedMean"; - } else if (typeid(Algorithm) == typeid(dp::BoundedSum)) { - name = "BoundedSum"; - } else if (typeid(Algorithm) == typeid(dp::BoundedStandardDeviation)) { - name = "BoundedStandardDeviation"; - } else if (typeid(Algorithm) == typeid(dp::BoundedVariance)) { - name = "BoundedVariance"; - } else { - throw std::runtime_error(std::string("Binding error - Unsupported algorithm: ") + - std::string(typeid(Algorithm).name())); - } - return (name + suffix); + return (algorithm_to_name[typeid(Algorithm)] + type_to_name[typeid(T)]); } };