blob: 1c7154b528644c3c6a51ccf496ec16c263599c6b [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{
99 s << type.m_type << (type.m_units ? " units: " + *type.m_units : "");
100 return s;
101}
Václav Kubernát82086872020-04-29 01:09:50 +0200102
103std::ostream& operator<<(std::ostream& s, const boost::optional<std::string>& opt)
104{
105 s << (opt ? *opt : "std::nullopt");
106 return s;
107}
Václav Kubernátd9fa27c2020-05-06 00:48:01 +0200108
109std::ostream& operator<<(std::ostream& s, const std::set<ModuleNodePair>& set)
110{
111 std::transform(set.begin(), set.end(),
112 std::experimental::make_ostream_joiner(s, ", "),
113 [] (const ModuleNodePair& it) { return (it.first ? *it.first + ":" : "") + it.second; });
114 return s;
115}
116
Václav Kubernáted824d02020-06-09 15:48:30 +0200117std::ostream& operator<<(std::ostream& s, const std::set<std::string> set)
118{
Václav Kubernátb4e5b182020-11-16 19:55:09 +0100119 s << std::endl
120 << "{";
Václav Kubernáted824d02020-06-09 15:48:30 +0200121 std::copy(set.begin(), set.end(), std::experimental::make_ostream_joiner(s, ", "));
122 s << "}" << std::endl;
123 return s;
124}
125
126std::ostream& operator<<(std::ostream& s, const std::vector<ListInstance> set)
127{
Václav Kubernátb4e5b182020-11-16 19:55:09 +0100128 s << std::endl
129 << "{" << std::endl;
Václav Kubernáted824d02020-06-09 15:48:30 +0200130 std::transform(set.begin(), set.end(), std::experimental::make_ostream_joiner(s, ", \n"), [](const auto& map) {
131 std::ostringstream ss;
Václav Kubernátb4e5b182020-11-16 19:55:09 +0100132 ss << " {" << std::endl
133 << " ";
134 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 +0200135 return "{" + keyValue.first + "{" + boost::core::demangle(keyValue.second.type().name()) + "}" + ", " + leafDataToString(keyValue.second) + "}";
136 });
Václav Kubernátb4e5b182020-11-16 19:55:09 +0100137 ss << std::endl
138 << " }";
Václav Kubernáted824d02020-06-09 15:48:30 +0200139 return ss.str();
140 });
Václav Kubernátb4e5b182020-11-16 19:55:09 +0100141 s << std::endl
142 << "}" << std::endl;
Václav Kubernáted824d02020-06-09 15:48:30 +0200143 return s;
144}
Václav Kubernát82086872020-04-29 01:09:50 +0200145}
146
147std::ostream& operator<<(std::ostream& s, const boost::variant<dataPath_, schemaPath_, module_>& path)
148{
149 if (path.type() == typeid(module_)) {
150 s << "module: " << boost::get<module_>(path).m_name << "\n";
151 } else if (path.type() == typeid(dataPath_)) {
152 s << "dataPath: " << pathToDataString(boost::get<dataPath_>(path), Prefixes::WhenNeeded) << "\n";
153 } else {
154 s << "schemaPath: " << pathToSchemaString(boost::get<schemaPath_>(path), Prefixes::WhenNeeded) << "\n";
155 }
156 return s;
Václav Kubernát1ed4aa32020-01-23 13:13:28 +0100157}
Václav Kubernát4a58ce62020-05-14 17:58:10 +0200158
159std::ostream& operator<<(std::ostream& s, const boost::optional<boost::variant<dataPath_, schemaPath_, module_>>& path)
160{
161 if (path) {
162 s << *path;
163 } else {
164 s << "boost::none";
165 }
166
167 return s;
168}
169
Václav Kubernát1bcee3b2020-05-28 22:19:59 +0200170std::ostream& operator<<(std::ostream& s, const create_& create)
171{
172 s << "\nls_ {\n " << create.m_path << "}\n";
173 return s;
174}
Václav Kubernát4a58ce62020-05-14 17:58:10 +0200175
176std::ostream& operator<<(std::ostream& s, const ls_& ls)
177{
178 s << "\nls_ {\n " << ls.m_path << "}\n";
179 return s;
180}
Václav Kubernátbf65dd72020-05-28 02:32:31 +0200181
182std::ostream& operator<<(std::ostream& s, const move_& move)
183{
184 s << "\nmove_ {\n";
185 s << " path: " << move.m_source;
186 s << " mode: ";
187 if (std::holds_alternative<yang::move::Absolute>(move.m_destination)) {
188 if (std::get<yang::move::Absolute>(move.m_destination) == yang::move::Absolute::Begin) {
189 s << "Absolute::Begin";
190 } else {
191 s << "Absolute::End";
192 }
193 } else {
Václav Kubernát742e11c2020-07-08 17:19:07 +0200194 const auto& relative = std::get<yang::move::Relative>(move.m_destination);
Václav Kubernátbf65dd72020-05-28 02:32:31 +0200195 s << "Relative {\n";
196 s << " position: ";
197 if (relative.m_position == yang::move::Relative::Position::After) {
198 s << "Position::After\n";
199 } else {
200 s << "Position::Before\n";
201 }
202 s << " path: ";
203 s << relative.m_path;
204 }
205 s << "\n}\n";
206 return s;
207}
Václav Kubernáted824d02020-06-09 15:48:30 +0200208
209std::ostream& operator<<(std::ostream& s, const set_ cmd)
210{
211 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) << "}";
212}
Václav Kubernát3d787b12020-10-29 09:11:26 +0100213
214std::ostream& operator<<(std::ostream& s, const prepare_ cmd)
215{
216 return s << "Command PREPARE {path: " << pathToDataString(cmd.m_path, Prefixes::Always) << "}";
217}