Václav Kubernát | bddbb17 | 2018-06-13 16:27:39 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 CESNET, https://photonics.cesnet.cz/ |
| 3 | * Copyright (C) 2018 FIT CVUT, https://fit.cvut.cz/ |
| 4 | * |
| 5 | * Written by Václav Kubernát <kubervac@fit.cvut.cz> |
| 6 | * |
| 7 | */ |
| 8 | |
| 9 | #pragma once |
| 10 | |
Václav Kubernát | bddbb17 | 2018-06-13 16:27:39 +0200 | [diff] [blame] | 11 | #include <set> |
| 12 | #include <stdexcept> |
| 13 | #include <unordered_map> |
| 14 | #include "ast_path.hpp" |
| 15 | #include "schema.hpp" |
| 16 | |
| 17 | |
| 18 | /*! \class StaticSchema |
| 19 | * \brief Static schema, used mainly for testing |
| 20 | * */ |
| 21 | |
| 22 | class StaticSchema : public Schema { |
| 23 | public: |
| 24 | StaticSchema(); |
| 25 | |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 26 | bool isContainer(const path_& location, const ModuleNodePair& node) const override; |
| 27 | bool isModule(const path_& location, const std::string& name) const override; |
| 28 | bool isLeaf(const path_& location, const ModuleNodePair& node) const override; |
| 29 | bool isList(const path_& location, const ModuleNodePair& node) const override; |
| 30 | bool isPresenceContainer(const path_& location, const ModuleNodePair& node) const override; |
| 31 | bool leafEnumHasValue(const path_& location, const ModuleNodePair& node, const std::string& value) const override; |
| 32 | bool listHasKey(const path_& location, const ModuleNodePair& node, const std::string& key) const override; |
| 33 | bool nodeExists(const std::string& location, const std::string& node) const override; |
Václav Kubernát | 76e983c | 2018-08-06 13:56:03 +0200 | [diff] [blame] | 34 | const std::set<std::string> listKeys(const path_& location, const ModuleNodePair& node) const override; |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 35 | yang::LeafDataTypes leafType(const path_& location, const ModuleNodePair& node) const override; |
Václav Kubernát | e7d4aea | 2018-09-11 18:15:48 +0200 | [diff] [blame^] | 36 | std::set<std::string> childNodes(const path_& path, const Recursion) const override; |
Václav Kubernát | bddbb17 | 2018-06-13 16:27:39 +0200 | [diff] [blame] | 37 | |
| 38 | void addContainer(const std::string& location, const std::string& name, yang::ContainerTraits isPresence = yang::ContainerTraits::None); |
| 39 | void addLeaf(const std::string& location, const std::string& name, const yang::LeafDataTypes& type); |
| 40 | void addLeafEnum(const std::string& location, const std::string& name, std::set<std::string> enumValues); |
| 41 | void addList(const std::string& location, const std::string& name, const std::set<std::string>& keys); |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 42 | void addModule(const std::string& name); |
Václav Kubernát | bddbb17 | 2018-06-13 16:27:39 +0200 | [diff] [blame] | 43 | |
| 44 | private: |
| 45 | const std::unordered_map<std::string, NodeType>& children(const std::string& name) const; |
| 46 | |
| 47 | std::unordered_map<std::string, std::unordered_map<std::string, NodeType>> m_nodes; |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 48 | std::set<std::string> m_modules; |
Václav Kubernát | bddbb17 | 2018-06-13 16:27:39 +0200 | [diff] [blame] | 49 | }; |