Add Schema::leafIsKey
Will be used in the upcoming describe command.
Change-Id: Ifed7b959b235dc9cf00c896df9c9321fb155a756
diff --git a/src/schema.hpp b/src/schema.hpp
index a45149a..89a100c 100644
--- a/src/schema.hpp
+++ b/src/schema.hpp
@@ -73,6 +73,7 @@
virtual bool leafEnumHasValue(const schemaPath_& location, const ModuleNodePair& node, const std::string& value) const = 0;
virtual bool leafIdentityIsValid(const schemaPath_& location, const ModuleNodePair& node, const ModuleValuePair& value) const = 0;
virtual bool listHasKey(const schemaPath_& location, const ModuleNodePair& node, const std::string& key) const = 0;
+ virtual bool leafIsKey(const std::string& leafPath) const = 0;
virtual const std::set<std::string> listKeys(const schemaPath_& location, const ModuleNodePair& node) const = 0;
virtual yang::LeafDataTypes leafType(const schemaPath_& location, const ModuleNodePair& node) const = 0;
virtual yang::LeafDataTypes leafType(const std::string& path) const = 0;
diff --git a/src/static_schema.cpp b/src/static_schema.cpp
index 511e420..0eb564a 100644
--- a/src/static_schema.cpp
+++ b/src/static_schema.cpp
@@ -300,3 +300,8 @@
{
throw std::runtime_error{"Internal error: StaticSchema::leafrefPath(std::string) not implemented. The tests should not have called this overload."};
}
+
+bool StaticSchema::leafIsKey([[maybe_unused]] const std::string& leafPath) const
+{
+ throw std::runtime_error{"Internal error: StaticSchema::leafIsKey(std::string) not implemented. The tests should not have called this overload."};
+}
diff --git a/src/static_schema.hpp b/src/static_schema.hpp
index c586083..a3ab4bc 100644
--- a/src/static_schema.hpp
+++ b/src/static_schema.hpp
@@ -54,6 +54,7 @@
bool leafEnumHasValue(const schemaPath_& location, const ModuleNodePair& node, const std::string& value) const override;
bool leafIdentityIsValid(const schemaPath_& location, const ModuleNodePair& node, const ModuleValuePair& value) const override;
bool listHasKey(const schemaPath_& location, const ModuleNodePair& node, const std::string& key) const override;
+ bool leafIsKey(const std::string& leafPath) const override;
const std::set<std::string> listKeys(const schemaPath_& location, const ModuleNodePair& node) const override;
yang::LeafDataTypes leafType(const schemaPath_& location, const ModuleNodePair& node) const override;
yang::LeafDataTypes leafType(const std::string& path) const override;
diff --git a/src/yang_schema.cpp b/src/yang_schema.cpp
index 254f8a9..0795b2b 100644
--- a/src/yang_schema.cpp
+++ b/src/yang_schema.cpp
@@ -175,6 +175,15 @@
return keys.find(key) != keys.end();
}
+bool YangSchema::leafIsKey(const std::string& leafPath) const
+{
+ auto node = getSchemaNode(leafPath);
+ if (!node || node->nodetype() != LYS_LEAF)
+ return false;
+
+ return libyang::Schema_Node_Leaf{node}.is_key().get();
+}
+
libyang::S_Schema_Node YangSchema::impl_getSchemaNode(const std::string& node) const
{
// If no node is found find_path prints an error message, so we have to
diff --git a/src/yang_schema.hpp b/src/yang_schema.hpp
index e610383..1165094 100644
--- a/src/yang_schema.hpp
+++ b/src/yang_schema.hpp
@@ -36,6 +36,7 @@
bool leafEnumHasValue(const schemaPath_& location, const ModuleNodePair& node, const std::string& value) const override;
bool leafIdentityIsValid(const schemaPath_& location, const ModuleNodePair& node, const ModuleValuePair& value) const override;
bool listHasKey(const schemaPath_& location, const ModuleNodePair& node, const std::string& key) const override;
+ bool leafIsKey(const std::string& leafPath) const override;
const std::set<std::string> listKeys(const schemaPath_& location, const ModuleNodePair& node) const override;
yang::LeafDataTypes leafType(const schemaPath_& location, const ModuleNodePair& node) const override;
yang::LeafDataTypes leafType(const std::string& path) const override;