blob: 557b01fd8a29495a318536d6bb41e7dc9f54d83d [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;
Václav Kubernát5c75b252018-10-10 18:33:47 +020082 boost::variant<container_, listElement_, nodeup_, leaf_, list_> 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átd6fd2492018-11-19 15:11:16 +010090enum class TrailingSlash {
91 Present,
92 NonPresent
93};
94
Václav Kubernátb6ff0b62018-08-30 16:14:53 +020095enum class Scope {
Václav Kubernát37171a12018-08-31 17:01:48 +020096 Absolute,
97 Relative
98};
99
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200100struct schemaPath_ {
101 bool operator==(const schemaPath_& b) const;
Václav Kubernát37171a12018-08-31 17:01:48 +0200102 Scope m_scope = Scope::Relative;
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200103 std::vector<schemaNode_> m_nodes;
Václav Kubernátd6fd2492018-11-19 15:11:16 +0100104 TrailingSlash m_trailingSlash = TrailingSlash::NonPresent;
Václav Kubernát744f57f2018-06-29 22:46:26 +0200105};
106
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200107struct dataPath_ {
108 bool operator==(const dataPath_& b) const;
109 Scope m_scope = Scope::Relative;
110 std::vector<dataNode_> m_nodes;
Václav Kubernátd6fd2492018-11-19 15:11:16 +0100111 TrailingSlash m_trailingSlash = TrailingSlash::NonPresent;
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200112};
Václav Kubernát744f57f2018-06-29 22:46:26 +0200113
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200114std::string nodeToSchemaString(decltype(dataPath_::m_nodes)::value_type node);
115
116std::string pathToAbsoluteSchemaString(const dataPath_& path);
117std::string pathToAbsoluteSchemaString(const schemaPath_& path);
118std::string pathToDataString(const dataPath_& path);
Václav Kubernát5c75b252018-10-10 18:33:47 +0200119std::string pathToSchemaString(const schemaPath_& path);
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200120schemaNode_ dataNodeToSchemaNode(const dataNode_& node);
121schemaPath_ dataPathToSchemaPath(const dataPath_& path);
Václav Kubernát24df80e2018-06-06 15:18:03 +0200122
123BOOST_FUSION_ADAPT_STRUCT(container_, m_name)
124BOOST_FUSION_ADAPT_STRUCT(listElement_, m_name, m_keys)
Václav Kubernát744f57f2018-06-29 22:46:26 +0200125BOOST_FUSION_ADAPT_STRUCT(module_, m_name)
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200126BOOST_FUSION_ADAPT_STRUCT(dataNode_, m_prefix, m_suffix)
127BOOST_FUSION_ADAPT_STRUCT(schemaNode_, m_prefix, m_suffix)
Václav Kubernátd6fd2492018-11-19 15:11:16 +0100128BOOST_FUSION_ADAPT_STRUCT(dataPath_, m_scope, m_nodes, m_trailingSlash)
129BOOST_FUSION_ADAPT_STRUCT(schemaPath_, m_scope, m_nodes, m_trailingSlash)