blob: 97f1e7e70690b29d5b1cf625f44e2ef134d7e888 [file] [log] [blame]
Václav Kubernátbddbb172018-06-13 16:27:39 +02001/*
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átbddbb172018-06-13 16:27:39 +020011#include <set>
Václav Kubernátbddbb172018-06-13 16:27:39 +020012#include <unordered_map>
13#include "ast_path.hpp"
14#include "schema.hpp"
15
Václav Kubernátff45f312019-10-09 12:45:27 +020016namespace yang {
17enum class ContainerTraits {
18 Presence,
19 None,
20};
21
22struct container {
23 yang::ContainerTraits m_presence;
24};
25struct list {
26 std::set<std::string> m_keys;
27};
28
29struct leaf {
30 yang::LeafDataTypes m_type;
31 std::set<std::string> m_enumValues;
32 ModuleValuePair m_identBase;
Václav Kubernát6a8d1d92019-04-24 20:30:36 +020033 std::string m_leafRefSource;
Václav Kubernátff45f312019-10-09 12:45:27 +020034};
35
36struct module {
37};
38}
39
40using NodeType = boost::variant<yang::container, yang::list, yang::leaf, yang::module>;
41
42
Václav Kubernátbddbb172018-06-13 16:27:39 +020043/*! \class StaticSchema
44 * \brief Static schema, used mainly for testing
45 * */
46
47class StaticSchema : public Schema {
48public:
49 StaticSchema();
50
Václav Kubernát34ee85a2020-02-18 17:12:12 +010051 yang::NodeTypes nodeType(const std::string& path) const override;
52 yang::NodeTypes nodeType(const schemaPath_& location, const ModuleNodePair& node) const override;
Václav Kubernát75877de2019-11-20 17:43:02 +010053 bool isModule(const std::string& name) const override;
Václav Kubernát2eaceb82018-10-08 19:56:30 +020054 bool leafEnumHasValue(const schemaPath_& location, const ModuleNodePair& node, const std::string& value) const override;
Václav Kubernáteeb38842019-03-20 19:46:05 +010055 bool leafIdentityIsValid(const schemaPath_& location, const ModuleNodePair& node, const ModuleValuePair& value) const override;
Václav Kubernát2eaceb82018-10-08 19:56:30 +020056 bool listHasKey(const schemaPath_& location, const ModuleNodePair& node, const std::string& key) const override;
Václav Kubernátc3866792020-02-20 14:12:56 +010057 bool leafIsKey(const std::string& leafPath) const override;
Václav Kubernát2eaceb82018-10-08 19:56:30 +020058 const std::set<std::string> listKeys(const schemaPath_& location, const ModuleNodePair& node) const override;
59 yang::LeafDataTypes leafType(const schemaPath_& location, const ModuleNodePair& node) const override;
Václav Kubernát9bf36852020-02-18 17:47:56 +010060 yang::LeafDataTypes leafType(const std::string& path) const override;
Václav Kubernát6fcd0282020-02-21 16:33:08 +010061 std::optional<std::string> leafTypeName(const std::string& path) const override;
Václav Kubernátf0fe7692020-02-19 14:39:47 +010062 yang::LeafDataTypes leafrefBaseType(const schemaPath_& location, const ModuleNodePair& node) const override;
Václav Kubernátad87ece2020-02-19 15:20:56 +010063 yang::LeafDataTypes leafrefBaseType(const std::string& path) const override;
Václav Kubernátbd5e3c22020-02-19 15:22:00 +010064 std::string leafrefPath(const std::string& leafrefPath) const override;
Václav Kubernát989b5de2019-02-20 16:28:35 +010065 const std::set<std::string> enumValues(const schemaPath_& location, const ModuleNodePair& node) const override;
Václav Kubernáteeb38842019-03-20 19:46:05 +010066 const std::set<std::string> validIdentities(const schemaPath_& location, const ModuleNodePair& node, const Prefixes prefixes) const override;
Václav Kubernát2eaceb82018-10-08 19:56:30 +020067 std::set<std::string> childNodes(const schemaPath_& path, const Recursion) const override;
Václav Kubernát9456b5c2019-10-02 21:14:52 +020068 std::set<std::string> moduleNodes(const module_& module, const Recursion recursion) const override;
Václav Kubernát1e09bd62020-02-17 15:13:38 +010069 std::optional<std::string> description(const std::string& path) const override;
70 std::optional<std::string> units(const std::string& path) const override;
Václav Kubernátbddbb172018-06-13 16:27:39 +020071
72 void addContainer(const std::string& location, const std::string& name, yang::ContainerTraits isPresence = yang::ContainerTraits::None);
73 void addLeaf(const std::string& location, const std::string& name, const yang::LeafDataTypes& type);
74 void addLeafEnum(const std::string& location, const std::string& name, std::set<std::string> enumValues);
Václav Kubernáteeb38842019-03-20 19:46:05 +010075 void addLeafIdentityRef(const std::string& location, const std::string& name, const ModuleValuePair& base);
Václav Kubernát6a8d1d92019-04-24 20:30:36 +020076 void addLeafRef(const std::string& location, const std::string& name, const std::string& source);
Václav Kubernátbddbb172018-06-13 16:27:39 +020077 void addList(const std::string& location, const std::string& name, const std::set<std::string>& keys);
Václav Kubernát744f57f2018-06-29 22:46:26 +020078 void addModule(const std::string& name);
Václav Kubernáteeb38842019-03-20 19:46:05 +010079 void addIdentity(const std::optional<ModuleValuePair>& base, const ModuleValuePair& name);
Václav Kubernátbddbb172018-06-13 16:27:39 +020080
81private:
82 const std::unordered_map<std::string, NodeType>& children(const std::string& name) const;
Václav Kubernáteeb38842019-03-20 19:46:05 +010083 void getIdentSet(const ModuleValuePair& ident, std::set<ModuleValuePair>& res) const;
Václav Kubernát9d799ac2019-04-11 12:59:07 +020084 bool nodeExists(const std::string& location, const std::string& node) const;
Václav Kubernátbddbb172018-06-13 16:27:39 +020085
86 std::unordered_map<std::string, std::unordered_map<std::string, NodeType>> m_nodes;
Václav Kubernát744f57f2018-06-29 22:46:26 +020087 std::set<std::string> m_modules;
Václav Kubernáteeb38842019-03-20 19:46:05 +010088 std::map<ModuleValuePair, std::set<ModuleValuePair>> m_identities;
Václav Kubernátbddbb172018-06-13 16:27:39 +020089};