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" |
| 18 | |
Václav Kubernát | efcac93 | 2020-01-10 15:26:32 +0100 | [diff] [blame] | 19 | enum class Prefixes { |
| 20 | Always, |
| 21 | WhenNeeded |
| 22 | }; |
| 23 | |
Václav Kubernát | 24df80e | 2018-06-06 15:18:03 +0200 | [diff] [blame] | 24 | struct nodeup_ { |
| 25 | bool operator==(const nodeup_&) const |
| 26 | { |
| 27 | return true; |
| 28 | } |
| 29 | }; |
| 30 | |
| 31 | struct 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 | |
| 40 | struct 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át | 5b8a8f3 | 2020-05-20 00:57:22 +0200 | [diff] [blame] | 49 | struct 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 | |
| 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_ { |
| 66 | listElement_() {} |
Václav Kubernát | 7707cae | 2020-01-16 12:04:53 +0100 | [diff] [blame] | 67 | listElement_(const std::string& listName, const std::map<std::string, leaf_data_>& 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 | 7707cae | 2020-01-16 12:04:53 +0100 | [diff] [blame] | 72 | std::map<std::string, leaf_data_> 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_ { |
| 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át | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 84 | struct schemaNode_ { |
| 85 | boost::optional<module_> m_prefix; |
Václav Kubernát | b5ca154 | 2020-05-27 01:03:54 +0200 | [diff] [blame] | 86 | std::variant<container_, list_, nodeup_, leaf_, leafList_> m_suffix; |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 87 | |
| 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 | |
| 94 | struct dataNode_ { |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 95 | boost::optional<module_> m_prefix; |
Václav Kubernát | b5ca154 | 2020-05-27 01:03:54 +0200 | [diff] [blame] | 96 | std::variant<container_, listElement_, nodeup_, leaf_, leafListElement_, leafList_, list_> m_suffix; |
Václav Kubernát | 24df80e | 2018-06-06 15:18:03 +0200 | [diff] [blame] | 97 | |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 98 | dataNode_(); |
| 99 | dataNode_(decltype(m_suffix) node); |
| 100 | dataNode_(module_ module, decltype(m_suffix) node); |
| 101 | bool operator==(const dataNode_& b) const; |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 102 | }; |
| 103 | |
Václav Kubernát | d6fd249 | 2018-11-19 15:11:16 +0100 | [diff] [blame] | 104 | enum class TrailingSlash { |
| 105 | Present, |
| 106 | NonPresent |
| 107 | }; |
| 108 | |
Václav Kubernát | b6ff0b6 | 2018-08-30 16:14:53 +0200 | [diff] [blame] | 109 | enum class Scope { |
Václav Kubernát | 37171a1 | 2018-08-31 17:01:48 +0200 | [diff] [blame] | 110 | Absolute, |
| 111 | Relative |
| 112 | }; |
| 113 | |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 114 | struct schemaPath_ { |
| 115 | bool operator==(const schemaPath_& b) const; |
Václav Kubernát | 37171a1 | 2018-08-31 17:01:48 +0200 | [diff] [blame] | 116 | Scope m_scope = Scope::Relative; |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 117 | std::vector<schemaNode_> m_nodes; |
Václav Kubernát | d6fd249 | 2018-11-19 15:11:16 +0100 | [diff] [blame] | 118 | TrailingSlash m_trailingSlash = TrailingSlash::NonPresent; |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 119 | }; |
| 120 | |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 121 | struct dataPath_ { |
| 122 | bool operator==(const dataPath_& b) const; |
| 123 | Scope m_scope = Scope::Relative; |
| 124 | std::vector<dataNode_> m_nodes; |
Václav Kubernát | d6fd249 | 2018-11-19 15:11:16 +0100 | [diff] [blame] | 125 | TrailingSlash m_trailingSlash = TrailingSlash::NonPresent; |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 126 | }; |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 127 | |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 128 | std::string nodeToSchemaString(decltype(dataPath_::m_nodes)::value_type node); |
| 129 | |
Václav Kubernát | efcac93 | 2020-01-10 15:26:32 +0100 | [diff] [blame] | 130 | std::string pathToDataString(const dataPath_& path, Prefixes prefixes); |
| 131 | std::string pathToSchemaString(const schemaPath_& path, Prefixes prefixes); |
| 132 | std::string pathToSchemaString(const dataPath_& path, Prefixes prefixes); |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 133 | schemaNode_ dataNodeToSchemaNode(const dataNode_& node); |
| 134 | schemaPath_ dataPathToSchemaPath(const dataPath_& path); |
Václav Kubernát | bbfd1fa | 2019-12-13 13:51:28 +0100 | [diff] [blame] | 135 | std::string escapeListKeyString(const std::string& what); |
Václav Kubernát | 24df80e | 2018-06-06 15:18:03 +0200 | [diff] [blame] | 136 | |
| 137 | BOOST_FUSION_ADAPT_STRUCT(container_, m_name) |
| 138 | BOOST_FUSION_ADAPT_STRUCT(listElement_, m_name, m_keys) |
Václav Kubernát | 5b8a8f3 | 2020-05-20 00:57:22 +0200 | [diff] [blame] | 139 | BOOST_FUSION_ADAPT_STRUCT(leafListElement_, m_name, m_value) |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 140 | BOOST_FUSION_ADAPT_STRUCT(module_, m_name) |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 141 | BOOST_FUSION_ADAPT_STRUCT(dataNode_, m_prefix, m_suffix) |
| 142 | BOOST_FUSION_ADAPT_STRUCT(schemaNode_, m_prefix, m_suffix) |
Václav Kubernát | d6fd249 | 2018-11-19 15:11:16 +0100 | [diff] [blame] | 143 | BOOST_FUSION_ADAPT_STRUCT(dataPath_, m_scope, m_nodes, m_trailingSlash) |
| 144 | BOOST_FUSION_ADAPT_STRUCT(schemaPath_, m_scope, m_nodes, m_trailingSlash) |