Add support for leafrefs

Change-Id: I2286aaa96abd960d13bb0b04a778fb264b2f74a4
diff --git a/src/static_schema.cpp b/src/static_schema.cpp
index 280f0da..3c3fced 100644
--- a/src/static_schema.cpp
+++ b/src/static_schema.cpp
@@ -105,7 +105,7 @@
 
 void StaticSchema::addLeaf(const std::string& location, const std::string& name, const yang::LeafDataTypes& type)
 {
-    m_nodes.at(location).emplace(name, yang::leaf{type, {}, {}});
+    m_nodes.at(location).emplace(name, yang::leaf{type, {}, {}, {}});
 }
 
 void StaticSchema::addLeafEnum(const std::string& location, const std::string& name, std::set<std::string> enumValues)
@@ -125,6 +125,14 @@
     m_nodes.at(location).emplace(name, toAdd);
 }
 
+void StaticSchema::addLeafRef(const std::string& location, const std::string& name, const std::string& source)
+{
+    yang::leaf toAdd;
+    toAdd.m_type = yang::LeafDataTypes::LeafRef;
+    toAdd.m_leafRefSource = source;
+    m_nodes.at(location).emplace(name, toAdd);
+}
+
 void StaticSchema::addModule(const std::string& name)
 {
     m_modules.emplace(name);
@@ -198,6 +206,24 @@
     return children(locationString).at(fullName).type() == typeid(yang::leaf);
 }
 
+std::string lastNodeOfSchemaPath(const std::string& path)
+{
+    std::string res = path;
+    auto pos = res.find_last_of('/');
+    if (pos != res.npos)
+        res.erase(0, pos);
+    return res;
+}
+
+yang::LeafDataTypes StaticSchema::leafrefBase(const schemaPath_& location, const ModuleNodePair& node) const
+{
+    std::string locationString = pathToAbsoluteSchemaString(location);
+    auto leaf{boost::get<yang::leaf>(children(locationString).at(fullNodeName(location, node)))};
+    auto locationOfSource = stripLastNodeFromPath(leaf.m_leafRefSource);
+    auto nameOfSource = lastNodeOfSchemaPath(leaf.m_leafRefSource);
+    return boost::get<yang::leaf>(children(locationOfSource).at(nameOfSource)).m_type;
+}
+
 yang::LeafDataTypes StaticSchema::leafType(const schemaPath_& location, const ModuleNodePair& node) const
 {
     std::string locationString = pathToAbsoluteSchemaString(location);