Václav Kubernát | 24df80e | 2018-06-06 15:18:03 +0200 | [diff] [blame] | 1 | /* |
| 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át | 24df80e | 2018-06-06 15:18:03 +0200 | [diff] [blame] | 10 | #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át | 24df80e | 2018-06-06 15:18:03 +0200 | [diff] [blame] | 13 | #include <map> |
Václav Kubernát | b5ca154 | 2020-05-27 01:03:54 +0200 | [diff] [blame] | 14 | #include <variant> |
Václav Kubernát | 24df80e | 2018-06-06 15:18:03 +0200 | [diff] [blame] | 15 | #include <vector> |
| 16 | |
Václav Kubernát | eeb3884 | 2019-03-20 19:46:05 +0100 | [diff] [blame] | 17 | #include "ast_values.hpp" |
Václav Kubernát | a93f900 | 2020-05-28 03:09:42 +0200 | [diff] [blame] | 18 | #include "list_instance.hpp" |
Václav Kubernát | eeb3884 | 2019-03-20 19:46:05 +0100 | [diff] [blame] | 19 | |
Václav Kubernát | efcac93 | 2020-01-10 15:26:32 +0100 | [diff] [blame] | 20 | enum class Prefixes { |
| 21 | Always, |
| 22 | WhenNeeded |
| 23 | }; |
| 24 | |
Václav Kubernát | 24df80e | 2018-06-06 15:18:03 +0200 | [diff] [blame] | 25 | struct nodeup_ { |
| 26 | bool operator==(const nodeup_&) const |
| 27 | { |
| 28 | return true; |
| 29 | } |
| 30 | }; |
| 31 | |
| 32 | struct 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 | |
| 41 | struct 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át | 5b8a8f3 | 2020-05-20 00:57:22 +0200 | [diff] [blame] | 50 | struct leafList_ { |
Václav Kubernát | 5b8a8f3 | 2020-05-20 00:57:22 +0200 | [diff] [blame] | 51 | leafList_(const std::string& name); |
| 52 | |
| 53 | bool operator==(const leafList_& b) const; |
| 54 | |
| 55 | std::string m_name; |
| 56 | }; |
| 57 | |
| 58 | struct leafListElement_ { |
| 59 | bool operator==(const leafListElement_& b) const; |
| 60 | |
| 61 | std::string m_name; |
| 62 | leaf_data_ m_value; |
| 63 | }; |
| 64 | |
Václav Kubernát | 24df80e | 2018-06-06 15:18:03 +0200 | [diff] [blame] | 65 | struct listElement_ { |
Václav Kubernát | 51fa48e | 2020-07-08 17:17:34 +0200 | [diff] [blame] | 66 | listElement_() = default; |
Václav Kubernát | c15fe82 | 2020-06-04 11:28:39 +0200 | [diff] [blame] | 67 | listElement_(const std::string& listName, const ListInstance& keys); |
Václav Kubernát | 24df80e | 2018-06-06 15:18:03 +0200 | [diff] [blame] | 68 | |
| 69 | bool operator==(const listElement_& b) const; |
| 70 | |
| 71 | std::string m_name; |
Václav Kubernát | a93f900 | 2020-05-28 03:09:42 +0200 | [diff] [blame] | 72 | ListInstance m_keys; |
Václav Kubernát | 24df80e | 2018-06-06 15:18:03 +0200 | [diff] [blame] | 73 | }; |
| 74 | |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 75 | struct list_ { |
Václav Kubernát | 51fa48e | 2020-07-08 17:17:34 +0200 | [diff] [blame] | 76 | list_() = default; |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 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át | e7248b2 | 2020-06-26 15:38:59 +0200 | [diff] [blame] | 84 | struct rpcNode_ { |
| 85 | bool operator==(const rpcNode_& other) const; |
| 86 | |
| 87 | std::string m_name; |
| 88 | }; |
| 89 | |
Václav Kubernát | aa4250a | 2020-07-22 00:02:23 +0200 | [diff] [blame] | 90 | struct actionNode_ { |
| 91 | bool operator==(const actionNode_& other) const; |
| 92 | |
| 93 | std::string m_name; |
| 94 | }; |
| 95 | |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 96 | struct schemaNode_ { |
| 97 | boost::optional<module_> m_prefix; |
Václav Kubernát | aa4250a | 2020-07-22 00:02:23 +0200 | [diff] [blame] | 98 | std::variant<container_, list_, nodeup_, leaf_, leafList_, rpcNode_, actionNode_> m_suffix; |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 99 | |
| 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 | |
| 106 | struct dataNode_ { |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 107 | boost::optional<module_> m_prefix; |
Václav Kubernát | aa4250a | 2020-07-22 00:02:23 +0200 | [diff] [blame] | 108 | std::variant<container_, listElement_, nodeup_, leaf_, leafListElement_, leafList_, list_, rpcNode_, actionNode_> m_suffix; |
Václav Kubernát | 24df80e | 2018-06-06 15:18:03 +0200 | [diff] [blame] | 109 | |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 110 | dataNode_(); |
| 111 | dataNode_(decltype(m_suffix) node); |
Václav Kubernát | 2db124c | 2020-05-28 21:58:36 +0200 | [diff] [blame] | 112 | dataNode_(boost::optional<module_> module, decltype(m_suffix) node); |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 113 | dataNode_(module_ module, decltype(m_suffix) node); |
| 114 | bool operator==(const dataNode_& b) const; |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 115 | }; |
| 116 | |
Václav Kubernát | d6fd249 | 2018-11-19 15:11:16 +0100 | [diff] [blame] | 117 | enum class TrailingSlash { |
| 118 | Present, |
| 119 | NonPresent |
| 120 | }; |
| 121 | |
Václav Kubernát | b6ff0b6 | 2018-08-30 16:14:53 +0200 | [diff] [blame] | 122 | enum class Scope { |
Václav Kubernát | 37171a1 | 2018-08-31 17:01:48 +0200 | [diff] [blame] | 123 | Absolute, |
| 124 | Relative |
| 125 | }; |
| 126 | |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 127 | struct schemaPath_ { |
Jan Kundrát | 97376f7 | 2020-06-15 19:26:31 +0200 | [diff] [blame] | 128 | schemaPath_(); |
| 129 | schemaPath_(const Scope scope, const std::vector<schemaNode_>& nodes, const TrailingSlash trailingSlash = TrailingSlash::NonPresent); |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 130 | bool operator==(const schemaPath_& b) const; |
Václav Kubernát | 37171a1 | 2018-08-31 17:01:48 +0200 | [diff] [blame] | 131 | Scope m_scope = Scope::Relative; |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 132 | std::vector<schemaNode_> m_nodes; |
Václav Kubernát | d6fd249 | 2018-11-19 15:11:16 +0100 | [diff] [blame] | 133 | TrailingSlash m_trailingSlash = TrailingSlash::NonPresent; |
Václav Kubernát | e781b90 | 2020-06-15 14:35:11 +0200 | [diff] [blame] | 134 | // @brief Pushes a new fragment. Pops a fragment if it's nodeup_ |
| 135 | void pushFragment(const schemaNode_& fragment); |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 136 | }; |
| 137 | |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 138 | struct dataPath_ { |
Jan Kundrát | 97376f7 | 2020-06-15 19:26:31 +0200 | [diff] [blame] | 139 | dataPath_(); |
| 140 | dataPath_(const Scope scope, const std::vector<dataNode_>& nodes, const TrailingSlash trailingSlash = TrailingSlash::NonPresent); |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 141 | bool operator==(const dataPath_& b) const; |
| 142 | Scope m_scope = Scope::Relative; |
| 143 | std::vector<dataNode_> m_nodes; |
Václav Kubernát | d6fd249 | 2018-11-19 15:11:16 +0100 | [diff] [blame] | 144 | TrailingSlash m_trailingSlash = TrailingSlash::NonPresent; |
Václav Kubernát | e781b90 | 2020-06-15 14:35:11 +0200 | [diff] [blame] | 145 | |
| 146 | // @brief Pushes a new fragment. Pops a fragment if it's nodeup_ |
| 147 | void pushFragment(const dataNode_& fragment); |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 148 | }; |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 149 | |
Václav Kubernát | 28cf336 | 2020-06-29 17:52:51 +0200 | [diff] [blame] | 150 | enum class WritableOps { |
| 151 | Yes, |
| 152 | No |
| 153 | }; |
| 154 | |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 155 | std::string nodeToSchemaString(decltype(dataPath_::m_nodes)::value_type node); |
| 156 | |
Václav Kubernát | efcac93 | 2020-01-10 15:26:32 +0100 | [diff] [blame] | 157 | std::string pathToDataString(const dataPath_& path, Prefixes prefixes); |
| 158 | std::string pathToSchemaString(const schemaPath_& path, Prefixes prefixes); |
| 159 | std::string pathToSchemaString(const dataPath_& path, Prefixes prefixes); |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 160 | schemaNode_ dataNodeToSchemaNode(const dataNode_& node); |
| 161 | schemaPath_ dataPathToSchemaPath(const dataPath_& path); |
Václav Kubernát | bbfd1fa | 2019-12-13 13:51:28 +0100 | [diff] [blame] | 162 | std::string escapeListKeyString(const std::string& what); |
Václav Kubernát | 24df80e | 2018-06-06 15:18:03 +0200 | [diff] [blame] | 163 | |
| 164 | BOOST_FUSION_ADAPT_STRUCT(container_, m_name) |
| 165 | BOOST_FUSION_ADAPT_STRUCT(listElement_, m_name, m_keys) |
Václav Kubernát | 5b8a8f3 | 2020-05-20 00:57:22 +0200 | [diff] [blame] | 166 | BOOST_FUSION_ADAPT_STRUCT(leafListElement_, m_name, m_value) |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 167 | BOOST_FUSION_ADAPT_STRUCT(module_, m_name) |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 168 | BOOST_FUSION_ADAPT_STRUCT(dataNode_, m_prefix, m_suffix) |
| 169 | BOOST_FUSION_ADAPT_STRUCT(schemaNode_, m_prefix, m_suffix) |
Václav Kubernát | d6fd249 | 2018-11-19 15:11:16 +0100 | [diff] [blame] | 170 | BOOST_FUSION_ADAPT_STRUCT(dataPath_, m_scope, m_nodes, m_trailingSlash) |
| 171 | BOOST_FUSION_ADAPT_STRUCT(schemaPath_, m_scope, m_nodes, m_trailingSlash) |