Václav Kubernát | 624a887 | 2018-03-02 17:28:47 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 CESNET, https://photonics.cesnet.cz/ |
Václav Kubernát | d666296 | 2018-03-22 17:41:33 +0100 | [diff] [blame] | 3 | * Copyright (C) 2018 FIT CVUT, https://fit.cvut.cz/ |
Václav Kubernát | 624a887 | 2018-03-02 17:28:47 +0100 | [diff] [blame] | 4 | * |
| 5 | * Written by Václav Kubernát <kubervac@fit.cvut.cz> |
| 6 | * |
| 7 | */ |
| 8 | |
| 9 | #pragma once |
| 10 | |
Václav Kubernát | 509ce65 | 2019-05-29 19:46:44 +0200 | [diff] [blame] | 11 | #include <boost/variant/variant.hpp> |
Václav Kubernát | b96eef7 | 2018-05-04 19:10:22 +0200 | [diff] [blame] | 12 | #include <set> |
Václav Kubernát | 624a887 | 2018-03-02 17:28:47 +0100 | [diff] [blame] | 13 | #include <stdexcept> |
| 14 | #include <unordered_map> |
Václav Kubernát | 24df80e | 2018-06-06 15:18:03 +0200 | [diff] [blame] | 15 | #include "ast_path.hpp" |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 16 | #include "leaf_data_type.hpp" |
Václav Kubernát | d666296 | 2018-03-22 17:41:33 +0100 | [diff] [blame] | 17 | |
Václav Kubernát | 48fc383 | 2018-05-28 14:21:22 +0200 | [diff] [blame] | 18 | namespace yang { |
Václav Kubernát | 34ee85a | 2020-02-18 17:12:12 +0100 | [diff] [blame] | 19 | enum class NodeTypes { |
| 20 | Container, |
| 21 | PresenceContainer, |
| 22 | List, |
Václav Kubernát | aaafeae | 2020-05-05 15:41:45 +0200 | [diff] [blame] | 23 | Leaf, |
| 24 | Rpc, |
| 25 | Action, |
| 26 | Notification, |
| 27 | AnyXml, |
| 28 | LeafList |
Václav Kubernát | 34ee85a | 2020-02-18 17:12:12 +0100 | [diff] [blame] | 29 | }; |
Václav Kubernát | a1c4c9e | 2020-04-22 00:37:52 +0200 | [diff] [blame] | 30 | |
| 31 | enum class Status { |
| 32 | Current, |
| 33 | Deprecated, |
| 34 | Obsolete |
| 35 | }; |
Václav Kubernát | b96eef7 | 2018-05-04 19:10:22 +0200 | [diff] [blame] | 36 | } |
Václav Kubernát | d666296 | 2018-03-22 17:41:33 +0100 | [diff] [blame] | 37 | |
Václav Kubernát | e7d4aea | 2018-09-11 18:15:48 +0200 | [diff] [blame] | 38 | enum class Recursion { |
| 39 | NonRecursive, |
| 40 | Recursive |
| 41 | }; |
Václav Kubernát | f2e463f | 2018-05-28 15:51:08 +0200 | [diff] [blame] | 42 | |
Václav Kubernát | 624a887 | 2018-03-02 17:28:47 +0100 | [diff] [blame] | 43 | |
Václav Kubernát | bbaedc8 | 2020-07-09 10:28:53 +0200 | [diff] [blame] | 44 | class InvalidNodeException : std::exception { |
Václav Kubernát | 624a887 | 2018-03-02 17:28:47 +0100 | [diff] [blame] | 45 | }; |
| 46 | |
Václav Kubernát | 48fc383 | 2018-05-28 14:21:22 +0200 | [diff] [blame] | 47 | /*! \class Schema |
Václav Kubernát | bddbb17 | 2018-06-13 16:27:39 +0200 | [diff] [blame] | 48 | * \brief A base schema class for schemas |
Václav Kubernát | 624a887 | 2018-03-02 17:28:47 +0100 | [diff] [blame] | 49 | * */ |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 50 | |
| 51 | using ModuleNodePair = std::pair<boost::optional<std::string>, std::string>; |
| 52 | |
Václav Kubernát | 48fc383 | 2018-05-28 14:21:22 +0200 | [diff] [blame] | 53 | class Schema { |
Václav Kubernát | 624a887 | 2018-03-02 17:28:47 +0100 | [diff] [blame] | 54 | public: |
Václav Kubernát | bddbb17 | 2018-06-13 16:27:39 +0200 | [diff] [blame] | 55 | virtual ~Schema(); |
Václav Kubernát | d666296 | 2018-03-22 17:41:33 +0100 | [diff] [blame] | 56 | |
Václav Kubernát | 59e4ee4 | 2020-07-08 17:32:45 +0200 | [diff] [blame] | 57 | [[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át | 6a8d1d9 | 2019-04-24 20:30:36 +0200 | [diff] [blame] | 71 | |
Václav Kubernát | 59e4ee4 | 2020-07-08 17:32:45 +0200 | [diff] [blame] | 72 | [[nodiscard]] virtual std::set<ModuleNodePair> availableNodes(const boost::variant<dataPath_, schemaPath_, module_>& path, const Recursion recursion) const = 0; |
Václav Kubernát | 624a887 | 2018-03-02 17:28:47 +0100 | [diff] [blame] | 73 | }; |