aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2011-06-25 16:39:32 -0700
committerJosh Blum <josh@joshknows.com>2011-06-25 20:22:23 -0700
commit81c15feaafca2b788b89e55669f1c3ad370a89d2 (patch)
treebddea1dab138bf5e8b3f690f0ef5cc6c032cb736
parenta951db18fd0edfe19e9e75b91bb30dfa731dbd9c (diff)
downloaduhd-81c15feaafca2b788b89e55669f1c3ad370a89d2.tar.gz
uhd-81c15feaafca2b788b89e55669f1c3ad370a89d2.tar.bz2
uhd-81c15feaafca2b788b89e55669f1c3ad370a89d2.zip
uhd: created a property tree to store properties
-rw-r--r--host/include/uhd/CMakeLists.txt1
-rw-r--r--host/include/uhd/exception.hpp6
-rw-r--r--host/include/uhd/property.hpp6
-rw-r--r--host/lib/CMakeLists.txt1
-rw-r--r--host/tests/property_test.cpp25
5 files changed, 35 insertions, 4 deletions
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 <http://www.gnu.org/licenses/>.
//
-#ifndef INCLUDED_UHD_UTILS_EXCEPTION_HPP
-#define INCLUDED_UHD_UTILS_EXCEPTION_HPP
+#ifndef INCLUDED_UHD_EXCEPTION_HPP
+#define INCLUDED_UHD_EXCEPTION_HPP
#include <uhd/config.hpp>
#include <boost/current_function.hpp>
@@ -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 <typename T> class property{
+/*!
+ * A templated property interface for holding a value
+ * and registering callbacks when that value changes.
+ */
+template <typename T> class UHD_API property{
public:
typedef boost::function<void(const T &)> subscriber_type;
typedef boost::function<T(const T &)> 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 <boost/test/unit_test.hpp>
#include <uhd/property.hpp>
+#include <uhd/property_tree.hpp>
#include <boost/bind.hpp>
+#include <iostream>
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<int>());
+ tree->create("/test/prop1", uhd::property<int>());
+
+ BOOST_CHECK(tree->exists("/test"));
+ BOOST_CHECK(tree->exists("/test/prop0"));
+ BOOST_CHECK(tree->exists("/test/prop1"));
+
+ tree->access<int>("/test/prop0").set(42);
+ tree->access<int>("/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"));
+
+}