blob: c15351f23fd7241f5a9d0f9d015ee57180b52e59 [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
Václav Kubernát24df80e2018-06-06 15:18:03 +020010#include <boost/fusion/adapted/struct/adapt_struct.hpp>
11#include <boost/fusion/include/adapt_struct.hpp>
12#include <boost/fusion/include/std_pair.hpp>
Václav Kubernát509ce652019-05-29 19:46:44 +020013#include <boost/variant/variant.hpp>
Václav Kubernát24df80e2018-06-06 15:18:03 +020014#include <map>
15#include <vector>
16
Václav Kubernáteeb38842019-03-20 19:46:05 +010017#include "ast_values.hpp"
18
Václav Kubernát24df80e2018-06-06 15:18:03 +020019struct nodeup_ {
20 bool operator==(const nodeup_&) const
21 {
22 return true;
23 }
24};
25
26struct container_ {
27 container_() = default;
28 container_(const std::string& name);
29
30 bool operator==(const container_& b) const;
31
32 std::string m_name;
33};
34
35struct leaf_ {
36 leaf_() = default;
37 leaf_(const std::string& name);
38
39 bool operator==(const leaf_& b) const;
40
41 std::string m_name;
42};
43
44struct listElement_ {
45 listElement_() {}
46 listElement_(const std::string& listName, const std::map<std::string, std::string>& keys);
47
48 bool operator==(const listElement_& b) const;
49
50 std::string m_name;
51 std::map<std::string, std::string> m_keys;
52};
53
Václav Kubernát2eaceb82018-10-08 19:56:30 +020054struct list_ {
55 list_() {}
56 list_(const std::string& listName);
57
58 bool operator==(const list_& b) const;
59
60 std::string m_name;
61};
62
Václav Kubernát2eaceb82018-10-08 19:56:30 +020063struct schemaNode_ {
64 boost::optional<module_> m_prefix;
65 boost::variant<container_, list_, nodeup_, leaf_> m_suffix;
66
67 schemaNode_();
68 schemaNode_(decltype(m_suffix) node);
69 schemaNode_(module_ module, decltype(m_suffix) node);
70 bool operator==(const schemaNode_& b) const;
71};
72
73struct dataNode_ {
Václav Kubernát744f57f2018-06-29 22:46:26 +020074 boost::optional<module_> m_prefix;
Václav Kubernát5c75b252018-10-10 18:33:47 +020075 boost::variant<container_, listElement_, nodeup_, leaf_, list_> m_suffix;
Václav Kubernát24df80e2018-06-06 15:18:03 +020076
Václav Kubernát2eaceb82018-10-08 19:56:30 +020077 dataNode_();
78 dataNode_(decltype(m_suffix) node);
79 dataNode_(module_ module, decltype(m_suffix) node);
80 bool operator==(const dataNode_& b) const;
Václav Kubernát744f57f2018-06-29 22:46:26 +020081};
82
Václav Kubernátd6fd2492018-11-19 15:11:16 +010083enum class TrailingSlash {
84 Present,
85 NonPresent
86};
87
Václav Kubernátb6ff0b62018-08-30 16:14:53 +020088enum class Scope {
Václav Kubernát37171a12018-08-31 17:01:48 +020089 Absolute,
90 Relative
91};
92
Václav Kubernát2eaceb82018-10-08 19:56:30 +020093struct schemaPath_ {
94 bool operator==(const schemaPath_& b) const;
Václav Kubernát37171a12018-08-31 17:01:48 +020095 Scope m_scope = Scope::Relative;
Václav Kubernát2eaceb82018-10-08 19:56:30 +020096 std::vector<schemaNode_> m_nodes;
Václav Kubernátd6fd2492018-11-19 15:11:16 +010097 TrailingSlash m_trailingSlash = TrailingSlash::NonPresent;
Václav Kubernát744f57f2018-06-29 22:46:26 +020098};
99
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200100struct dataPath_ {
101 bool operator==(const dataPath_& b) const;
102 Scope m_scope = Scope::Relative;
103 std::vector<dataNode_> m_nodes;
Václav Kubernátd6fd2492018-11-19 15:11:16 +0100104 TrailingSlash m_trailingSlash = TrailingSlash::NonPresent;
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200105};
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);
Václav Kubernát5c75b252018-10-10 18:33:47 +0200112std::string pathToSchemaString(const schemaPath_& path);
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200113schemaNode_ dataNodeToSchemaNode(const dataNode_& node);
114schemaPath_ dataPathToSchemaPath(const dataPath_& path);
Václav Kubernátbbfd1fa2019-12-13 13:51:28 +0100115std::string escapeListKeyString(const std::string& what);
Václav Kubernát24df80e2018-06-06 15:18:03 +0200116
117BOOST_FUSION_ADAPT_STRUCT(container_, m_name)
118BOOST_FUSION_ADAPT_STRUCT(listElement_, m_name, m_keys)
Václav Kubernát744f57f2018-06-29 22:46:26 +0200119BOOST_FUSION_ADAPT_STRUCT(module_, m_name)
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200120BOOST_FUSION_ADAPT_STRUCT(dataNode_, m_prefix, m_suffix)
121BOOST_FUSION_ADAPT_STRUCT(schemaNode_, m_prefix, m_suffix)
Václav Kubernátd6fd2492018-11-19 15:11:16 +0100122BOOST_FUSION_ADAPT_STRUCT(dataPath_, m_scope, m_nodes, m_trailingSlash)
123BOOST_FUSION_ADAPT_STRUCT(schemaPath_, m_scope, m_nodes, m_trailingSlash)