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> |
Václav Kubernát | ed824d0 | 2020-06-09 15:48:30 +0200 | [diff] [blame] | 9 | #include <sstream> |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 10 | #include "parser.hpp" |
Václav Kubernát | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 11 | #include "utils.hpp" |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 12 | namespace std { |
Václav Kubernát | 2e4cafe | 2020-11-05 01:53:21 +0100 | [diff] [blame] | 13 | std::ostream& operator<<(std::ostream& s, const leaf_data_& value) |
| 14 | { |
Václav Kubernát | b4e5b18 | 2020-11-16 19:55:09 +0100 | [diff] [blame] | 15 | s << "leaf_data_<" << boost::core::demangle(value.type().name()) << ">{" << leafDataToString(value) << "}" << std::endl; |
Václav Kubernát | 2e4cafe | 2020-11-05 01:53:21 +0100 | [diff] [blame] | 16 | return s; |
| 17 | } |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 18 | std::ostream& operator<<(std::ostream& s, const Completions& completion) |
| 19 | { |
Václav Kubernát | b4e5b18 | 2020-11-16 19:55:09 +0100 | [diff] [blame] | 20 | s << std::endl |
| 21 | << "Completions {" << std::endl |
| 22 | << " m_completions: "; |
| 23 | std::transform(completion.m_completions.begin(), completion.m_completions.end(), std::experimental::make_ostream_joiner(s, ", "), [](auto it) { return '"' + it + '"'; }); |
| 24 | s << std::endl |
| 25 | << " m_contextLength: " << completion.m_contextLength << std::endl; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 26 | s << "}" << std::endl; |
| 27 | return s; |
| 28 | } |
Václav Kubernát | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 29 | |
| 30 | std::ostream& operator<<(std::ostream& s, const std::optional<std::string>& opt) |
| 31 | { |
| 32 | s << (opt ? *opt : "std::nullopt"); |
| 33 | return s; |
| 34 | } |
| 35 | |
Václav Kubernát | bf65dd7 | 2020-05-28 02:32:31 +0200 | [diff] [blame] | 36 | std::ostream& operator<<(std::ostream& s, const ListInstance& map) |
Václav Kubernát | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 37 | { |
| 38 | s << std::endl |
| 39 | << "{"; |
| 40 | for (const auto& it : map) { |
| 41 | s << "{\"" << it.first << "\", " << leafDataToString(it.second) << "}" << std::endl; |
| 42 | } |
| 43 | s << "}" << std::endl; |
| 44 | return s; |
| 45 | } |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 46 | |
Václav Kubernát | bf65dd7 | 2020-05-28 02:32:31 +0200 | [diff] [blame] | 47 | std::ostream& operator<<(std::ostream& s, const DatastoreAccess::Tree& tree) |
| 48 | { |
| 49 | s << "DatastoreAccess::Tree {\n"; |
| 50 | for (const auto& [xpath, value] : tree) { |
Václav Kubernát | 19097f3 | 2020-10-05 10:08:29 +0200 | [diff] [blame] | 51 | s << " {" << xpath << ", " << boost::core::demangle(value.type().name()) << "{" << leafDataToString(value) << "}},\n"; |
Václav Kubernát | bf65dd7 | 2020-05-28 02:32:31 +0200 | [diff] [blame] | 52 | } |
| 53 | s << "}\n"; |
| 54 | return s; |
| 55 | } |
| 56 | |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 57 | std::ostream& operator<<(std::ostream& s, const yang::LeafDataType& type) |
| 58 | { |
| 59 | s << std::endl |
| 60 | << leafDataTypeToString(type); |
| 61 | if (std::holds_alternative<yang::Enum>(type)) { |
| 62 | s << "{"; |
| 63 | auto values = std::get<yang::Enum>(type).m_allowedValues; |
| 64 | std::transform(values.begin(), values.end(), std::experimental::make_ostream_joiner(s, ", "), [](const auto& value) { |
| 65 | return value.m_value; |
| 66 | }); |
| 67 | s << "}"; |
| 68 | } |
| 69 | if (std::holds_alternative<yang::IdentityRef>(type)) { |
| 70 | s << "{"; |
| 71 | auto values = std::get<yang::IdentityRef>(type).m_allowedValues; |
| 72 | std::transform(values.begin(), values.end(), std::experimental::make_ostream_joiner(s, ", "), [](const auto& value) { |
| 73 | std::string res; |
| 74 | if (value.m_prefix) { |
| 75 | res += value.m_prefix->m_name; |
| 76 | res += ":"; |
| 77 | } |
| 78 | res += value.m_value; |
| 79 | return res; |
| 80 | }); |
| 81 | s << "}"; |
| 82 | } |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 83 | if (std::holds_alternative<yang::LeafRef>(type)) { |
Václav Kubernát | b4e5b18 | 2020-11-16 19:55:09 +0100 | [diff] [blame] | 84 | 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] | 85 | } |
| 86 | if (std::holds_alternative<yang::Union>(type)) { |
| 87 | s << "{" << std::endl; |
| 88 | auto types = std::get<yang::Union>(type).m_unionTypes; |
Václav Kubernát | b4e5b18 | 2020-11-16 19:55:09 +0100 | [diff] [blame] | 89 | std::transform(types.begin(), types.end(), std::experimental::make_ostream_joiner(s, ",\n"), [](const auto& type) { |
Václav Kubernát | 13b23d7 | 2020-04-16 21:49:51 +0200 | [diff] [blame] | 90 | return type.m_type; |
| 91 | }); |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 92 | } |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 93 | s << std::endl; |
| 94 | return s; |
| 95 | } |
Václav Kubernát | 13b23d7 | 2020-04-16 21:49:51 +0200 | [diff] [blame] | 96 | |
| 97 | std::ostream& operator<<(std::ostream& s, const yang::TypeInfo& type) |
| 98 | { |
Václav Kubernát | 1ae24f4 | 2020-12-01 02:32:04 +0100 | [diff] [blame] | 99 | s << type.m_type; |
| 100 | s << " units: " << (type.m_units ? *type.m_units : "std::nullopt"); |
| 101 | s << " description: " << (type.m_description ? *type.m_description : "std::nullopt"); |
Václav Kubernát | 13b23d7 | 2020-04-16 21:49:51 +0200 | [diff] [blame] | 102 | return s; |
| 103 | } |
Václav Kubernát | 8208687 | 2020-04-29 01:09:50 +0200 | [diff] [blame] | 104 | |
| 105 | std::ostream& operator<<(std::ostream& s, const boost::optional<std::string>& opt) |
| 106 | { |
| 107 | s << (opt ? *opt : "std::nullopt"); |
| 108 | return s; |
| 109 | } |
Václav Kubernát | d9fa27c | 2020-05-06 00:48:01 +0200 | [diff] [blame] | 110 | |
| 111 | std::ostream& operator<<(std::ostream& s, const std::set<ModuleNodePair>& set) |
| 112 | { |
| 113 | std::transform(set.begin(), set.end(), |
| 114 | std::experimental::make_ostream_joiner(s, ", "), |
| 115 | [] (const ModuleNodePair& it) { return (it.first ? *it.first + ":" : "") + it.second; }); |
| 116 | return s; |
| 117 | } |
| 118 | |
Václav Kubernát | ed824d0 | 2020-06-09 15:48:30 +0200 | [diff] [blame] | 119 | std::ostream& operator<<(std::ostream& s, const std::set<std::string> set) |
| 120 | { |
Václav Kubernát | b4e5b18 | 2020-11-16 19:55:09 +0100 | [diff] [blame] | 121 | s << std::endl |
| 122 | << "{"; |
Václav Kubernát | ed824d0 | 2020-06-09 15:48:30 +0200 | [diff] [blame] | 123 | std::copy(set.begin(), set.end(), std::experimental::make_ostream_joiner(s, ", ")); |
| 124 | s << "}" << std::endl; |
| 125 | return s; |
| 126 | } |
| 127 | |
| 128 | std::ostream& operator<<(std::ostream& s, const std::vector<ListInstance> set) |
| 129 | { |
Václav Kubernát | b4e5b18 | 2020-11-16 19:55:09 +0100 | [diff] [blame] | 130 | s << std::endl |
| 131 | << "{" << std::endl; |
Václav Kubernát | ed824d0 | 2020-06-09 15:48:30 +0200 | [diff] [blame] | 132 | std::transform(set.begin(), set.end(), std::experimental::make_ostream_joiner(s, ", \n"), [](const auto& map) { |
| 133 | std::ostringstream ss; |
Václav Kubernát | b4e5b18 | 2020-11-16 19:55:09 +0100 | [diff] [blame] | 134 | ss << " {" << std::endl |
| 135 | << " "; |
| 136 | std::transform(map.begin(), map.end(), std::experimental::make_ostream_joiner(ss, ", \n "), [](const auto& keyValue) { |
Václav Kubernát | ed824d0 | 2020-06-09 15:48:30 +0200 | [diff] [blame] | 137 | return "{" + keyValue.first + "{" + boost::core::demangle(keyValue.second.type().name()) + "}" + ", " + leafDataToString(keyValue.second) + "}"; |
| 138 | }); |
Václav Kubernát | b4e5b18 | 2020-11-16 19:55:09 +0100 | [diff] [blame] | 139 | ss << std::endl |
| 140 | << " }"; |
Václav Kubernát | ed824d0 | 2020-06-09 15:48:30 +0200 | [diff] [blame] | 141 | return ss.str(); |
| 142 | }); |
Václav Kubernát | b4e5b18 | 2020-11-16 19:55:09 +0100 | [diff] [blame] | 143 | s << std::endl |
| 144 | << "}" << std::endl; |
Václav Kubernát | ed824d0 | 2020-06-09 15:48:30 +0200 | [diff] [blame] | 145 | return s; |
| 146 | } |
Václav Kubernát | 8208687 | 2020-04-29 01:09:50 +0200 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | std::ostream& operator<<(std::ostream& s, const boost::variant<dataPath_, schemaPath_, module_>& path) |
| 150 | { |
| 151 | if (path.type() == typeid(module_)) { |
| 152 | s << "module: " << boost::get<module_>(path).m_name << "\n"; |
| 153 | } else if (path.type() == typeid(dataPath_)) { |
| 154 | s << "dataPath: " << pathToDataString(boost::get<dataPath_>(path), Prefixes::WhenNeeded) << "\n"; |
| 155 | } else { |
| 156 | s << "schemaPath: " << pathToSchemaString(boost::get<schemaPath_>(path), Prefixes::WhenNeeded) << "\n"; |
| 157 | } |
| 158 | return s; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 159 | } |
Václav Kubernát | 4a58ce6 | 2020-05-14 17:58:10 +0200 | [diff] [blame] | 160 | |
| 161 | std::ostream& operator<<(std::ostream& s, const boost::optional<boost::variant<dataPath_, schemaPath_, module_>>& path) |
| 162 | { |
| 163 | if (path) { |
| 164 | s << *path; |
| 165 | } else { |
| 166 | s << "boost::none"; |
| 167 | } |
| 168 | |
| 169 | return s; |
| 170 | } |
| 171 | |
Václav Kubernát | 1bcee3b | 2020-05-28 22:19:59 +0200 | [diff] [blame] | 172 | std::ostream& operator<<(std::ostream& s, const create_& create) |
| 173 | { |
| 174 | s << "\nls_ {\n " << create.m_path << "}\n"; |
| 175 | return s; |
| 176 | } |
Václav Kubernát | 4a58ce6 | 2020-05-14 17:58:10 +0200 | [diff] [blame] | 177 | |
| 178 | std::ostream& operator<<(std::ostream& s, const ls_& ls) |
| 179 | { |
| 180 | s << "\nls_ {\n " << ls.m_path << "}\n"; |
| 181 | return s; |
| 182 | } |
Václav Kubernát | bf65dd7 | 2020-05-28 02:32:31 +0200 | [diff] [blame] | 183 | |
Václav Kubernát | ce108db | 2021-01-25 10:05:40 +0100 | [diff] [blame] | 184 | std::ostream& operator<<(std::ostream& s, const cd_& cd) |
| 185 | { |
| 186 | s << "\ncd_ {\n " << cd.m_path << "}\n"; |
| 187 | return s; |
| 188 | } |
| 189 | |
Václav Kubernát | bf65dd7 | 2020-05-28 02:32:31 +0200 | [diff] [blame] | 190 | std::ostream& operator<<(std::ostream& s, const move_& move) |
| 191 | { |
| 192 | s << "\nmove_ {\n"; |
| 193 | s << " path: " << move.m_source; |
| 194 | s << " mode: "; |
| 195 | if (std::holds_alternative<yang::move::Absolute>(move.m_destination)) { |
| 196 | if (std::get<yang::move::Absolute>(move.m_destination) == yang::move::Absolute::Begin) { |
| 197 | s << "Absolute::Begin"; |
| 198 | } else { |
| 199 | s << "Absolute::End"; |
| 200 | } |
| 201 | } else { |
Václav Kubernát | 742e11c | 2020-07-08 17:19:07 +0200 | [diff] [blame] | 202 | const auto& relative = std::get<yang::move::Relative>(move.m_destination); |
Václav Kubernát | bf65dd7 | 2020-05-28 02:32:31 +0200 | [diff] [blame] | 203 | s << "Relative {\n"; |
| 204 | s << " position: "; |
| 205 | if (relative.m_position == yang::move::Relative::Position::After) { |
| 206 | s << "Position::After\n"; |
| 207 | } else { |
| 208 | s << "Position::Before\n"; |
| 209 | } |
| 210 | s << " path: "; |
| 211 | s << relative.m_path; |
| 212 | } |
| 213 | s << "\n}\n"; |
| 214 | return s; |
| 215 | } |
Václav Kubernát | ed824d0 | 2020-06-09 15:48:30 +0200 | [diff] [blame] | 216 | |
| 217 | std::ostream& operator<<(std::ostream& s, const set_ cmd) |
| 218 | { |
| 219 | return s << "Command SET {path: " << pathToSchemaString(cmd.m_path, Prefixes::Always) << ", type " << boost::core::demangle(cmd.m_data.type().name()) << ", data: " << leafDataToString(cmd.m_data) << "}"; |
| 220 | } |
Václav Kubernát | 3d787b1 | 2020-10-29 09:11:26 +0100 | [diff] [blame] | 221 | |
| 222 | std::ostream& operator<<(std::ostream& s, const prepare_ cmd) |
| 223 | { |
| 224 | return s << "Command PREPARE {path: " << pathToDataString(cmd.m_path, Prefixes::Always) << "}"; |
| 225 | } |