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