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