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, |
| 25 | Leaf |
| 26 | }; |
Václav Kubernát | b96eef7 | 2018-05-04 19:10:22 +0200 | [diff] [blame] | 27 | } |
Václav Kubernát | d666296 | 2018-03-22 17:41:33 +0100 | [diff] [blame] | 28 | |
Václav Kubernát | e7d4aea | 2018-09-11 18:15:48 +0200 | [diff] [blame] | 29 | enum class Recursion { |
| 30 | NonRecursive, |
| 31 | Recursive |
| 32 | }; |
Václav Kubernát | f2e463f | 2018-05-28 15:51:08 +0200 | [diff] [blame] | 33 | |
Václav Kubernát | 624a887 | 2018-03-02 17:28:47 +0100 | [diff] [blame] | 34 | |
Václav Kubernát | 34ee85a | 2020-02-18 17:12:12 +0100 | [diff] [blame] | 35 | class InvalidNodeException { |
Václav Kubernát | 624a887 | 2018-03-02 17:28:47 +0100 | [diff] [blame] | 36 | }; |
| 37 | |
Václav Kubernát | 48fc383 | 2018-05-28 14:21:22 +0200 | [diff] [blame] | 38 | /*! \class Schema |
Václav Kubernát | bddbb17 | 2018-06-13 16:27:39 +0200 | [diff] [blame] | 39 | * \brief A base schema class for schemas |
Václav Kubernát | 624a887 | 2018-03-02 17:28:47 +0100 | [diff] [blame] | 40 | * */ |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 41 | |
| 42 | using ModuleNodePair = std::pair<boost::optional<std::string>, std::string>; |
| 43 | |
Václav Kubernát | 48fc383 | 2018-05-28 14:21:22 +0200 | [diff] [blame] | 44 | class Schema { |
Václav Kubernát | 624a887 | 2018-03-02 17:28:47 +0100 | [diff] [blame] | 45 | public: |
Václav Kubernát | bddbb17 | 2018-06-13 16:27:39 +0200 | [diff] [blame] | 46 | virtual ~Schema(); |
Václav Kubernát | d666296 | 2018-03-22 17:41:33 +0100 | [diff] [blame] | 47 | |
Václav Kubernát | 2a14139 | 2020-02-18 17:12:32 +0100 | [diff] [blame] | 48 | bool isContainer(const schemaPath_& location, const ModuleNodePair& node) const; |
| 49 | bool isLeaf(const schemaPath_& location, const ModuleNodePair& node) const; |
| 50 | bool isList(const schemaPath_& location, const ModuleNodePair& node) const; |
| 51 | bool isPresenceContainer(const schemaPath_& location, const ModuleNodePair& node) const; |
Václav Kubernát | 34ee85a | 2020-02-18 17:12:12 +0100 | [diff] [blame] | 52 | virtual yang::NodeTypes nodeType(const std::string& path) const = 0; |
| 53 | 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] | 54 | virtual bool isModule(const std::string& name) const = 0; |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 55 | 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] | 56 | virtual bool leafIsKey(const std::string& leafPath) const = 0; |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 57 | virtual const std::set<std::string> listKeys(const schemaPath_& location, const ModuleNodePair& node) const = 0; |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame^] | 58 | virtual yang::LeafDataType leafType(const schemaPath_& location, const ModuleNodePair& node) const = 0; |
| 59 | virtual yang::LeafDataType leafType(const std::string& path) const = 0; |
Václav Kubernát | 6fcd028 | 2020-02-21 16:33:08 +0100 | [diff] [blame] | 60 | 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] | 61 | virtual std::string leafrefPath(const std::string& leafrefPath) const = 0; |
Václav Kubernát | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 62 | virtual std::optional<std::string> description(const std::string& location) const = 0; |
| 63 | virtual std::optional<std::string> units(const std::string& location) const = 0; |
Václav Kubernát | 6a8d1d9 | 2019-04-24 20:30:36 +0200 | [diff] [blame] | 64 | |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 65 | virtual std::set<std::string> childNodes(const schemaPath_& path, const Recursion recursion) const = 0; |
Václav Kubernát | 9456b5c | 2019-10-02 21:14:52 +0200 | [diff] [blame] | 66 | virtual std::set<std::string> moduleNodes(const module_& module, const Recursion recursion) const = 0; |
Václav Kubernát | 624a887 | 2018-03-02 17:28:47 +0100 | [diff] [blame] | 67 | }; |