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