Add leafrefBaseType(const std::string&)

Will be useful in the upcoming describe command.

Change-Id: I180b0a3c87db8e856251e28f34aa3940c52d1ad0
diff --git a/src/schema.hpp b/src/schema.hpp
index 561455c..137dbe9 100644
--- a/src/schema.hpp
+++ b/src/schema.hpp
@@ -77,6 +77,7 @@
     virtual yang::LeafDataTypes leafType(const schemaPath_& location, const ModuleNodePair& node) const = 0;
     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::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 afbb018..14b5666 100644
--- a/src/static_schema.cpp
+++ b/src/static_schema.cpp
@@ -290,3 +290,8 @@
 {
     throw std::runtime_error{"Internal error: StaticSchema::nodeType(std::string) not implemented. The tests should not have called this overload."};
 }
+
+yang::LeafDataTypes StaticSchema::leafrefBaseType([[maybe_unused]] const std::string& path) const
+{
+    throw std::runtime_error{"Internal error: StaticSchema::leafrefBaseType(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 7c0b0c2..1328a93 100644
--- a/src/static_schema.hpp
+++ b/src/static_schema.hpp
@@ -58,6 +58,7 @@
     yang::LeafDataTypes leafType(const schemaPath_& location, const ModuleNodePair& node) const override;
     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;
     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 297ea53..4b4a8bb 100644
--- a/src/yang_schema.cpp
+++ b/src/yang_schema.cpp
@@ -281,16 +281,28 @@
     return impl_leafType(getSchemaNode(path));
 }
 
-yang::LeafDataTypes YangSchema::leafrefBaseType(const schemaPath_& location, const ModuleNodePair& node) const
+namespace {
+yang::LeafDataTypes impl_leafrefBaseType(const libyang::S_Schema_Node& node)
 {
     using namespace std::string_literals;
-    libyang::Schema_Node_Leaf leaf(getSchemaNode(location, node));
+    libyang::Schema_Node_Leaf leaf(node);
     try {
         return lyTypeToLeafDataTypes(leaf.type()->info()->lref()->target()->type()->base());
     } catch (std::logic_error& ex) {
-        throw UnsupportedYangTypeException("the type of "s + fullNodeName(location, node) + " is not supported: " + ex.what());
+        throw UnsupportedYangTypeException("the type of "s + node->name() + " is not supported: " + ex.what());
     }
 }
+}
+
+yang::LeafDataTypes YangSchema::leafrefBaseType(const schemaPath_& location, const ModuleNodePair& node) const
+{
+    return impl_leafrefBaseType(getSchemaNode(location, node));
+}
+
+yang::LeafDataTypes YangSchema::leafrefBaseType(const std::string& path) const
+{
+    return impl_leafrefBaseType(getSchemaNode(path));
+}
 
 std::set<std::string> YangSchema::modules() const
 {
diff --git a/src/yang_schema.hpp b/src/yang_schema.hpp
index 3eaace6..ad112e7 100644
--- a/src/yang_schema.hpp
+++ b/src/yang_schema.hpp
@@ -40,6 +40,7 @@
     yang::LeafDataTypes leafType(const schemaPath_& location, const ModuleNodePair& node) const override;
     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;
     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;