blob: cb84e806ae860715908b1db00d38a7c30cf7ac2c [file] [log] [blame]
Václav Kubernát24df80e2018-06-06 15:18:03 +02001/*
2 * Copyright (C) 2018 CESNET, https://photonics.cesnet.cz/
3 * Copyright (C) 2018 FIT CVUT, https://fit.cvut.cz/
4 *
5 * Written by Václav Kubernát <kubervac@fit.cvut.cz>
6 *
7*/
8#pragma once
9
Václav Kubernát24df80e2018-06-06 15:18:03 +020010#include <boost/fusion/adapted/struct/adapt_struct.hpp>
11#include <boost/fusion/include/adapt_struct.hpp>
12#include <boost/fusion/include/std_pair.hpp>
Václav Kubernát24df80e2018-06-06 15:18:03 +020013#include <map>
Václav Kubernátb5ca1542020-05-27 01:03:54 +020014#include <variant>
Václav Kubernát24df80e2018-06-06 15:18:03 +020015#include <vector>
16
Václav Kubernáteeb38842019-03-20 19:46:05 +010017#include "ast_values.hpp"
18
Václav Kubernátefcac932020-01-10 15:26:32 +010019enum class Prefixes {
20 Always,
21 WhenNeeded
22};
23
Václav Kubernát24df80e2018-06-06 15:18:03 +020024struct nodeup_ {
25 bool operator==(const nodeup_&) const
26 {
27 return true;
28 }
29};
30
31struct container_ {
32 container_() = default;
33 container_(const std::string& name);
34
35 bool operator==(const container_& b) const;
36
37 std::string m_name;
38};
39
40struct leaf_ {
41 leaf_() = default;
42 leaf_(const std::string& name);
43
44 bool operator==(const leaf_& b) const;
45
46 std::string m_name;
47};
48
Václav Kubernát5b8a8f32020-05-20 00:57:22 +020049struct leafList_ {
50 leafList_();
51 leafList_(const std::string& name);
52
53 bool operator==(const leafList_& b) const;
54
55 std::string m_name;
56};
57
58struct leafListElement_ {
59 bool operator==(const leafListElement_& b) const;
60
61 std::string m_name;
62 leaf_data_ m_value;
63};
64
Václav Kubernát24df80e2018-06-06 15:18:03 +020065struct listElement_ {
66 listElement_() {}
Václav Kubernát7707cae2020-01-16 12:04:53 +010067 listElement_(const std::string& listName, const std::map<std::string, leaf_data_>& keys);
Václav Kubernát24df80e2018-06-06 15:18:03 +020068
69 bool operator==(const listElement_& b) const;
70
71 std::string m_name;
Václav Kubernát7707cae2020-01-16 12:04:53 +010072 std::map<std::string, leaf_data_> m_keys;
Václav Kubernát24df80e2018-06-06 15:18:03 +020073};
74
Václav Kubernát2eaceb82018-10-08 19:56:30 +020075struct list_ {
76 list_() {}
77 list_(const std::string& listName);
78
79 bool operator==(const list_& b) const;
80
81 std::string m_name;
82};
83
Václav Kubernát2eaceb82018-10-08 19:56:30 +020084struct schemaNode_ {
85 boost::optional<module_> m_prefix;
Václav Kubernátb5ca1542020-05-27 01:03:54 +020086 std::variant<container_, list_, nodeup_, leaf_, leafList_> m_suffix;
Václav Kubernát2eaceb82018-10-08 19:56:30 +020087
88 schemaNode_();
89 schemaNode_(decltype(m_suffix) node);
90 schemaNode_(module_ module, decltype(m_suffix) node);
91 bool operator==(const schemaNode_& b) const;
92};
93
94struct dataNode_ {
Václav Kubernát744f57f2018-06-29 22:46:26 +020095 boost::optional<module_> m_prefix;
Václav Kubernátb5ca1542020-05-27 01:03:54 +020096 std::variant<container_, listElement_, nodeup_, leaf_, leafListElement_, leafList_, list_> m_suffix;
Václav Kubernát24df80e2018-06-06 15:18:03 +020097
Václav Kubernát2eaceb82018-10-08 19:56:30 +020098 dataNode_();
99 dataNode_(decltype(m_suffix) node);
Václav Kubernát2db124c2020-05-28 21:58:36 +0200100 dataNode_(boost::optional<module_> module, decltype(m_suffix) node);
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200101 dataNode_(module_ module, decltype(m_suffix) node);
102 bool operator==(const dataNode_& b) const;
Václav Kubernát744f57f2018-06-29 22:46:26 +0200103};
104
Václav Kubernátd6fd2492018-11-19 15:11:16 +0100105enum class TrailingSlash {
106 Present,
107 NonPresent
108};
109
Václav Kubernátb6ff0b62018-08-30 16:14:53 +0200110enum class Scope {
Václav Kubernát37171a12018-08-31 17:01:48 +0200111 Absolute,
112 Relative
113};
114
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200115struct schemaPath_ {
116 bool operator==(const schemaPath_& b) const;
Václav Kubernát37171a12018-08-31 17:01:48 +0200117 Scope m_scope = Scope::Relative;
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200118 std::vector<schemaNode_> m_nodes;
Václav Kubernátd6fd2492018-11-19 15:11:16 +0100119 TrailingSlash m_trailingSlash = TrailingSlash::NonPresent;
Václav Kubernát744f57f2018-06-29 22:46:26 +0200120};
121
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200122struct dataPath_ {
123 bool operator==(const dataPath_& b) const;
124 Scope m_scope = Scope::Relative;
125 std::vector<dataNode_> m_nodes;
Václav Kubernátd6fd2492018-11-19 15:11:16 +0100126 TrailingSlash m_trailingSlash = TrailingSlash::NonPresent;
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200127};
Václav Kubernát744f57f2018-06-29 22:46:26 +0200128
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200129std::string nodeToSchemaString(decltype(dataPath_::m_nodes)::value_type node);
130
Václav Kubernátefcac932020-01-10 15:26:32 +0100131std::string pathToDataString(const dataPath_& path, Prefixes prefixes);
132std::string pathToSchemaString(const schemaPath_& path, Prefixes prefixes);
133std::string pathToSchemaString(const dataPath_& path, Prefixes prefixes);
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200134schemaNode_ dataNodeToSchemaNode(const dataNode_& node);
135schemaPath_ dataPathToSchemaPath(const dataPath_& path);
Václav Kubernátbbfd1fa2019-12-13 13:51:28 +0100136std::string escapeListKeyString(const std::string& what);
Václav Kubernát24df80e2018-06-06 15:18:03 +0200137
138BOOST_FUSION_ADAPT_STRUCT(container_, m_name)
139BOOST_FUSION_ADAPT_STRUCT(listElement_, m_name, m_keys)
Václav Kubernát5b8a8f32020-05-20 00:57:22 +0200140BOOST_FUSION_ADAPT_STRUCT(leafListElement_, m_name, m_value)
Václav Kubernát744f57f2018-06-29 22:46:26 +0200141BOOST_FUSION_ADAPT_STRUCT(module_, m_name)
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200142BOOST_FUSION_ADAPT_STRUCT(dataNode_, m_prefix, m_suffix)
143BOOST_FUSION_ADAPT_STRUCT(schemaNode_, m_prefix, m_suffix)
Václav Kubernátd6fd2492018-11-19 15:11:16 +0100144BOOST_FUSION_ADAPT_STRUCT(dataPath_, m_scope, m_nodes, m_trailingSlash)
145BOOST_FUSION_ADAPT_STRUCT(schemaPath_, m_scope, m_nodes, m_trailingSlash)