Václav Kubernát | 624a887 | 2018-03-02 17:28:47 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 CESNET, https://photonics.cesnet.cz/ |
| 3 | * |
| 4 | * Written by Václav Kubernát <kubervac@fit.cvut.cz> |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | #pragma once |
| 9 | |
| 10 | #include <stdexcept> |
| 11 | #include <unordered_map> |
| 12 | #include <unordered_set> |
| 13 | |
| 14 | class InvalidNodeException : public std::invalid_argument { |
| 15 | public: |
| 16 | using std::invalid_argument::invalid_argument; |
| 17 | ~InvalidNodeException() override; |
| 18 | |
| 19 | }; |
| 20 | |
| 21 | /*! \class CTree |
| 22 | * \brief The class representing the tree, that the user traverses. |
| 23 | * |
| 24 | * This class holds the current position in the tree and handles changing the position, |
| 25 | * including checking what nodes are available. |
| 26 | * */ |
| 27 | class CTree { |
| 28 | public: |
| 29 | bool checkNode(const std::string& location, const std::string& node) const; |
| 30 | void changeNode(const std::string& node); |
| 31 | void initDefault(); |
| 32 | std::string currentNode() const; |
| 33 | |
| 34 | private: |
| 35 | void addNode(const std::string& location, const std::string& node); |
| 36 | const std::unordered_set<std::string>& children(const std::string& node) const; |
| 37 | |
| 38 | std::unordered_map<std::string, std::unordered_set<std::string>> m_nodes; |
| 39 | std::string m_curDir; |
| 40 | }; |