a typedef for returning "tree of data"
I'm working on adding support for RPCs, and that function requires
passing a tree of input data, and returning another tree of data. Given
that getItems()'s return value is quite similar (and something that's
widely supported through the code), let's requse this type for RPC I/O
as well.
I took care to only use this typedef at places where we have already
been dealing with tree data. This means that tests for, say,
leaf_editing were not changed because it's "something else than a
datastore". Coincidentally, the other use of the same structure is for
defining list keys, see I2c978762d3a78286b4f7fb97e16118772ddeb7bc.
Change-Id: I2a01cc6f8c6624e673eab43bc642c16d2bcfe2d7
diff --git a/src/datastore_access.hpp b/src/datastore_access.hpp
index 72e3553..9e5c317 100644
--- a/src/datastore_access.hpp
+++ b/src/datastore_access.hpp
@@ -38,8 +38,9 @@
class DatastoreAccess {
public:
+ using Tree = std::map<std::string, leaf_data_>;
virtual ~DatastoreAccess() = 0;
- virtual std::map<std::string, leaf_data_> getItems(const std::string& path) = 0;
+ virtual Tree getItems(const std::string& path) = 0;
virtual void setLeaf(const std::string& path, leaf_data_ value) = 0;
virtual void createPresenceContainer(const std::string& path) = 0;
virtual void deletePresenceContainer(const std::string& path) = 0;
diff --git a/src/netconf_access.cpp b/src/netconf_access.cpp
index 5b1ad78..e648a33 100644
--- a/src/netconf_access.cpp
+++ b/src/netconf_access.cpp
@@ -15,10 +15,9 @@
NetconfAccess::~NetconfAccess() = default;
-std::map<std::string, leaf_data_> NetconfAccess::getItems(const std::string& path)
+DatastoreAccess::Tree NetconfAccess::getItems(const std::string& path)
{
- using namespace std::string_literals;
- std::map<std::string, leaf_data_> res;
+ Tree res;
// This is very similar to the fillMap lambda in SysrepoAccess, however,
// Sysrepo returns a weird array-like structure, while libnetconf
diff --git a/src/netconf_access.hpp b/src/netconf_access.hpp
index 29101ed..a5e0485 100644
--- a/src/netconf_access.hpp
+++ b/src/netconf_access.hpp
@@ -33,7 +33,7 @@
NetconfAccess(const std::string& socketPath);
NetconfAccess(std::unique_ptr<libnetconf::client::Session>&& session);
~NetconfAccess() override;
- std::map<std::string, leaf_data_> getItems(const std::string& path) override;
+ Tree getItems(const std::string& path) override;
void setLeaf(const std::string& path, leaf_data_ value) override;
void createPresenceContainer(const std::string& path) override;
void deletePresenceContainer(const std::string& path) override;
diff --git a/src/sysrepo_access.cpp b/src/sysrepo_access.cpp
index 221f482..499597f 100644
--- a/src/sysrepo_access.cpp
+++ b/src/sysrepo_access.cpp
@@ -111,10 +111,10 @@
}
}
-std::map<std::string, leaf_data_> SysrepoAccess::getItems(const std::string& path)
+DatastoreAccess::Tree SysrepoAccess::getItems(const std::string& path)
{
using namespace std::string_literals;
- std::map<std::string, leaf_data_> res;
+ Tree res;
auto fillMap = [&res](auto items) {
if (!items)
diff --git a/src/sysrepo_access.hpp b/src/sysrepo_access.hpp
index 9861ab4..ff26e7a 100644
--- a/src/sysrepo_access.hpp
+++ b/src/sysrepo_access.hpp
@@ -28,7 +28,7 @@
public:
~SysrepoAccess() override;
SysrepoAccess(const std::string& appname);
- std::map<std::string, leaf_data_> getItems(const std::string& path) override;
+ Tree getItems(const std::string& path) override;
void setLeaf(const std::string& path, leaf_data_ value) override;
void createPresenceContainer(const std::string& path) override;
void deletePresenceContainer(const std::string& path) override;
diff --git a/tests/datastore_access.cpp b/tests/datastore_access.cpp
index 535abdc..ff29594 100644
--- a/tests/datastore_access.cpp
+++ b/tests/datastore_access.cpp
@@ -25,7 +25,7 @@
};
namespace std {
-std::ostream& operator<<(std::ostream& s, const std::map<std::string, leaf_data_> map)
+std::ostream& operator<<(std::ostream& s, const DatastoreAccess::Tree& map)
{
s << std::endl
<< "{";
@@ -183,7 +183,7 @@
datastore.commitChanges();
}
- std::map<std::string, leaf_data_> expected{{"/example-schema:down", bool{true}}};
+ DatastoreAccess::Tree expected{{"/example-schema:down", bool{true}}};
REQUIRE(datastore.getItems("/example-schema:down") == expected);
}
@@ -197,7 +197,7 @@
datastore.commitChanges();
}
- std::map<std::string, leaf_data_> expected{{"/example-schema:down", bool{false}},
+ DatastoreAccess::Tree expected{{"/example-schema:down", bool{false}},
// Sysrepo always returns containers when getting values, but
// libnetconf does not. This is fine by the YANG standard:
// https://tools.ietf.org/html/rfc7950#section-7.5.7 Furthermore,
@@ -220,7 +220,7 @@
datastore.setLeaf("/example-schema:leafEnum", enum_{"lol"});
datastore.commitChanges();
}
- std::map<std::string, leaf_data_> expected{{"/example-schema:leafEnum", enum_{"lol"}}};
+ DatastoreAccess::Tree expected{{"/example-schema:leafEnum", enum_{"lol"}}};
REQUIRE(datastore.getItems("/example-schema:leafEnum") == expected);
}
@@ -239,7 +239,7 @@
datastore.createListInstance("/example-schema:person[name='Petr']");
datastore.commitChanges();
}
- std::map<std::string, leaf_data_> expected{
+ DatastoreAccess::Tree expected{
{"/example-schema:person[name='Jan']", special_{SpecialValue::List}},
{"/example-schema:person[name='Jan']/name", std::string{"Jan"}},
{"/example-schema:person[name='Michal']", special_{SpecialValue::List}},