blob: 3f32575fab490b5065365dcefd338660d5fea761 [file] [log] [blame]
Václav Kubernátbabbab92021-01-27 09:25:05 +01001#include <fmt/format.h>
Václav Kubernátcbdc98a2021-01-28 13:24:37 +01002#include <libyang/Tree_Data.hpp>
3#include "utils/libyang.h"
4
5const char* getValueAsString(const libyang::S_Data_Node& node)
6{
7 if (!node || node->schema()->nodetype() != LYS_LEAF) {
8 throw std::logic_error("retrieveString: invalid node");
9 }
10
11 return libyang::Data_Node_Leaf_List(node).value_str();
12}
13
14libyang::S_Data_Node getSubtree(const libyang::S_Data_Node& start, const char* path)
15{
16 auto set = start->find_path(path);
17 if (set->number() != 1) {
Václav Kubernátbabbab92021-01-27 09:25:05 +010018 throw std::runtime_error(fmt::format("getSubtree({}, {}): didn't get exactly one match (got {})", start->path(), path, set->number()));
Václav Kubernátcbdc98a2021-01-28 13:24:37 +010019 }
20
21 return set->data().front();
22}