blob: e5b6659031b2114c06874f6ac8439d88c2621c31 [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)) {
67 s << "{" << std::get<yang::LeafRef>(type).m_targetXPath << "," << *std::get<yang::LeafRef>(type).m_targetType << "}";
68 }
69 if (std::holds_alternative<yang::Union>(type)) {
70 s << "{" << std::endl;
71 auto types = std::get<yang::Union>(type).m_unionTypes;
72 std::copy(types.begin(), types.end(), std::experimental::make_ostream_joiner(s, ",\n"));
73 }
Václav Kubernát3a99f002020-03-31 02:27:41 +020074 s << std::endl;
75 return s;
76}
Václav Kubernát1ed4aa32020-01-23 13:13:28 +010077}