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 | { |
| 99 | s << type.m_type << (type.m_units ? " units: " + *type.m_units : ""); |
| 100 | return s; |
| 101 | } |
Václav Kubernát | 8208687 | 2020-04-29 01:09:50 +0200 | [diff] [blame] | 102 | |
| 103 | std::ostream& operator<<(std::ostream& s, const boost::optional<std::string>& opt) |
| 104 | { |
| 105 | s << (opt ? *opt : "std::nullopt"); |
| 106 | return s; |
| 107 | } |
Václav Kubernát | d9fa27c | 2020-05-06 00:48:01 +0200 | [diff] [blame] | 108 | |
| 109 | std::ostream& operator<<(std::ostream& s, const std::set<ModuleNodePair>& set) |
| 110 | { |
| 111 | std::transform(set.begin(), set.end(), |
| 112 | std::experimental::make_ostream_joiner(s, ", "), |
| 113 | [] (const ModuleNodePair& it) { return (it.first ? *it.first + ":" : "") + it.second; }); |
| 114 | return s; |
| 115 | } |
| 116 | |
Václav Kubernát | ed824d0 | 2020-06-09 15:48:30 +0200 | [diff] [blame] | 117 | std::ostream& operator<<(std::ostream& s, const std::set<std::string> set) |
| 118 | { |
Václav Kubernát | b4e5b18 | 2020-11-16 19:55:09 +0100 | [diff] [blame] | 119 | s << std::endl |
| 120 | << "{"; |
Václav Kubernát | ed824d0 | 2020-06-09 15:48:30 +0200 | [diff] [blame] | 121 | std::copy(set.begin(), set.end(), std::experimental::make_ostream_joiner(s, ", ")); |
| 122 | s << "}" << std::endl; |
| 123 | return s; |
| 124 | } |
| 125 | |
| 126 | std::ostream& operator<<(std::ostream& s, const std::vector<ListInstance> set) |
| 127 | { |
Václav Kubernát | b4e5b18 | 2020-11-16 19:55:09 +0100 | [diff] [blame] | 128 | s << std::endl |
| 129 | << "{" << std::endl; |
Václav Kubernát | ed824d0 | 2020-06-09 15:48:30 +0200 | [diff] [blame] | 130 | std::transform(set.begin(), set.end(), std::experimental::make_ostream_joiner(s, ", \n"), [](const auto& map) { |
| 131 | std::ostringstream ss; |
Václav Kubernát | b4e5b18 | 2020-11-16 19:55:09 +0100 | [diff] [blame] | 132 | ss << " {" << std::endl |
| 133 | << " "; |
| 134 | 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] | 135 | return "{" + keyValue.first + "{" + boost::core::demangle(keyValue.second.type().name()) + "}" + ", " + leafDataToString(keyValue.second) + "}"; |
| 136 | }); |
Václav Kubernát | b4e5b18 | 2020-11-16 19:55:09 +0100 | [diff] [blame] | 137 | ss << std::endl |
| 138 | << " }"; |
Václav Kubernát | ed824d0 | 2020-06-09 15:48:30 +0200 | [diff] [blame] | 139 | return ss.str(); |
| 140 | }); |
Václav Kubernát | b4e5b18 | 2020-11-16 19:55:09 +0100 | [diff] [blame] | 141 | s << std::endl |
| 142 | << "}" << std::endl; |
Václav Kubernát | ed824d0 | 2020-06-09 15:48:30 +0200 | [diff] [blame] | 143 | return s; |
| 144 | } |
Václav Kubernát | 8208687 | 2020-04-29 01:09:50 +0200 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | std::ostream& operator<<(std::ostream& s, const boost::variant<dataPath_, schemaPath_, module_>& path) |
| 148 | { |
| 149 | if (path.type() == typeid(module_)) { |
| 150 | s << "module: " << boost::get<module_>(path).m_name << "\n"; |
| 151 | } else if (path.type() == typeid(dataPath_)) { |
| 152 | s << "dataPath: " << pathToDataString(boost::get<dataPath_>(path), Prefixes::WhenNeeded) << "\n"; |
| 153 | } else { |
| 154 | s << "schemaPath: " << pathToSchemaString(boost::get<schemaPath_>(path), Prefixes::WhenNeeded) << "\n"; |
| 155 | } |
| 156 | return s; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 157 | } |
Václav Kubernát | 4a58ce6 | 2020-05-14 17:58:10 +0200 | [diff] [blame] | 158 | |
| 159 | std::ostream& operator<<(std::ostream& s, const boost::optional<boost::variant<dataPath_, schemaPath_, module_>>& path) |
| 160 | { |
| 161 | if (path) { |
| 162 | s << *path; |
| 163 | } else { |
| 164 | s << "boost::none"; |
| 165 | } |
| 166 | |
| 167 | return s; |
| 168 | } |
| 169 | |
Václav Kubernát | 1bcee3b | 2020-05-28 22:19:59 +0200 | [diff] [blame] | 170 | std::ostream& operator<<(std::ostream& s, const create_& create) |
| 171 | { |
| 172 | s << "\nls_ {\n " << create.m_path << "}\n"; |
| 173 | return s; |
| 174 | } |
Václav Kubernát | 4a58ce6 | 2020-05-14 17:58:10 +0200 | [diff] [blame] | 175 | |
| 176 | std::ostream& operator<<(std::ostream& s, const ls_& ls) |
| 177 | { |
| 178 | s << "\nls_ {\n " << ls.m_path << "}\n"; |
| 179 | return s; |
| 180 | } |
Václav Kubernát | bf65dd7 | 2020-05-28 02:32:31 +0200 | [diff] [blame] | 181 | |
| 182 | std::ostream& operator<<(std::ostream& s, const move_& move) |
| 183 | { |
| 184 | s << "\nmove_ {\n"; |
| 185 | s << " path: " << move.m_source; |
| 186 | s << " mode: "; |
| 187 | if (std::holds_alternative<yang::move::Absolute>(move.m_destination)) { |
| 188 | if (std::get<yang::move::Absolute>(move.m_destination) == yang::move::Absolute::Begin) { |
| 189 | s << "Absolute::Begin"; |
| 190 | } else { |
| 191 | s << "Absolute::End"; |
| 192 | } |
| 193 | } else { |
Václav Kubernát | 742e11c | 2020-07-08 17:19:07 +0200 | [diff] [blame] | 194 | 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] | 195 | s << "Relative {\n"; |
| 196 | s << " position: "; |
| 197 | if (relative.m_position == yang::move::Relative::Position::After) { |
| 198 | s << "Position::After\n"; |
| 199 | } else { |
| 200 | s << "Position::Before\n"; |
| 201 | } |
| 202 | s << " path: "; |
| 203 | s << relative.m_path; |
| 204 | } |
| 205 | s << "\n}\n"; |
| 206 | return s; |
| 207 | } |
Václav Kubernát | ed824d0 | 2020-06-09 15:48:30 +0200 | [diff] [blame] | 208 | |
| 209 | std::ostream& operator<<(std::ostream& s, const set_ cmd) |
| 210 | { |
| 211 | 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) << "}"; |
| 212 | } |
Václav Kubernát | 3d787b1 | 2020-10-29 09:11:26 +0100 | [diff] [blame] | 213 | |
| 214 | std::ostream& operator<<(std::ostream& s, const prepare_ cmd) |
| 215 | { |
| 216 | return s << "Command PREPARE {path: " << pathToDataString(cmd.m_path, Prefixes::Always) << "}"; |
| 217 | } |