Port to libyang-cpp and sysrepo-cpp API change to std::string
Change-Id: I9e683e0ab3a5db696c35699d22cf1cb982c8ceda
Depends-on: https://gerrit.cesnet.cz/c/CzechLight/dependencies/+/5564
diff --git a/src/yang_schema.cpp b/src/yang_schema.cpp
index 1c2df80..5a31a49 100644
--- a/src/yang_schema.cpp
+++ b/src/yang_schema.cpp
@@ -32,7 +32,7 @@
};
YangSchema::YangSchema()
- : m_context(nullptr, libyang::ContextOptions::DisableSearchDirs | libyang::ContextOptions::SetPrivParsed)
+ : m_context(std::nullopt, libyang::ContextOptions::DisableSearchDirs | libyang::ContextOptions::SetPrivParsed)
{
}
@@ -60,7 +60,7 @@
bool YangSchema::isModule(const std::string& name) const
{
- return m_context.getModuleImplemented(name.c_str()).has_value();
+ return m_context.getModuleImplemented(name).has_value();
}
bool YangSchema::listHasKey(const schemaPath_& listPath, const std::string& key) const
@@ -86,14 +86,14 @@
//
// Also, we need to use findPath twice if we're trying to find output nodes.
try {
- return m_context.findPath(node.c_str());
+ return m_context.findPath(node);
} catch (libyang::ErrorWithCode& err) {
if (err.code() != libyang::ErrorCode::ValidationFailure) {
throw;
}
}
try {
- return m_context.findPath(node.c_str(), libyang::OutputNodes::Yes);
+ return m_context.findPath(node, libyang::OutputNodes::Yes);
} catch (libyang::ErrorWithCode& err) {
if (err.code() != libyang::ErrorCode::ValidationFailure) {
throw;
@@ -325,7 +325,7 @@
std::string topLevelModule;
if (path.type() == typeid(module_)) {
- nodeCollections.emplace_back(m_context.getModule(boost::get<module_>(path).m_name.c_str())->childInstantiables());
+ nodeCollections.emplace_back(m_context.getModule(boost::get<module_>(path).m_name)->childInstantiables());
} else {
auto schemaPath = anyPathToSchemaPath(path);
if (schemaPath.m_nodes.empty()) {
@@ -372,7 +372,7 @@
void YangSchema::loadModule(const std::string& moduleName)
{
- m_context.loadModule(moduleName.c_str());
+ m_context.loadModule(moduleName);
}
void YangSchema::setEnabledFeatures(const std::string& moduleName, const std::vector<std::string>& features)
@@ -389,16 +389,16 @@
}
}
-void YangSchema::registerModuleCallback(const std::function<std::string(const char*, const char*, const char*, const char*)>& clb)
+void YangSchema::registerModuleCallback(const std::function<std::string(const std::string_view, const std::optional<std::string_view>, const std::optional<std::string_view>, const std::optional<std::string_view>)>& clb)
{
- auto lambda = [clb](const char* mod_name, const char* mod_revision, const char* submod_name, const char* submod_revision) -> std::optional<libyang::ModuleInfo> {
+ auto lambda = [clb](const auto mod_name, const auto mod_revision, const auto submod_name, const auto submod_revision) -> std::optional<libyang::ModuleInfo> {
(void)submod_revision;
auto moduleSource = clb(mod_name, mod_revision, submod_name, submod_revision);
if (moduleSource.empty()) {
return std::nullopt;
}
return libyang::ModuleInfo {
- .data = moduleSource.c_str(),
+ .data = moduleSource,
.format = libyang::SchemaFormat::YANG
};
@@ -420,12 +420,12 @@
return std::optional<libyang::CreationOptions>{};
}();
- return m_context.newPath2(path.c_str(), value ? value->c_str() : nullptr, options);
+ return m_context.newPath2(path, value, options);
}
std::optional<libyang::Module> YangSchema::getYangModule(const std::string& name)
{
- return m_context.getModuleImplemented(name.c_str());
+ return m_context.getModuleImplemented(name);
}
namespace {