From 7236d1cfe15d984563952ce370fb0e0b08727f42 Mon Sep 17 00:00:00 2001
From: Dmitri Naumov <dmitri.naumov@ufz.de>
Date: Tue, 24 Oct 2023 18:05:03 +0200
Subject: [PATCH] [BL] Extend checkConfigParam error message

Since only the char overload was used, the template is removed.
---
 BaseLib/ConfigTree-impl.h        | 20 --------------------
 BaseLib/ConfigTree.cpp           | 11 +++++++++++
 BaseLib/ConfigTree.h             | 10 ++++------
 Tests/BaseLib/TestConfigTree.cpp |  4 ++--
 4 files changed, 17 insertions(+), 28 deletions(-)

diff --git a/BaseLib/ConfigTree-impl.h b/BaseLib/ConfigTree-impl.h
index 525d2b8e588..ddf0ecf5939 100644
--- a/BaseLib/ConfigTree-impl.h
+++ b/BaseLib/ConfigTree-impl.h
@@ -145,26 +145,6 @@ T ConfigTree::peekConfigParameter(std::string const& param) const
     }
 }
 
-template <typename T>
-void ConfigTree::checkConfigParameter(std::string const& param,
-                                      T const& value) const
-{
-    if (getConfigParameter<T>(param) != value)
-    {
-        error("The value of key <" + param + "> is not the expected one.");
-    }
-}
-
-template <typename Ch>
-void ConfigTree::checkConfigParameter(std::string const& param,
-                                      Ch const* value) const
-{
-    if (getConfigParameter<std::string>(param) != value)
-    {
-        error("The value of key <" + param + "> is not the expected one.");
-    }
-}
-
 template <typename T>
 T ConfigTree::getValue() const
 {
diff --git a/BaseLib/ConfigTree.cpp b/BaseLib/ConfigTree.cpp
index 34362a57333..d12e0f44ffa 100644
--- a/BaseLib/ConfigTree.cpp
+++ b/BaseLib/ConfigTree.cpp
@@ -148,6 +148,17 @@ Range<ConfigTree::ParameterIterator> ConfigTree::getConfigParameterList(
                                     ParameterIterator(p.second, param, *this));
 }
 
+void ConfigTree::checkConfigParameter(std::string const& param,
+                                      std::string_view const value) const
+{
+    auto const parameter_value = getConfigParameter<std::string>(param);
+    if (parameter_value != value)
+    {
+        error("For the tag <" + param + "> expected to read value '" +
+              value.data() + "', but got '" + parameter_value + "'.");
+    }
+}
+
 ConfigTree ConfigTree::getConfigSubtree(std::string const& root) const
 {
     if (auto t = getConfigSubtreeOptional(root))
diff --git a/BaseLib/ConfigTree.h b/BaseLib/ConfigTree.h
index 8b735f994a6..cda81b323dc 100644
--- a/BaseLib/ConfigTree.h
+++ b/BaseLib/ConfigTree.h
@@ -17,6 +17,8 @@
 #include <map>
 #include <memory>
 #include <optional>
+#include <string>
+#include <string_view>
 #include <typeindex>
 #include <utility>
 #include <vector>
@@ -464,12 +466,8 @@ public:
      * Convenience method combining getConfigParameter(std::string const&) with
      * a check.
      */
-    template <typename T>
-    void checkConfigParameter(std::string const& param, T const& value) const;
-
-    //! Make checkConfigParameter() work for string literals.
-    template <typename Ch>
-    void checkConfigParameter(std::string const& param, Ch const* value) const;
+    void checkConfigParameter(std::string const& param,
+                              std::string_view const value) const;
 
     //!\}
 
diff --git a/Tests/BaseLib/TestConfigTree.cpp b/Tests/BaseLib/TestConfigTree.cpp
index 1fa4a84cc51..5eced648837 100644
--- a/Tests/BaseLib/TestConfigTree.cpp
+++ b/Tests/BaseLib/TestConfigTree.cpp
@@ -220,7 +220,7 @@ TEST(BaseLibConfigTree, Get)
             EXPECT_EQ("Y", conf.peekConfigParameter<std::string>("x"));
             EXPECT_ERR_WARN(cbs, false, false);
         }
-        conf.checkConfigParameter<std::string>("x", "Y");
+        conf.checkConfigParameter("x", "Y");
         EXPECT_ERR_WARN(cbs, false, false);
 
         // Testing attributes
@@ -539,7 +539,7 @@ TEST(BaseLibConfigTree, BadKeynames)
 
             EXPECT_ANY_THROW(conf.peekConfigParameter<int>(tag));
             EXPECT_ERR_WARN(cbs, true, false);
-            EXPECT_ANY_THROW(conf.checkConfigParameter<int>(tag, 500));
+            EXPECT_ANY_THROW(conf.checkConfigParameter(tag, "500"));
             EXPECT_ERR_WARN(cbs, true, false);
 
             EXPECT_ANY_THROW(conf.getConfigSubtree(tag));
-- 
GitLab