blob: 2da836f032a5a2b877bf6793eded2b887df1674f [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"
Václav Kubernáta93f9002020-05-28 03:09:42 +020018#include "list_instance.hpp"
Václav Kubernáteeb38842019-03-20 19:46:05 +010019
Václav Kubernátefcac932020-01-10 15:26:32 +010020enum class Prefixes {
21 Always,
22 WhenNeeded
23};
24
Václav Kubernát24df80e2018-06-06 15:18:03 +020025struct nodeup_ {
26 bool operator==(const nodeup_&) const
27 {
28 return true;
29 }
30};
31
32struct container_ {
33 container_() = default;
34 container_(const std::string& name);
35
36 bool operator==(const container_& b) const;
37
38 std::string m_name;
39};
40
41struct leaf_ {
42 leaf_() = default;
43 leaf_(const std::string& name);
44
45 bool operator==(const leaf_& b) const;
46
47 std::string m_name;
48};
49
Václav Kubernát5b8a8f32020-05-20 00:57:22 +020050struct leafList_ {
Václav Kubernát5b8a8f32020-05-20 00:57:22 +020051 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_ {
Václav Kubernát51fa48e2020-07-08 17:17:34 +020066 listElement_() = default;
Václav Kubernátc15fe822020-06-04 11:28:39 +020067 listElement_(const std::string& listName, const ListInstance& 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áta93f9002020-05-28 03:09:42 +020072 ListInstance m_keys;
Václav Kubernát24df80e2018-06-06 15:18:03 +020073};
74
Václav Kubernát2eaceb82018-10-08 19:56:30 +020075struct list_ {
Václav Kubernát51fa48e2020-07-08 17:17:34 +020076 list_() = default;
Václav Kubernát2eaceb82018-10-08 19:56:30 +020077 list_(const std::string& listName);
78
79 bool operator==(const list_& b) const;
80
81 std::string m_name;
82};
83
Václav Kubernáte7248b22020-06-26 15:38:59 +020084struct rpcNode_ {
85 bool operator==(const rpcNode_& other) const;
86
87 std::string m_name;
88};
89
Václav Kubernátaa4250a2020-07-22 00:02:23 +020090struct actionNode_ {
91 bool operator==(const actionNode_& other) const;
92
93 std::string m_name;
94};
95
Václav Kubernát2eaceb82018-10-08 19:56:30 +020096struct schemaNode_ {
97 boost::optional<module_> m_prefix;
Václav Kubernátaa4250a2020-07-22 00:02:23 +020098 std::variant<container_, list_, nodeup_, leaf_, leafList_, rpcNode_, actionNode_> m_suffix;
Václav Kubernát2eaceb82018-10-08 19:56:30 +020099
100 schemaNode_();
101 schemaNode_(decltype(m_suffix) node);
102 schemaNode_(module_ module, decltype(m_suffix) node);
103 bool operator==(const schemaNode_& b) const;
104};
105
106struct dataNode_ {
Václav Kubernát744f57f2018-06-29 22:46:26 +0200107 boost::optional<module_> m_prefix;
Václav Kubernátaa4250a2020-07-22 00:02:23 +0200108 std::variant<container_, listElement_, nodeup_, leaf_, leafListElement_, leafList_, list_, rpcNode_, actionNode_> m_suffix;
Václav Kubernát24df80e2018-06-06 15:18:03 +0200109
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200110 dataNode_();
111 dataNode_(decltype(m_suffix) node);
Václav Kubernát2db124c2020-05-28 21:58:36 +0200112 dataNode_(boost::optional<module_> module, decltype(m_suffix) node);
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200113 dataNode_(module_ module, decltype(m_suffix) node);
114 bool operator==(const dataNode_& b) const;
Václav Kubernát744f57f2018-06-29 22:46:26 +0200115};
116
Václav Kubernátb6ff0b62018-08-30 16:14:53 +0200117enum class Scope {
Václav Kubernát37171a12018-08-31 17:01:48 +0200118 Absolute,
119 Relative
120};
121
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200122struct schemaPath_ {
Jan Kundrát97376f72020-06-15 19:26:31 +0200123 schemaPath_();
Václav Kubernát39f83f52021-02-19 02:52:08 +0100124 schemaPath_(const Scope scope, const std::vector<schemaNode_>& nodes);
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200125 bool operator==(const schemaPath_& b) const;
Václav Kubernát37171a12018-08-31 17:01:48 +0200126 Scope m_scope = Scope::Relative;
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200127 std::vector<schemaNode_> m_nodes;
Václav Kubernáte781b902020-06-15 14:35:11 +0200128 // @brief Pushes a new fragment. Pops a fragment if it's nodeup_
129 void pushFragment(const schemaNode_& fragment);
Václav Kubernát744f57f2018-06-29 22:46:26 +0200130};
131
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200132struct dataPath_ {
Jan Kundrát97376f72020-06-15 19:26:31 +0200133 dataPath_();
Václav Kubernát39f83f52021-02-19 02:52:08 +0100134 dataPath_(const Scope scope, const std::vector<dataNode_>& nodes);
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200135 bool operator==(const dataPath_& b) const;
136 Scope m_scope = Scope::Relative;
137 std::vector<dataNode_> m_nodes;
Václav Kubernáte781b902020-06-15 14:35:11 +0200138
139 // @brief Pushes a new fragment. Pops a fragment if it's nodeup_
140 void pushFragment(const dataNode_& fragment);
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200141};
Václav Kubernát744f57f2018-06-29 22:46:26 +0200142
Václav Kubernát28cf3362020-06-29 17:52:51 +0200143enum class WritableOps {
144 Yes,
145 No
146};
147
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200148std::string nodeToSchemaString(decltype(dataPath_::m_nodes)::value_type node);
149
Václav Kubernátefcac932020-01-10 15:26:32 +0100150std::string pathToDataString(const dataPath_& path, Prefixes prefixes);
151std::string pathToSchemaString(const schemaPath_& path, Prefixes prefixes);
152std::string pathToSchemaString(const dataPath_& path, Prefixes prefixes);
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200153schemaNode_ dataNodeToSchemaNode(const dataNode_& node);
154schemaPath_ dataPathToSchemaPath(const dataPath_& path);
Václav Kubernátbbfd1fa2019-12-13 13:51:28 +0100155std::string escapeListKeyString(const std::string& what);
Václav Kubernát24df80e2018-06-06 15:18:03 +0200156
aleskucera@cesnet.cz39b39fa2023-11-10 16:03:30 +0100157// @brief Combining the current working directory with a new path, this function returns the resulting absolute path
158dataPath_ realPath(const dataPath_& cwd, const dataPath_& newPath);
159
Václav Kubernát24df80e2018-06-06 15:18:03 +0200160BOOST_FUSION_ADAPT_STRUCT(container_, m_name)
161BOOST_FUSION_ADAPT_STRUCT(listElement_, m_name, m_keys)
Václav Kubernát5b8a8f32020-05-20 00:57:22 +0200162BOOST_FUSION_ADAPT_STRUCT(leafListElement_, m_name, m_value)
Václav Kubernát744f57f2018-06-29 22:46:26 +0200163BOOST_FUSION_ADAPT_STRUCT(module_, m_name)
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200164BOOST_FUSION_ADAPT_STRUCT(dataNode_, m_prefix, m_suffix)
165BOOST_FUSION_ADAPT_STRUCT(schemaNode_, m_prefix, m_suffix)
Václav Kubernát39f83f52021-02-19 02:52:08 +0100166BOOST_FUSION_ADAPT_STRUCT(dataPath_, m_scope, m_nodes)
167BOOST_FUSION_ADAPT_STRUCT(schemaPath_, m_scope, m_nodes)