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> |
Václav Kubernát | bddbb17 | 2018-06-13 16:27:39 +0200 | [diff] [blame] | 12 | #include <unordered_map> |
| 13 | #include "ast_path.hpp" |
| 14 | #include "schema.hpp" |
| 15 | |
Václav Kubernát | ff45f31 | 2019-10-09 12:45:27 +0200 | [diff] [blame] | 16 | namespace yang { |
| 17 | enum class ContainerTraits { |
| 18 | Presence, |
| 19 | None, |
| 20 | }; |
| 21 | |
| 22 | struct container { |
| 23 | yang::ContainerTraits m_presence; |
| 24 | }; |
| 25 | struct list { |
| 26 | std::set<std::string> m_keys; |
| 27 | }; |
| 28 | |
| 29 | struct leaf { |
| 30 | yang::LeafDataTypes m_type; |
| 31 | std::set<std::string> m_enumValues; |
| 32 | ModuleValuePair m_identBase; |
Václav Kubernát | 6a8d1d9 | 2019-04-24 20:30:36 +0200 | [diff] [blame] | 33 | std::string m_leafRefSource; |
Václav Kubernát | ff45f31 | 2019-10-09 12:45:27 +0200 | [diff] [blame] | 34 | }; |
| 35 | |
| 36 | struct module { |
| 37 | }; |
| 38 | } |
| 39 | |
| 40 | using NodeType = boost::variant<yang::container, yang::list, yang::leaf, yang::module>; |
| 41 | |
| 42 | |
Václav Kubernát | bddbb17 | 2018-06-13 16:27:39 +0200 | [diff] [blame] | 43 | /*! \class StaticSchema |
| 44 | * \brief Static schema, used mainly for testing |
| 45 | * */ |
| 46 | |
| 47 | class StaticSchema : public Schema { |
| 48 | public: |
| 49 | StaticSchema(); |
| 50 | |
Václav Kubernát | 34ee85a | 2020-02-18 17:12:12 +0100 | [diff] [blame] | 51 | yang::NodeTypes nodeType(const std::string& path) const override; |
| 52 | yang::NodeTypes nodeType(const schemaPath_& location, const ModuleNodePair& node) const override; |
Václav Kubernát | 75877de | 2019-11-20 17:43:02 +0100 | [diff] [blame] | 53 | bool isModule(const std::string& name) const override; |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 54 | bool leafEnumHasValue(const schemaPath_& location, const ModuleNodePair& node, const std::string& value) const override; |
Václav Kubernát | eeb3884 | 2019-03-20 19:46:05 +0100 | [diff] [blame] | 55 | bool leafIdentityIsValid(const schemaPath_& location, const ModuleNodePair& node, const ModuleValuePair& value) const override; |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 56 | bool listHasKey(const schemaPath_& location, const ModuleNodePair& node, const std::string& key) const override; |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 57 | const std::set<std::string> listKeys(const schemaPath_& location, const ModuleNodePair& node) const override; |
| 58 | yang::LeafDataTypes leafType(const schemaPath_& location, const ModuleNodePair& node) const override; |
Václav Kubernát | 9bf3685 | 2020-02-18 17:47:56 +0100 | [diff] [blame^] | 59 | yang::LeafDataTypes leafType(const std::string& path) const override; |
Václav Kubernát | 6a8d1d9 | 2019-04-24 20:30:36 +0200 | [diff] [blame] | 60 | yang::LeafDataTypes leafrefBase(const schemaPath_& location, const ModuleNodePair& node) const override; |
Václav Kubernát | 989b5de | 2019-02-20 16:28:35 +0100 | [diff] [blame] | 61 | const std::set<std::string> enumValues(const schemaPath_& location, const ModuleNodePair& node) const override; |
Václav Kubernát | eeb3884 | 2019-03-20 19:46:05 +0100 | [diff] [blame] | 62 | const std::set<std::string> validIdentities(const schemaPath_& location, const ModuleNodePair& node, const Prefixes prefixes) const override; |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 63 | std::set<std::string> childNodes(const schemaPath_& path, const Recursion) const override; |
Václav Kubernát | 9456b5c | 2019-10-02 21:14:52 +0200 | [diff] [blame] | 64 | std::set<std::string> moduleNodes(const module_& module, const Recursion recursion) const override; |
Václav Kubernát | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 65 | std::optional<std::string> description(const std::string& path) const override; |
| 66 | std::optional<std::string> units(const std::string& path) const override; |
Václav Kubernát | bddbb17 | 2018-06-13 16:27:39 +0200 | [diff] [blame] | 67 | |
| 68 | void addContainer(const std::string& location, const std::string& name, yang::ContainerTraits isPresence = yang::ContainerTraits::None); |
| 69 | void addLeaf(const std::string& location, const std::string& name, const yang::LeafDataTypes& type); |
| 70 | void addLeafEnum(const std::string& location, const std::string& name, std::set<std::string> enumValues); |
Václav Kubernát | eeb3884 | 2019-03-20 19:46:05 +0100 | [diff] [blame] | 71 | void addLeafIdentityRef(const std::string& location, const std::string& name, const ModuleValuePair& base); |
Václav Kubernát | 6a8d1d9 | 2019-04-24 20:30:36 +0200 | [diff] [blame] | 72 | void addLeafRef(const std::string& location, const std::string& name, const std::string& source); |
Václav Kubernát | bddbb17 | 2018-06-13 16:27:39 +0200 | [diff] [blame] | 73 | 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] | 74 | void addModule(const std::string& name); |
Václav Kubernát | eeb3884 | 2019-03-20 19:46:05 +0100 | [diff] [blame] | 75 | void addIdentity(const std::optional<ModuleValuePair>& base, const ModuleValuePair& name); |
Václav Kubernát | bddbb17 | 2018-06-13 16:27:39 +0200 | [diff] [blame] | 76 | |
| 77 | private: |
| 78 | const std::unordered_map<std::string, NodeType>& children(const std::string& name) const; |
Václav Kubernát | eeb3884 | 2019-03-20 19:46:05 +0100 | [diff] [blame] | 79 | void getIdentSet(const ModuleValuePair& ident, std::set<ModuleValuePair>& res) const; |
Václav Kubernát | 9d799ac | 2019-04-11 12:59:07 +0200 | [diff] [blame] | 80 | bool nodeExists(const std::string& location, const std::string& node) const; |
Václav Kubernát | bddbb17 | 2018-06-13 16:27:39 +0200 | [diff] [blame] | 81 | |
| 82 | 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] | 83 | std::set<std::string> m_modules; |
Václav Kubernát | eeb3884 | 2019-03-20 19:46:05 +0100 | [diff] [blame] | 84 | std::map<ModuleValuePair, std::set<ModuleValuePair>> m_identities; |
Václav Kubernát | bddbb17 | 2018-06-13 16:27:39 +0200 | [diff] [blame] | 85 | }; |