-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathutils.hpp
More file actions
71 lines (61 loc) · 3.07 KB
/
utils.hpp
File metadata and controls
71 lines (61 loc) · 3.07 KB
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
/*
* Copyright (C) 2022 CESNET, https://photonics.cesnet.cz/
*
* Written by Václav Kubernát <[email protected]>
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#pragma once
#include <libnetconf2-cpp/Enum.hpp>
#include <libnetconf2/log.h>
#include <libnetconf2/messages_client.h>
namespace libnetconf::utils {
constexpr NC_VERB_LEVEL toLogLevel(const LogLevel level)
{
return static_cast<NC_VERB_LEVEL>(level);
}
constexpr LogLevel toLogLevel(const NC_VERB_LEVEL level)
{
return static_cast<LogLevel>(level);
}
// These tests ensure that I used the right numbers when defining my enum.
static_assert(LogLevel::Error == toLogLevel(NC_VERB_LEVEL::NC_VERB_ERROR));
static_assert(LogLevel::Warning == toLogLevel(NC_VERB_LEVEL::NC_VERB_WARNING));
static_assert(LogLevel::Verbose == toLogLevel(NC_VERB_LEVEL::NC_VERB_VERBOSE));
static_assert(LogLevel::Debug == toLogLevel(NC_VERB_LEVEL::NC_VERB_DEBUG));
static_assert(LogLevel::DebugLowLvl == toLogLevel(NC_VERB_LEVEL::NC_VERB_DEBUG_LOWLVL));
constexpr NC_DATASTORE toDatastore(const Datastore ds)
{
return static_cast<NC_DATASTORE>(ds);
}
static_assert(toDatastore(Datastore::Error) == NC_DATASTORE::NC_DATASTORE_ERROR);
static_assert(toDatastore(Datastore::Config) == NC_DATASTORE::NC_DATASTORE_CONFIG);
static_assert(toDatastore(Datastore::Url) == NC_DATASTORE::NC_DATASTORE_URL);
static_assert(toDatastore(Datastore::Running) == NC_DATASTORE::NC_DATASTORE_RUNNING);
static_assert(toDatastore(Datastore::Startup) == NC_DATASTORE::NC_DATASTORE_STARTUP);
static_assert(toDatastore(Datastore::Candidate) == NC_DATASTORE::NC_DATASTORE_CANDIDATE);
constexpr NC_RPC_EDIT_DFLTOP toDefaultOp(const EditDefaultOp ds)
{
return static_cast<NC_RPC_EDIT_DFLTOP>(ds);
}
static_assert(toDefaultOp(EditDefaultOp::Unknown) == NC_RPC_EDIT_DFLTOP::NC_RPC_EDIT_DFLTOP_UNKNOWN);
static_assert(toDefaultOp(EditDefaultOp::Merge) == NC_RPC_EDIT_DFLTOP::NC_RPC_EDIT_DFLTOP_MERGE);
static_assert(toDefaultOp(EditDefaultOp::Replace) == NC_RPC_EDIT_DFLTOP::NC_RPC_EDIT_DFLTOP_REPLACE);
static_assert(toDefaultOp(EditDefaultOp::None) == NC_RPC_EDIT_DFLTOP::NC_RPC_EDIT_DFLTOP_NONE);
constexpr NC_RPC_EDIT_TESTOPT toTestOpt(const EditTestOpt ds)
{
return static_cast<NC_RPC_EDIT_TESTOPT>(ds);
}
static_assert(toTestOpt(EditTestOpt::Unknown) == NC_RPC_EDIT_TESTOPT::NC_RPC_EDIT_TESTOPT_UNKNOWN);
static_assert(toTestOpt(EditTestOpt::TestSet) == NC_RPC_EDIT_TESTOPT::NC_RPC_EDIT_TESTOPT_TESTSET);
static_assert(toTestOpt(EditTestOpt::Set) == NC_RPC_EDIT_TESTOPT::NC_RPC_EDIT_TESTOPT_SET);
static_assert(toTestOpt(EditTestOpt::Test) == NC_RPC_EDIT_TESTOPT::NC_RPC_EDIT_TESTOPT_TEST);
constexpr NC_RPC_EDIT_ERROPT toErrorOpt(const EditErrorOpt ds)
{
return static_cast<NC_RPC_EDIT_ERROPT >(ds);
}
static_assert(toErrorOpt(EditErrorOpt::Unknown) == NC_RPC_EDIT_ERROPT::NC_RPC_EDIT_ERROPT_UNKNOWN);
static_assert(toErrorOpt(EditErrorOpt::Stop) == NC_RPC_EDIT_ERROPT::NC_RPC_EDIT_ERROPT_STOP);
static_assert(toErrorOpt(EditErrorOpt::Continue) == NC_RPC_EDIT_ERROPT::NC_RPC_EDIT_ERROPT_CONTINUE);
static_assert(toErrorOpt(EditErrorOpt::Rollback) == NC_RPC_EDIT_ERROPT::NC_RPC_EDIT_ERROPT_ROLLBACK);
}