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 | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 56 | struct module_ { |
| 57 | bool operator==(const module_& b) const; |
| 58 | std::string m_name; |
Václav Kubernát | 24df80e | 2018-06-06 15:18:03 +0200 | [diff] [blame] | 59 | }; |
| 60 | |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 61 | struct node_ { |
| 62 | boost::optional<module_> m_prefix; |
| 63 | boost::variant<container_, listElement_, nodeup_, leaf_> m_suffix; |
Václav Kubernát | 24df80e | 2018-06-06 15:18:03 +0200 | [diff] [blame] | 64 | |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 65 | node_(); |
| 66 | node_(decltype(m_suffix) node); |
| 67 | node_(module_ module, decltype(m_suffix) node); |
| 68 | bool operator==(const node_& b) const; |
| 69 | }; |
| 70 | |
Václav Kubernát | b6ff0b6 | 2018-08-30 16:14:53 +0200 | [diff] [blame] | 71 | enum class Scope { |
Václav Kubernát | 37171a1 | 2018-08-31 17:01:48 +0200 | [diff] [blame] | 72 | Absolute, |
| 73 | Relative |
| 74 | }; |
| 75 | |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 76 | struct path_ { |
| 77 | bool operator==(const path_& b) const; |
Václav Kubernát | 37171a1 | 2018-08-31 17:01:48 +0200 | [diff] [blame] | 78 | Scope m_scope = Scope::Relative; |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 79 | std::vector<node_> m_nodes; |
| 80 | }; |
| 81 | |
| 82 | std::string nodeToSchemaString(decltype(path_::m_nodes)::value_type node); |
| 83 | |
| 84 | std::string pathToAbsoluteSchemaString(const path_& path); |
Václav Kubernát | 24df80e | 2018-06-06 15:18:03 +0200 | [diff] [blame] | 85 | std::string pathToDataString(const path_& path); |
| 86 | std::string pathToSchemaString(const path_& path); |
| 87 | |
| 88 | BOOST_FUSION_ADAPT_STRUCT(container_, m_name) |
| 89 | BOOST_FUSION_ADAPT_STRUCT(listElement_, m_name, m_keys) |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 90 | BOOST_FUSION_ADAPT_STRUCT(module_, m_name) |
| 91 | BOOST_FUSION_ADAPT_STRUCT(node_, m_prefix, m_suffix) |
Václav Kubernát | 37171a1 | 2018-08-31 17:01:48 +0200 | [diff] [blame] | 92 | BOOST_FUSION_ADAPT_STRUCT(path_, m_scope, m_nodes) |