blob: f11265ff6adbc59abec36c2409b47b61647eb832 [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,
Václav Kubernátaaafeae2020-05-05 15:41:45 +020025 Leaf,
26 Rpc,
27 Action,
28 Notification,
29 AnyXml,
30 LeafList
Václav Kubernát34ee85a2020-02-18 17:12:12 +010031};
Václav Kubernáta1c4c9e2020-04-22 00:37:52 +020032
33enum class Status {
34 Current,
35 Deprecated,
36 Obsolete
37};
Václav Kubernátb96eef72018-05-04 19:10:22 +020038}
Václav Kubernátd6662962018-03-22 17:41:33 +010039
Václav Kubernáte7d4aea2018-09-11 18:15:48 +020040enum class Recursion {
41 NonRecursive,
42 Recursive
43};
Václav Kubernátf2e463f2018-05-28 15:51:08 +020044
Václav Kubernát624a8872018-03-02 17:28:47 +010045
Václav Kubernát34ee85a2020-02-18 17:12:12 +010046class InvalidNodeException {
Václav Kubernát624a8872018-03-02 17:28:47 +010047};
48
Václav Kubernát48fc3832018-05-28 14:21:22 +020049/*! \class Schema
Václav Kubernátbddbb172018-06-13 16:27:39 +020050 * \brief A base schema class for schemas
Václav Kubernát624a8872018-03-02 17:28:47 +010051 * */
Václav Kubernát744f57f2018-06-29 22:46:26 +020052
53using ModuleNodePair = std::pair<boost::optional<std::string>, std::string>;
54
Václav Kubernát48fc3832018-05-28 14:21:22 +020055class Schema {
Václav Kubernát624a8872018-03-02 17:28:47 +010056public:
Václav Kubernátbddbb172018-06-13 16:27:39 +020057 virtual ~Schema();
Václav Kubernátd6662962018-03-22 17:41:33 +010058
Václav Kubernát2a141392020-02-18 17:12:32 +010059 bool isContainer(const schemaPath_& location, const ModuleNodePair& node) const;
60 bool isLeaf(const schemaPath_& location, const ModuleNodePair& node) const;
61 bool isList(const schemaPath_& location, const ModuleNodePair& node) const;
62 bool isPresenceContainer(const schemaPath_& location, const ModuleNodePair& node) const;
Václav Kubernát34ee85a2020-02-18 17:12:12 +010063 virtual yang::NodeTypes nodeType(const std::string& path) const = 0;
64 virtual yang::NodeTypes nodeType(const schemaPath_& location, const ModuleNodePair& node) const = 0;
Václav Kubernát75877de2019-11-20 17:43:02 +010065 virtual bool isModule(const std::string& name) const = 0;
Václav Kubernát2eaceb82018-10-08 19:56:30 +020066 virtual bool listHasKey(const schemaPath_& location, const ModuleNodePair& node, const std::string& key) const = 0;
Václav Kubernátc3866792020-02-20 14:12:56 +010067 virtual bool leafIsKey(const std::string& leafPath) const = 0;
Václav Kubernát0599e9f2020-04-21 09:51:33 +020068 virtual bool isConfig(const std::string& path) const = 0;
Václav Kubernátb1a75c62020-04-21 15:20:16 +020069 virtual std::optional<std::string> defaultValue(const std::string& leafPath) const = 0;
Václav Kubernát2eaceb82018-10-08 19:56:30 +020070 virtual const std::set<std::string> listKeys(const schemaPath_& location, const ModuleNodePair& node) const = 0;
Václav Kubernát13b23d72020-04-16 21:49:51 +020071 virtual yang::TypeInfo leafType(const schemaPath_& location, const ModuleNodePair& node) const = 0;
72 virtual yang::TypeInfo leafType(const std::string& path) const = 0;
Václav Kubernát6fcd0282020-02-21 16:33:08 +010073 virtual std::optional<std::string> leafTypeName(const std::string& path) const = 0;
Václav Kubernátbd5e3c22020-02-19 15:22:00 +010074 virtual std::string leafrefPath(const std::string& leafrefPath) const = 0;
Václav Kubernát1e09bd62020-02-17 15:13:38 +010075 virtual std::optional<std::string> description(const std::string& location) const = 0;
Václav Kubernáta1c4c9e2020-04-22 00:37:52 +020076 virtual yang::Status status(const std::string& location) const = 0;
Václav Kubernát6a8d1d92019-04-24 20:30:36 +020077
Václav Kubernát95b08872020-04-28 01:04:17 +020078 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 +010079};