blob: 0a9b2ff5c4e589723a26f506eddcb9543da353f9 [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át48fc3832018-05-28 14:21:22 +020018namespace yang {
Václav Kubernát34ee85a2020-02-18 17:12:12 +010019enum class NodeTypes {
20 Container,
21 PresenceContainer,
22 List,
Václav Kubernátaaafeae2020-05-05 15:41:45 +020023 Leaf,
24 Rpc,
25 Action,
26 Notification,
27 AnyXml,
28 LeafList
Václav Kubernát34ee85a2020-02-18 17:12:12 +010029};
Václav Kubernáta1c4c9e2020-04-22 00:37:52 +020030
31enum class Status {
32 Current,
33 Deprecated,
34 Obsolete
35};
Václav Kubernátb96eef72018-05-04 19:10:22 +020036}
Václav Kubernátd6662962018-03-22 17:41:33 +010037
Václav Kubernáte7d4aea2018-09-11 18:15:48 +020038enum class Recursion {
39 NonRecursive,
40 Recursive
41};
Václav Kubernátf2e463f2018-05-28 15:51:08 +020042
Václav Kubernát624a8872018-03-02 17:28:47 +010043
Václav Kubernát34ee85a2020-02-18 17:12:12 +010044class InvalidNodeException {
Václav Kubernát624a8872018-03-02 17:28:47 +010045};
46
Václav Kubernát48fc3832018-05-28 14:21:22 +020047/*! \class Schema
Václav Kubernátbddbb172018-06-13 16:27:39 +020048 * \brief A base schema class for schemas
Václav Kubernát624a8872018-03-02 17:28:47 +010049 * */
Václav Kubernát744f57f2018-06-29 22:46:26 +020050
51using ModuleNodePair = std::pair<boost::optional<std::string>, std::string>;
52
Václav Kubernát48fc3832018-05-28 14:21:22 +020053class Schema {
Václav Kubernát624a8872018-03-02 17:28:47 +010054public:
Václav Kubernátbddbb172018-06-13 16:27:39 +020055 virtual ~Schema();
Václav Kubernátd6662962018-03-22 17:41:33 +010056
Václav Kubernát2a141392020-02-18 17:12:32 +010057 bool isContainer(const schemaPath_& location, const ModuleNodePair& node) const;
58 bool isLeaf(const schemaPath_& location, const ModuleNodePair& node) const;
59 bool isList(const schemaPath_& location, const ModuleNodePair& node) const;
60 bool isPresenceContainer(const schemaPath_& location, const ModuleNodePair& node) const;
Václav Kubernát34ee85a2020-02-18 17:12:12 +010061 virtual yang::NodeTypes nodeType(const std::string& path) const = 0;
62 virtual yang::NodeTypes nodeType(const schemaPath_& location, const ModuleNodePair& node) const = 0;
Václav Kubernát75877de2019-11-20 17:43:02 +010063 virtual bool isModule(const std::string& name) const = 0;
Václav Kubernát2eaceb82018-10-08 19:56:30 +020064 virtual bool listHasKey(const schemaPath_& location, const ModuleNodePair& node, const std::string& key) const = 0;
Václav Kubernátc3866792020-02-20 14:12:56 +010065 virtual bool leafIsKey(const std::string& leafPath) const = 0;
Václav Kubernát0599e9f2020-04-21 09:51:33 +020066 virtual bool isConfig(const std::string& path) const = 0;
Václav Kubernátb1a75c62020-04-21 15:20:16 +020067 virtual std::optional<std::string> defaultValue(const std::string& leafPath) const = 0;
Václav Kubernát2eaceb82018-10-08 19:56:30 +020068 virtual const std::set<std::string> listKeys(const schemaPath_& location, const ModuleNodePair& node) const = 0;
Václav Kubernát13b23d72020-04-16 21:49:51 +020069 virtual yang::TypeInfo leafType(const schemaPath_& location, const ModuleNodePair& node) const = 0;
70 virtual yang::TypeInfo leafType(const std::string& path) const = 0;
Václav Kubernát6fcd0282020-02-21 16:33:08 +010071 virtual std::optional<std::string> leafTypeName(const std::string& path) const = 0;
Václav Kubernátbd5e3c22020-02-19 15:22:00 +010072 virtual std::string leafrefPath(const std::string& leafrefPath) const = 0;
Václav Kubernát1e09bd62020-02-17 15:13:38 +010073 virtual std::optional<std::string> description(const std::string& location) const = 0;
Václav Kubernáta1c4c9e2020-04-22 00:37:52 +020074 virtual yang::Status status(const std::string& location) const = 0;
Václav Kubernát6a8d1d92019-04-24 20:30:36 +020075
Václav Kubernát95b08872020-04-28 01:04:17 +020076 virtual std::set<ModuleNodePair> availableNodes(const boost::variant<dataPath_, schemaPath_, module_>& path, const Recursion recursion) const = 0;
Václav Kubernát624a8872018-03-02 17:28:47 +010077};