Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2020 CESNET, https://photonics.cesnet.cz/ |
| 3 | * |
| 4 | * Written by Václav Kubernát <kubernat@cesnet.cz> |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | #include <experimental/iterator> |
| 9 | #include "parser.hpp" |
Václav Kubernát | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 10 | #include "utils.hpp" |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 11 | namespace std { |
| 12 | std::ostream& operator<<(std::ostream& s, const Completions& completion) |
| 13 | { |
| 14 | s << std::endl << "Completions {" << std::endl << " m_completions: "; |
| 15 | std::transform(completion.m_completions.begin(), completion.m_completions.end(), |
| 16 | std::experimental::make_ostream_joiner(s, ", "), |
| 17 | [] (auto it) { return '"' + it + '"'; }); |
| 18 | s << std::endl << " m_contextLength: " << completion.m_contextLength << std::endl; |
| 19 | s << "}" << std::endl; |
| 20 | return s; |
| 21 | } |
Václav Kubernát | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 22 | |
| 23 | std::ostream& operator<<(std::ostream& s, const std::optional<std::string>& opt) |
| 24 | { |
| 25 | s << (opt ? *opt : "std::nullopt"); |
| 26 | return s; |
| 27 | } |
| 28 | |
Václav Kubernát | bf65dd7 | 2020-05-28 02:32:31 +0200 | [diff] [blame] | 29 | std::ostream& operator<<(std::ostream& s, const ListInstance& map) |
Václav Kubernát | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 30 | { |
| 31 | s << std::endl |
| 32 | << "{"; |
| 33 | for (const auto& it : map) { |
| 34 | s << "{\"" << it.first << "\", " << leafDataToString(it.second) << "}" << std::endl; |
| 35 | } |
| 36 | s << "}" << std::endl; |
| 37 | return s; |
| 38 | } |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 39 | |
Václav Kubernát | bf65dd7 | 2020-05-28 02:32:31 +0200 | [diff] [blame] | 40 | std::ostream& operator<<(std::ostream& s, const DatastoreAccess::Tree& tree) |
| 41 | { |
| 42 | s << "DatastoreAccess::Tree {\n"; |
| 43 | for (const auto& [xpath, value] : tree) { |
| 44 | s << " {" << xpath << ", " << leafDataToString(value) << "}\n"; |
| 45 | } |
| 46 | s << "}\n"; |
| 47 | return s; |
| 48 | } |
| 49 | |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 50 | std::ostream& operator<<(std::ostream& s, const yang::LeafDataType& type) |
| 51 | { |
| 52 | s << std::endl |
| 53 | << leafDataTypeToString(type); |
| 54 | if (std::holds_alternative<yang::Enum>(type)) { |
| 55 | s << "{"; |
| 56 | auto values = std::get<yang::Enum>(type).m_allowedValues; |
| 57 | std::transform(values.begin(), values.end(), std::experimental::make_ostream_joiner(s, ", "), [](const auto& value) { |
| 58 | return value.m_value; |
| 59 | }); |
| 60 | s << "}"; |
| 61 | } |
| 62 | if (std::holds_alternative<yang::IdentityRef>(type)) { |
| 63 | s << "{"; |
| 64 | auto values = std::get<yang::IdentityRef>(type).m_allowedValues; |
| 65 | std::transform(values.begin(), values.end(), std::experimental::make_ostream_joiner(s, ", "), [](const auto& value) { |
| 66 | std::string res; |
| 67 | if (value.m_prefix) { |
| 68 | res += value.m_prefix->m_name; |
| 69 | res += ":"; |
| 70 | } |
| 71 | res += value.m_value; |
| 72 | return res; |
| 73 | }); |
| 74 | s << "}"; |
| 75 | } |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 76 | if (std::holds_alternative<yang::LeafRef>(type)) { |
Václav Kubernát | 13b23d7 | 2020-04-16 21:49:51 +0200 | [diff] [blame] | 77 | s << "{" << std::get<yang::LeafRef>(type).m_targetXPath << "," << std::get<yang::LeafRef>(type).m_targetType->m_type << "}"; |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 78 | } |
| 79 | if (std::holds_alternative<yang::Union>(type)) { |
| 80 | s << "{" << std::endl; |
| 81 | auto types = std::get<yang::Union>(type).m_unionTypes; |
Václav Kubernát | 13b23d7 | 2020-04-16 21:49:51 +0200 | [diff] [blame] | 82 | std::transform(types.begin(), types.end(), std::experimental::make_ostream_joiner(s, ",\n"), [] (const auto& type) { |
| 83 | return type.m_type; |
| 84 | }); |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 85 | } |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 86 | s << std::endl; |
| 87 | return s; |
| 88 | } |
Václav Kubernát | 13b23d7 | 2020-04-16 21:49:51 +0200 | [diff] [blame] | 89 | |
| 90 | std::ostream& operator<<(std::ostream& s, const yang::TypeInfo& type) |
| 91 | { |
| 92 | s << type.m_type << (type.m_units ? " units: " + *type.m_units : ""); |
| 93 | return s; |
| 94 | } |
Václav Kubernát | 8208687 | 2020-04-29 01:09:50 +0200 | [diff] [blame] | 95 | |
| 96 | std::ostream& operator<<(std::ostream& s, const boost::optional<std::string>& opt) |
| 97 | { |
| 98 | s << (opt ? *opt : "std::nullopt"); |
| 99 | return s; |
| 100 | } |
Václav Kubernát | d9fa27c | 2020-05-06 00:48:01 +0200 | [diff] [blame] | 101 | |
| 102 | std::ostream& operator<<(std::ostream& s, const std::set<ModuleNodePair>& set) |
| 103 | { |
| 104 | std::transform(set.begin(), set.end(), |
| 105 | std::experimental::make_ostream_joiner(s, ", "), |
| 106 | [] (const ModuleNodePair& it) { return (it.first ? *it.first + ":" : "") + it.second; }); |
| 107 | return s; |
| 108 | } |
| 109 | |
Václav Kubernát | 8208687 | 2020-04-29 01:09:50 +0200 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | std::ostream& operator<<(std::ostream& s, const boost::variant<dataPath_, schemaPath_, module_>& path) |
| 113 | { |
| 114 | if (path.type() == typeid(module_)) { |
| 115 | s << "module: " << boost::get<module_>(path).m_name << "\n"; |
| 116 | } else if (path.type() == typeid(dataPath_)) { |
| 117 | s << "dataPath: " << pathToDataString(boost::get<dataPath_>(path), Prefixes::WhenNeeded) << "\n"; |
| 118 | } else { |
| 119 | s << "schemaPath: " << pathToSchemaString(boost::get<schemaPath_>(path), Prefixes::WhenNeeded) << "\n"; |
| 120 | } |
| 121 | return s; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 122 | } |
Václav Kubernát | 4a58ce6 | 2020-05-14 17:58:10 +0200 | [diff] [blame] | 123 | |
| 124 | std::ostream& operator<<(std::ostream& s, const boost::optional<boost::variant<dataPath_, schemaPath_, module_>>& path) |
| 125 | { |
| 126 | if (path) { |
| 127 | s << *path; |
| 128 | } else { |
| 129 | s << "boost::none"; |
| 130 | } |
| 131 | |
| 132 | return s; |
| 133 | } |
| 134 | |
Václav Kubernát | 1bcee3b | 2020-05-28 22:19:59 +0200 | [diff] [blame] | 135 | std::ostream& operator<<(std::ostream& s, const create_& create) |
| 136 | { |
| 137 | s << "\nls_ {\n " << create.m_path << "}\n"; |
| 138 | return s; |
| 139 | } |
Václav Kubernát | 4a58ce6 | 2020-05-14 17:58:10 +0200 | [diff] [blame] | 140 | |
| 141 | std::ostream& operator<<(std::ostream& s, const ls_& ls) |
| 142 | { |
| 143 | s << "\nls_ {\n " << ls.m_path << "}\n"; |
| 144 | return s; |
| 145 | } |
Václav Kubernát | bf65dd7 | 2020-05-28 02:32:31 +0200 | [diff] [blame] | 146 | |
| 147 | std::ostream& operator<<(std::ostream& s, const move_& move) |
| 148 | { |
| 149 | s << "\nmove_ {\n"; |
| 150 | s << " path: " << move.m_source; |
| 151 | s << " mode: "; |
| 152 | if (std::holds_alternative<yang::move::Absolute>(move.m_destination)) { |
| 153 | if (std::get<yang::move::Absolute>(move.m_destination) == yang::move::Absolute::Begin) { |
| 154 | s << "Absolute::Begin"; |
| 155 | } else { |
| 156 | s << "Absolute::End"; |
| 157 | } |
| 158 | } else { |
| 159 | const yang::move::Relative& relative = std::get<yang::move::Relative>(move.m_destination); |
| 160 | s << "Relative {\n"; |
| 161 | s << " position: "; |
| 162 | if (relative.m_position == yang::move::Relative::Position::After) { |
| 163 | s << "Position::After\n"; |
| 164 | } else { |
| 165 | s << "Position::Before\n"; |
| 166 | } |
| 167 | s << " path: "; |
| 168 | s << relative.m_path; |
| 169 | } |
| 170 | s << "\n}\n"; |
| 171 | return s; |
| 172 | } |