Václav Kubernát | bddbb17 | 2018-06-13 16:27:39 +0200 | [diff] [blame] | 1 | |
Václav Kubernát | 624a887 | 2018-03-02 17:28:47 +0100 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2018 CESNET, https://photonics.cesnet.cz/ |
Václav Kubernát | d666296 | 2018-03-22 17:41:33 +0100 | [diff] [blame] | 4 | * Copyright (C) 2018 FIT CVUT, https://fit.cvut.cz/ |
Václav Kubernát | 624a887 | 2018-03-02 17:28:47 +0100 | [diff] [blame] | 5 | * |
| 6 | * Written by Václav Kubernát <kubervac@fit.cvut.cz> |
| 7 | * |
| 8 | */ |
| 9 | |
| 10 | #pragma once |
| 11 | |
Václav Kubernát | 509ce65 | 2019-05-29 19:46:44 +0200 | [diff] [blame] | 12 | #include <boost/variant/variant.hpp> |
Václav Kubernát | b96eef7 | 2018-05-04 19:10:22 +0200 | [diff] [blame] | 13 | #include <set> |
Václav Kubernát | 624a887 | 2018-03-02 17:28:47 +0100 | [diff] [blame] | 14 | #include <stdexcept> |
| 15 | #include <unordered_map> |
Václav Kubernát | 24df80e | 2018-06-06 15:18:03 +0200 | [diff] [blame] | 16 | #include "ast_path.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 | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 21 | enum class LeafDataTypes { |
| 22 | String, |
| 23 | Decimal, |
| 24 | Bool, |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 25 | Int8, |
| 26 | Uint8, |
| 27 | Int16, |
| 28 | Uint16, |
| 29 | Int32, |
| 30 | Uint32, |
| 31 | Int64, |
| 32 | Uint64, |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 33 | Enum, |
Václav Kubernát | ab53899 | 2019-03-06 15:30:50 +0100 | [diff] [blame] | 34 | Binary, |
Václav Kubernát | eeb3884 | 2019-03-20 19:46:05 +0100 | [diff] [blame] | 35 | IdentityRef, |
Václav Kubernát | 6a8d1d9 | 2019-04-24 20:30:36 +0200 | [diff] [blame] | 36 | LeafRef, |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 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 | eeb3884 | 2019-03-20 19:46:05 +0100 | [diff] [blame] | 45 | enum class Prefixes { |
| 46 | Always, |
| 47 | WhenNeeded |
| 48 | }; |
| 49 | |
Václav Kubernát | 624a887 | 2018-03-02 17:28:47 +0100 | [diff] [blame] | 50 | |
| 51 | class InvalidNodeException : public std::invalid_argument { |
| 52 | public: |
| 53 | using std::invalid_argument::invalid_argument; |
| 54 | ~InvalidNodeException() override; |
Václav Kubernát | 624a887 | 2018-03-02 17:28:47 +0100 | [diff] [blame] | 55 | }; |
| 56 | |
Václav Kubernát | 48fc383 | 2018-05-28 14:21:22 +0200 | [diff] [blame] | 57 | /*! \class Schema |
Václav Kubernát | bddbb17 | 2018-06-13 16:27:39 +0200 | [diff] [blame] | 58 | * \brief A base schema class for schemas |
Václav Kubernát | 624a887 | 2018-03-02 17:28:47 +0100 | [diff] [blame] | 59 | * */ |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 60 | |
| 61 | using ModuleNodePair = std::pair<boost::optional<std::string>, std::string>; |
| 62 | |
Václav Kubernát | 48fc383 | 2018-05-28 14:21:22 +0200 | [diff] [blame] | 63 | class Schema { |
Václav Kubernát | 624a887 | 2018-03-02 17:28:47 +0100 | [diff] [blame] | 64 | public: |
Václav Kubernát | bddbb17 | 2018-06-13 16:27:39 +0200 | [diff] [blame] | 65 | virtual ~Schema(); |
Václav Kubernát | d666296 | 2018-03-22 17:41:33 +0100 | [diff] [blame] | 66 | |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 67 | virtual bool isContainer(const schemaPath_& location, const ModuleNodePair& node) const = 0; |
| 68 | virtual bool isLeaf(const schemaPath_& location, const ModuleNodePair& node) const = 0; |
| 69 | virtual bool isModule(const schemaPath_& location, const std::string& name) const = 0; |
| 70 | virtual bool isList(const schemaPath_& location, const ModuleNodePair& node) const = 0; |
| 71 | virtual bool isPresenceContainer(const schemaPath_& location, const ModuleNodePair& node) const = 0; |
| 72 | virtual bool leafEnumHasValue(const schemaPath_& location, const ModuleNodePair& node, const std::string& value) const = 0; |
Václav Kubernát | eeb3884 | 2019-03-20 19:46:05 +0100 | [diff] [blame] | 73 | virtual bool leafIdentityIsValid(const schemaPath_& location, const ModuleNodePair& node, const ModuleValuePair& value) const = 0; |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 74 | virtual bool listHasKey(const schemaPath_& location, const ModuleNodePair& node, const std::string& key) const = 0; |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 75 | virtual const std::set<std::string> listKeys(const schemaPath_& location, const ModuleNodePair& node) const = 0; |
| 76 | virtual yang::LeafDataTypes leafType(const schemaPath_& location, const ModuleNodePair& node) const = 0; |
Václav Kubernát | 6a8d1d9 | 2019-04-24 20:30:36 +0200 | [diff] [blame] | 77 | virtual yang::LeafDataTypes leafrefBase(const schemaPath_& location, const ModuleNodePair& node) const = 0; |
| 78 | |
Václav Kubernát | eeb3884 | 2019-03-20 19:46:05 +0100 | [diff] [blame] | 79 | virtual const std::set<std::string> validIdentities(const schemaPath_& location, const ModuleNodePair& node, const Prefixes prefixes) const = 0; |
Václav Kubernát | 989b5de | 2019-02-20 16:28:35 +0100 | [diff] [blame] | 80 | virtual const std::set<std::string> enumValues(const schemaPath_& location, const ModuleNodePair& node) const = 0; |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 81 | 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] | 82 | 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] | 83 | }; |