blob: 6fe54d8f5764535d1524a55d2454bb500e89e637 [file] [log] [blame]
Václav Kubernát624a8872018-03-02 17:28:47 +01001/*
2 * Copyright (C) 2018 CESNET, https://photonics.cesnet.cz/
Václav Kubernátd6662962018-03-22 17:41:33 +01003 * Copyright (C) 2018 FIT CVUT, https://fit.cvut.cz/
Václav Kubernát624a8872018-03-02 17:28:47 +01004 *
5 * Written by Václav Kubernát <kubervac@fit.cvut.cz>
6 *
7*/
8
9#pragma once
10
Václav Kubernátb96eef72018-05-04 19:10:22 +020011#include <boost/variant.hpp>
12#include <set>
Václav Kubernát624a8872018-03-02 17:28:47 +010013#include <stdexcept>
14#include <unordered_map>
Václav Kubernátff2c9f62018-05-16 20:26:31 +020015#include "ast.hpp"
Václav Kubernátd6662962018-03-22 17:41:33 +010016
Václav Kubernátb96eef72018-05-04 19:10:22 +020017namespace schema {
18 struct container {
19 };
20 struct list {
21 std::set<std::string> m_keys;
22 };
23}
Václav Kubernátd6662962018-03-22 17:41:33 +010024
Václav Kubernátb96eef72018-05-04 19:10:22 +020025
26using NodeType = boost::variant<schema::container, schema::list>;
27
Václav Kubernát624a8872018-03-02 17:28:47 +010028
29class InvalidNodeException : public std::invalid_argument {
30public:
31 using std::invalid_argument::invalid_argument;
32 ~InvalidNodeException() override;
Václav Kubernát624a8872018-03-02 17:28:47 +010033};
34
35/*! \class CTree
36 * \brief The class representing the tree, that the user traverses.
37 *
38 * This class holds the current position in the tree and handles changing the position,
39 * including checking what nodes are available.
40 * */
41class CTree {
42public:
Václav Kubernátd6662962018-03-22 17:41:33 +010043 CTree();
Václav Kubernátb96eef72018-05-04 19:10:22 +020044 bool nodeExists(const std::string& location, const std::string& name) const;
Václav Kubernátd6662962018-03-22 17:41:33 +010045
Václav Kubernátb96eef72018-05-04 19:10:22 +020046 bool isContainer(const std::string& location, const std::string& name) const;
47 void addContainer(const std::string& location, const std::string& name);
48 const std::set<std::string>& listKeys(const std::string& location, const std::string& name) const;
49 bool listHasKey(const std::string& location, const std::string& name, const std::string& key) const;
50 bool isList(const std::string& location, const std::string& name) const;
51 void addList(const std::string& location, const std::string& name, const std::set<std::string>& keys);
Václav Kubernátff2c9f62018-05-16 20:26:31 +020052 void changeNode(const path_& name);
Václav Kubernát624a8872018-03-02 17:28:47 +010053 std::string currentNode() const;
54
55private:
Václav Kubernátb96eef72018-05-04 19:10:22 +020056 const std::unordered_map<std::string, NodeType>& children(const std::string& name) const;
Václav Kubernát624a8872018-03-02 17:28:47 +010057
Václav Kubernátb96eef72018-05-04 19:10:22 +020058 std::unordered_map<std::string, std::unordered_map<std::string, NodeType>> m_nodes;
Václav Kubernát624a8872018-03-02 17:28:47 +010059 std::string m_curDir;
60};