Václav Kubernát | 94938b7 | 2018-05-04 15:12:24 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 CESNET, https://photonics.cesnet.cz/ |
| 3 | * Copyright (C) 2018 FIT CVUT, https://fit.cvut.cz/ |
| 4 | * |
| 5 | * Written by Václav Kubernát <kubervac@fit.cvut.cz> |
| 6 | * |
| 7 | */ |
| 8 | #include "utils.hpp" |
| 9 | |
| 10 | std::string joinPaths(const std::string& prefix, const std::string& suffix) |
| 11 | { |
Václav Kubernát | 50949e6 | 2018-08-30 12:50:08 +0200 | [diff] [blame] | 12 | if (prefix.empty() || suffix.empty() || prefix == "/") |
Václav Kubernát | 94938b7 | 2018-05-04 15:12:24 +0200 | [diff] [blame] | 13 | return prefix + suffix; |
| 14 | else |
| 15 | return prefix + '/' + suffix; |
| 16 | } |
Václav Kubernát | 60d6f29 | 2018-05-25 09:45:32 +0200 | [diff] [blame] | 17 | |
| 18 | std::string stripLastNodeFromPath(const std::string& path) |
| 19 | { |
| 20 | std::string res = path; |
| 21 | auto pos = res.find_last_of('/'); |
| 22 | if (pos == res.npos) |
| 23 | res.clear(); |
| 24 | else |
| 25 | res.erase(pos); |
| 26 | return res; |
| 27 | } |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 28 | |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame^] | 29 | schemaPath_ pathWithoutLastNode(const schemaPath_& path) |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 30 | { |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame^] | 31 | return schemaPath_{path.m_scope, decltype(schemaPath_::m_nodes)(path.m_nodes.begin(), path.m_nodes.end() - 1)}; |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 32 | } |
Václav Kubernát | 0b0272f | 2018-06-13 14:13:08 +0200 | [diff] [blame] | 33 | |
| 34 | std::string leafDataTypeToString(yang::LeafDataTypes type) |
| 35 | { |
| 36 | switch (type) { |
| 37 | case yang::LeafDataTypes::String: |
| 38 | return "a string"; |
| 39 | case yang::LeafDataTypes::Decimal: |
| 40 | return "a decimal"; |
| 41 | case yang::LeafDataTypes::Bool: |
| 42 | return "a boolean"; |
| 43 | case yang::LeafDataTypes::Int: |
| 44 | return "an integer"; |
| 45 | case yang::LeafDataTypes::Uint: |
| 46 | return "an unsigned integer"; |
| 47 | case yang::LeafDataTypes::Enum: |
| 48 | return "an enum"; |
| 49 | default: |
| 50 | return ""; |
| 51 | } |
| 52 | } |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 53 | |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame^] | 54 | std::string fullNodeName(const schemaPath_& location, const ModuleNodePair& pair) |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 55 | { |
| 56 | if (!pair.first) { |
| 57 | return location.m_nodes.at(0).m_prefix.value().m_name + ":" + pair.second; |
| 58 | } else { |
| 59 | return pair.first.value() + ":" + pair.second; |
| 60 | } |
| 61 | } |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame^] | 62 | |
| 63 | std::string fullNodeName(const dataPath_& location, const ModuleNodePair& pair) |
| 64 | { |
| 65 | return fullNodeName(dataPathToSchemaPath(location), pair); |
| 66 | } |