Václav Kubernát | bddbb17 | 2018-06-13 16:27:39 +0200 | [diff] [blame] | 1 | |
Václav Kubernát | 624a887 | 2018-03-02 17:28:47 +0100 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2018 CESNET, https://photonics.cesnet.cz/ |
Václav Kubernát | d666296 | 2018-03-22 17:41:33 +0100 | [diff] [blame] | 4 | * Copyright (C) 2018 FIT CVUT, https://fit.cvut.cz/ |
Václav Kubernát | 624a887 | 2018-03-02 17:28:47 +0100 | [diff] [blame] | 5 | * |
| 6 | * Written by Václav Kubernát <kubervac@fit.cvut.cz> |
| 7 | * |
| 8 | */ |
| 9 | |
| 10 | #pragma once |
| 11 | |
Václav Kubernát | b96eef7 | 2018-05-04 19:10:22 +0200 | [diff] [blame] | 12 | #include <boost/variant.hpp> |
| 13 | #include <set> |
Václav Kubernát | 624a887 | 2018-03-02 17:28:47 +0100 | [diff] [blame] | 14 | #include <stdexcept> |
| 15 | #include <unordered_map> |
Václav Kubernát | 24df80e | 2018-06-06 15:18:03 +0200 | [diff] [blame] | 16 | #include "ast_path.hpp" |
Václav Kubernát | d666296 | 2018-03-22 17:41:33 +0100 | [diff] [blame] | 17 | |
Václav Kubernát | 48fc383 | 2018-05-28 14:21:22 +0200 | [diff] [blame] | 18 | namespace yang { |
Václav Kubernát | b61336d | 2018-05-28 17:35:03 +0200 | [diff] [blame] | 19 | enum class ContainerTraits { |
| 20 | Presence, |
| 21 | None, |
| 22 | }; |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 23 | |
| 24 | enum class LeafDataTypes { |
| 25 | String, |
| 26 | Decimal, |
| 27 | Bool, |
| 28 | Int, |
| 29 | Uint, |
| 30 | Enum, |
| 31 | }; |
| 32 | |
Václav Kubernát | 48fc383 | 2018-05-28 14:21:22 +0200 | [diff] [blame] | 33 | struct container { |
Václav Kubernát | b61336d | 2018-05-28 17:35:03 +0200 | [diff] [blame] | 34 | yang::ContainerTraits m_presence; |
Václav Kubernát | 48fc383 | 2018-05-28 14:21:22 +0200 | [diff] [blame] | 35 | }; |
| 36 | struct list { |
| 37 | std::set<std::string> m_keys; |
| 38 | }; |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 39 | struct leaf { |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 40 | yang::LeafDataTypes m_type; |
| 41 | std::set<std::string> m_enumValues; |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 42 | }; |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 43 | |
| 44 | struct module { |
| 45 | }; |
Václav Kubernát | b96eef7 | 2018-05-04 19:10:22 +0200 | [diff] [blame] | 46 | } |
Václav Kubernát | d666296 | 2018-03-22 17:41:33 +0100 | [diff] [blame] | 47 | |
Václav Kubernát | f2e463f | 2018-05-28 15:51:08 +0200 | [diff] [blame] | 48 | |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 49 | using NodeType = boost::variant<yang::container, yang::list, yang::leaf, yang::module>; |
Václav Kubernát | b96eef7 | 2018-05-04 19:10:22 +0200 | [diff] [blame] | 50 | |
Václav Kubernát | 624a887 | 2018-03-02 17:28:47 +0100 | [diff] [blame] | 51 | |
| 52 | class InvalidNodeException : public std::invalid_argument { |
| 53 | public: |
| 54 | using std::invalid_argument::invalid_argument; |
| 55 | ~InvalidNodeException() override; |
Václav Kubernát | 624a887 | 2018-03-02 17:28:47 +0100 | [diff] [blame] | 56 | }; |
| 57 | |
Václav Kubernát | 48fc383 | 2018-05-28 14:21:22 +0200 | [diff] [blame] | 58 | /*! \class Schema |
Václav Kubernát | bddbb17 | 2018-06-13 16:27:39 +0200 | [diff] [blame] | 59 | * \brief A base schema class for schemas |
Václav Kubernát | 624a887 | 2018-03-02 17:28:47 +0100 | [diff] [blame] | 60 | * */ |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 61 | |
| 62 | using ModuleNodePair = std::pair<boost::optional<std::string>, std::string>; |
| 63 | |
Václav Kubernát | 48fc383 | 2018-05-28 14:21:22 +0200 | [diff] [blame] | 64 | class Schema { |
Václav Kubernát | 624a887 | 2018-03-02 17:28:47 +0100 | [diff] [blame] | 65 | public: |
Václav Kubernát | bddbb17 | 2018-06-13 16:27:39 +0200 | [diff] [blame] | 66 | virtual ~Schema(); |
Václav Kubernát | d666296 | 2018-03-22 17:41:33 +0100 | [diff] [blame] | 67 | |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 68 | virtual bool isContainer(const path_& location, const ModuleNodePair& node) const = 0; |
| 69 | virtual bool isLeaf(const path_& location, const ModuleNodePair& node) const = 0; |
| 70 | virtual bool isModule(const path_& location, const std::string& name) const = 0; |
| 71 | virtual bool isList(const path_& location, const ModuleNodePair& node) const = 0; |
| 72 | virtual bool isPresenceContainer(const path_& location, const ModuleNodePair& node) const = 0; |
| 73 | virtual bool leafEnumHasValue(const path_& location, const ModuleNodePair& node, const std::string& value) const = 0; |
| 74 | virtual bool listHasKey(const path_& location, const ModuleNodePair& node, const std::string& key) const = 0; |
| 75 | virtual bool nodeExists(const std::string& location, const std::string& node) const = 0; |
Václav Kubernát | 76e983c | 2018-08-06 13:56:03 +0200 | [diff] [blame] | 76 | virtual const std::set<std::string> listKeys(const path_& location, const ModuleNodePair& node) const = 0; |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 77 | virtual yang::LeafDataTypes leafType(const path_& location, const ModuleNodePair& node) const = 0; |
| 78 | virtual std::set<std::string> childNodes(const path_& path) const = 0; |
Václav Kubernát | 624a887 | 2018-03-02 17:28:47 +0100 | [diff] [blame] | 79 | |
| 80 | private: |
Václav Kubernát | b96eef7 | 2018-05-04 19:10:22 +0200 | [diff] [blame] | 81 | const std::unordered_map<std::string, NodeType>& children(const std::string& name) const; |
Václav Kubernát | 624a887 | 2018-03-02 17:28:47 +0100 | [diff] [blame] | 82 | |
Václav Kubernát | b96eef7 | 2018-05-04 19:10:22 +0200 | [diff] [blame] | 83 | std::unordered_map<std::string, std::unordered_map<std::string, NodeType>> m_nodes; |
Václav Kubernát | 624a887 | 2018-03-02 17:28:47 +0100 | [diff] [blame] | 84 | }; |