blob: 3bf60f09e7320fa6a4fe18e9a8eb5dbefbf15d68 [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>
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
22class StaticSchema : public Schema {
23public:
24 StaticSchema();
25
Václav Kubernát2eaceb82018-10-08 19:56:30 +020026 bool isContainer(const schemaPath_& location, const ModuleNodePair& node) const override;
27 bool isModule(const schemaPath_& location, const std::string& name) const override;
28 bool isLeaf(const schemaPath_& location, const ModuleNodePair& node) const override;
29 bool isList(const schemaPath_& location, const ModuleNodePair& node) const override;
30 bool isPresenceContainer(const schemaPath_& location, const ModuleNodePair& node) const override;
31 bool leafEnumHasValue(const schemaPath_& location, const ModuleNodePair& node, const std::string& value) const override;
Václav Kubernáteeb38842019-03-20 19:46:05 +010032 bool leafIdentityIsValid(const schemaPath_& location, const ModuleNodePair& node, const ModuleValuePair& value) const override;
Václav Kubernát2eaceb82018-10-08 19:56:30 +020033 bool listHasKey(const schemaPath_& location, const ModuleNodePair& node, const std::string& key) const override;
Václav Kubernát744f57f2018-06-29 22:46:26 +020034 bool nodeExists(const std::string& location, const std::string& node) const override;
Václav Kubernát2eaceb82018-10-08 19:56:30 +020035 const std::set<std::string> listKeys(const schemaPath_& location, const ModuleNodePair& node) const override;
36 yang::LeafDataTypes leafType(const schemaPath_& location, const ModuleNodePair& node) const override;
Václav Kubernát989b5de2019-02-20 16:28:35 +010037 const std::set<std::string> enumValues(const schemaPath_& location, const ModuleNodePair& node) const override;
Václav Kubernáteeb38842019-03-20 19:46:05 +010038 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 +020039 std::set<std::string> childNodes(const schemaPath_& path, const Recursion) const override;
Václav Kubernátbddbb172018-06-13 16:27:39 +020040
41 void addContainer(const std::string& location, const std::string& name, yang::ContainerTraits isPresence = yang::ContainerTraits::None);
42 void addLeaf(const std::string& location, const std::string& name, const yang::LeafDataTypes& type);
43 void addLeafEnum(const std::string& location, const std::string& name, std::set<std::string> enumValues);
Václav Kubernáteeb38842019-03-20 19:46:05 +010044 void addLeafIdentityRef(const std::string& location, const std::string& name, const ModuleValuePair& base);
Václav Kubernátbddbb172018-06-13 16:27:39 +020045 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 +020046 void addModule(const std::string& name);
Václav Kubernáteeb38842019-03-20 19:46:05 +010047 void addIdentity(const std::optional<ModuleValuePair>& base, const ModuleValuePair& name);
Václav Kubernátbddbb172018-06-13 16:27:39 +020048
49private:
50 const std::unordered_map<std::string, NodeType>& children(const std::string& name) const;
Václav Kubernáteeb38842019-03-20 19:46:05 +010051 void getIdentSet(const ModuleValuePair& ident, std::set<ModuleValuePair>& res) const;
Václav Kubernátbddbb172018-06-13 16:27:39 +020052
53 std::unordered_map<std::string, std::unordered_map<std::string, NodeType>> m_nodes;
Václav Kubernát744f57f2018-06-29 22:46:26 +020054 std::set<std::string> m_modules;
Václav Kubernáteeb38842019-03-20 19:46:05 +010055 std::map<ModuleValuePair, std::set<ModuleValuePair>> m_identities;
Václav Kubernátbddbb172018-06-13 16:27:39 +020056};