blob: e87619b89b2186854b8a35393a6d665bf53f3f90 [file] [log] [blame]
Václav Kubernát624a8872018-03-02 17:28:47 +01001/*
2 * Copyright (C) 2018 CESNET, https://photonics.cesnet.cz/
Václav Kubernátd6662962018-03-22 17:41:33 +01003 * Copyright (C) 2018 FIT CVUT, https://fit.cvut.cz/
Václav Kubernát624a8872018-03-02 17:28:47 +01004 *
5 * Written by Václav Kubernát <kubervac@fit.cvut.cz>
6 *
7*/
8
9#pragma once
10
Václav Kubernátb96eef72018-05-04 19:10:22 +020011#include <boost/variant.hpp>
12#include <set>
Václav Kubernát624a8872018-03-02 17:28:47 +010013#include <stdexcept>
14#include <unordered_map>
Václav Kubernát24df80e2018-06-06 15:18:03 +020015#include "ast_path.hpp"
Václav Kubernátd6662962018-03-22 17:41:33 +010016
Václav Kubernát48fc3832018-05-28 14:21:22 +020017namespace yang {
Václav Kubernátb61336d2018-05-28 17:35:03 +020018enum class ContainerTraits {
19 Presence,
20 None,
21};
Václav Kubernátebca2552018-06-08 19:06:02 +020022
23enum class LeafDataTypes {
24 String,
25 Decimal,
26 Bool,
27 Int,
28 Uint,
29 Enum,
30};
31
Václav Kubernát48fc3832018-05-28 14:21:22 +020032struct container {
Václav Kubernátb61336d2018-05-28 17:35:03 +020033 yang::ContainerTraits m_presence;
Václav Kubernát48fc3832018-05-28 14:21:22 +020034};
35struct list {
36 std::set<std::string> m_keys;
37};
Václav Kubernát07204242018-06-04 18:12:09 +020038struct leaf {
Václav Kubernátebca2552018-06-08 19:06:02 +020039 yang::LeafDataTypes m_type;
40 std::set<std::string> m_enumValues;
Václav Kubernát07204242018-06-04 18:12:09 +020041};
Václav Kubernátb96eef72018-05-04 19:10:22 +020042}
Václav Kubernátd6662962018-03-22 17:41:33 +010043
Václav Kubernátf2e463f2018-05-28 15:51:08 +020044
Václav Kubernát07204242018-06-04 18:12:09 +020045using NodeType = boost::variant<yang::container, yang::list, yang::leaf>;
Václav Kubernátb96eef72018-05-04 19:10:22 +020046
Václav Kubernát624a8872018-03-02 17:28:47 +010047
48class InvalidNodeException : public std::invalid_argument {
49public:
50 using std::invalid_argument::invalid_argument;
51 ~InvalidNodeException() override;
Václav Kubernát624a8872018-03-02 17:28:47 +010052};
53
Václav Kubernát48fc3832018-05-28 14:21:22 +020054/*! \class Schema
55 * \brief The class representing the schema, that the user traverses.
Václav Kubernát624a8872018-03-02 17:28:47 +010056 * */
Václav Kubernát48fc3832018-05-28 14:21:22 +020057class Schema {
Václav Kubernát624a8872018-03-02 17:28:47 +010058public:
Václav Kubernát48fc3832018-05-28 14:21:22 +020059 Schema();
Václav Kubernátb96eef72018-05-04 19:10:22 +020060 bool nodeExists(const std::string& location, const std::string& name) const;
Václav Kubernátd6662962018-03-22 17:41:33 +010061
Václav Kubernát814fa412018-05-25 19:47:18 +020062 bool isContainer(const path_& location, const std::string& name) const;
Václav Kubernátb61336d2018-05-28 17:35:03 +020063 void addContainer(const std::string& location, const std::string& name, yang::ContainerTraits isPresence = yang::ContainerTraits::None);
Václav Kubernát814fa412018-05-25 19:47:18 +020064 const std::set<std::string>& listKeys(const path_& location, const std::string& name) const;
65 bool listHasKey(const path_& location, const std::string& name, const std::string& key) const;
66 bool isList(const path_& location, const std::string& name) const;
Václav Kubernátb96eef72018-05-04 19:10:22 +020067 void addList(const std::string& location, const std::string& name, const std::set<std::string>& keys);
Václav Kubernátb61336d2018-05-28 17:35:03 +020068 bool isPresenceContainer(const path_& location, const std::string& name) const;
Václav Kubernátebca2552018-06-08 19:06:02 +020069 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);
71 bool leafEnumHasValue(const path_& location, const std::string& name, const std::string& value) const;
Václav Kubernát07204242018-06-04 18:12:09 +020072 bool isLeaf(const path_& location, const std::string& name) const;
Václav Kubernátebca2552018-06-08 19:06:02 +020073 yang::LeafDataTypes leafType(const path_& location, const std::string& name) const;
Václav Kubernát624a8872018-03-02 17:28:47 +010074
75private:
Václav Kubernátb96eef72018-05-04 19:10:22 +020076 const std::unordered_map<std::string, NodeType>& children(const std::string& name) const;
Václav Kubernát624a8872018-03-02 17:28:47 +010077
Václav Kubernátb96eef72018-05-04 19:10:22 +020078 std::unordered_map<std::string, std::unordered_map<std::string, NodeType>> m_nodes;
Václav Kubernát624a8872018-03-02 17:28:47 +010079};