blob: 7c05d17a278f51aa19d3d3df3ba30b5908f3e91d [file] [log] [blame]
Václav Kubernátbddbb172018-06-13 16:27:39 +02001
Václav Kubernát624a8872018-03-02 17:28:47 +01002/*
3 * Copyright (C) 2018 CESNET, https://photonics.cesnet.cz/
Václav Kubernátd6662962018-03-22 17:41:33 +01004 * Copyright (C) 2018 FIT CVUT, https://fit.cvut.cz/
Václav Kubernát624a8872018-03-02 17:28:47 +01005 *
6 * Written by Václav Kubernát <kubervac@fit.cvut.cz>
7 *
8*/
9
10#pragma once
11
Václav Kubernátb96eef72018-05-04 19:10:22 +020012#include <boost/variant.hpp>
13#include <set>
Václav Kubernát624a8872018-03-02 17:28:47 +010014#include <stdexcept>
15#include <unordered_map>
Václav Kubernát24df80e2018-06-06 15:18:03 +020016#include "ast_path.hpp"
Václav Kubernátd6662962018-03-22 17:41:33 +010017
Václav Kubernát48fc3832018-05-28 14:21:22 +020018namespace yang {
Václav Kubernátb61336d2018-05-28 17:35:03 +020019enum class ContainerTraits {
20 Presence,
21 None,
22};
Václav Kubernátebca2552018-06-08 19:06:02 +020023
24enum class LeafDataTypes {
25 String,
26 Decimal,
27 Bool,
28 Int,
29 Uint,
30 Enum,
31};
32
Václav Kubernát48fc3832018-05-28 14:21:22 +020033struct container {
Václav Kubernátb61336d2018-05-28 17:35:03 +020034 yang::ContainerTraits m_presence;
Václav Kubernát48fc3832018-05-28 14:21:22 +020035};
36struct list {
37 std::set<std::string> m_keys;
38};
Václav Kubernát07204242018-06-04 18:12:09 +020039struct leaf {
Václav Kubernátebca2552018-06-08 19:06:02 +020040 yang::LeafDataTypes m_type;
41 std::set<std::string> m_enumValues;
Václav Kubernát07204242018-06-04 18:12:09 +020042};
Václav Kubernátb96eef72018-05-04 19:10:22 +020043}
Václav Kubernátd6662962018-03-22 17:41:33 +010044
Václav Kubernátf2e463f2018-05-28 15:51:08 +020045
Václav Kubernát07204242018-06-04 18:12:09 +020046using NodeType = boost::variant<yang::container, yang::list, yang::leaf>;
Václav Kubernátb96eef72018-05-04 19:10:22 +020047
Václav Kubernát624a8872018-03-02 17:28:47 +010048
49class InvalidNodeException : public std::invalid_argument {
50public:
51 using std::invalid_argument::invalid_argument;
52 ~InvalidNodeException() override;
Václav Kubernát624a8872018-03-02 17:28:47 +010053};
54
Václav Kubernát48fc3832018-05-28 14:21:22 +020055/*! \class Schema
Václav Kubernátbddbb172018-06-13 16:27:39 +020056 * \brief A base schema class for schemas
Václav Kubernát624a8872018-03-02 17:28:47 +010057 * */
Václav Kubernát48fc3832018-05-28 14:21:22 +020058class Schema {
Václav Kubernát624a8872018-03-02 17:28:47 +010059public:
Václav Kubernátbddbb172018-06-13 16:27:39 +020060 virtual ~Schema();
Václav Kubernátd6662962018-03-22 17:41:33 +010061
Václav Kubernátbddbb172018-06-13 16:27:39 +020062 virtual bool isContainer(const path_& location, const std::string& name) const = 0;
63 virtual bool isLeaf(const path_& location, const std::string& name) const = 0;
64 virtual bool isList(const path_& location, const std::string& name) const = 0;
65 virtual bool isPresenceContainer(const path_& location, const std::string& name) const = 0;
66 virtual bool leafEnumHasValue(const path_& location, const std::string& name, const std::string& value) const = 0;
67 virtual bool listHasKey(const path_& location, const std::string& name, const std::string& key) const = 0;
68 virtual bool nodeExists(const std::string& location, const std::string& name) const = 0;
69 virtual const std::set<std::string>& listKeys(const path_& location, const std::string& name) const = 0;
70 virtual yang::LeafDataTypes leafType(const path_& location, const std::string& name) const = 0;
Václav Kubernát624a8872018-03-02 17:28:47 +010071
72private:
Václav Kubernátb96eef72018-05-04 19:10:22 +020073 const std::unordered_map<std::string, NodeType>& children(const std::string& name) const;
Václav Kubernát624a8872018-03-02 17:28:47 +010074
Václav Kubernátb96eef72018-05-04 19:10:22 +020075 std::unordered_map<std::string, std::unordered_map<std::string, NodeType>> m_nodes;
Václav Kubernát624a8872018-03-02 17:28:47 +010076};