blob: 65e28a6b01195face12987afd89060145a0de739 [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 {
13std::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át1e09bd62020-02-17 15:13:38 +010023
24std::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átbf65dd72020-05-28 02:32:31 +020030std::ostream& operator<<(std::ostream& s, const ListInstance& map)
Václav Kubernát1e09bd62020-02-17 15:13:38 +010031{
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át3a99f002020-03-31 02:27:41 +020040
Václav Kubernátbf65dd72020-05-28 02:32:31 +020041std::ostream& operator<<(std::ostream& s, const DatastoreAccess::Tree& tree)
42{
43 s << "DatastoreAccess::Tree {\n";
44 for (const auto& [xpath, value] : tree) {
45 s << " {" << xpath << ", " << leafDataToString(value) << "}\n";
46 }
47 s << "}\n";
48 return s;
49}
50
Václav Kubernát3a99f002020-03-31 02:27:41 +020051std::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át2984f442020-02-20 17:43:35 +010077 if (std::holds_alternative<yang::LeafRef>(type)) {
Václav Kubernát13b23d72020-04-16 21:49:51 +020078 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 +010079 }
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át13b23d72020-04-16 21:49:51 +020083 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át2984f442020-02-20 17:43:35 +010086 }
Václav Kubernát3a99f002020-03-31 02:27:41 +020087 s << std::endl;
88 return s;
89}
Václav Kubernát13b23d72020-04-16 21:49:51 +020090
91std::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át82086872020-04-29 01:09:50 +020096
97std::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átd9fa27c2020-05-06 00:48:01 +0200102
103std::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áted824d02020-06-09 15:48:30 +0200111std::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
119std::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át82086872020-04-29 01:09:50 +0200134}
135
136std::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át1ed4aa32020-01-23 13:13:28 +0100146}
Václav Kubernát4a58ce62020-05-14 17:58:10 +0200147
148std::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át1bcee3b2020-05-28 22:19:59 +0200159std::ostream& operator<<(std::ostream& s, const create_& create)
160{
161 s << "\nls_ {\n " << create.m_path << "}\n";
162 return s;
163}
Václav Kubernát4a58ce62020-05-14 17:58:10 +0200164
165std::ostream& operator<<(std::ostream& s, const ls_& ls)
166{
167 s << "\nls_ {\n " << ls.m_path << "}\n";
168 return s;
169}
Václav Kubernátbf65dd72020-05-28 02:32:31 +0200170
171std::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át742e11c2020-07-08 17:19:07 +0200183 const auto& relative = std::get<yang::move::Relative>(move.m_destination);
Václav Kubernátbf65dd72020-05-28 02:32:31 +0200184 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áted824d02020-06-09 15:48:30 +0200197
198std::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}