Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2020 CESNET, https://photonics.cesnet.cz/ |
| 3 | * |
| 4 | * Written by Václav Kubernát <kubernat@cesnet.cz> |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | #pragma once |
| 9 | #include <memory> |
Jan Kundrát | cc5dbe2 | 2021-05-17 13:02:03 +0200 | [diff] [blame] | 10 | #include <optional> |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 11 | #include <set> |
| 12 | #include <string> |
| 13 | #include <variant> |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 14 | #include <vector> |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 15 | |
| 16 | struct enum_; |
| 17 | struct identityRef_; |
| 18 | |
| 19 | namespace yang { |
| 20 | struct String { |
| 21 | bool operator==(const String&) const; |
| 22 | }; |
| 23 | struct Decimal { |
| 24 | bool operator==(const Decimal&) const; |
| 25 | }; |
| 26 | struct Bool { |
| 27 | bool operator==(const Bool&) const; |
| 28 | }; |
| 29 | struct Int8 { |
| 30 | bool operator==(const Int8&) const; |
| 31 | }; |
| 32 | struct Uint8 { |
| 33 | bool operator==(const Uint8&) const; |
| 34 | }; |
| 35 | struct Int16 { |
| 36 | bool operator==(const Int16&) const; |
| 37 | }; |
| 38 | struct Uint16 { |
| 39 | bool operator==(const Uint16&) const; |
| 40 | }; |
| 41 | struct Int32 { |
| 42 | bool operator==(const Int32&) const; |
| 43 | }; |
| 44 | struct Uint32 { |
| 45 | bool operator==(const Uint32&) const; |
| 46 | }; |
| 47 | struct Int64 { |
| 48 | bool operator==(const Int64&) const; |
| 49 | }; |
| 50 | struct Uint64 { |
| 51 | bool operator==(const Uint64&) const; |
| 52 | }; |
| 53 | struct Binary { |
| 54 | bool operator==(const Binary&) const; |
| 55 | }; |
Jan Kundrát | 379bb57 | 2020-05-07 03:23:13 +0200 | [diff] [blame] | 56 | struct Empty { |
| 57 | bool operator==(const Empty&) const; |
| 58 | }; |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 59 | struct Enum { |
| 60 | Enum(std::set<enum_>&& values); |
| 61 | bool operator==(const Enum& other) const; |
| 62 | std::set<enum_> m_allowedValues; |
| 63 | }; |
| 64 | struct IdentityRef { |
| 65 | IdentityRef(std::set<identityRef_>&& list); |
| 66 | bool operator==(const IdentityRef& other) const; |
| 67 | std::set<identityRef_> m_allowedValues; |
| 68 | }; |
Václav Kubernát | dab73ca | 2020-10-26 23:44:43 +0100 | [diff] [blame] | 69 | struct Bits { |
| 70 | bool operator==(const Bits& other) const; |
| 71 | std::set<std::string> m_allowedValues; |
| 72 | }; |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 73 | struct LeafRef; |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 74 | struct Union; |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 75 | using LeafDataType = std::variant< |
| 76 | yang::String, |
| 77 | yang::Decimal, |
| 78 | yang::Bool, |
| 79 | yang::Int8, |
| 80 | yang::Uint8, |
| 81 | yang::Int16, |
| 82 | yang::Uint16, |
| 83 | yang::Int32, |
| 84 | yang::Uint32, |
| 85 | yang::Int64, |
| 86 | yang::Uint64, |
| 87 | yang::Enum, |
| 88 | yang::Binary, |
Jan Kundrát | 379bb57 | 2020-05-07 03:23:13 +0200 | [diff] [blame] | 89 | yang::Empty, |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 90 | yang::IdentityRef, |
Václav Kubernát | dab73ca | 2020-10-26 23:44:43 +0100 | [diff] [blame] | 91 | yang::Bits, |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 92 | yang::LeafRef, |
| 93 | yang::Union |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 94 | >; |
Václav Kubernát | 13b23d7 | 2020-04-16 21:49:51 +0200 | [diff] [blame] | 95 | struct TypeInfo; |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 96 | struct LeafRef { |
| 97 | LeafRef(const LeafRef& src); |
Václav Kubernát | 13b23d7 | 2020-04-16 21:49:51 +0200 | [diff] [blame] | 98 | LeafRef(const std::string& xpath, std::unique_ptr<TypeInfo>&& type); |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 99 | bool operator==(const LeafRef& other) const; |
| 100 | std::string m_targetXPath; |
Václav Kubernát | 13b23d7 | 2020-04-16 21:49:51 +0200 | [diff] [blame] | 101 | std::unique_ptr<TypeInfo> m_targetType; |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 102 | }; |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 103 | |
| 104 | struct Union { |
| 105 | bool operator==(const Union& other) const; |
Václav Kubernát | 13b23d7 | 2020-04-16 21:49:51 +0200 | [diff] [blame] | 106 | std::vector<TypeInfo> m_unionTypes; |
| 107 | }; |
| 108 | struct TypeInfo { |
Václav Kubernát | 1ae24f4 | 2020-12-01 02:32:04 +0100 | [diff] [blame] | 109 | TypeInfo(const yang::LeafDataType& type, |
| 110 | const std::optional<std::string> units = std::nullopt, |
| 111 | const std::optional<std::string> description = std::nullopt); |
Václav Kubernát | 13b23d7 | 2020-04-16 21:49:51 +0200 | [diff] [blame] | 112 | bool operator==(const TypeInfo& other) const; |
| 113 | yang::LeafDataType m_type; |
| 114 | std::optional<std::string> m_units; |
Václav Kubernát | 1ae24f4 | 2020-12-01 02:32:04 +0100 | [diff] [blame] | 115 | std::optional<std::string> m_description; |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 116 | }; |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 117 | } |