blob: 9a860455685058b51d0dcc36bf93c9d86ed54e59 [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át509ce652019-05-29 19:46:44 +020011#include <boost/variant/variant.hpp>
Václav Kubernátb96eef72018-05-04 19:10:22 +020012#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át3a99f002020-03-31 02:27:41 +020016#include "leaf_data_type.hpp"
Václav Kubernátd6662962018-03-22 17:41:33 +010017
Václav Kubernáteeb38842019-03-20 19:46:05 +010018using ModuleValuePair = std::pair<boost::optional<std::string>, std::string>;
19
Václav Kubernát48fc3832018-05-28 14:21:22 +020020namespace yang {
Václav Kubernát34ee85a2020-02-18 17:12:12 +010021enum class NodeTypes {
22 Container,
23 PresenceContainer,
24 List,
25 Leaf
26};
Václav Kubernátb96eef72018-05-04 19:10:22 +020027}
Václav Kubernátd6662962018-03-22 17:41:33 +010028
Václav Kubernáte7d4aea2018-09-11 18:15:48 +020029enum class Recursion {
30 NonRecursive,
31 Recursive
32};
Václav Kubernátf2e463f2018-05-28 15:51:08 +020033
Václav Kubernát624a8872018-03-02 17:28:47 +010034
Václav Kubernát34ee85a2020-02-18 17:12:12 +010035class InvalidNodeException {
Václav Kubernát624a8872018-03-02 17:28:47 +010036};
37
Václav Kubernát48fc3832018-05-28 14:21:22 +020038/*! \class Schema
Václav Kubernátbddbb172018-06-13 16:27:39 +020039 * \brief A base schema class for schemas
Václav Kubernát624a8872018-03-02 17:28:47 +010040 * */
Václav Kubernát744f57f2018-06-29 22:46:26 +020041
42using ModuleNodePair = std::pair<boost::optional<std::string>, std::string>;
43
Václav Kubernát48fc3832018-05-28 14:21:22 +020044class Schema {
Václav Kubernát624a8872018-03-02 17:28:47 +010045public:
Václav Kubernátbddbb172018-06-13 16:27:39 +020046 virtual ~Schema();
Václav Kubernátd6662962018-03-22 17:41:33 +010047
Václav Kubernát2a141392020-02-18 17:12:32 +010048 bool isContainer(const schemaPath_& location, const ModuleNodePair& node) const;
49 bool isLeaf(const schemaPath_& location, const ModuleNodePair& node) const;
50 bool isList(const schemaPath_& location, const ModuleNodePair& node) const;
51 bool isPresenceContainer(const schemaPath_& location, const ModuleNodePair& node) const;
Václav Kubernát34ee85a2020-02-18 17:12:12 +010052 virtual yang::NodeTypes nodeType(const std::string& path) const = 0;
53 virtual yang::NodeTypes nodeType(const schemaPath_& location, const ModuleNodePair& node) const = 0;
Václav Kubernát75877de2019-11-20 17:43:02 +010054 virtual bool isModule(const std::string& name) const = 0;
Václav Kubernát2eaceb82018-10-08 19:56:30 +020055 virtual bool listHasKey(const schemaPath_& location, const ModuleNodePair& node, const std::string& key) const = 0;
Václav Kubernátc3866792020-02-20 14:12:56 +010056 virtual bool leafIsKey(const std::string& leafPath) const = 0;
Václav Kubernát2eaceb82018-10-08 19:56:30 +020057 virtual const std::set<std::string> listKeys(const schemaPath_& location, const ModuleNodePair& node) const = 0;
Václav Kubernát3a99f002020-03-31 02:27:41 +020058 virtual yang::LeafDataType leafType(const schemaPath_& location, const ModuleNodePair& node) const = 0;
59 virtual yang::LeafDataType leafType(const std::string& path) const = 0;
Václav Kubernát6fcd0282020-02-21 16:33:08 +010060 virtual std::optional<std::string> leafTypeName(const std::string& path) const = 0;
Václav Kubernátbd5e3c22020-02-19 15:22:00 +010061 virtual std::string leafrefPath(const std::string& leafrefPath) const = 0;
Václav Kubernát1e09bd62020-02-17 15:13:38 +010062 virtual std::optional<std::string> description(const std::string& location) const = 0;
63 virtual std::optional<std::string> units(const std::string& location) const = 0;
Václav Kubernát6a8d1d92019-04-24 20:30:36 +020064
Václav Kubernát2eaceb82018-10-08 19:56:30 +020065 virtual std::set<std::string> childNodes(const schemaPath_& path, const Recursion recursion) const = 0;
Václav Kubernát9456b5c2019-10-02 21:14:52 +020066 virtual std::set<std::string> moduleNodes(const module_& module, const Recursion recursion) const = 0;
Václav Kubernát624a8872018-03-02 17:28:47 +010067};