blob: 6955686eca834a44b7fbe032f036e4225d3f729a [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átbbaedc82020-07-09 10:28:53 +020044class InvalidNodeException : std::exception {
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át59e4ee42020-07-08 17:32:45 +020057 [[nodiscard]] virtual yang::NodeTypes nodeType(const std::string& path) const = 0;
58 [[nodiscard]] virtual yang::NodeTypes nodeType(const schemaPath_& location, const ModuleNodePair& node) const = 0;
59 [[nodiscard]] virtual bool isModule(const std::string& name) const = 0;
60 [[nodiscard]] virtual bool listHasKey(const schemaPath_& listPath, const std::string& key) const = 0;
61 [[nodiscard]] virtual bool leafIsKey(const std::string& leafPath) const = 0;
62 [[nodiscard]] virtual bool isConfig(const std::string& path) const = 0;
63 [[nodiscard]] virtual std::optional<std::string> defaultValue(const std::string& leafPath) const = 0;
64 [[nodiscard]] virtual const std::set<std::string> listKeys(const schemaPath_& listPath) const = 0;
65 [[nodiscard]] virtual yang::TypeInfo leafType(const schemaPath_& location, const ModuleNodePair& node) const = 0;
66 [[nodiscard]] virtual yang::TypeInfo leafType(const std::string& path) const = 0;
67 [[nodiscard]] virtual std::optional<std::string> leafTypeName(const std::string& path) const = 0;
68 [[nodiscard]] virtual std::string leafrefPath(const std::string& leafrefPath) const = 0;
69 [[nodiscard]] virtual std::optional<std::string> description(const std::string& location) const = 0;
70 [[nodiscard]] virtual yang::Status status(const std::string& location) const = 0;
Václav Kubernátd8408e02020-12-02 05:13:27 +010071 [[nodiscard]] virtual bool hasInputNodes(const std::string& path) const = 0;
Václav Kubernát6a8d1d92019-04-24 20:30:36 +020072
Václav Kubernát59e4ee42020-07-08 17:32:45 +020073 [[nodiscard]] 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 +010074};