blob: 9c7114b2ee9b82261658466778abcfaa3b9aa143 [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átb96eef72018-05-04 19:10:22 +020028}
Václav Kubernátd6662962018-03-22 17:41:33 +010029
Václav Kubernátf2e463f2018-05-28 15:51:08 +020030
Václav Kubernát48fc3832018-05-28 14:21:22 +020031using NodeType = boost::variant<yang::container, yang::list>;
Václav Kubernátb96eef72018-05-04 19:10:22 +020032
Václav Kubernát624a8872018-03-02 17:28:47 +010033
34class InvalidNodeException : public std::invalid_argument {
35public:
36 using std::invalid_argument::invalid_argument;
37 ~InvalidNodeException() override;
Václav Kubernát624a8872018-03-02 17:28:47 +010038};
39
Václav Kubernát48fc3832018-05-28 14:21:22 +020040/*! \class Schema
41 * \brief The class representing the schema, that the user traverses.
Václav Kubernát624a8872018-03-02 17:28:47 +010042 * */
Václav Kubernát48fc3832018-05-28 14:21:22 +020043class Schema {
Václav Kubernát624a8872018-03-02 17:28:47 +010044public:
Václav Kubernát48fc3832018-05-28 14:21:22 +020045 Schema();
Václav Kubernátb96eef72018-05-04 19:10:22 +020046 bool nodeExists(const std::string& location, const std::string& name) const;
Václav Kubernátd6662962018-03-22 17:41:33 +010047
Václav Kubernát814fa412018-05-25 19:47:18 +020048 bool isContainer(const path_& location, const std::string& name) const;
Václav Kubernátb61336d2018-05-28 17:35:03 +020049 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 +020050 const std::set<std::string>& listKeys(const path_& location, const std::string& name) const;
51 bool listHasKey(const path_& location, const std::string& name, const std::string& key) const;
52 bool isList(const path_& location, const std::string& name) const;
Václav Kubernátb96eef72018-05-04 19:10:22 +020053 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 +020054 bool isPresenceContainer(const path_& location, const std::string& name) const;
Václav Kubernát624a8872018-03-02 17:28:47 +010055
56private:
Václav Kubernátb96eef72018-05-04 19:10:22 +020057 const std::unordered_map<std::string, NodeType>& children(const std::string& name) const;
Václav Kubernát624a8872018-03-02 17:28:47 +010058
Václav Kubernátb96eef72018-05-04 19:10:22 +020059 std::unordered_map<std::string, std::unordered_map<std::string, NodeType>> m_nodes;
Václav Kubernát624a8872018-03-02 17:28:47 +010060};