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 | eeb3884 | 2019-03-20 19:46:05 +0100 | [diff] [blame] | 18 | using ModuleValuePair = std::pair<boost::optional<std::string>, std::string>; |
| 19 | |
Václav Kubernát | 48fc383 | 2018-05-28 14:21:22 +0200 | [diff] [blame] | 20 | namespace yang { |
Václav Kubernát | 34ee85a | 2020-02-18 17:12:12 +0100 | [diff] [blame] | 21 | enum class NodeTypes { |
| 22 | Container, |
| 23 | PresenceContainer, |
| 24 | List, |
Václav Kubernát | aaafeae | 2020-05-05 15:41:45 +0200 | [diff] [blame^] | 25 | Leaf, |
| 26 | Rpc, |
| 27 | Action, |
| 28 | Notification, |
| 29 | AnyXml, |
| 30 | LeafList |
Václav Kubernát | 34ee85a | 2020-02-18 17:12:12 +0100 | [diff] [blame] | 31 | }; |
Václav Kubernát | a1c4c9e | 2020-04-22 00:37:52 +0200 | [diff] [blame] | 32 | |
| 33 | enum class Status { |
| 34 | Current, |
| 35 | Deprecated, |
| 36 | Obsolete |
| 37 | }; |
Václav Kubernát | b96eef7 | 2018-05-04 19:10:22 +0200 | [diff] [blame] | 38 | } |
Václav Kubernát | d666296 | 2018-03-22 17:41:33 +0100 | [diff] [blame] | 39 | |
Václav Kubernát | e7d4aea | 2018-09-11 18:15:48 +0200 | [diff] [blame] | 40 | enum class Recursion { |
| 41 | NonRecursive, |
| 42 | Recursive |
| 43 | }; |
Václav Kubernát | f2e463f | 2018-05-28 15:51:08 +0200 | [diff] [blame] | 44 | |
Václav Kubernát | 624a887 | 2018-03-02 17:28:47 +0100 | [diff] [blame] | 45 | |
Václav Kubernát | 34ee85a | 2020-02-18 17:12:12 +0100 | [diff] [blame] | 46 | class InvalidNodeException { |
Václav Kubernát | 624a887 | 2018-03-02 17:28:47 +0100 | [diff] [blame] | 47 | }; |
| 48 | |
Václav Kubernát | 48fc383 | 2018-05-28 14:21:22 +0200 | [diff] [blame] | 49 | /*! \class Schema |
Václav Kubernát | bddbb17 | 2018-06-13 16:27:39 +0200 | [diff] [blame] | 50 | * \brief A base schema class for schemas |
Václav Kubernát | 624a887 | 2018-03-02 17:28:47 +0100 | [diff] [blame] | 51 | * */ |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 52 | |
| 53 | using ModuleNodePair = std::pair<boost::optional<std::string>, std::string>; |
| 54 | |
Václav Kubernát | 48fc383 | 2018-05-28 14:21:22 +0200 | [diff] [blame] | 55 | class Schema { |
Václav Kubernát | 624a887 | 2018-03-02 17:28:47 +0100 | [diff] [blame] | 56 | public: |
Václav Kubernát | bddbb17 | 2018-06-13 16:27:39 +0200 | [diff] [blame] | 57 | virtual ~Schema(); |
Václav Kubernát | d666296 | 2018-03-22 17:41:33 +0100 | [diff] [blame] | 58 | |
Václav Kubernát | 2a14139 | 2020-02-18 17:12:32 +0100 | [diff] [blame] | 59 | 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át | 34ee85a | 2020-02-18 17:12:12 +0100 | [diff] [blame] | 63 | 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át | 75877de | 2019-11-20 17:43:02 +0100 | [diff] [blame] | 65 | virtual bool isModule(const std::string& name) const = 0; |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 66 | virtual bool listHasKey(const schemaPath_& location, const ModuleNodePair& node, const std::string& key) const = 0; |
Václav Kubernát | c386679 | 2020-02-20 14:12:56 +0100 | [diff] [blame] | 67 | virtual bool leafIsKey(const std::string& leafPath) const = 0; |
Václav Kubernát | 0599e9f | 2020-04-21 09:51:33 +0200 | [diff] [blame] | 68 | virtual bool isConfig(const std::string& path) const = 0; |
Václav Kubernát | b1a75c6 | 2020-04-21 15:20:16 +0200 | [diff] [blame] | 69 | virtual std::optional<std::string> defaultValue(const std::string& leafPath) const = 0; |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 70 | virtual const std::set<std::string> listKeys(const schemaPath_& location, const ModuleNodePair& node) const = 0; |
Václav Kubernát | 13b23d7 | 2020-04-16 21:49:51 +0200 | [diff] [blame] | 71 | 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át | 6fcd028 | 2020-02-21 16:33:08 +0100 | [diff] [blame] | 73 | virtual std::optional<std::string> leafTypeName(const std::string& path) const = 0; |
Václav Kubernát | bd5e3c2 | 2020-02-19 15:22:00 +0100 | [diff] [blame] | 74 | virtual std::string leafrefPath(const std::string& leafrefPath) const = 0; |
Václav Kubernát | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 75 | virtual std::optional<std::string> description(const std::string& location) const = 0; |
Václav Kubernát | a1c4c9e | 2020-04-22 00:37:52 +0200 | [diff] [blame] | 76 | virtual yang::Status status(const std::string& location) const = 0; |
Václav Kubernát | 6a8d1d9 | 2019-04-24 20:30:36 +0200 | [diff] [blame] | 77 | |
Václav Kubernát | 95b0887 | 2020-04-28 01:04:17 +0200 | [diff] [blame] | 78 | 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] | 79 | }; |