From 01fd6d52cefdb2baa7070b91ed483e9456141966 Mon Sep 17 00:00:00 2001 From: Brent Stapleton Date: Thu, 11 Apr 2019 11:36:31 -0700 Subject: prop_tree: add pop() function Adding pop function to property tree, which will remove and return a property from the property tree. This also includes unit tests. --- host/lib/property_tree.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'host/lib') diff --git a/host/lib/property_tree.cpp b/host/lib/property_tree.cpp index 07da0cf59..85868b27c 100644 --- a/host/lib/property_tree.cpp +++ b/host/lib/property_tree.cpp @@ -133,6 +133,29 @@ public: return node->keys(); } + boost::shared_ptr _pop(const fs_path& path_) + { + const fs_path path = _root / path_; + boost::mutex::scoped_lock lock(_guts->mutex); + + node_type* parent = NULL; + node_type* node = &_guts->root; + for (const std::string& name : path_tokenizer(path)) { + if (not node->has_key(name)) + throw_path_not_found(path); + parent = node; + node = &(*node)[name]; + } + + if (node->prop.get() == NULL) + throw uhd::runtime_error("Cannot access! Property uninitialized at: " + path); + if (parent == NULL) + throw uhd::runtime_error("Cannot pop"); + auto prop = node->prop; + parent->pop(fs_path(path.leaf())); + return prop; + } + void _create(const fs_path& path_, const boost::shared_ptr& prop) { const fs_path path = _root / path_; -- cgit v1.2.3