Remove Schema::is* methods
These methods are not really used anywhere, and if they are, they can be
replaced with a call to Schema::nodeType. No reason to keep them. I had
to implement StaticSchema::nodeType(std::string) because of
presenceContainerPath_class, but that's ok.
Change-Id: Ia27f6aa1f1cd098f087767365cb6a706c255c206
diff --git a/src/ast_handlers.hpp b/src/ast_handlers.hpp
index b9d7a9d..b522957 100644
--- a/src/ast_handlers.hpp
+++ b/src/ast_handlers.hpp
@@ -157,19 +157,8 @@
return;
}
- try {
- boost::optional<std::string> module;
- if (ast.m_nodes.back().m_prefix)
- module = ast.m_nodes.back().m_prefix.value().m_name;
- container_ cont = std::get<container_>(ast.m_nodes.back().m_suffix);
- auto location = pathWithoutLastNode(parserContext.currentSchemaPath());
-
- if (!schema.isPresenceContainer(location, {module, cont.m_name})) {
- parserContext.m_errorMsg = "This container is not a presence container.";
- _pass(context) = false;
- }
- } catch (std::bad_variant_access&) {
- parserContext.m_errorMsg = "This is not a container.";
+ if (schema.nodeType(pathToSchemaString(parserContext.currentSchemaPath(), Prefixes::Always)) != yang::NodeTypes::PresenceContainer) {
+ parserContext.m_errorMsg = "This container is not a presence container.";
_pass(context) = false;
}
}
diff --git a/src/schema.cpp b/src/schema.cpp
index e092569..c390e31 100644
--- a/src/schema.cpp
+++ b/src/schema.cpp
@@ -9,49 +9,3 @@
#include "schema.hpp"
Schema::~Schema() = default;
-
-bool Schema::isList(const schemaPath_& location, const ModuleNodePair& node) const
-{
- try {
- return nodeType(location, node) == yang::NodeTypes::List;
- } catch (InvalidNodeException&) {
- return false;
- }
-}
-
-bool Schema::isPresenceContainer(const schemaPath_& location, const ModuleNodePair& node) const
-{
- try {
- return nodeType(location, node) == yang::NodeTypes::PresenceContainer;
- } catch (InvalidNodeException&) {
- return false;
- }
-}
-
-bool Schema::isContainer(const schemaPath_& location, const ModuleNodePair& node) const
-{
- try {
- auto type = nodeType(location, node);
- return type == yang::NodeTypes::Container || type == yang::NodeTypes::PresenceContainer;
- } catch (InvalidNodeException&) {
- return false;
- }
-}
-
-bool Schema::isLeaf(const schemaPath_& location, const ModuleNodePair& node) const
-{
- try {
- return nodeType(location, node) == yang::NodeTypes::Leaf;
- } catch (InvalidNodeException&) {
- return false;
- }
-}
-
-bool Schema::isLeafList(const std::string& path) const
-{
- try {
- return nodeType(path) == yang::NodeTypes::LeafList;
- } catch (InvalidNodeException&) {
- return false;
- }
-}
diff --git a/src/schema.hpp b/src/schema.hpp
index 2daa73f..75c1f8f 100644
--- a/src/schema.hpp
+++ b/src/schema.hpp
@@ -54,10 +54,6 @@
public:
virtual ~Schema();
- bool isContainer(const schemaPath_& location, const ModuleNodePair& node) const;
- bool isLeaf(const schemaPath_& location, const ModuleNodePair& node) const;
- bool isList(const schemaPath_& location, const ModuleNodePair& node) const;
- bool isPresenceContainer(const schemaPath_& location, const ModuleNodePair& node) const;
bool isLeafList(const std::string& path) const;
virtual yang::NodeTypes nodeType(const std::string& path) const = 0;
virtual yang::NodeTypes nodeType(const schemaPath_& location, const ModuleNodePair& node) const = 0;
diff --git a/src/static_schema.cpp b/src/static_schema.cpp
index 989ef21..a7130b3 100644
--- a/src/static_schema.cpp
+++ b/src/static_schema.cpp
@@ -244,9 +244,12 @@
throw std::runtime_error{"Internal error: StaticSchema::status(std::string) not implemented. The tests should not have called this overload."};
}
-yang::NodeTypes StaticSchema::nodeType([[maybe_unused]] const std::string& path) const
+yang::NodeTypes StaticSchema::nodeType(const std::string& path) const
{
- throw std::runtime_error{"Internal error: StaticSchema::nodeType(std::string) not implemented. The tests should not have called this overload."};
+ auto locationString = stripLastNodeFromPath(path);
+
+ auto node = fullNodeName(locationString, lastNodeOfSchemaPath(path));
+ return std::visit(impl_nodeType{}, children(locationString).at(node).m_nodeType);
}
std::string StaticSchema::leafrefPath([[maybe_unused]] const std::string& leafrefPath) const
diff --git a/src/sysrepo_access.cpp b/src/sysrepo_access.cpp
index 3af5f79..3278766 100644
--- a/src/sysrepo_access.cpp
+++ b/src/sysrepo_access.cpp
@@ -196,7 +196,7 @@
return;
for (unsigned int i = 0; i < items->val_cnt(); i++) {
auto value = leafValueFromVal(items->val(i));
- if (m_schema->isLeafList(items->val(i)->xpath())) {
+ if (m_schema->nodeType(items->val(i)->xpath()) == yang::NodeTypes::LeafList) {
res.push_back({items->val(i)->xpath(), special_{SpecialValue::LeafList}});
std::string leafListPath = items->val(i)->xpath();
while (i < items->val_cnt() && leafListPath == items->val(i)->xpath()) {