aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib
diff options
context:
space:
mode:
authorBrent Stapleton <brent.stapleton@ettus.com>2019-04-11 11:36:31 -0700
committerMartin Braun <martin.braun@ettus.com>2019-05-02 08:39:54 -0700
commit01fd6d52cefdb2baa7070b91ed483e9456141966 (patch)
treef43dae9b6291c28108b3896641374d643c7c8ca4 /host/lib
parentd44277d7ac7acc621442fe7ef4555f568fbe88d0 (diff)
downloaduhd-01fd6d52cefdb2baa7070b91ed483e9456141966.tar.gz
uhd-01fd6d52cefdb2baa7070b91ed483e9456141966.tar.bz2
uhd-01fd6d52cefdb2baa7070b91ed483e9456141966.zip
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.
Diffstat (limited to 'host/lib')
-rw-r--r--host/lib/property_tree.cpp23
1 files changed, 23 insertions, 0 deletions
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<void> _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<void>& prop)
{
const fs_path path = _root / path_;