blob: 487f820950c58c3253ae68a23639c2c4edede829 [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átff2c9f62018-05-16 20:26:31 +020015#include "ast.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át48fc3832018-05-28 14:21:22 +020022struct container {
Václav Kubernátb61336d2018-05-28 17:35:03 +020023 yang::ContainerTraits m_presence;
Václav Kubernát48fc3832018-05-28 14:21:22 +020024};
25struct list {
26 std::set<std::string> m_keys;
27};
Václav Kubernát07204242018-06-04 18:12:09 +020028struct leaf {
29};
Václav Kubernátb96eef72018-05-04 19:10:22 +020030}
Václav Kubernátd6662962018-03-22 17:41:33 +010031
Václav Kubernátf2e463f2018-05-28 15:51:08 +020032
Václav Kubernát07204242018-06-04 18:12:09 +020033using NodeType = boost::variant<yang::container, yang::list, yang::leaf>;
Václav Kubernátb96eef72018-05-04 19:10:22 +020034
Václav Kubernát624a8872018-03-02 17:28:47 +010035
36class InvalidNodeException : public std::invalid_argument {
37public:
38 using std::invalid_argument::invalid_argument;
39 ~InvalidNodeException() override;
Václav Kubernát624a8872018-03-02 17:28:47 +010040};
41
Václav Kubernát48fc3832018-05-28 14:21:22 +020042/*! \class Schema
43 * \brief The class representing the schema, that the user traverses.
Václav Kubernát624a8872018-03-02 17:28:47 +010044 * */
Václav Kubernát48fc3832018-05-28 14:21:22 +020045class Schema {
Václav Kubernát624a8872018-03-02 17:28:47 +010046public:
Václav Kubernát48fc3832018-05-28 14:21:22 +020047 Schema();
Václav Kubernátb96eef72018-05-04 19:10:22 +020048 bool nodeExists(const std::string& location, const std::string& name) const;
Václav Kubernátd6662962018-03-22 17:41:33 +010049
Václav Kubernát814fa412018-05-25 19:47:18 +020050 bool isContainer(const path_& location, const std::string& name) const;
Václav Kubernátb61336d2018-05-28 17:35:03 +020051 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 +020052 const std::set<std::string>& listKeys(const path_& location, const std::string& name) const;
53 bool listHasKey(const path_& location, const std::string& name, const std::string& key) const;
54 bool isList(const path_& location, const std::string& name) const;
Václav Kubernátb96eef72018-05-04 19:10:22 +020055 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 +020056 bool isPresenceContainer(const path_& location, const std::string& name) const;
Václav Kubernát07204242018-06-04 18:12:09 +020057 void addLeaf(const std::string& location, const std::string& name);
58 bool isLeaf(const path_& location, const std::string& name) const;
Václav Kubernát624a8872018-03-02 17:28:47 +010059
60private:
Václav Kubernátb96eef72018-05-04 19:10:22 +020061 const std::unordered_map<std::string, NodeType>& children(const std::string& name) const;
Václav Kubernát624a8872018-03-02 17:28:47 +010062
Václav Kubernátb96eef72018-05-04 19:10:22 +020063 std::unordered_map<std::string, std::unordered_map<std::string, NodeType>> m_nodes;
Václav Kubernát624a8872018-03-02 17:28:47 +010064};