Get rid of ModuleValuePair
It's better to use the identityRef_ struct instead of the pair.
Change-Id: I3122ac8320efdb2708d7d2e42b5be0053044ddc2
diff --git a/src/schema.hpp b/src/schema.hpp
index f11265f..0a9b2ff 100644
--- a/src/schema.hpp
+++ b/src/schema.hpp
@@ -15,8 +15,6 @@
#include "ast_path.hpp"
#include "leaf_data_type.hpp"
-using ModuleValuePair = std::pair<boost::optional<std::string>, std::string>;
-
namespace yang {
enum class NodeTypes {
Container,
diff --git a/src/static_schema.cpp b/src/static_schema.cpp
index 2395aa0..aecad5a 100644
--- a/src/static_schema.cpp
+++ b/src/static_schema.cpp
@@ -73,15 +73,10 @@
std::set<identityRef_> StaticSchema::validIdentities(std::string_view module, std::string_view value)
{
- std::set<ModuleValuePair> identities;
- getIdentSet(ModuleNodePair{boost::optional<std::string>{module}, value}, identities);
- std::set<identityRef_> res;
+ std::set<identityRef_> identities;
+ getIdentSet(identityRef_{std::string{module}, std::string{value}}, identities);
- std::transform(identities.begin(), identities.end(), std::inserter(res, res.end()), [](const auto& identity) {
- return identityRef_{*identity.first, identity.second};
- });
-
- return res;
+ return identities;
}
void StaticSchema::addLeaf(const std::string& location, const std::string& name, const yang::LeafDataType& type)
@@ -96,15 +91,15 @@
m_modules.emplace(name);
}
-void StaticSchema::addIdentity(const std::optional<ModuleValuePair>& base, const ModuleValuePair& name)
+void StaticSchema::addIdentity(const std::optional<identityRef_>& base, const identityRef_& name)
{
if (base)
m_identities.at(base.value()).emplace(name);
- m_identities.emplace(name, std::set<ModuleValuePair>());
+ m_identities.emplace(name, std::set<identityRef_>());
}
-void StaticSchema::getIdentSet(const ModuleValuePair& ident, std::set<ModuleValuePair>& res) const
+void StaticSchema::getIdentSet(const identityRef_& ident, std::set<identityRef_>& res) const
{
res.insert(ident);
auto derivedIdentities = m_identities.at(ident);
diff --git a/src/static_schema.hpp b/src/static_schema.hpp
index 67bd7b9..5184ae6 100644
--- a/src/static_schema.hpp
+++ b/src/static_schema.hpp
@@ -69,16 +69,15 @@
void addLeaf(const std::string& location, const std::string& name, const yang::LeafDataType& type);
void addList(const std::string& location, const std::string& name, const std::set<std::string>& keys);
void addModule(const std::string& name);
- void addIdentity(const std::optional<ModuleValuePair>& base, const ModuleValuePair& name);
+ void addIdentity(const std::optional<identityRef_>& base, const identityRef_& name);
private:
const std::unordered_map<std::string, NodeType>& children(const std::string& name) const;
- void getIdentSet(const ModuleValuePair& ident, std::set<ModuleValuePair>& res) const;
+ void getIdentSet(const identityRef_& ident, std::set<identityRef_>& res) const;
bool nodeExists(const std::string& location, const std::string& node) const;
std::unordered_map<std::string, std::unordered_map<std::string, NodeType>> m_nodes;
std::set<std::string> m_modules;
- // FIXME: Change the template arguments to identityRef_
- std::map<ModuleValuePair, std::set<ModuleValuePair>> m_identities;
+ std::map<identityRef_, std::set<identityRef_>> m_identities;
};
diff --git a/tests/leaf_editing.cpp b/tests/leaf_editing.cpp
index 64abbf2..986139d 100644
--- a/tests/leaf_editing.cpp
+++ b/tests/leaf_editing.cpp
@@ -37,11 +37,11 @@
schema->addLeaf("/", "mod:leafUint32", yang::Uint32{});
schema->addLeaf("/", "mod:leafUint64", yang::Uint64{});
schema->addLeaf("/", "mod:leafBinary", yang::Binary{});
- schema->addIdentity(std::nullopt, ModuleValuePair{"mod", "food"});
- schema->addIdentity(std::nullopt, ModuleValuePair{"mod", "vehicle"});
- schema->addIdentity(ModuleValuePair{"mod", "food"}, ModuleValuePair{"mod", "pizza"});
- schema->addIdentity(ModuleValuePair{"mod", "food"}, ModuleValuePair{"mod", "spaghetti"});
- schema->addIdentity(ModuleValuePair{"mod", "pizza"}, ModuleValuePair{"pizza-module", "hawaii"});
+ schema->addIdentity(std::nullopt, identityRef_{"mod", "food"});
+ schema->addIdentity(std::nullopt, identityRef_{"mod", "vehicle"});
+ schema->addIdentity(identityRef_{"mod", "food"}, identityRef_{"mod", "pizza"});
+ schema->addIdentity(identityRef_{"mod", "food"}, identityRef_{"mod", "spaghetti"});
+ schema->addIdentity(identityRef_{"mod", "pizza"}, identityRef_{"pizza-module", "hawaii"});
schema->addLeaf("/", "mod:foodIdentRef", yang::IdentityRef{schema->validIdentities("mod", "food")});
schema->addLeaf("/", "mod:pizzaIdentRef", yang::IdentityRef{schema->validIdentities("mod", "pizza")});
schema->addLeaf("/mod:contA", "mod:identInCont", yang::IdentityRef{schema->validIdentities("mod", "pizza")});