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 | |
| 29 | std::ostream& operator<<(std::ostream& s, const DatastoreAccess::Tree& map) |
| 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 | |
| 40 | std::ostream& operator<<(std::ostream& s, const yang::LeafDataType& type) |
| 41 | { |
| 42 | s << std::endl |
| 43 | << leafDataTypeToString(type); |
| 44 | if (std::holds_alternative<yang::Enum>(type)) { |
| 45 | s << "{"; |
| 46 | auto values = std::get<yang::Enum>(type).m_allowedValues; |
| 47 | std::transform(values.begin(), values.end(), std::experimental::make_ostream_joiner(s, ", "), [](const auto& value) { |
| 48 | return value.m_value; |
| 49 | }); |
| 50 | s << "}"; |
| 51 | } |
| 52 | if (std::holds_alternative<yang::IdentityRef>(type)) { |
| 53 | s << "{"; |
| 54 | auto values = std::get<yang::IdentityRef>(type).m_allowedValues; |
| 55 | std::transform(values.begin(), values.end(), std::experimental::make_ostream_joiner(s, ", "), [](const auto& value) { |
| 56 | std::string res; |
| 57 | if (value.m_prefix) { |
| 58 | res += value.m_prefix->m_name; |
| 59 | res += ":"; |
| 60 | } |
| 61 | res += value.m_value; |
| 62 | return res; |
| 63 | }); |
| 64 | s << "}"; |
| 65 | } |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 66 | if (std::holds_alternative<yang::LeafRef>(type)) { |
Václav Kubernát | 13b23d7 | 2020-04-16 21:49:51 +0200 | [diff] [blame] | 67 | 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] | 68 | } |
| 69 | if (std::holds_alternative<yang::Union>(type)) { |
| 70 | s << "{" << std::endl; |
| 71 | auto types = std::get<yang::Union>(type).m_unionTypes; |
Václav Kubernát | 13b23d7 | 2020-04-16 21:49:51 +0200 | [diff] [blame] | 72 | std::transform(types.begin(), types.end(), std::experimental::make_ostream_joiner(s, ",\n"), [] (const auto& type) { |
| 73 | return type.m_type; |
| 74 | }); |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 75 | } |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 76 | s << std::endl; |
| 77 | return s; |
| 78 | } |
Václav Kubernát | 13b23d7 | 2020-04-16 21:49:51 +0200 | [diff] [blame] | 79 | |
| 80 | std::ostream& operator<<(std::ostream& s, const yang::TypeInfo& type) |
| 81 | { |
| 82 | s << type.m_type << (type.m_units ? " units: " + *type.m_units : ""); |
| 83 | return s; |
| 84 | } |
Václav Kubernát | 8208687 | 2020-04-29 01:09:50 +0200 | [diff] [blame] | 85 | |
| 86 | std::ostream& operator<<(std::ostream& s, const boost::optional<std::string>& opt) |
| 87 | { |
| 88 | s << (opt ? *opt : "std::nullopt"); |
| 89 | return s; |
| 90 | } |
Václav Kubernát | d9fa27c | 2020-05-06 00:48:01 +0200 | [diff] [blame] | 91 | |
| 92 | std::ostream& operator<<(std::ostream& s, const std::set<ModuleNodePair>& set) |
| 93 | { |
| 94 | std::transform(set.begin(), set.end(), |
| 95 | std::experimental::make_ostream_joiner(s, ", "), |
| 96 | [] (const ModuleNodePair& it) { return (it.first ? *it.first + ":" : "") + it.second; }); |
| 97 | return s; |
| 98 | } |
| 99 | |
Václav Kubernát | 8208687 | 2020-04-29 01:09:50 +0200 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | std::ostream& operator<<(std::ostream& s, const boost::variant<dataPath_, schemaPath_, module_>& path) |
| 103 | { |
| 104 | if (path.type() == typeid(module_)) { |
| 105 | s << "module: " << boost::get<module_>(path).m_name << "\n"; |
| 106 | } else if (path.type() == typeid(dataPath_)) { |
| 107 | s << "dataPath: " << pathToDataString(boost::get<dataPath_>(path), Prefixes::WhenNeeded) << "\n"; |
| 108 | } else { |
| 109 | s << "schemaPath: " << pathToSchemaString(boost::get<schemaPath_>(path), Prefixes::WhenNeeded) << "\n"; |
| 110 | } |
| 111 | return s; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 112 | } |
Václav Kubernát | 4a58ce6 | 2020-05-14 17:58:10 +0200 | [diff] [blame] | 113 | |
| 114 | std::ostream& operator<<(std::ostream& s, const boost::optional<boost::variant<dataPath_, schemaPath_, module_>>& path) |
| 115 | { |
| 116 | if (path) { |
| 117 | s << *path; |
| 118 | } else { |
| 119 | s << "boost::none"; |
| 120 | } |
| 121 | |
| 122 | return s; |
| 123 | } |
| 124 | |
| 125 | |
| 126 | std::ostream& operator<<(std::ostream& s, const ls_& ls) |
| 127 | { |
| 128 | s << "\nls_ {\n " << ls.m_path << "}\n"; |
| 129 | return s; |
| 130 | } |