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