Remove unused overloads in Schema
Change-Id: I919c7175401c557a489b6f288f7f5517a77472d9
diff --git a/src/schema.hpp b/src/schema.hpp
index 42d0728..2daa73f 100644
--- a/src/schema.hpp
+++ b/src/schema.hpp
@@ -62,12 +62,10 @@
virtual yang::NodeTypes nodeType(const std::string& path) const = 0;
virtual yang::NodeTypes nodeType(const schemaPath_& location, const ModuleNodePair& node) const = 0;
virtual bool isModule(const std::string& name) const = 0;
- virtual bool listHasKey(const schemaPath_& location, const ModuleNodePair& node, const std::string& key) const = 0;
virtual bool listHasKey(const schemaPath_& listPath, const std::string& key) const = 0;
virtual bool leafIsKey(const std::string& leafPath) const = 0;
virtual bool isConfig(const std::string& path) const = 0;
virtual std::optional<std::string> defaultValue(const std::string& leafPath) const = 0;
- virtual const std::set<std::string> listKeys(const schemaPath_& location, const ModuleNodePair& node) const = 0;
virtual const std::set<std::string> listKeys(const schemaPath_& listPath) const = 0;
virtual yang::TypeInfo leafType(const schemaPath_& location, const ModuleNodePair& node) const = 0;
virtual yang::TypeInfo leafType(const std::string& path) const = 0;
diff --git a/src/static_schema.cpp b/src/static_schema.cpp
index 203b61e..989ef21 100644
--- a/src/static_schema.cpp
+++ b/src/static_schema.cpp
@@ -34,31 +34,11 @@
m_nodes.emplace(key, std::unordered_map<std::string, NodeInfo>());
}
-bool StaticSchema::listHasKey(const schemaPath_& location, const ModuleNodePair& node, const std::string& key) const
-{
- std::string locationString = pathToSchemaString(location, Prefixes::Always);
- assert(isList(location, node));
-
- const auto& child = children(locationString).at(fullNodeName(location, node));
- const auto& list = std::get<yang::list>(child.m_nodeType);
- return list.m_keys.find(key) != list.m_keys.end();
-}
-
bool StaticSchema::listHasKey(const schemaPath_& listPath, const std::string& key) const
{
return listKeys(listPath).count(key);
}
-const std::set<std::string> StaticSchema::listKeys(const schemaPath_& location, const ModuleNodePair& node) const
-{
- std::string locationString = pathToSchemaString(location, Prefixes::Always);
- assert(isList(location, node));
-
- const auto& child = children(locationString).at(fullNodeName(location, node));
- const auto& list = std::get<yang::list>(child.m_nodeType);
- return list.m_keys;
-}
-
std::string lastNodeOfSchemaPath(const std::string& path)
{
std::string res = path;
diff --git a/src/static_schema.hpp b/src/static_schema.hpp
index 09b6271..9d897b1 100644
--- a/src/static_schema.hpp
+++ b/src/static_schema.hpp
@@ -62,12 +62,10 @@
yang::NodeTypes nodeType(const std::string& path) const override;
yang::NodeTypes nodeType(const schemaPath_& location, const ModuleNodePair& node) const override;
bool isModule(const std::string& name) const override;
- bool listHasKey(const schemaPath_& location, const ModuleNodePair& node, const std::string& key) const override;
bool listHasKey(const schemaPath_& listPath, const std::string& key) const override;
bool leafIsKey(const std::string& leafPath) const override;
bool isConfig(const std::string& leafPath) const override;
std::optional<std::string> defaultValue(const std::string& leafPath) const override;
- const std::set<std::string> listKeys(const schemaPath_& location, const ModuleNodePair& node) const override;
const std::set<std::string> listKeys(const schemaPath_& listPath) const override;
yang::TypeInfo leafType(const schemaPath_& location, const ModuleNodePair& node) const override;
yang::TypeInfo leafType(const std::string& path) const override;
diff --git a/src/yang_schema.cpp b/src/yang_schema.cpp
index b44ef5f..c8bf540 100644
--- a/src/yang_schema.cpp
+++ b/src/yang_schema.cpp
@@ -93,14 +93,6 @@
return set.find(name) != set.end();
}
-bool YangSchema::listHasKey(const schemaPath_& location, const ModuleNodePair& node, const std::string& key) const
-{
- if (!isList(location, node))
- return false;
- const auto keys = listKeys(location, node);
- return keys.find(key) != keys.end();
-}
-
bool YangSchema::listHasKey(const schemaPath_& listPath, const std::string& key) const
{
const auto keys = listKeys(listPath);
@@ -153,30 +145,20 @@
return impl_getSchemaNode(absPath);
}
-namespace {
-const std::set<std::string> impl_listKeys(const libyang::S_Schema_Node_List& list)
+const std::set<std::string> YangSchema::listKeys(const schemaPath_& listPath) const
{
+ auto node = getSchemaNode(listPath);
+ if (node->nodetype() != LYS_LIST) {
+ return {};
+ }
+
+ auto list = std::make_shared<libyang::Schema_Node_List>(node);
std::set<std::string> keys;
const auto& keysVec = list->keys();
std::transform(keysVec.begin(), keysVec.end(), std::inserter(keys, keys.begin()), [](const auto& it) { return it->name(); });
return keys;
}
-}
-
-const std::set<std::string> YangSchema::listKeys(const schemaPath_& location, const ModuleNodePair& node) const
-{
- if (!isList(location, node))
- return {};
- auto list = std::make_shared<libyang::Schema_Node_List>(getSchemaNode(location, node));
- return impl_listKeys(list);
-}
-
-const std::set<std::string> YangSchema::listKeys(const schemaPath_& listPath) const
-{
- auto list = std::make_shared<libyang::Schema_Node_List>(getSchemaNode(listPath));
- return impl_listKeys(list);
-}
namespace {
std::set<enum_> enumValues(const libyang::S_Type& typeArg)
diff --git a/src/yang_schema.hpp b/src/yang_schema.hpp
index aed1a5d..3663ccd 100644
--- a/src/yang_schema.hpp
+++ b/src/yang_schema.hpp
@@ -34,12 +34,10 @@
yang::NodeTypes nodeType(const std::string& path) const override;
yang::NodeTypes nodeType(const schemaPath_& location, const ModuleNodePair& node) const override;
bool isModule(const std::string& name) const override;
- bool listHasKey(const schemaPath_& location, const ModuleNodePair& node, const std::string& key) const override;
bool listHasKey(const schemaPath_& listPath, const std::string& key) const override;
bool leafIsKey(const std::string& leafPath) const override;
bool isConfig(const std::string& path) const override;
std::optional<std::string> defaultValue(const std::string& leafPath) const override;
- const std::set<std::string> listKeys(const schemaPath_& location, const ModuleNodePair& node) const override;
const std::set<std::string> listKeys(const schemaPath_& listPath) const override;
yang::TypeInfo leafType(const schemaPath_& location, const ModuleNodePair& node) const override;
yang::TypeInfo leafType(const std::string& path) const override;
diff --git a/tests/ls_interpreter.cpp b/tests/ls_interpreter.cpp
index 4a60762..2ae0b7c 100644
--- a/tests/ls_interpreter.cpp
+++ b/tests/ls_interpreter.cpp
@@ -26,11 +26,9 @@
IMPLEMENT_CONST_MOCK1(leafTypeName);
IMPLEMENT_CONST_MOCK1(isModule);
IMPLEMENT_CONST_MOCK1(leafrefPath);
- MAKE_CONST_MOCK3(listHasKey, bool(const schemaPath_& location, const ModuleNodePair& node, const std::string& key), override);
- MAKE_CONST_MOCK2(listHasKey, bool(const schemaPath_& listPath, const std::string& key), override);
+ IMPLEMENT_CONST_MOCK2(listHasKey);
IMPLEMENT_CONST_MOCK1(leafIsKey);
- MAKE_CONST_MOCK2(listKeys, const std::set<std::string>(const schemaPath_& location, const ModuleNodePair& node), override);
- MAKE_CONST_MOCK1(listKeys, const std::set<std::string>(const schemaPath_& listPath), override);
+ IMPLEMENT_CONST_MOCK1(listKeys);
MAKE_CONST_MOCK1(nodeType, yang::NodeTypes(const std::string&), override);
MAKE_CONST_MOCK2(nodeType, yang::NodeTypes(const schemaPath_&, const ModuleNodePair&), override);
IMPLEMENT_CONST_MOCK1(status);
diff --git a/tests/yang.cpp b/tests/yang.cpp
index 71cb69d..e2ece6f 100644
--- a/tests/yang.cpp
+++ b/tests/yang.cpp
@@ -566,23 +566,27 @@
SECTION("_list")
{
- node.first = "example-schema";
- node.second = "_list";
+ path.m_nodes.push_back(schemaNode_{module_{"example-schema"}, list_{"_list"}});
SECTION("number")
- key = "number";
+ {
+ key = "number";
+ }
}
SECTION("twoKeyList")
{
- node.first = "example-schema";
- node.second = "twoKeyList";
+ path.m_nodes.push_back(schemaNode_{module_{"example-schema"}, list_{"twoKeyList"}});
SECTION("number")
- key = "number";
+ {
+ key = "number";
+ }
SECTION("name")
- key = "name";
+ {
+ key = "name";
+ }
}
- REQUIRE(ys.listHasKey(path, node, key));
+ REQUIRE(ys.listHasKey(path, key));
}
SECTION("listKeys")
{
@@ -590,19 +594,17 @@
SECTION("_list")
{
+ path.m_nodes.push_back(schemaNode_{module_{"example-schema"}, list_{"_list"}});
set = {"number"};
- node.first = "example-schema";
- node.second = "_list";
}
SECTION("twoKeyList")
{
+ path.m_nodes.push_back(schemaNode_{module_{"example-schema"}, list_{"twoKeyList"}});
set = {"number", "name"};
- node.first = "example-schema";
- node.second = "twoKeyList";
}
- REQUIRE(ys.listKeys(path, node) == set);
+ REQUIRE(ys.listKeys(path) == set);
}
SECTION("leafType")
{
@@ -1257,9 +1259,9 @@
SECTION("nodetype-specific methods called with different nodetypes")
{
path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a")));
- node.second = "a2";
+ path.m_nodes.push_back(schemaNode_(container_("a2")));
- REQUIRE(!ys.listHasKey(path, node, "chacha"));
+ REQUIRE(!ys.listHasKey(path, "chacha"));
}
SECTION("nonexistent module")