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