blob: 4fbeaeacb21b3ce535acc552c4e41c1812a57640 [file] [log] [blame]
Václav Kubernát24df80e2018-06-06 15:18:03 +02001/*
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
21struct nodeup_ {
22 bool operator==(const nodeup_&) const
23 {
24 return true;
25 }
26};
27
28struct 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
37struct 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
46struct 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át2eaceb82018-10-08 19:56:30 +020056struct 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át744f57f2018-06-29 22:46:26 +020065struct module_ {
66 bool operator==(const module_& b) const;
67 std::string m_name;
Václav Kubernát24df80e2018-06-06 15:18:03 +020068};
69
Václav Kubernát2eaceb82018-10-08 19:56:30 +020070struct 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
80struct dataNode_ {
Václav Kubernát744f57f2018-06-29 22:46:26 +020081 boost::optional<module_> m_prefix;
82 boost::variant<container_, listElement_, nodeup_, leaf_> m_suffix;
Václav Kubernát24df80e2018-06-06 15:18:03 +020083
Václav Kubernát2eaceb82018-10-08 19:56:30 +020084 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át744f57f2018-06-29 22:46:26 +020088};
89
Václav Kubernátb6ff0b62018-08-30 16:14:53 +020090enum class Scope {
Václav Kubernát37171a12018-08-31 17:01:48 +020091 Absolute,
92 Relative
93};
94
Václav Kubernát2eaceb82018-10-08 19:56:30 +020095struct schemaPath_ {
96 bool operator==(const schemaPath_& b) const;
Václav Kubernát37171a12018-08-31 17:01:48 +020097 Scope m_scope = Scope::Relative;
Václav Kubernát2eaceb82018-10-08 19:56:30 +020098 std::vector<schemaNode_> m_nodes;
Václav Kubernát744f57f2018-06-29 22:46:26 +020099};
100
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200101struct dataPath_ {
102 bool operator==(const dataPath_& b) const;
103 Scope m_scope = Scope::Relative;
104 std::vector<dataNode_> m_nodes;
105};
Václav Kubernát744f57f2018-06-29 22:46:26 +0200106
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200107std::string nodeToSchemaString(decltype(dataPath_::m_nodes)::value_type node);
108
109std::string pathToAbsoluteSchemaString(const dataPath_& path);
110std::string pathToAbsoluteSchemaString(const schemaPath_& path);
111std::string pathToDataString(const dataPath_& path);
112std::string pathToSchemaString(const dataPath_& path);
113schemaNode_ dataNodeToSchemaNode(const dataNode_& node);
114schemaPath_ dataPathToSchemaPath(const dataPath_& path);
Václav Kubernát24df80e2018-06-06 15:18:03 +0200115
116BOOST_FUSION_ADAPT_STRUCT(container_, m_name)
117BOOST_FUSION_ADAPT_STRUCT(listElement_, m_name, m_keys)
Václav Kubernát744f57f2018-06-29 22:46:26 +0200118BOOST_FUSION_ADAPT_STRUCT(module_, m_name)
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200119BOOST_FUSION_ADAPT_STRUCT(dataNode_, m_prefix, m_suffix)
120BOOST_FUSION_ADAPT_STRUCT(schemaNode_, m_prefix, m_suffix)
121BOOST_FUSION_ADAPT_STRUCT(dataPath_, m_scope, m_nodes)
122BOOST_FUSION_ADAPT_STRUCT(schemaPath_, m_scope, m_nodes)