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_access.cpp b/src/yang_access.cpp
index 7fd9010..6c18779 100644
--- a/src/yang_access.cpp
+++ b/src/yang_access.cpp
@@ -16,7 +16,7 @@
}
YangAccess::YangAccess()
- : m_ctx(nullptr, libyang::ContextOptions::DisableSearchCwd | libyang::ContextOptions::SetPrivParsed)
+ : m_ctx(std::nullopt, libyang::ContextOptions::DisableSearchCwd | libyang::ContextOptions::SetPrivParsed)
, m_datastore(std::nullopt)
, m_schema(std::make_shared<YangSchema>(m_ctx))
{
@@ -45,9 +45,9 @@
{
try {
if (m_datastore) {
- m_datastore->newPath(path.c_str(), value ? value->c_str() : nullptr, libyang::CreationOptions::Update);
+ m_datastore->newPath(path, value, libyang::CreationOptions::Update);
} else {
- m_datastore = m_ctx.newPath(path.c_str(), value ? value->c_str() : nullptr, libyang::CreationOptions::Update);
+ m_datastore = m_ctx.newPath(path, value, libyang::CreationOptions::Update);
}
} catch (libyang::Error&) {
getErrorsAndThrow();
@@ -82,7 +82,7 @@
// Otherwise the datastore just doesn't contain the wanted node.
throw DatastoreException{{DatastoreError{"Datastore is empty.", path}}};
}
- auto toRemove = m_datastore->findPath(path.c_str());
+ auto toRemove = m_datastore->findPath(path);
if (!toRemove) {
// Otherwise the datastore just doesn't contain the wanted node.
throw DatastoreException{{DatastoreError{"Data node doesn't exist.", path}}};
@@ -105,7 +105,7 @@
return res;
}
- auto set = m_datastore->findXPath(path == "/" ? "/*" : path.c_str());
+ auto set = m_datastore->findXPath(path == "/" ? "/*" : path);
lyNodesToTree(res, set);
return res;
@@ -134,7 +134,7 @@
void operator()(yang::move::Absolute absolute) const
{
- auto set = m_sourceNode.findXPath(m_sourceNode.schema().path().get().get());
+ auto set = m_sourceNode.findXPath(m_sourceNode.schema().path());
if (set.size() == 1) { // m_sourceNode is the sole instance, do nothing
return;
}
@@ -160,7 +160,7 @@
{
auto keySuffix = m_sourceNode.schema().nodeType() == libyang::NodeType::List ? instanceToString(relative.m_path)
: leafDataToString(relative.m_path.at("."));
- auto destNode = m_sourceNode.findSiblingVal(m_sourceNode.schema(), keySuffix.c_str());
+ auto destNode = m_sourceNode.findSiblingVal(m_sourceNode.schema(), keySuffix);
if (relative.m_position == yang::move::Relative::Position::After) {
destNode->insertAfter(m_sourceNode);
@@ -177,7 +177,7 @@
throw DatastoreException{{DatastoreError{"Datastore is empty.", source}}};
}
- auto sourceNode = m_datastore->findPath(source.c_str());
+ auto sourceNode = m_datastore->findPath(source);
if (!sourceNode) {
// The datastore doesn't contain the wanted node.
@@ -199,7 +199,7 @@
{
auto root = [&path, this] {
try {
- return m_ctx.newPath(path.c_str());
+ return m_ctx.newPath(path);
} catch (libyang::ErrorWithCode& err) {
getErrorsAndThrow();
}
@@ -211,7 +211,7 @@
}
try {
- root.newPath(k.c_str(), leafDataToString(v).c_str(), libyang::CreationOptions::Update);
+ root.newPath(k, leafDataToString(v), libyang::CreationOptions::Update);
} catch (libyang::ErrorWithCode& err) {
getErrorsAndThrow();
}
@@ -238,7 +238,7 @@
return res;
}
- auto instances = m_datastore->findXPath(path.c_str());
+ auto instances = m_datastore->findXPath(path);
for (const auto& list : instances) {
ListInstance instance;
for (const auto& child : list.child()->siblings()) {
@@ -297,7 +297,7 @@
std::cout << "Parsing \"" << path << "\" as " << (firstChar == '{' ? "JSON" : "XML") << "...\n";
auto dataNode = m_ctx.parseDataPath(
- path.c_str(),
+ path,
firstChar == '{' ? libyang::DataFormat::JSON : libyang::DataFormat::XML,
strict == StrictDataParsing::Yes ? std::optional{libyang::ParseOptions::Strict} : std::nullopt,
libyang::ValidationOptions::Present);