blob: 429a0e9362a8de26f6d5a5741223ec03c5c32014 [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
29std::ostream& operator<<(std::ostream& s, const DatastoreAccess::Tree& map)
30{
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
40std::ostream& operator<<(std::ostream& s, const yang::LeafDataType& type)
41{
42 s << std::endl
43 << leafDataTypeToString(type);
44 if (std::holds_alternative<yang::Enum>(type)) {
45 s << "{";
46 auto values = std::get<yang::Enum>(type).m_allowedValues;
47 std::transform(values.begin(), values.end(), std::experimental::make_ostream_joiner(s, ", "), [](const auto& value) {
48 return value.m_value;
49 });
50 s << "}";
51 }
52 if (std::holds_alternative<yang::IdentityRef>(type)) {
53 s << "{";
54 auto values = std::get<yang::IdentityRef>(type).m_allowedValues;
55 std::transform(values.begin(), values.end(), std::experimental::make_ostream_joiner(s, ", "), [](const auto& value) {
56 std::string res;
57 if (value.m_prefix) {
58 res += value.m_prefix->m_name;
59 res += ":";
60 }
61 res += value.m_value;
62 return res;
63 });
64 s << "}";
65 }
Václav Kubernát2984f442020-02-20 17:43:35 +010066 if (std::holds_alternative<yang::LeafRef>(type)) {
Václav Kubernát13b23d72020-04-16 21:49:51 +020067 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 +010068 }
69 if (std::holds_alternative<yang::Union>(type)) {
70 s << "{" << std::endl;
71 auto types = std::get<yang::Union>(type).m_unionTypes;
Václav Kubernát13b23d72020-04-16 21:49:51 +020072 std::transform(types.begin(), types.end(), std::experimental::make_ostream_joiner(s, ",\n"), [] (const auto& type) {
73 return type.m_type;
74 });
Václav Kubernát2984f442020-02-20 17:43:35 +010075 }
Václav Kubernát3a99f002020-03-31 02:27:41 +020076 s << std::endl;
77 return s;
78}
Václav Kubernát13b23d72020-04-16 21:49:51 +020079
80std::ostream& operator<<(std::ostream& s, const yang::TypeInfo& type)
81{
82 s << type.m_type << (type.m_units ? " units: " + *type.m_units : "");
83 return s;
84}
Václav Kubernát82086872020-04-29 01:09:50 +020085
86std::ostream& operator<<(std::ostream& s, const boost::optional<std::string>& opt)
87{
88 s << (opt ? *opt : "std::nullopt");
89 return s;
90}
Václav Kubernátd9fa27c2020-05-06 00:48:01 +020091
92std::ostream& operator<<(std::ostream& s, const std::set<ModuleNodePair>& set)
93{
94 std::transform(set.begin(), set.end(),
95 std::experimental::make_ostream_joiner(s, ", "),
96 [] (const ModuleNodePair& it) { return (it.first ? *it.first + ":" : "") + it.second; });
97 return s;
98}
99
Václav Kubernát82086872020-04-29 01:09:50 +0200100}
101
102std::ostream& operator<<(std::ostream& s, const boost::variant<dataPath_, schemaPath_, module_>& path)
103{
104 if (path.type() == typeid(module_)) {
105 s << "module: " << boost::get<module_>(path).m_name << "\n";
106 } else if (path.type() == typeid(dataPath_)) {
107 s << "dataPath: " << pathToDataString(boost::get<dataPath_>(path), Prefixes::WhenNeeded) << "\n";
108 } else {
109 s << "schemaPath: " << pathToSchemaString(boost::get<schemaPath_>(path), Prefixes::WhenNeeded) << "\n";
110 }
111 return s;
Václav Kubernát1ed4aa32020-01-23 13:13:28 +0100112}
Václav Kubernát4a58ce62020-05-14 17:58:10 +0200113
114std::ostream& operator<<(std::ostream& s, const boost::optional<boost::variant<dataPath_, schemaPath_, module_>>& path)
115{
116 if (path) {
117 s << *path;
118 } else {
119 s << "boost::none";
120 }
121
122 return s;
123}
124
Václav Kubernát1bcee3b2020-05-28 22:19:59 +0200125std::ostream& operator<<(std::ostream& s, const create_& create)
126{
127 s << "\nls_ {\n " << create.m_path << "}\n";
128 return s;
129}
Václav Kubernát4a58ce62020-05-14 17:58:10 +0200130
131std::ostream& operator<<(std::ostream& s, const ls_& ls)
132{
133 s << "\nls_ {\n " << ls.m_path << "}\n";
134 return s;
135}