-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathnewPath.cpp
More file actions
44 lines (36 loc) · 1.58 KB
/
newPath.cpp
File metadata and controls
44 lines (36 loc) · 1.58 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
/*
* Copyright (C) 2021 CESNET, https://photonics.cesnet.cz/
*
* Written by Václav Kubernát <[email protected]>
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <libyang-cpp/Utils.hpp>
#include "enum.hpp"
#include "exception.hpp"
#include "newPath.hpp"
using namespace std::string_literals;
namespace libyang::impl {
std::optional<DataNode> newPath(lyd_node* node, ly_ctx* ctx, std::shared_ptr<internal_refcount> refs, const std::string& path, const std::optional<std::string>& value, const std::optional<CreationOptions> options)
{
lyd_node* out;
auto err = lyd_new_path(node, ctx, path.c_str(), value ? value->c_str() : nullptr, options ? utils::toCreationOptions(*options) : 0, &out);
throwIfError(err, "Couldn't create a node with path '"s + path + "'");
if (out) {
return DataNode{out, refs};
} else {
return std::nullopt;
}
}
CreatedNodes newPath2(lyd_node* node, ly_ctx* ctx, std::shared_ptr<internal_refcount> refs, const std::string& path, const void* const value, const AnydataHints anyHints, const std::optional<CreationOptions> options)
{
lyd_node* newParent;
lyd_node* newNode;
auto err = lyd_new_path2(node, ctx, path.c_str(), value, 0, static_cast<uint32_t>(anyHints), options ? utils::toCreationOptions(*options) : 0, &newParent, &newNode);
throwIfError(err, "Couldn't create a node with path '"s + path + "'");
return {
.createdParent = (newParent ? std::optional{DataNode{newParent, refs}} : std::nullopt),
.createdNode = (newNode ? std::optional{DataNode{newNode, refs}} : std::nullopt),
};
}
}