From 999f98e281c2a1f54fc35b90a5e933829359bcd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A5rd=20Skaflestad?= Date: Wed, 29 Jan 2025 11:48:19 +0100 Subject: [PATCH] Implement Property Tree Put/Get for std::size_t This replaces the original specialisations for "bare" size_t from the header. While here, also reorder the specialisations to match declaration order in the header. --- opm/simulators/linalg/PropertyTree.cpp | 18 +++++++++--------- tests/test_propertytree.cpp | 17 +++++++++++++++++ 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/opm/simulators/linalg/PropertyTree.cpp b/opm/simulators/linalg/PropertyTree.cpp index 81952839d..a64c4b30c 100644 --- a/opm/simulators/linalg/PropertyTree.cpp +++ b/opm/simulators/linalg/PropertyTree.cpp @@ -23,13 +23,12 @@ #include +#include #include #include #include #include -#include - namespace Opm { PropertyTree::PropertyTree() @@ -102,23 +101,24 @@ PropertyTree& PropertyTree::operator=(const PropertyTree& tree) return *this; } +template void PropertyTree::put(const std::string& key, const std::string& value); +template void PropertyTree::put(const std::string& key, const double& value); +template void PropertyTree::put(const std::string& key, const float& value); +template void PropertyTree::put(const std::string& key, const int& value); +template void PropertyTree::put(const std::string& key, const std::size_t& value); + template std::string PropertyTree::get(const std::string& key) const; template double PropertyTree::get(const std::string& key) const; template float PropertyTree::get(const std::string& key) const; template int PropertyTree::get(const std::string& key) const; -template size_t PropertyTree::get(const std::string& key) const; +template std::size_t PropertyTree::get(const std::string& key) const; template bool PropertyTree::get(const std::string& key) const; template std::string PropertyTree::get(const std::string& key, const std::string& defValue) const; template double PropertyTree::get(const std::string& key, const double& defValue) const; template float PropertyTree::get(const std::string& key, const float& defValue) const; template int PropertyTree::get(const std::string& key, const int& defValue) const; -template size_t PropertyTree::get(const std::string& key, const size_t& defValue) const; +template std::size_t PropertyTree::get(const std::string& key, const std::size_t& defValue) const; template bool PropertyTree::get(const std::string& key, const bool& defValue) const; -template void PropertyTree::put(const std::string& key, const std::string& value); -template void PropertyTree::put(const std::string& key, const float& value); -template void PropertyTree::put(const std::string& key, const double& value); -template void PropertyTree::put(const std::string& key, const int& value); - } // namespace Opm diff --git a/tests/test_propertytree.cpp b/tests/test_propertytree.cpp index ac8ab04f6..f75fa8341 100644 --- a/tests/test_propertytree.cpp +++ b/tests/test_propertytree.cpp @@ -36,9 +36,11 @@ #include +#include #include #include #include +#include #include #include #include @@ -88,6 +90,21 @@ BOOST_AUTO_TEST_CASE(Top_Node_Only) } } +BOOST_AUTO_TEST_CASE(Size_T) +{ + auto t = Opm::PropertyTree{}; + + t.put("s.ramanujan", std::size_t{1729}); + BOOST_CHECK_EQUAL(t.get("s.ramanujan"), std::size_t{1729}); + + t.put("m", static_cast(-1)); + BOOST_CHECK_EQUAL(t.get("m"), std::numeric_limits::max()); + + // Conversion: int -> std::size_t + t.put("n", -1); + BOOST_CHECK_EQUAL(t.get("n"), std::numeric_limits::max()); +} + BOOST_AUTO_TEST_CASE(Missing_Keys) { auto t = Opm::PropertyTree{};