diff options
-rw-r--r-- | host/include/uhd/property_tree.hpp | 1 | ||||
-rw-r--r-- | host/lib/property_tree.cpp | 6 | ||||
-rw-r--r-- | host/tests/property_test.cpp | 21 |
3 files changed, 28 insertions, 0 deletions
diff --git a/host/include/uhd/property_tree.hpp b/host/include/uhd/property_tree.hpp index f889ba235..3c24de7e6 100644 --- a/host/include/uhd/property_tree.hpp +++ b/host/include/uhd/property_tree.hpp @@ -113,6 +113,7 @@ struct fs_path : std::string{ }; UHD_API fs_path operator/(const fs_path &, const fs_path &); +UHD_API fs_path operator/(const fs_path &, size_t); /*! * The property tree provides a file system structure for accessing properties. diff --git a/host/lib/property_tree.cpp b/host/lib/property_tree.cpp index 50e82a6ba..5666e2639 100644 --- a/host/lib/property_tree.cpp +++ b/host/lib/property_tree.cpp @@ -65,6 +65,12 @@ fs_path uhd::operator/(const fs_path &lhs, const fs_path &rhs){ return fs_path(lhs + "/" + rhs); } +fs_path uhd::operator/(const fs_path &lhs, size_t rhs) +{ + fs_path rhs_str = boost::lexical_cast<std::string>(rhs); + return lhs / rhs_str; +} + /*********************************************************************** * Property tree implementation **********************************************************************/ diff --git a/host/tests/property_test.cpp b/host/tests/property_test.cpp index 04d3a831c..00bb3c022 100644 --- a/host/tests/property_test.cpp +++ b/host/tests/property_test.cpp @@ -173,3 +173,24 @@ BOOST_AUTO_TEST_CASE(test_prop_subtree){ BOOST_CHECK_EQUAL_COLLECTIONS(tree_dirs2.begin(), tree_dirs2.end(), subtree2_dirs.begin(), subtree2_dirs.end()); } + + +BOOST_AUTO_TEST_CASE(test_prop_operators) +{ + uhd::fs_path path1 = "/root/"; + path1 = path1 / "leaf"; + BOOST_CHECK_EQUAL(path1, "/root/leaf"); + + uhd::fs_path path2 = "/root"; + path2 = path2 / "leaf"; + BOOST_CHECK_EQUAL(path2, "/root/leaf"); + + uhd::fs_path path3 = "/root/"; + path3 = path3 / "/leaf/"; + BOOST_CHECK_EQUAL(path3, "/root/leaf/"); + + uhd::fs_path path4 = "/root/"; + size_t x = 2; + path4 = path4 / x; + BOOST_CHECK_EQUAL(path4, "/root/2"); +} |