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/libyang_utils.cpp b/src/libyang_utils.cpp
index 2669151..15b1b06 100644
--- a/src/libyang_utils.cpp
+++ b/src/libyang_utils.cpp
@@ -1,5 +1,7 @@
-#include "libyang_utils.hpp"
 #include <cmath>
+#include "datastore_access.hpp"
+#include "libyang_utils.hpp"
+#include "utils.hpp"
 
 leaf_data_ leafValueFromValue(const libyang::S_Value& value, LY_DATA_TYPE type)
 {
@@ -42,3 +44,34 @@
         return "(can't print)"s;
     }
 }
+
+// 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 lyNodesToTree(DatastoreAccess::Tree& res, const std::vector<std::shared_ptr<libyang::Data_Node>> items, std::optional<std::string> ignoredXPathPrefix)
+{
+    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);
+        }
+    }
+}
diff --git a/src/libyang_utils.hpp b/src/libyang_utils.hpp
index 42b6198..d8bf4ad 100644
--- a/src/libyang_utils.hpp
+++ b/src/libyang_utils.hpp
@@ -7,5 +7,7 @@
 
 #include <libyang/Tree_Data.hpp>
 #include "ast_values.hpp"
+#include "datastore_access.hpp"
 
 leaf_data_ leafValueFromValue(const libyang::S_Value& value, LY_DATA_TYPE type);
+void lyNodesToTree(DatastoreAccess::Tree& res, const std::vector<std::shared_ptr<libyang::Data_Node>> items, std::optional<std::string> ignoredXPathPrefix = std::nullopt);
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;