blob: d49d244cf8382c6cc38ca44105755440cda6e36d [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}
91}
92
93std::ostream& operator<<(std::ostream& s, const boost::variant<dataPath_, schemaPath_, module_>& path)
94{
95 if (path.type() == typeid(module_)) {
96 s << "module: " << boost::get<module_>(path).m_name << "\n";
97 } else if (path.type() == typeid(dataPath_)) {
98 s << "dataPath: " << pathToDataString(boost::get<dataPath_>(path), Prefixes::WhenNeeded) << "\n";
99 } else {
100 s << "schemaPath: " << pathToSchemaString(boost::get<schemaPath_>(path), Prefixes::WhenNeeded) << "\n";
101 }
102 return s;
Václav Kubernát1ed4aa32020-01-23 13:13:28 +0100103}