summaryrefslogtreecommitdiffstats
path: root/host/lib/property_tree.cpp
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2011-06-25 20:23:19 -0700
committerJosh Blum <josh@joshknows.com>2011-06-25 20:23:19 -0700
commitba2a6b4b39f66f0edaef710561019d7cd43cb417 (patch)
tree57394af58a5dd0120f72cc5f9fad59fa4383fae5 /host/lib/property_tree.cpp
parentbff29cbbde74d4c5ab77ae717ee04c9533fc7cab (diff)
downloaduhd-ba2a6b4b39f66f0edaef710561019d7cd43cb417.tar.gz
uhd-ba2a6b4b39f66f0edaef710561019d7cd43cb417.tar.bz2
uhd-ba2a6b4b39f66f0edaef710561019d7cd43cb417.zip
uhd: forgot to commit properties file
Diffstat (limited to 'host/lib/property_tree.cpp')
-rw-r--r--host/lib/property_tree.cpp104
1 files changed, 104 insertions, 0 deletions
diff --git a/host/lib/property_tree.cpp b/host/lib/property_tree.cpp
new file mode 100644
index 000000000..7cda7a524
--- /dev/null
+++ b/host/lib/property_tree.cpp
@@ -0,0 +1,104 @@
+//
+// Copyright 2011 Ettus Research LLC
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+//
+
+#include <uhd/property_tree.hpp>
+#include <uhd/types/dict.hpp>
+#include <boost/foreach.hpp>
+#include <boost/thread/mutex.hpp>
+#include <iostream>
+
+class property_tree_impl : public uhd::property_tree{
+public:
+
+ void remove(const path_type &path){
+ boost::mutex::scoped_lock lock(_mutex);
+
+ node_type *parent = NULL;
+ node_type *node = &_root;
+ BOOST_FOREACH(const std::string &leaf, path){
+ if (not node->has_key(leaf)) throw_path_not_found(path);
+ parent = node;
+ node = &(*node)[leaf];
+ }
+ if (parent == NULL) throw uhd::runtime_error("Cannot uproot");
+ parent->pop(path.leaf());
+ }
+
+ bool exists(const path_type &path){
+ boost::mutex::scoped_lock lock(_mutex);
+
+ node_type *node = &_root;
+ BOOST_FOREACH(const std::string &leaf, path){
+ if (not node->has_key(leaf)) return false;
+ node = &(*node)[leaf];
+ }
+ return true;
+ }
+
+ iterator_type iterate(const path_type &path){
+ boost::mutex::scoped_lock lock(_mutex);
+
+ node_type *node = &_root;
+ BOOST_FOREACH(const std::string &leaf, path){
+ if (not node->has_key(leaf)) throw_path_not_found(path);
+ node = &(*node)[leaf];
+ }
+
+ iterator_type iter;
+ BOOST_FOREACH(const std::string &name, node->keys()){
+ iter.push_back(name);
+ }
+ return iter;
+ }
+
+ void _create(const path_type &path, const boost::any &prop){
+ boost::mutex::scoped_lock lock(_mutex);
+
+ node_type *node = &_root;
+ BOOST_FOREACH(const std::string &leaf, path){
+ if (not node->has_key(leaf)) (*node)[leaf] = node_type();
+ node = &(*node)[leaf];
+ }
+ node->prop = prop;
+ }
+
+ boost::any &_access(const path_type &path){
+ boost::mutex::scoped_lock lock(_mutex);
+
+ node_type *node = &_root;
+ BOOST_FOREACH(const std::string &leaf, path){
+ if (not node->has_key(leaf)) throw_path_not_found(path);
+ node = &(*node)[leaf];
+ }
+ return node->prop;
+ }
+
+private:
+ void throw_path_not_found(const path_type &path){
+ throw uhd::lookup_error("Path not found in tree: " + path.string());
+ }
+
+ struct node_type : uhd::dict<std::string, node_type>{
+ boost::any prop;
+ } _root;
+
+ boost::mutex _mutex;
+};
+
+uhd::property_tree::sptr uhd::property_tree::make(void){
+ return sptr(new property_tree_impl());
+}