blob: 69c06f50cbf8d4b34f4dc63e97dd288c33fc5f79 [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>
9#include "parser.hpp"
Václav Kubernát1e09bd62020-02-17 15:13:38 +010010#include "utils.hpp"
Václav Kubernát1ed4aa32020-01-23 13:13:28 +010011namespace std {
12std::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át1e09bd62020-02-17 15:13:38 +010022
23std::ostream& operator<<(std::ostream& s, const std::optional<std::string>& opt)
24{
25 s << (opt ? *opt : "std::nullopt");
26 return s;
27}
28
Václav Kubernátbf65dd72020-05-28 02:32:31 +020029std::ostream& operator<<(std::ostream& s, const ListInstance& map)
Václav Kubernát1e09bd62020-02-17 15:13:38 +010030{
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át3a99f002020-03-31 02:27:41 +020039
Václav Kubernátbf65dd72020-05-28 02:32:31 +020040std::ostream& operator<<(std::ostream& s, const DatastoreAccess::Tree& tree)
41{
42 s << "DatastoreAccess::Tree {\n";
43 for (const auto& [xpath, value] : tree) {
44 s << " {" << xpath << ", " << leafDataToString(value) << "}\n";
45 }
46 s << "}\n";
47 return s;
48}
49
Václav Kubernát3a99f002020-03-31 02:27:41 +020050std::ostream& operator<<(std::ostream& s, const yang::LeafDataType& type)
51{
52 s << std::endl
53 << leafDataTypeToString(type);
54 if (std::holds_alternative<yang::Enum>(type)) {
55 s << "{";
56 auto values = std::get<yang::Enum>(type).m_allowedValues;
57 std::transform(values.begin(), values.end(), std::experimental::make_ostream_joiner(s, ", "), [](const auto& value) {
58 return value.m_value;
59 });
60 s << "}";
61 }
62 if (std::holds_alternative<yang::IdentityRef>(type)) {
63 s << "{";
64 auto values = std::get<yang::IdentityRef>(type).m_allowedValues;
65 std::transform(values.begin(), values.end(), std::experimental::make_ostream_joiner(s, ", "), [](const auto& value) {
66 std::string res;
67 if (value.m_prefix) {
68 res += value.m_prefix->m_name;
69 res += ":";
70 }
71 res += value.m_value;
72 return res;
73 });
74 s << "}";
75 }
Václav Kubernát2984f442020-02-20 17:43:35 +010076 if (std::holds_alternative<yang::LeafRef>(type)) {
Václav Kubernát13b23d72020-04-16 21:49:51 +020077 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 +010078 }
79 if (std::holds_alternative<yang::Union>(type)) {
80 s << "{" << std::endl;
81 auto types = std::get<yang::Union>(type).m_unionTypes;
Václav Kubernát13b23d72020-04-16 21:49:51 +020082 std::transform(types.begin(), types.end(), std::experimental::make_ostream_joiner(s, ",\n"), [] (const auto& type) {
83 return type.m_type;
84 });
Václav Kubernát2984f442020-02-20 17:43:35 +010085 }
Václav Kubernát3a99f002020-03-31 02:27:41 +020086 s << std::endl;
87 return s;
88}
Václav Kubernát13b23d72020-04-16 21:49:51 +020089
90std::ostream& operator<<(std::ostream& s, const yang::TypeInfo& type)
91{
92 s << type.m_type << (type.m_units ? " units: " + *type.m_units : "");
93 return s;
94}
Václav Kubernát82086872020-04-29 01:09:50 +020095
96std::ostream& operator<<(std::ostream& s, const boost::optional<std::string>& opt)
97{
98 s << (opt ? *opt : "std::nullopt");
99 return s;
100}
Václav Kubernátd9fa27c2020-05-06 00:48:01 +0200101
102std::ostream& operator<<(std::ostream& s, const std::set<ModuleNodePair>& set)
103{
104 std::transform(set.begin(), set.end(),
105 std::experimental::make_ostream_joiner(s, ", "),
106 [] (const ModuleNodePair& it) { return (it.first ? *it.first + ":" : "") + it.second; });
107 return s;
108}
109
Václav Kubernát82086872020-04-29 01:09:50 +0200110}
111
112std::ostream& operator<<(std::ostream& s, const boost::variant<dataPath_, schemaPath_, module_>& path)
113{
114 if (path.type() == typeid(module_)) {
115 s << "module: " << boost::get<module_>(path).m_name << "\n";
116 } else if (path.type() == typeid(dataPath_)) {
117 s << "dataPath: " << pathToDataString(boost::get<dataPath_>(path), Prefixes::WhenNeeded) << "\n";
118 } else {
119 s << "schemaPath: " << pathToSchemaString(boost::get<schemaPath_>(path), Prefixes::WhenNeeded) << "\n";
120 }
121 return s;
Václav Kubernát1ed4aa32020-01-23 13:13:28 +0100122}
Václav Kubernát4a58ce62020-05-14 17:58:10 +0200123
124std::ostream& operator<<(std::ostream& s, const boost::optional<boost::variant<dataPath_, schemaPath_, module_>>& path)
125{
126 if (path) {
127 s << *path;
128 } else {
129 s << "boost::none";
130 }
131
132 return s;
133}
134
Václav Kubernát1bcee3b2020-05-28 22:19:59 +0200135std::ostream& operator<<(std::ostream& s, const create_& create)
136{
137 s << "\nls_ {\n " << create.m_path << "}\n";
138 return s;
139}
Václav Kubernát4a58ce62020-05-14 17:58:10 +0200140
141std::ostream& operator<<(std::ostream& s, const ls_& ls)
142{
143 s << "\nls_ {\n " << ls.m_path << "}\n";
144 return s;
145}
Václav Kubernátbf65dd72020-05-28 02:32:31 +0200146
147std::ostream& operator<<(std::ostream& s, const move_& move)
148{
149 s << "\nmove_ {\n";
150 s << " path: " << move.m_source;
151 s << " mode: ";
152 if (std::holds_alternative<yang::move::Absolute>(move.m_destination)) {
153 if (std::get<yang::move::Absolute>(move.m_destination) == yang::move::Absolute::Begin) {
154 s << "Absolute::Begin";
155 } else {
156 s << "Absolute::End";
157 }
158 } else {
159 const yang::move::Relative& relative = std::get<yang::move::Relative>(move.m_destination);
160 s << "Relative {\n";
161 s << " position: ";
162 if (relative.m_position == yang::move::Relative::Position::After) {
163 s << "Position::After\n";
164 } else {
165 s << "Position::Before\n";
166 }
167 s << " path: ";
168 s << relative.m_path;
169 }
170 s << "\n}\n";
171 return s;
172}