From 81c15feaafca2b788b89e55669f1c3ad370a89d2 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sat, 25 Jun 2011 16:39:32 -0700 Subject: uhd: created a property tree to store properties --- host/include/uhd/CMakeLists.txt | 1 + host/include/uhd/exception.hpp | 6 +++--- host/include/uhd/property.hpp | 6 +++++- host/lib/CMakeLists.txt | 1 + host/tests/property_test.cpp | 25 +++++++++++++++++++++++++ 5 files changed, 35 insertions(+), 4 deletions(-) (limited to 'host') diff --git a/host/include/uhd/CMakeLists.txt b/host/include/uhd/CMakeLists.txt index c3c51279c..1ee3e69df 100644 --- a/host/include/uhd/CMakeLists.txt +++ b/host/include/uhd/CMakeLists.txt @@ -27,6 +27,7 @@ INSTALL(FILES device.hpp exception.hpp property.hpp + property_tree.hpp version.hpp wax.hpp DESTINATION ${INCLUDE_DIR}/uhd diff --git a/host/include/uhd/exception.hpp b/host/include/uhd/exception.hpp index 10cd8f501..c05861788 100644 --- a/host/include/uhd/exception.hpp +++ b/host/include/uhd/exception.hpp @@ -15,8 +15,8 @@ // along with this program. If not, see . // -#ifndef INCLUDED_UHD_UTILS_EXCEPTION_HPP -#define INCLUDED_UHD_UTILS_EXCEPTION_HPP +#ifndef INCLUDED_UHD_EXCEPTION_HPP +#define INCLUDED_UHD_EXCEPTION_HPP #include #include @@ -163,4 +163,4 @@ namespace uhd{ } //namespace uhd -#endif /* INCLUDED_UHD_UTILS_EXCEPTION_HPP */ +#endif /* INCLUDED_UHD_EXCEPTION_HPP */ diff --git a/host/include/uhd/property.hpp b/host/include/uhd/property.hpp index 5b47f9482..e3b917334 100644 --- a/host/include/uhd/property.hpp +++ b/host/include/uhd/property.hpp @@ -25,7 +25,11 @@ namespace uhd{ -template class property{ +/*! + * A templated property interface for holding a value + * and registering callbacks when that value changes. + */ +template class UHD_API property{ public: typedef boost::function subscriber_type; typedef boost::function master_type; diff --git a/host/lib/CMakeLists.txt b/host/lib/CMakeLists.txt index ebb211566..60ddbce5b 100644 --- a/host/lib/CMakeLists.txt +++ b/host/lib/CMakeLists.txt @@ -89,6 +89,7 @@ SET_SOURCE_FILES_PROPERTIES( LIBUHD_APPEND_SOURCES( ${CMAKE_CURRENT_SOURCE_DIR}/device.cpp ${CMAKE_CURRENT_SOURCE_DIR}/exception.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/property_tree.cpp ${CMAKE_CURRENT_SOURCE_DIR}/version.cpp ${CMAKE_CURRENT_SOURCE_DIR}/wax.cpp ) diff --git a/host/tests/property_test.cpp b/host/tests/property_test.cpp index c5ef7f1c9..0cea20c8c 100644 --- a/host/tests/property_test.cpp +++ b/host/tests/property_test.cpp @@ -17,7 +17,9 @@ #include #include +#include #include +#include struct coercer_type{ int doit(int x){ @@ -73,3 +75,26 @@ BOOST_AUTO_TEST_CASE(test_prop_with_coercion){ BOOST_CHECK_EQUAL(prop.get(), 32); BOOST_CHECK_EQUAL(setter._x, 32); } + +BOOST_AUTO_TEST_CASE(test_prop_tree){ + uhd::property_tree::sptr tree = uhd::property_tree::make(); + + tree->create("/test/prop0", uhd::property()); + tree->create("/test/prop1", uhd::property()); + + BOOST_CHECK(tree->exists("/test")); + BOOST_CHECK(tree->exists("/test/prop0")); + BOOST_CHECK(tree->exists("/test/prop1")); + + tree->access("/test/prop0").set(42); + tree->access("/test/prop1").set(34); + + tree->remove("/test/prop0"); + BOOST_CHECK(not tree->exists("/test/prop0")); + BOOST_CHECK(tree->exists("/test/prop1")); + + tree->remove("/test"); + BOOST_CHECK(not tree->exists("/test/prop0")); + BOOST_CHECK(not tree->exists("/test/prop1")); + +} -- cgit v1.2.3