1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
/*
 * Copyright (C) 2021 CESNET, https://photonics.cesnet.cz/
 *
 * Written by Václav Kubernát <kubernat@cesnet.cz>
 *
 * SPDX-License-Identifier: BSD-3-Clause
*/
#pragma once

#include <cstdint>
#include <iosfwd>
#include <libyang-cpp/export.h>
#include <type_traits>
namespace libyang {
/**
 * Controls whether findPath should consider input or output nodes
 */
enum class InputOutputNodes {
    Input,
    Output,
};

/*
 * Iteration type for Collection and Iterator.
 */
enum class IterationType {
    Dfs,
    Meta,
    Sibling
};

/**
 * Wraps LYS_INFORMAT.
 */
enum class SchemaFormat {
    YANG = 1,
    YIN = 3
};

/**
 * Wraps LYD_FORMAT.
 */
enum class DataFormat {
    Detect = 0,
    XML,
    JSON
};

/**
 * Wraps `lyd_type`.
 */
enum class OperationType : uint32_t {
    DataYang = 0,
    RpcYang,
    NotificationYang,
    ReplyYang,
    RpcNetconf,
    NotificationNetconf,
    ReplyNetconf,
    RpcRestconf,
    NotificationRestconf,
    ReplyRestconf,
};

/**
 * Wraps LYD_PRINT_* flags.
 */
enum class PrintFlags : uint32_t {
    WithDefaultsExplicit = 0x00,
    WithSiblings = 0x01,
    Shrink = 0x02,
    KeepEmptyCont = 0x04,
    WithDefaultsTrim = 0x10,
    WithDefaultsAll = 0x20,
    WithDefaultsAllTag = 0x40,
    WithDefaultsImplicitTag = 0x80,
    WithDefaultsMask = 0xF0,
};

/**
 * Wraps LY_ERR.
 */
enum class ErrorCode : uint32_t {
    Success,
    MemoryFailure,
    SyscallFail,
    InvalidValue,
    ItemAlreadyExists,
    NotFound,
    InternalError,
    ValidationFailure,
    OperationDenied,
    OperationIncomplete,
    RecompileRequired,
    Negative,
    Unknown,
    PluginError = 128
};

/**
 * Wraps LY_VECODE.
 */
enum class ValidationErrorCode : uint32_t {
    Success,
    Syntax,
    YangSyntax,
    YinSyntax,
    Reference,
    Xpath,
    Semantics,
    XmlSyntax,
    JsonSyntax,
    Data,
    Other
};

enum class CreationOptions : uint32_t {
    Output = 0x01,
    StoreOnly = 0x02,
    // BinaryLyb = 0x04, TODO
    CanonicalValue = 0x08,
    ClearDefaultFromParents = 0x10,
    Update = 0x20,
    Opaque = 0x40,
    PathWithOpaque = 0x80,
    // LYD_NEW_ANY_USE_VALUE is not relevant
};

/**
 * Wraps LYD_DUP_* flags. Supports operator|.
 */
enum class DuplicationOptions : uint32_t {
    Recursive   = 0x01,
    NoMeta      = 0x02,
    WithParents = 0x04,
    WithFlags   = 0x08,
    NoExt       = 0x10,
    WithPriv    = 0x20,
};

enum class NodeType : uint16_t {
    Unknown      = 0x0000,
    Container    = 0x0001,
    Choice       = 0x0002,
    Leaf         = 0x0004,
    Leaflist     = 0x0008,
    List         = 0x0010,
    AnyXML       = 0x0020,
    AnyData      = 0x0060,
    Case         = 0x0080,
    RPC          = 0x0100,
    Action       = 0x0200,
    Notification = 0x0400,
    Uses         = 0x0800,
    Input        = 0x1000,
    Output       = 0x2000,
    Grouping     = 0x4000,
    Augment      = 0x8000,
};

enum class ContextOptions : uint16_t {
    AllImplemented    = 0x01,
    RefImplemented    = 0x02,
    NoYangLibrary     = 0x04,
    DisableSearchDirs = 0x08,
    DisableSearchCwd  = 0x10,
    PreferSearchDirs  = 0x20,
    SetPrivParsed     = 0x40,
    ExplicitCompile   = 0x80,
};

/**
 * Wraps LY_DATA_TYPE.
 */
enum class LeafBaseType : uint32_t {
    Unknown = 0,
    Binary,
    Uint8,
    Uint16,
    Uint32,
    Uint64,
    String,
    Bits,
    Bool,
    Dec64,
    Empty,
    Enum,
    IdentityRef,
    InstanceIdentifier,
    Leafref,
    Union,
    Int8,
    Int16,
    Int32,
    Int64
};

/**
 * Wraps LYD_ANYDATA_VALUETYPE.
 */
enum class AnydataValueType : uint32_t {
    DataTree,
    String,
    XML,
    JSON,
    LYB
};

/**
 * Wraps LY_LO* flags. Supports operator|.
 */
enum class LogOptions : uint32_t {
    NoLog     = 0x00,
    Log       = 0x01,
    Store     = 0x02,
    StoreLast = 0x06,
};

/**
 * Wraps LY_LOG_LEVEL.
 */
enum class LogLevel : uint32_t {
    Error,
    Warning,
    Verbose,
    Debug
};

/**
 * Enum for the YANG `status` statement.
 */
enum class Status {
    Current,
    Deprecated,
    Obsolete
};

/**
 * Enum for the YANG `config` statement.
 */
enum class Config {
    True,
    False
};

/**
 * Wraps LYD_VALIDATE_* flags.
 */
enum class ValidationOptions {
    NoState = 0x0001,
    Present = 0x0002,
    MultiError = 0x0004,
    Operational = 0x0008,
    NoDefaults = 0x0010,
};

/**
 * Wraps LYD_PARSE_* flags.
 */
enum class ParseOptions {
    ParseOnly    = 0x010000,
    Strict       = 0x020000,
    Opaque       = 0x040000,
    NoState      = 0x080000,
    LybModUpdate = 0x100000,
    Ordered      = 0x200000,
    Subtree      = 0x400000, /**< Do not use this one for parsing of data subtrees */
    WhenTrue     = 0x800000,
    NoNew        = 0x1000000,
};

/**
 * @brief Wraps LYS_OUT_* schema output format flags
 */
enum class SchemaOutputFormat : unsigned int {
    Unknown = 0,
    Yang = 1,
    CompiledYang = 2,
    Yin = 3,
    Tree = 4,
};

/**
 * @brief Wraps LYS_PRINT_* flags.
 */
enum class SchemaPrintFlags : uint32_t {
    NoSubStatements = 0x10,
    Shrink = 0x02,
};

/**
 * @brief Wraps LYD_COMPARE_* flags.
 */
enum class DataCompare : uint32_t {
    NoOptions = 0x00, /**< Equivalent of a raw C 0 to say "no flags given" in a typesafe manner */
    DistinguishExplicitDefaults = 0x02, /**< LYD_COMPARE_DEFAULTS */
    FullRecursion = 0x01, /**< LYD_COMPARE_FULL_RECURSION*/
    OpaqueAsData = 0x04, /**< LYD_COMPARE_OPAQ */
};

template <typename Enum>
constexpr Enum implEnumBitOr(const Enum a, const Enum b)<--- Function parameter 'a' should be passed by const reference.<--- Function parameter 'b' should be passed by const reference.
{
    using Type = std::underlying_type_t<Enum>;
    return static_cast<Enum>(static_cast<Type>(a) | static_cast<Type>(b));
}

constexpr PrintFlags operator|(const PrintFlags a, const PrintFlags b)
{
    return implEnumBitOr(a, b);
}

constexpr CreationOptions operator|(const CreationOptions a, const CreationOptions b)
{
    return implEnumBitOr(a, b);
}

constexpr ContextOptions operator|(const ContextOptions a, const ContextOptions b)
{
    return implEnumBitOr(a, b);
}

constexpr DuplicationOptions operator|(const DuplicationOptions a, const DuplicationOptions b)
{
    return implEnumBitOr(a, b);
}

constexpr LogOptions operator|(const LogOptions a, const LogOptions b)
{
    return implEnumBitOr(a, b);
}

constexpr ValidationOptions operator|(const ValidationOptions a, const ValidationOptions b)
{
    return implEnumBitOr(a, b);
}

constexpr ParseOptions operator|(const ParseOptions a, const ParseOptions b)
{
    return implEnumBitOr(a, b);
}

constexpr SchemaPrintFlags operator|(const SchemaPrintFlags a, const SchemaPrintFlags b)
{
    return implEnumBitOr(a, b);
}

constexpr DataCompare operator|(const DataCompare a, const DataCompare b)
{
    return implEnumBitOr(a, b);
}

LIBYANG_CPP_EXPORT std::ostream& operator<<(std::ostream& os, const NodeType& type);
LIBYANG_CPP_EXPORT std::ostream& operator<<(std::ostream& os, const ErrorCode& err);
LIBYANG_CPP_EXPORT std::ostream& operator<<(std::ostream& os, const ValidationErrorCode& err);
LIBYANG_CPP_EXPORT std::ostream& operator<<(std::ostream& os, const LogLevel& level);
}