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 | |
| 11 | #include <boost/variant.hpp> |
| 12 | #include <set> |
| 13 | #include <stdexcept> |
| 14 | #include <unordered_map> |
| 15 | #include "ast_path.hpp" |
| 16 | #include "schema.hpp" |
| 17 | |
| 18 | |
| 19 | /*! \class StaticSchema |
| 20 | * \brief Static schema, used mainly for testing |
| 21 | * */ |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame^] | 22 | using ModuleNodePair = std::pair<boost::optional<std::string>, std::string>; |
Václav Kubernát | bddbb17 | 2018-06-13 16:27:39 +0200 | [diff] [blame] | 23 | |
| 24 | class StaticSchema : public Schema { |
| 25 | public: |
| 26 | StaticSchema(); |
| 27 | |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame^] | 28 | bool isContainer(const path_& location, const ModuleNodePair& node) const override; |
| 29 | bool isModule(const path_& location, const std::string& name) const override; |
| 30 | bool isLeaf(const path_& location, const ModuleNodePair& node) const override; |
| 31 | bool isList(const path_& location, const ModuleNodePair& node) const override; |
| 32 | bool isPresenceContainer(const path_& location, const ModuleNodePair& node) const override; |
| 33 | bool leafEnumHasValue(const path_& location, const ModuleNodePair& node, const std::string& value) const override; |
| 34 | bool listHasKey(const path_& location, const ModuleNodePair& node, const std::string& key) const override; |
| 35 | bool nodeExists(const std::string& location, const std::string& node) const override; |
| 36 | const std::set<std::string>& listKeys(const path_& location, const ModuleNodePair& node) const override; |
| 37 | yang::LeafDataTypes leafType(const path_& location, const ModuleNodePair& node) const override; |
| 38 | std::set<std::string> childNodes(const path_& path) const override; |
Václav Kubernát | bddbb17 | 2018-06-13 16:27:39 +0200 | [diff] [blame] | 39 | |
| 40 | void addContainer(const std::string& location, const std::string& name, yang::ContainerTraits isPresence = yang::ContainerTraits::None); |
| 41 | void addLeaf(const std::string& location, const std::string& name, const yang::LeafDataTypes& type); |
| 42 | void addLeafEnum(const std::string& location, const std::string& name, std::set<std::string> enumValues); |
| 43 | 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^] | 44 | void addModule(const std::string& name); |
Václav Kubernát | bddbb17 | 2018-06-13 16:27:39 +0200 | [diff] [blame] | 45 | |
| 46 | private: |
| 47 | const std::unordered_map<std::string, NodeType>& children(const std::string& name) const; |
| 48 | |
| 49 | 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^] | 50 | std::set<std::string> m_modules; |
Václav Kubernát | bddbb17 | 2018-06-13 16:27:39 +0200 | [diff] [blame] | 51 | }; |