diff options
Diffstat (limited to 'host/lib/property_tree.cpp')
-rw-r--r-- | host/lib/property_tree.cpp | 43 |
1 files changed, 28 insertions, 15 deletions
diff --git a/host/lib/property_tree.cpp b/host/lib/property_tree.cpp index 14d3ae8c4..a21254336 100644 --- a/host/lib/property_tree.cpp +++ b/host/lib/property_tree.cpp @@ -30,16 +30,18 @@ fs_path::fs_path(const std::string& p) : std::string(p) {} std::string fs_path::leaf(void) const { const size_t pos = this->rfind("/"); - if (pos == std::string::npos) + if (pos == std::string::npos) { return *this; + } return this->substr(pos + 1); } fs_path fs_path::branch_path(void) const { const size_t pos = this->rfind("/"); - if (pos == std::string::npos) + if (pos == std::string::npos) { return *this; + } return fs_path(this->substr(0, pos)); } @@ -93,13 +95,15 @@ public: node_type* parent = NULL; node_type* node = &_guts->root; for (const std::string& name : path_tokenizer(path)) { - if (not node->has_key(name)) + if (not node->has_key(name)) { throw_path_not_found(path); + } parent = node; node = &(*node)[name]; } - if (parent == NULL) + if (parent == NULL) { throw uhd::runtime_error("Cannot uproot"); + } parent->pop(fs_path(path.leaf())); } @@ -110,8 +114,9 @@ public: node_type* node = &_guts->root; for (const std::string& name : path_tokenizer(path)) { - if (not node->has_key(name)) + if (not node->has_key(name)) { return false; + } node = &(*node)[name]; } return true; @@ -124,8 +129,9 @@ public: node_type* node = &_guts->root; for (const std::string& name : path_tokenizer(path)) { - if (not node->has_key(name)) + if (not node->has_key(name)) { throw_path_not_found(path); + } node = &(*node)[name]; } @@ -140,16 +146,19 @@ public: node_type* parent = NULL; node_type* node = &_guts->root; for (const std::string& name : path_tokenizer(path)) { - if (not node->has_key(name)) + if (not node->has_key(name)) { throw_path_not_found(path); + } parent = node; node = &(*node)[name]; } - if (node->prop.get() == NULL) + if (node->prop.get() == NULL) { throw uhd::runtime_error("Cannot access! Property uninitialized at: " + path); - if (parent == NULL) + } + if (parent == NULL) { throw uhd::runtime_error("Cannot pop"); + } auto prop = node->prop; parent->pop(fs_path(path.leaf())); return prop; @@ -162,14 +171,16 @@ public: node_type* node = &_guts->root; for (const std::string& name : path_tokenizer(path)) { - if (not node->has_key(name)) + if (not node->has_key(name)) { (*node)[name] = node_type(); + } node = &(*node)[name]; } - if (node->prop.get() != NULL) + if (node->prop.get() != NULL) { throw uhd::runtime_error( "Cannot create! Property already exists at: " + path); - node->prop = prop; + } + node->prop = prop; } std::shared_ptr<void>& _access(const fs_path& path_) const override @@ -179,12 +190,14 @@ public: node_type* node = &_guts->root; for (const std::string& name : path_tokenizer(path)) { - if (not node->has_key(name)) + if (not node->has_key(name)) { throw_path_not_found(path); + } node = &(*node)[name]; } - if (node->prop.get() == NULL) + if (node->prop.get() == NULL) { throw uhd::runtime_error("Cannot access! Property uninitialized at: " + path); + } return node->prop; } @@ -222,5 +235,5 @@ property_tree::~property_tree(void) **********************************************************************/ uhd::property_tree::sptr uhd::property_tree::make(void) { - return sptr(new property_tree_impl()); + return std::make_shared<property_tree_impl>(); } |