Václav Kubernát | cbdc98a | 2021-01-28 13:24:37 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2021 CESNET, https://photonics.cesnet.cz/ |
| 3 | * |
| 4 | * Written by Václav Kubernát <kubernat@cesnet.cz> |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | #pragma once |
| 9 | #include <memory> |
Tomáš Pecka | fd90efb | 2021-10-07 10:40:44 +0200 | [diff] [blame] | 10 | #include <optional> |
Jan Kundrát | 4a10d0a | 2024-04-10 03:33:43 +0200 | [diff] [blame] | 11 | #include <string> |
Václav Kubernát | cbdc98a | 2021-01-28 13:24:37 +0100 | [diff] [blame] | 12 | |
| 13 | namespace libyang { |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 14 | class DataNode; |
Václav Kubernát | cbdc98a | 2021-01-28 13:24:37 +0100 | [diff] [blame] | 15 | } |
| 16 | |
Tomáš Pecka | fd5ebd3 | 2021-10-07 09:48:13 +0200 | [diff] [blame] | 17 | namespace velia::utils { |
| 18 | |
Václav Kubernát | cbdc98a | 2021-01-28 13:24:37 +0100 | [diff] [blame] | 19 | /** |
| 20 | * @brief Gets a string value from a node. |
| 21 | * |
| 22 | * @param node A libyang data node. Mustn't be nullptr. Must be a leaf. |
| 23 | * |
| 24 | */ |
Jan Kundrát | 4a10d0a | 2024-04-10 03:33:43 +0200 | [diff] [blame] | 25 | std::string getValueAsString(const libyang::DataNode& node); |
Václav Kubernát | cbdc98a | 2021-01-28 13:24:37 +0100 | [diff] [blame] | 26 | |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 27 | /** @brief Gets exactly one node based on `path` starting from `start`. Uses findXPath, so it works even with lists with |
| 28 | * missing predicates. |
Václav Kubernát | cbdc98a | 2021-01-28 13:24:37 +0100 | [diff] [blame] | 29 | * |
Tomáš Pecka | fd90efb | 2021-10-07 10:40:44 +0200 | [diff] [blame] | 30 | * Throws if there is more than one matching node. Returns std::nullopt if no node matches. |
Václav Kubernát | cbdc98a | 2021-01-28 13:24:37 +0100 | [diff] [blame] | 31 | */ |
Jan Kundrát | b3e9998 | 2022-03-18 17:38:20 +0100 | [diff] [blame] | 32 | std::optional<libyang::DataNode> getUniqueSubtree(const libyang::DataNode& start, const std::string& path); |
Tomáš Pecka | fd5ebd3 | 2021-10-07 09:48:13 +0200 | [diff] [blame] | 33 | } |