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 | 509ce65 | 2019-05-29 19:46:44 +0200 | [diff] [blame] | 13 | #include <boost/variant/variant.hpp> |
Václav Kubernát | 24df80e | 2018-06-06 15:18:03 +0200 | [diff] [blame] | 14 | #include <map> |
| 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 | |
| 49 | struct listElement_ { |
| 50 | listElement_() {} |
Václav Kubernát | 7707cae | 2020-01-16 12:04:53 +0100 | [diff] [blame] | 51 | 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] | 52 | |
| 53 | bool operator==(const listElement_& b) const; |
| 54 | |
| 55 | std::string m_name; |
Václav Kubernát | 7707cae | 2020-01-16 12:04:53 +0100 | [diff] [blame] | 56 | std::map<std::string, leaf_data_> m_keys; |
Václav Kubernát | 24df80e | 2018-06-06 15:18:03 +0200 | [diff] [blame] | 57 | }; |
| 58 | |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 59 | struct list_ { |
| 60 | list_() {} |
| 61 | list_(const std::string& listName); |
| 62 | |
| 63 | bool operator==(const list_& b) const; |
| 64 | |
| 65 | std::string m_name; |
| 66 | }; |
| 67 | |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 68 | struct schemaNode_ { |
| 69 | boost::optional<module_> m_prefix; |
| 70 | boost::variant<container_, list_, nodeup_, leaf_> m_suffix; |
| 71 | |
| 72 | schemaNode_(); |
| 73 | schemaNode_(decltype(m_suffix) node); |
| 74 | schemaNode_(module_ module, decltype(m_suffix) node); |
| 75 | bool operator==(const schemaNode_& b) const; |
| 76 | }; |
| 77 | |
| 78 | struct dataNode_ { |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 79 | boost::optional<module_> m_prefix; |
Václav Kubernát | 5c75b25 | 2018-10-10 18:33:47 +0200 | [diff] [blame] | 80 | boost::variant<container_, listElement_, nodeup_, leaf_, list_> m_suffix; |
Václav Kubernát | 24df80e | 2018-06-06 15:18:03 +0200 | [diff] [blame] | 81 | |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 82 | dataNode_(); |
| 83 | dataNode_(decltype(m_suffix) node); |
| 84 | dataNode_(module_ module, decltype(m_suffix) node); |
| 85 | bool operator==(const dataNode_& b) const; |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 86 | }; |
| 87 | |
Václav Kubernát | d6fd249 | 2018-11-19 15:11:16 +0100 | [diff] [blame] | 88 | enum class TrailingSlash { |
| 89 | Present, |
| 90 | NonPresent |
| 91 | }; |
| 92 | |
Václav Kubernát | b6ff0b6 | 2018-08-30 16:14:53 +0200 | [diff] [blame] | 93 | enum class Scope { |
Václav Kubernát | 37171a1 | 2018-08-31 17:01:48 +0200 | [diff] [blame] | 94 | Absolute, |
| 95 | Relative |
| 96 | }; |
| 97 | |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 98 | struct schemaPath_ { |
| 99 | bool operator==(const schemaPath_& b) const; |
Václav Kubernát | 37171a1 | 2018-08-31 17:01:48 +0200 | [diff] [blame] | 100 | Scope m_scope = Scope::Relative; |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 101 | std::vector<schemaNode_> m_nodes; |
Václav Kubernát | d6fd249 | 2018-11-19 15:11:16 +0100 | [diff] [blame] | 102 | TrailingSlash m_trailingSlash = TrailingSlash::NonPresent; |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 103 | }; |
| 104 | |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 105 | struct dataPath_ { |
| 106 | bool operator==(const dataPath_& b) const; |
| 107 | Scope m_scope = Scope::Relative; |
| 108 | std::vector<dataNode_> m_nodes; |
Václav Kubernát | d6fd249 | 2018-11-19 15:11:16 +0100 | [diff] [blame] | 109 | TrailingSlash m_trailingSlash = TrailingSlash::NonPresent; |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 110 | }; |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 111 | |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 112 | std::string nodeToSchemaString(decltype(dataPath_::m_nodes)::value_type node); |
| 113 | |
Václav Kubernát | efcac93 | 2020-01-10 15:26:32 +0100 | [diff] [blame] | 114 | std::string pathToDataString(const dataPath_& path, Prefixes prefixes); |
| 115 | std::string pathToSchemaString(const schemaPath_& path, Prefixes prefixes); |
| 116 | std::string pathToSchemaString(const dataPath_& path, Prefixes prefixes); |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 117 | schemaNode_ dataNodeToSchemaNode(const dataNode_& node); |
| 118 | schemaPath_ dataPathToSchemaPath(const dataPath_& path); |
Václav Kubernát | bbfd1fa | 2019-12-13 13:51:28 +0100 | [diff] [blame] | 119 | std::string escapeListKeyString(const std::string& what); |
Václav Kubernát | 24df80e | 2018-06-06 15:18:03 +0200 | [diff] [blame] | 120 | |
| 121 | BOOST_FUSION_ADAPT_STRUCT(container_, m_name) |
| 122 | BOOST_FUSION_ADAPT_STRUCT(listElement_, m_name, m_keys) |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 123 | BOOST_FUSION_ADAPT_STRUCT(module_, m_name) |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 124 | BOOST_FUSION_ADAPT_STRUCT(dataNode_, m_prefix, m_suffix) |
| 125 | BOOST_FUSION_ADAPT_STRUCT(schemaNode_, m_prefix, m_suffix) |
Václav Kubernát | d6fd249 | 2018-11-19 15:11:16 +0100 | [diff] [blame] | 126 | BOOST_FUSION_ADAPT_STRUCT(dataPath_, m_scope, m_nodes, m_trailingSlash) |
| 127 | BOOST_FUSION_ADAPT_STRUCT(schemaPath_, m_scope, m_nodes, m_trailingSlash) |