Add leafrefPath(const std::string&)
Will be useful in the upcoming describe command.
Change-Id: I480b93491f98c23eab6498503ca07d6b7c9c8e4f
diff --git a/src/schema.hpp b/src/schema.hpp
index 137dbe9..a45149a 100644
--- a/src/schema.hpp
+++ b/src/schema.hpp
@@ -78,6 +78,7 @@
virtual yang::LeafDataTypes leafType(const std::string& path) const = 0;
virtual yang::LeafDataTypes leafrefBaseType(const schemaPath_& location, const ModuleNodePair& node) const = 0;
virtual yang::LeafDataTypes leafrefBaseType(const std::string& path) const = 0;
+ virtual std::string leafrefPath(const std::string& leafrefPath) const = 0;
virtual std::optional<std::string> description(const std::string& location) const = 0;
virtual std::optional<std::string> units(const std::string& location) const = 0;
diff --git a/src/static_schema.cpp b/src/static_schema.cpp
index 14b5666..511e420 100644
--- a/src/static_schema.cpp
+++ b/src/static_schema.cpp
@@ -295,3 +295,8 @@
{
throw std::runtime_error{"Internal error: StaticSchema::leafrefBaseType(std::string) not implemented. The tests should not have called this overload."};
}
+
+std::string StaticSchema::leafrefPath([[maybe_unused]] const std::string& leafrefPath) const
+{
+ throw std::runtime_error{"Internal error: StaticSchema::leafrefPath(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 1328a93..c586083 100644
--- a/src/static_schema.hpp
+++ b/src/static_schema.hpp
@@ -59,6 +59,7 @@
yang::LeafDataTypes leafType(const std::string& path) const override;
yang::LeafDataTypes leafrefBaseType(const schemaPath_& location, const ModuleNodePair& node) const override;
yang::LeafDataTypes leafrefBaseType(const std::string& path) const override;
+ std::string leafrefPath(const std::string& leafrefPath) const override;
const std::set<std::string> enumValues(const schemaPath_& location, const ModuleNodePair& node) const override;
const std::set<std::string> validIdentities(const schemaPath_& location, const ModuleNodePair& node, const Prefixes prefixes) const override;
std::set<std::string> childNodes(const schemaPath_& path, const Recursion) const override;
diff --git a/src/yang_schema.cpp b/src/yang_schema.cpp
index 4b4a8bb..254f8a9 100644
--- a/src/yang_schema.cpp
+++ b/src/yang_schema.cpp
@@ -304,6 +304,13 @@
return impl_leafrefBaseType(getSchemaNode(path));
}
+std::string YangSchema::leafrefPath(const std::string& leafrefPath) const
+{
+ using namespace std::string_literals;
+ libyang::Schema_Node_Leaf leaf(getSchemaNode(leafrefPath));
+ return leaf.type()->info()->lref()->target()->path(LYS_PATH_FIRST_PREFIX);
+}
+
std::set<std::string> YangSchema::modules() const
{
const auto& modules = m_context->get_module_iter();
diff --git a/src/yang_schema.hpp b/src/yang_schema.hpp
index ad112e7..e610383 100644
--- a/src/yang_schema.hpp
+++ b/src/yang_schema.hpp
@@ -41,6 +41,7 @@
yang::LeafDataTypes leafType(const std::string& path) const override;
yang::LeafDataTypes leafrefBaseType(const schemaPath_& location, const ModuleNodePair& node) const override;
yang::LeafDataTypes leafrefBaseType(const std::string& path) const override;
+ std::string leafrefPath(const std::string& leafrefPath) const override;
const std::set<std::string> validIdentities(const schemaPath_& location, const ModuleNodePair& node, const Prefixes prefixes) const override;
const std::set<std::string> enumValues(const schemaPath_& location, const ModuleNodePair& node) const override;
std::set<std::string> childNodes(const schemaPath_& path, const Recursion recursion) const override;