Merge pull request #5927 from bska/property-tree-std-sizet

Implement Property Tree Put/Get for std::size_t
This commit is contained in:
Bård Skaflestad 2025-01-29 14:54:49 +01:00 committed by GitHub
commit 2fe71ce294
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 26 additions and 9 deletions

View File

@ -23,13 +23,12 @@
#include <boost/property_tree/json_parser.hpp> #include <boost/property_tree/json_parser.hpp>
#include <cstddef>
#include <memory> #include <memory>
#include <optional> #include <optional>
#include <ostream> #include <ostream>
#include <string> #include <string>
#include <stddef.h>
namespace Opm { namespace Opm {
PropertyTree::PropertyTree() PropertyTree::PropertyTree()
@ -102,23 +101,24 @@ PropertyTree& PropertyTree::operator=(const PropertyTree& tree)
return *this; 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 std::string PropertyTree::get(const std::string& key) const;
template double 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 float PropertyTree::get(const std::string& key) const;
template int 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 bool PropertyTree::get(const std::string& key) const;
template std::string PropertyTree::get(const std::string& key, const std::string& defValue) 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 double PropertyTree::get(const std::string& key, const double& defValue) const;
template float PropertyTree::get(const std::string& key, const float& 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 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 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 } // namespace Opm

View File

@ -36,9 +36,11 @@
#include <opm/common/utility/FileSystem.hpp> #include <opm/common/utility/FileSystem.hpp>
#include <cstddef>
#include <filesystem> #include <filesystem>
#include <fstream> #include <fstream>
#include <ios> #include <ios>
#include <limits>
#include <stdexcept> #include <stdexcept>
#include <string> #include <string>
#include <string_view> #include <string_view>
@ -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<std::size_t>("s.ramanujan"), std::size_t{1729});
t.put("m", static_cast<std::size_t>(-1));
BOOST_CHECK_EQUAL(t.get<std::size_t>("m"), std::numeric_limits<std::size_t>::max());
// Conversion: int -> std::size_t
t.put("n", -1);
BOOST_CHECK_EQUAL(t.get<std::size_t>("n"), std::numeric_limits<std::size_t>::max());
}
BOOST_AUTO_TEST_CASE(Missing_Keys) BOOST_AUTO_TEST_CASE(Missing_Keys)
{ {
auto t = Opm::PropertyTree{}; auto t = Opm::PropertyTree{};