blob: fa99df600cd44495cee06441c1a365c5d8719840 [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
11#include <stdexcept>
12#include <unordered_map>
Václav Kubernátd6662962018-03-22 17:41:33 +010013
14enum NODE_TYPE {
15 TYPE_CONTAINER,
16 TYPE_LIST,
17 TYPE_LIST_ELEMENT
18};
19
20struct TreeNode {
21 bool operator<(const TreeNode& b) const;
22 std::string m_name;
23 NODE_TYPE m_type;
24};
Václav Kubernát624a8872018-03-02 17:28:47 +010025
26class InvalidNodeException : public std::invalid_argument {
27public:
28 using std::invalid_argument::invalid_argument;
29 ~InvalidNodeException() override;
Václav Kubernát624a8872018-03-02 17:28:47 +010030};
31
32/*! \class CTree
33 * \brief The class representing the tree, that the user traverses.
34 *
35 * This class holds the current position in the tree and handles changing the position,
36 * including checking what nodes are available.
37 * */
38class CTree {
39public:
Václav Kubernátd6662962018-03-22 17:41:33 +010040 CTree();
41 bool nodeExists(const std::string& location, const std::string& node) const;
42
43 bool isContainer(const std::string& location, const std::string& node) const;
44 void addContainer(const std::string& location, const std::string& node);
Václav Kubernát624a8872018-03-02 17:28:47 +010045 void changeNode(const std::string& node);
Václav Kubernát624a8872018-03-02 17:28:47 +010046 std::string currentNode() const;
47
48private:
Václav Kubernátd6662962018-03-22 17:41:33 +010049 const std::unordered_map<std::string, NODE_TYPE>& children(const std::string& node) const;
Václav Kubernát624a8872018-03-02 17:28:47 +010050
Václav Kubernátd6662962018-03-22 17:41:33 +010051 std::unordered_map<std::string, std::unordered_map<std::string, NODE_TYPE>> m_nodes;
Václav Kubernát624a8872018-03-02 17:28:47 +010052 std::string m_curDir;
53};