blob: dcd13ff9bb7ff639ae9abb992b8ee78f757e67e3 [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
Václav Kubernáteeb38842019-03-20 19:46:05 +010021#include "ast_values.hpp"
22
Václav Kubernát24df80e2018-06-06 15:18:03 +020023struct nodeup_ {
24 bool operator==(const nodeup_&) const
25 {
26 return true;
27 }
28};
29
30struct 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
39struct 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
48struct 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át2eaceb82018-10-08 19:56:30 +020058struct 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át2eaceb82018-10-08 19:56:30 +020067struct 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
77struct dataNode_ {
Václav Kubernát744f57f2018-06-29 22:46:26 +020078 boost::optional<module_> m_prefix;
Václav Kubernát5c75b252018-10-10 18:33:47 +020079 boost::variant<container_, listElement_, nodeup_, leaf_, list_> m_suffix;
Václav Kubernát24df80e2018-06-06 15:18:03 +020080
Václav Kubernát2eaceb82018-10-08 19:56:30 +020081 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át744f57f2018-06-29 22:46:26 +020085};
86
Václav Kubernátd6fd2492018-11-19 15:11:16 +010087enum class TrailingSlash {
88 Present,
89 NonPresent
90};
91
Václav Kubernátb6ff0b62018-08-30 16:14:53 +020092enum class Scope {
Václav Kubernát37171a12018-08-31 17:01:48 +020093 Absolute,
94 Relative
95};
96
Václav Kubernát2eaceb82018-10-08 19:56:30 +020097struct schemaPath_ {
98 bool operator==(const schemaPath_& b) const;
Václav Kubernát37171a12018-08-31 17:01:48 +020099 Scope m_scope = Scope::Relative;
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200100 std::vector<schemaNode_> m_nodes;
Václav Kubernátd6fd2492018-11-19 15:11:16 +0100101 TrailingSlash m_trailingSlash = TrailingSlash::NonPresent;
Václav Kubernát744f57f2018-06-29 22:46:26 +0200102};
103
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200104struct dataPath_ {
105 bool operator==(const dataPath_& b) const;
106 Scope m_scope = Scope::Relative;
107 std::vector<dataNode_> m_nodes;
Václav Kubernátd6fd2492018-11-19 15:11:16 +0100108 TrailingSlash m_trailingSlash = TrailingSlash::NonPresent;
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200109};
Václav Kubernát744f57f2018-06-29 22:46:26 +0200110
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200111std::string nodeToSchemaString(decltype(dataPath_::m_nodes)::value_type node);
112
113std::string pathToAbsoluteSchemaString(const dataPath_& path);
114std::string pathToAbsoluteSchemaString(const schemaPath_& path);
115std::string pathToDataString(const dataPath_& path);
Václav Kubernát5c75b252018-10-10 18:33:47 +0200116std::string pathToSchemaString(const schemaPath_& path);
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200117schemaNode_ dataNodeToSchemaNode(const dataNode_& node);
118schemaPath_ dataPathToSchemaPath(const dataPath_& path);
Václav Kubernát24df80e2018-06-06 15:18:03 +0200119
120BOOST_FUSION_ADAPT_STRUCT(container_, m_name)
121BOOST_FUSION_ADAPT_STRUCT(listElement_, m_name, m_keys)
Václav Kubernát744f57f2018-06-29 22:46:26 +0200122BOOST_FUSION_ADAPT_STRUCT(module_, m_name)
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200123BOOST_FUSION_ADAPT_STRUCT(dataNode_, m_prefix, m_suffix)
124BOOST_FUSION_ADAPT_STRUCT(schemaNode_, m_prefix, m_suffix)
Václav Kubernátd6fd2492018-11-19 15:11:16 +0100125BOOST_FUSION_ADAPT_STRUCT(dataPath_, m_scope, m_nodes, m_trailingSlash)
126BOOST_FUSION_ADAPT_STRUCT(schemaPath_, m_scope, m_nodes, m_trailingSlash)