blob: 67bd7b9f76a6c238c5a395d35e0dfb1aa74533c6 [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 {
Václav Kubernát13b23d72020-04-16 21:49:51 +020030 yang::TypeInfo m_type;
Václav Kubernátff45f312019-10-09 12:45:27 +020031};
32
33struct module {
34};
35}
36
37using NodeType = boost::variant<yang::container, yang::list, yang::leaf, yang::module>;
38
39
Václav Kubernátbddbb172018-06-13 16:27:39 +020040/*! \class StaticSchema
41 * \brief Static schema, used mainly for testing
42 * */
43
44class StaticSchema : public Schema {
45public:
46 StaticSchema();
47
Václav Kubernát34ee85a2020-02-18 17:12:12 +010048 yang::NodeTypes nodeType(const std::string& path) const override;
49 yang::NodeTypes nodeType(const schemaPath_& location, const ModuleNodePair& node) const override;
Václav Kubernát75877de2019-11-20 17:43:02 +010050 bool isModule(const std::string& name) const override;
Václav Kubernát2eaceb82018-10-08 19:56:30 +020051 bool listHasKey(const schemaPath_& location, const ModuleNodePair& node, const std::string& key) const override;
Václav Kubernátc3866792020-02-20 14:12:56 +010052 bool leafIsKey(const std::string& leafPath) const override;
Václav Kubernát0599e9f2020-04-21 09:51:33 +020053 bool isConfig(const std::string& leafPath) const override;
Václav Kubernátb1a75c62020-04-21 15:20:16 +020054 std::optional<std::string> defaultValue(const std::string& leafPath) const override;
Václav Kubernát2eaceb82018-10-08 19:56:30 +020055 const std::set<std::string> listKeys(const schemaPath_& location, const ModuleNodePair& node) const override;
Václav Kubernát13b23d72020-04-16 21:49:51 +020056 yang::TypeInfo leafType(const schemaPath_& location, const ModuleNodePair& node) const override;
57 yang::TypeInfo leafType(const std::string& path) const override;
Václav Kubernát6fcd0282020-02-21 16:33:08 +010058 std::optional<std::string> leafTypeName(const std::string& path) const override;
Václav Kubernátbd5e3c22020-02-19 15:22:00 +010059 std::string leafrefPath(const std::string& leafrefPath) const override;
Václav Kubernát95b08872020-04-28 01:04:17 +020060 std::set<ModuleNodePair> availableNodes(const boost::variant<dataPath_, schemaPath_, module_>& path, const Recursion recursion) const override;
Václav Kubernát1e09bd62020-02-17 15:13:38 +010061 std::optional<std::string> description(const std::string& path) const override;
Václav Kubernáta1c4c9e2020-04-22 00:37:52 +020062 yang::Status status(const std::string& location) const override;
Václav Kubernátbddbb172018-06-13 16:27:39 +020063
Václav Kubernát3a99f002020-03-31 02:27:41 +020064 /** A helper for making tests a little bit easier. It returns all
65 * identities which are based on the argument passed and which can then be
66 * used in addLeaf for the `type` argument */
67 std::set<identityRef_> validIdentities(std::string_view module, std::string_view value);
Václav Kubernátbddbb172018-06-13 16:27:39 +020068 void addContainer(const std::string& location, const std::string& name, yang::ContainerTraits isPresence = yang::ContainerTraits::None);
Václav Kubernát3a99f002020-03-31 02:27:41 +020069 void addLeaf(const std::string& location, const std::string& name, const yang::LeafDataType& type);
Václav Kubernátbddbb172018-06-13 16:27:39 +020070 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 +020071 void addModule(const std::string& name);
Václav Kubernáteeb38842019-03-20 19:46:05 +010072 void addIdentity(const std::optional<ModuleValuePair>& base, const ModuleValuePair& name);
Václav Kubernátbddbb172018-06-13 16:27:39 +020073
74private:
75 const std::unordered_map<std::string, NodeType>& children(const std::string& name) const;
Václav Kubernáteeb38842019-03-20 19:46:05 +010076 void getIdentSet(const ModuleValuePair& ident, std::set<ModuleValuePair>& res) const;
Václav Kubernát9d799ac2019-04-11 12:59:07 +020077 bool nodeExists(const std::string& location, const std::string& node) const;
Václav Kubernátbddbb172018-06-13 16:27:39 +020078
79 std::unordered_map<std::string, std::unordered_map<std::string, NodeType>> m_nodes;
Václav Kubernát744f57f2018-06-29 22:46:26 +020080 std::set<std::string> m_modules;
Václav Kubernát3a99f002020-03-31 02:27:41 +020081
82 // FIXME: Change the template arguments to identityRef_
Václav Kubernáteeb38842019-03-20 19:46:05 +010083 std::map<ModuleValuePair, std::set<ModuleValuePair>> m_identities;
Václav Kubernátbddbb172018-06-13 16:27:39 +020084};