blob: cb9962e9d7eca0f14996fb1931aa05c8aa058999 [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{
Václav Kubernátb4e5b182020-11-16 19:55:09 +010015 s << "leaf_data_<" << boost::core::demangle(value.type().name()) << ">{" << leafDataToString(value) << "}" << std::endl;
Václav Kubernát2e4cafe2020-11-05 01:53:21 +010016 return s;
17}
Václav Kubernát1ed4aa32020-01-23 13:13:28 +010018std::ostream& operator<<(std::ostream& s, const Completions& completion)
19{
Václav Kubernátb4e5b182020-11-16 19:55:09 +010020 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át1ed4aa32020-01-23 13:13:28 +010026 s << "}" << std::endl;
27 return s;
28}
Václav Kubernát1e09bd62020-02-17 15:13:38 +010029
30std::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átbf65dd72020-05-28 02:32:31 +020036std::ostream& operator<<(std::ostream& s, const ListInstance& map)
Václav Kubernát1e09bd62020-02-17 15:13:38 +010037{
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át3a99f002020-03-31 02:27:41 +020046
Václav Kubernátbf65dd72020-05-28 02:32:31 +020047std::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át19097f32020-10-05 10:08:29 +020051 s << " {" << xpath << ", " << boost::core::demangle(value.type().name()) << "{" << leafDataToString(value) << "}},\n";
Václav Kubernátbf65dd72020-05-28 02:32:31 +020052 }
53 s << "}\n";
54 return s;
55}
56
Václav Kubernát3a99f002020-03-31 02:27:41 +020057std::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át2984f442020-02-20 17:43:35 +010083 if (std::holds_alternative<yang::LeafRef>(type)) {
Václav Kubernátb4e5b182020-11-16 19:55:09 +010084 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 +010085 }
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átb4e5b182020-11-16 19:55:09 +010089 std::transform(types.begin(), types.end(), std::experimental::make_ostream_joiner(s, ",\n"), [](const auto& type) {
Václav Kubernát13b23d72020-04-16 21:49:51 +020090 return type.m_type;
91 });
Václav Kubernát2984f442020-02-20 17:43:35 +010092 }
Václav Kubernát3a99f002020-03-31 02:27:41 +020093 s << std::endl;
94 return s;
95}
Václav Kubernát13b23d72020-04-16 21:49:51 +020096
97std::ostream& operator<<(std::ostream& s, const yang::TypeInfo& type)
98{
Václav Kubernát1ae24f42020-12-01 02:32:04 +010099 s << type.m_type;
100 s << " units: " << (type.m_units ? *type.m_units : "std::nullopt");
101 s << " description: " << (type.m_description ? *type.m_description : "std::nullopt");
Václav Kubernát13b23d72020-04-16 21:49:51 +0200102 return s;
103}
Václav Kubernát82086872020-04-29 01:09:50 +0200104
105std::ostream& operator<<(std::ostream& s, const boost::optional<std::string>& opt)
106{
107 s << (opt ? *opt : "std::nullopt");
108 return s;
109}
Václav Kubernátd9fa27c2020-05-06 00:48:01 +0200110
111std::ostream& operator<<(std::ostream& s, const std::set<ModuleNodePair>& set)
112{
113 std::transform(set.begin(), set.end(),
114 std::experimental::make_ostream_joiner(s, ", "),
115 [] (const ModuleNodePair& it) { return (it.first ? *it.first + ":" : "") + it.second; });
116 return s;
117}
118
Václav Kubernáted824d02020-06-09 15:48:30 +0200119std::ostream& operator<<(std::ostream& s, const std::set<std::string> set)
120{
Václav Kubernátb4e5b182020-11-16 19:55:09 +0100121 s << std::endl
122 << "{";
Václav Kubernáted824d02020-06-09 15:48:30 +0200123 std::copy(set.begin(), set.end(), std::experimental::make_ostream_joiner(s, ", "));
124 s << "}" << std::endl;
125 return s;
126}
127
128std::ostream& operator<<(std::ostream& s, const std::vector<ListInstance> set)
129{
Václav Kubernátb4e5b182020-11-16 19:55:09 +0100130 s << std::endl
131 << "{" << std::endl;
Václav Kubernáted824d02020-06-09 15:48:30 +0200132 std::transform(set.begin(), set.end(), std::experimental::make_ostream_joiner(s, ", \n"), [](const auto& map) {
133 std::ostringstream ss;
Václav Kubernátb4e5b182020-11-16 19:55:09 +0100134 ss << " {" << std::endl
135 << " ";
136 std::transform(map.begin(), map.end(), std::experimental::make_ostream_joiner(ss, ", \n "), [](const auto& keyValue) {
Václav Kubernáted824d02020-06-09 15:48:30 +0200137 return "{" + keyValue.first + "{" + boost::core::demangle(keyValue.second.type().name()) + "}" + ", " + leafDataToString(keyValue.second) + "}";
138 });
Václav Kubernátb4e5b182020-11-16 19:55:09 +0100139 ss << std::endl
140 << " }";
Václav Kubernáted824d02020-06-09 15:48:30 +0200141 return ss.str();
142 });
Václav Kubernátb4e5b182020-11-16 19:55:09 +0100143 s << std::endl
144 << "}" << std::endl;
Václav Kubernáted824d02020-06-09 15:48:30 +0200145 return s;
146}
Václav Kubernát82086872020-04-29 01:09:50 +0200147}
148
149std::ostream& operator<<(std::ostream& s, const boost::variant<dataPath_, schemaPath_, module_>& path)
150{
151 if (path.type() == typeid(module_)) {
152 s << "module: " << boost::get<module_>(path).m_name << "\n";
153 } else if (path.type() == typeid(dataPath_)) {
154 s << "dataPath: " << pathToDataString(boost::get<dataPath_>(path), Prefixes::WhenNeeded) << "\n";
155 } else {
156 s << "schemaPath: " << pathToSchemaString(boost::get<schemaPath_>(path), Prefixes::WhenNeeded) << "\n";
157 }
158 return s;
Václav Kubernát1ed4aa32020-01-23 13:13:28 +0100159}
Václav Kubernát4a58ce62020-05-14 17:58:10 +0200160
161std::ostream& operator<<(std::ostream& s, const boost::optional<boost::variant<dataPath_, schemaPath_, module_>>& path)
162{
163 if (path) {
164 s << *path;
165 } else {
166 s << "boost::none";
167 }
168
169 return s;
170}
171
Václav Kubernát1bcee3b2020-05-28 22:19:59 +0200172std::ostream& operator<<(std::ostream& s, const create_& create)
173{
174 s << "\nls_ {\n " << create.m_path << "}\n";
175 return s;
176}
Václav Kubernát4a58ce62020-05-14 17:58:10 +0200177
178std::ostream& operator<<(std::ostream& s, const ls_& ls)
179{
180 s << "\nls_ {\n " << ls.m_path << "}\n";
181 return s;
182}
Václav Kubernátbf65dd72020-05-28 02:32:31 +0200183
Václav Kubernátce108db2021-01-25 10:05:40 +0100184std::ostream& operator<<(std::ostream& s, const cd_& cd)
185{
186 s << "\ncd_ {\n " << cd.m_path << "}\n";
187 return s;
188}
189
Václav Kubernátbf65dd72020-05-28 02:32:31 +0200190std::ostream& operator<<(std::ostream& s, const move_& move)
191{
192 s << "\nmove_ {\n";
193 s << " path: " << move.m_source;
194 s << " mode: ";
195 if (std::holds_alternative<yang::move::Absolute>(move.m_destination)) {
196 if (std::get<yang::move::Absolute>(move.m_destination) == yang::move::Absolute::Begin) {
197 s << "Absolute::Begin";
198 } else {
199 s << "Absolute::End";
200 }
201 } else {
Václav Kubernát742e11c2020-07-08 17:19:07 +0200202 const auto& relative = std::get<yang::move::Relative>(move.m_destination);
Václav Kubernátbf65dd72020-05-28 02:32:31 +0200203 s << "Relative {\n";
204 s << " position: ";
205 if (relative.m_position == yang::move::Relative::Position::After) {
206 s << "Position::After\n";
207 } else {
208 s << "Position::Before\n";
209 }
210 s << " path: ";
211 s << relative.m_path;
212 }
213 s << "\n}\n";
214 return s;
215}
Václav Kubernáted824d02020-06-09 15:48:30 +0200216
217std::ostream& operator<<(std::ostream& s, const set_ cmd)
218{
219 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) << "}";
220}
Václav Kubernát3d787b12020-10-29 09:11:26 +0100221
222std::ostream& operator<<(std::ostream& s, const prepare_ cmd)
223{
224 return s << "Command PREPARE {path: " << pathToDataString(cmd.m_path, Prefixes::Always) << "}";
225}