Rename fillMap and move it for reuse
The tree is still being filled, but it's no longer a map, so let's
change the name. Also, I want to use this function in the upcoming
in-memory data tree.
Change-Id: I472c0b323d6097fbf23305085df8f905aa22cac5
diff --git a/src/netconf_access.cpp b/src/netconf_access.cpp
index e4a1859..2a2fa96 100644
--- a/src/netconf_access.cpp
+++ b/src/netconf_access.cpp
@@ -14,40 +14,6 @@
#include "utils.hpp"
#include "yang_schema.hpp"
-namespace {
-
-// This is very similar to the fillMap lambda in SysrepoAccess, however,
-// Sysrepo returns a weird array-like structure, while libnetconf
-// returns libyang::Data_Node
-void fillMap(DatastoreAccess::Tree& res, const std::vector<std::shared_ptr<libyang::Data_Node>> items, std::optional<std::string> ignoredXPathPrefix = std::nullopt)
-{
- auto stripXPathPrefix = [&ignoredXPathPrefix] (auto path) {
- return ignoredXPathPrefix ? path.substr(ignoredXPathPrefix->size()) : path;
- };
-
- for (const auto& it : items) {
- if (!it)
- continue;
- if (it->schema()->nodetype() == LYS_CONTAINER) {
- if (libyang::Schema_Node_Container{it->schema()}.presence()) {
- // The fact that the container is included in the data tree
- // means that it is present and I don't need to check any
- // value.
- res.emplace_back(stripXPathPrefix(it->path()), special_{SpecialValue::PresenceContainer});
- }
- }
- if (it->schema()->nodetype() == LYS_LIST) {
- res.push_back({stripXPathPrefix(it->path()), special_{SpecialValue::List}});
- }
- if (it->schema()->nodetype() == LYS_LEAF || it->schema()->nodetype() == LYS_LEAFLIST) {
- libyang::Data_Node_Leaf_List leaf(it);
- auto value = leafValueFromValue(leaf.value(), leaf.leaf_type()->base());
- res.emplace_back(stripXPathPrefix(it->path()), value);
- }
- }
-}
-}
-
NetconfAccess::~NetconfAccess() = default;
@@ -63,11 +29,11 @@
auto leafListPath = stripLeafListValueFromPath((*it)->path());
res.emplace_back(leafListPath, special_{SpecialValue::LeafList});
while (it != siblings.end() && boost::starts_with((*it)->path(), leafListPath)) {
- fillMap(res, (*it)->tree_dfs());
+ lyNodesToTree(res, (*it)->tree_dfs());
it++;
}
} else {
- fillMap(res, (*it)->tree_dfs());
+ lyNodesToTree(res, (*it)->tree_dfs());
}
}
}
@@ -203,7 +169,7 @@
auto output = m_session->rpc(data);
if (output) {
for (auto it : output->tree_for()) {
- fillMap(res, it->tree_dfs(), joinPaths(path, "/"));
+ lyNodesToTree(res, it->tree_dfs(), joinPaths(path, "/"));
}
}
return res;