blob: d3d67d30a5a6f205884ccf4f864ca1ba1fff109f [file] [log] [blame]
Václav Kubernát1ed4aa32020-01-23 13:13:28 +01001/*
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áted824d02020-06-09 15:48:30 +02009#include <sstream>
Václav Kubernát1ed4aa32020-01-23 13:13:28 +010010#include "parser.hpp"
Václav Kubernát1e09bd62020-02-17 15:13:38 +010011#include "utils.hpp"
Václav Kubernát1ed4aa32020-01-23 13:13:28 +010012namespace std {
Václav Kubernát2e4cafe2020-11-05 01:53:21 +010013std::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át1ed4aa32020-01-23 13:13:28 +010018std::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át1e09bd62020-02-17 15:13:38 +010028
29std::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átbf65dd72020-05-28 02:32:31 +020035std::ostream& operator<<(std::ostream& s, const ListInstance& map)
Václav Kubernát1e09bd62020-02-17 15:13:38 +010036{
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át3a99f002020-03-31 02:27:41 +020045
Václav Kubernátbf65dd72020-05-28 02:32:31 +020046std::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át19097f32020-10-05 10:08:29 +020050 s << " {" << xpath << ", " << boost::core::demangle(value.type().name()) << "{" << leafDataToString(value) << "}},\n";
Václav Kubernátbf65dd72020-05-28 02:32:31 +020051 }
52 s << "}\n";
53 return s;
54}
55
Václav Kubernát3a99f002020-03-31 02:27:41 +020056std::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át2984f442020-02-20 17:43:35 +010082 if (std::holds_alternative<yang::LeafRef>(type)) {
Václav Kubernát13b23d72020-04-16 21:49:51 +020083 s << "{" << std::get<yang::LeafRef>(type).m_targetXPath << "," << std::get<yang::LeafRef>(type).m_targetType->m_type << "}";
Václav Kubernát2984f442020-02-20 17:43:35 +010084 }
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át13b23d72020-04-16 21:49:51 +020088 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át2984f442020-02-20 17:43:35 +010091 }
Václav Kubernát3a99f002020-03-31 02:27:41 +020092 s << std::endl;
93 return s;
94}
Václav Kubernát13b23d72020-04-16 21:49:51 +020095
96std::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át82086872020-04-29 01:09:50 +0200101
102std::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átd9fa27c2020-05-06 00:48:01 +0200107
108std::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áted824d02020-06-09 15:48:30 +0200116std::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
124std::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át82086872020-04-29 01:09:50 +0200139}
140
141std::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át1ed4aa32020-01-23 13:13:28 +0100151}
Václav Kubernát4a58ce62020-05-14 17:58:10 +0200152
153std::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át1bcee3b2020-05-28 22:19:59 +0200164std::ostream& operator<<(std::ostream& s, const create_& create)
165{
166 s << "\nls_ {\n " << create.m_path << "}\n";
167 return s;
168}
Václav Kubernát4a58ce62020-05-14 17:58:10 +0200169
170std::ostream& operator<<(std::ostream& s, const ls_& ls)
171{
172 s << "\nls_ {\n " << ls.m_path << "}\n";
173 return s;
174}
Václav Kubernátbf65dd72020-05-28 02:32:31 +0200175
176std::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át742e11c2020-07-08 17:19:07 +0200188 const auto& relative = std::get<yang::move::Relative>(move.m_destination);
Václav Kubernátbf65dd72020-05-28 02:32:31 +0200189 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áted824d02020-06-09 15:48:30 +0200202
203std::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át3d787b12020-10-29 09:11:26 +0100207
208std::ostream& operator<<(std::ostream& s, const prepare_ cmd)
209{
210 return s << "Command PREPARE {path: " << pathToDataString(cmd.m_path, Prefixes::Always) << "}";
211}