Support Inserting Bools Into Property Trees

While here, also add a simple unit test that as_vector<T>() returns
nullopt for non-existing property nodes.
This commit is contained in:
Halvor M Nilsen 2025-01-31 18:05:33 +01:00 committed by Bård Skaflestad
parent c8b5732bd6
commit bc227ab784
2 changed files with 15 additions and 0 deletions

View File

@ -126,6 +126,7 @@ 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 float& value);
template void PropertyTree::put(const std::string& key, const int& 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 void PropertyTree::put(const std::string& key, const std::size_t& value);
template void PropertyTree::put(const std::string& key, const bool& 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;

View File

@ -56,6 +56,7 @@ BOOST_AUTO_TEST_CASE(Top_Node_Only)
t.put("b", 123.4); t.put("b", 123.4);
t.put("c", std::string { "hello" }); t.put("c", std::string { "hello" });
t.put("d", 12.34f); t.put("d", 12.34f);
t.put("e", true);
{ {
const auto a = t.get<int>("a"); const auto a = t.get<int>("a");
@ -88,6 +89,14 @@ BOOST_AUTO_TEST_CASE(Top_Node_Only)
const auto dd = t.get("dd", -1.618f); const auto dd = t.get("dd", -1.618f);
BOOST_CHECK_CLOSE(dd, -1.618f, 1.0e-6f); BOOST_CHECK_CLOSE(dd, -1.618f, 1.0e-6f);
} }
{
const auto e = t.get<bool>("e");
BOOST_CHECK_EQUAL(e, true);
const auto ee = t.get<bool>("ee", false);
BOOST_CHECK_EQUAL(ee, false);
}
} }
BOOST_AUTO_TEST_CASE(Size_T) BOOST_AUTO_TEST_CASE(Size_T)
@ -278,6 +287,11 @@ BOOST_AUTO_TEST_CASE(Vector)
expect.begin(), expect.end()); expect.begin(), expect.end());
} }
{
const auto aa = t.get_child_items_as_vector<int>("aa");
BOOST_CHECK_MESSAGE(!aa.has_value(), R"(Node "aa" must NOT exist)");
}
{ {
const auto b = t.get_child_items_as_vector<double>("b"); const auto b = t.get_child_items_as_vector<double>("b");
BOOST_REQUIRE_MESSAGE(b.has_value(), R"(Node "b" must exist)"); BOOST_REQUIRE_MESSAGE(b.has_value(), R"(Node "b" must exist)");