Václav Kubernát | cbdc98a | 2021-01-28 13:24:37 +0100 | [diff] [blame^] | 1 | #include <libyang/Tree_Data.hpp> |
| 2 | #include "utils/libyang.h" |
| 3 | |
| 4 | const char* getValueAsString(const libyang::S_Data_Node& node) |
| 5 | { |
| 6 | if (!node || node->schema()->nodetype() != LYS_LEAF) { |
| 7 | throw std::logic_error("retrieveString: invalid node"); |
| 8 | } |
| 9 | |
| 10 | return libyang::Data_Node_Leaf_List(node).value_str(); |
| 11 | } |
| 12 | |
| 13 | libyang::S_Data_Node getSubtree(const libyang::S_Data_Node& start, const char* path) |
| 14 | { |
| 15 | auto set = start->find_path(path); |
| 16 | if (set->number() != 1) { |
| 17 | throw std::runtime_error("getSubtree: didn't get exactly one match (got " + std::to_string(set->number()) + ")"); |
| 18 | } |
| 19 | |
| 20 | return set->data().front(); |
| 21 | } |