Václav Kubernát | 624a887 | 2018-03-02 17:28:47 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 CESNET, https://photonics.cesnet.cz/ |
Václav Kubernát | d666296 | 2018-03-22 17:41:33 +0100 | [diff] [blame^] | 3 | * Copyright (C) 2018 FIT CVUT, https://fit.cvut.cz/ |
Václav Kubernát | 624a887 | 2018-03-02 17:28:47 +0100 | [diff] [blame] | 4 | * |
| 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át | d666296 | 2018-03-22 17:41:33 +0100 | [diff] [blame^] | 13 | |
| 14 | enum NODE_TYPE { |
| 15 | TYPE_CONTAINER, |
| 16 | TYPE_LIST, |
| 17 | TYPE_LIST_ELEMENT |
| 18 | }; |
| 19 | |
| 20 | struct TreeNode { |
| 21 | bool operator<(const TreeNode& b) const; |
| 22 | std::string m_name; |
| 23 | NODE_TYPE m_type; |
| 24 | }; |
Václav Kubernát | 624a887 | 2018-03-02 17:28:47 +0100 | [diff] [blame] | 25 | |
| 26 | class InvalidNodeException : public std::invalid_argument { |
| 27 | public: |
| 28 | using std::invalid_argument::invalid_argument; |
| 29 | ~InvalidNodeException() override; |
Václav Kubernát | 624a887 | 2018-03-02 17:28:47 +0100 | [diff] [blame] | 30 | }; |
| 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 | * */ |
| 38 | class CTree { |
| 39 | public: |
Václav Kubernát | d666296 | 2018-03-22 17:41:33 +0100 | [diff] [blame^] | 40 | 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át | 624a887 | 2018-03-02 17:28:47 +0100 | [diff] [blame] | 45 | void changeNode(const std::string& node); |
Václav Kubernát | 624a887 | 2018-03-02 17:28:47 +0100 | [diff] [blame] | 46 | std::string currentNode() const; |
| 47 | |
| 48 | private: |
Václav Kubernát | d666296 | 2018-03-22 17:41:33 +0100 | [diff] [blame^] | 49 | const std::unordered_map<std::string, NODE_TYPE>& children(const std::string& node) const; |
Václav Kubernát | 624a887 | 2018-03-02 17:28:47 +0100 | [diff] [blame] | 50 | |
Václav Kubernát | d666296 | 2018-03-22 17:41:33 +0100 | [diff] [blame^] | 51 | std::unordered_map<std::string, std::unordered_map<std::string, NODE_TYPE>> m_nodes; |
Václav Kubernát | 624a887 | 2018-03-02 17:28:47 +0100 | [diff] [blame] | 52 | std::string m_curDir; |
| 53 | }; |