libyang 1.0.184
YANG data modeling language library
Tree_Data.cpp
Go to the documentation of this file.
1
15#include <iostream>
16#include <memory>
17#include <stdexcept>
18#include <vector>
19
20#include "Xml.hpp"
21#include "Libyang.hpp"
22#include "Tree_Data.hpp"
23#include "Tree_Schema.hpp"
24
25extern "C" {
26#include "libyang.h"
27#include "tree_data.h"
28#include "tree_schema.h"
29}
30
31namespace libyang {
32
33Value::Value(lyd_val value, LY_DATA_TYPE* value_type, uint8_t value_flags, struct lys_type *type, S_Deleter deleter):
34 value(value),
35 value_type(*value_type),
36 value_flags(value_flags),
37 type(type),
38 deleter(deleter)
39{};
41std::vector<S_Type_Bit> Value::bit() {
42 if ((LY_TYPE_BITS != value_type) || (LY_TYPE_BITS != type->base)) {
43 throw "wrong type";
44 }
45 std::vector<S_Type_Bit> vec(type->info.bits.count);
46
47 for (unsigned int i = 0; i < type->info.bits.count; ++i) {
48 if (value.bit[i]) {
49 vec[i] = std::make_shared<Type_Bit>(value.bit[i], deleter);
50 }
51 }
52
53 return vec;
54}
55S_Data_Node Value::instance() {
56 if (LY_TYPE_INST != value_type) {
57 return nullptr;
58 }
59 return value.instance ? std::make_shared<Data_Node>(value.instance, deleter) : nullptr;
60}
61S_Data_Node Value::leafref() {
62 if (LY_TYPE_LEAFREF != value_type) {
63 return nullptr;
64 }
65 return value.leafref ? std::make_shared<Data_Node>(value.leafref, deleter) : nullptr;
66}
67
68Data_Node::Data_Node(struct lyd_node *node, S_Deleter deleter):
69 node(node),
70 deleter(deleter)
71{};
72Data_Node::Data_Node(S_Data_Node parent, S_Module module, const char *name) {
73 lyd_node *new_node = nullptr;
74
75 if (!module && !parent) {
76 throw std::invalid_argument("At least one of module or parent parameters must be set");
77 }
78
79 new_node = lyd_new(parent ? parent->node : NULL, module ? module->module : NULL, name);
80 if (!new_node) {
81 check_libyang_error(module ? module->module->ctx : parent->node->schema->module->ctx);
82 }
83
84 node = new_node;
85 deleter = !parent ? std::make_shared<Deleter>(node, module->deleter) : parent->deleter;
86};
87Data_Node::Data_Node(S_Data_Node parent, S_Module module, const char *name, const char *val_str) {
88 lyd_node *new_node = nullptr;
89
90 if (!module && !parent) {
91 throw std::invalid_argument("At least one of module or parent parameters must be set");
92 }
93
94 new_node = lyd_new_leaf(parent ? parent->node : NULL, module ? module->module : NULL, name, val_str);
95 if (!new_node) {
96 check_libyang_error(module ? module->module->ctx : parent->node->schema->module->ctx);
97 }
98
99 node = new_node;
100 deleter = !parent ? std::make_shared<Deleter>(node, module->deleter) : parent->deleter;
101};
102Data_Node::Data_Node(S_Data_Node parent, S_Module module, const char *name, const char *value, LYD_ANYDATA_VALUETYPE value_type) {
103 lyd_node *new_node = nullptr;
104
105 if (!module && !parent) {
106 throw std::invalid_argument("At least one of module or parent parameters must be set");
107 }
108
109 new_node = lyd_new_anydata(parent ? parent->node : NULL, module ? module->module : NULL, name, (void *) value, value_type);
110 if (!new_node) {
111 check_libyang_error(module ? module->module->ctx : parent->node->schema->module->ctx);
112 }
113
114 node = new_node;
115 deleter = !parent ? std::make_shared<Deleter>(node, module->deleter) : parent->deleter;
116};
117Data_Node::Data_Node(S_Data_Node parent, S_Module module, const char *name, S_Data_Node value) {
118 lyd_node *new_node = nullptr;
119
120 if (!module && !parent) {
121 throw std::invalid_argument("At least one of module or parent parameters must be set");
122 }
123
124 new_node = lyd_new_anydata(parent ? parent->node : NULL, module ? module->module : NULL, name,
125 value ? (void *)value->node : NULL, LYD_ANYDATA_DATATREE);
126 if (!new_node) {
127 check_libyang_error(module ? module->module->ctx : parent->node->schema->module->ctx);
128 }
129
130 node = new_node;
131 deleter = !parent ? std::make_shared<Deleter>(node, module->deleter) : parent->deleter;
132};
133Data_Node::Data_Node(S_Data_Node parent, S_Module module, const char *name, S_Xml_Elem value) {
134 lyd_node *new_node = nullptr;
135
136 if (!module && !parent) {
137 throw std::invalid_argument("At least one of module or parent parameters must be set");
138 }
139
140 new_node = lyd_new_anydata(parent ? parent->node : NULL, module->module, name,
141 value ? (void *)value->elem : NULL, LYD_ANYDATA_XML);
142 if (!new_node) {
143 check_libyang_error(module ? module->module->ctx : parent->node->schema->module->ctx);
144 }
145
146 node = new_node;
147 deleter = !parent ? std::make_shared<Deleter>(node, module->deleter) : parent->deleter;
148}
149Data_Node::Data_Node(S_Context context, const char *path, const char *value, LYD_ANYDATA_VALUETYPE value_type, int options) {
150 lyd_node *new_node = nullptr;
151
152 if (!context) {
153 throw std::invalid_argument("Context can not be empty");
154 }
155 if (!path) {
156 throw std::invalid_argument("Path can not be empty");
157 }
158
159 new_node = lyd_new_path(NULL, context->ctx, path, (void *) value, value_type, options);
160 if (!new_node) {
161 check_libyang_error(context->ctx);
162 }
163
164 node = new_node;
165 deleter = std::make_shared<Deleter>(node, context->deleter);
166}
167Data_Node::Data_Node(S_Context context, const char *path, S_Data_Node value, int options) {
168 lyd_node *new_node = nullptr;
169
170 if (!context) {
171 throw std::invalid_argument("Context can not be empty");
172 }
173 if (!path) {
174 throw std::invalid_argument("Path can not be empty");
175 }
176
177 new_node = lyd_new_path(NULL, context->ctx, path, (void *) value->node, LYD_ANYDATA_DATATREE, options);
178 if (!new_node) {
179 check_libyang_error(context->ctx);
180 }
181
182 node = new_node;
183 deleter = context->deleter;
184}
185Data_Node::Data_Node(S_Context context, const char *path, S_Xml_Elem value, int options) {
186 lyd_node *new_node = nullptr;
187
188 if (!context) {
189 throw std::invalid_argument("Context can not be empty");
190 }
191 if (!path) {
192 throw std::invalid_argument("Path can not be empty");
193 }
194
195 new_node = lyd_new_path(NULL, context->ctx, path, (void *) value->elem, LYD_ANYDATA_XML, options);
196 if (!new_node) {
197 check_libyang_error(context->ctx);
198 }
199
200 node = new_node;
201 deleter = context->deleter;
202}
203
205S_Attr Data_Node::attr() LY_NEW(node, attr, Attr);
206std::string Data_Node::path() {
207 char *path = nullptr;
208
209 path = lyd_path(node);
210 if (!path) {
211 check_libyang_error(node->schema->module->ctx);
212 return nullptr;
213 }
214
215 std::string s_path = path;
216 free(path);
217 return s_path;
218}
219S_Data_Node Data_Node::dup(int recursive) {
220 struct lyd_node *new_node = nullptr;
221
222 new_node = lyd_dup(node, recursive);
223 if (!new_node) {
224 return nullptr;
225 }
226
227 S_Deleter new_deleter = std::make_shared<Deleter>(new_node, deleter);
228 return std::make_shared<Data_Node>(new_node, new_deleter);
229}
230S_Data_Node Data_Node::dup_withsiblings(int recursive) {
231 struct lyd_node *new_node = nullptr;
232
233 new_node = lyd_dup_withsiblings(node, recursive);
234 if (!new_node) {
235 return nullptr;
236 }
237
238 S_Deleter new_deleter = std::make_shared<Deleter>(new_node, deleter);
239 return std::make_shared<Data_Node>(new_node, new_deleter);
240}
241S_Data_Node Data_Node::dup_to_ctx(int recursive, S_Context context) {
242 struct lyd_node *new_node = nullptr;
243
244 if (!context) {
245 throw std::invalid_argument("Context can not be empty");
246 }
247
248 new_node = lyd_dup_to_ctx(node, recursive, context->ctx);
249
250 S_Deleter new_deleter = std::make_shared<Deleter>(new_node, context->deleter);
251 return new_node ? std::make_shared<Data_Node>(new_node, new_deleter) : nullptr;
252}
253int Data_Node::merge(S_Data_Node source, int options) {
254 int ret;
255
256 if (!source) {
257 throw std::invalid_argument("Source can not be empty");
258 }
259
260 ret = lyd_merge(node, source->node, options);
261 if (ret) {
262 check_libyang_error(source->node->schema->module->ctx);
263 }
264 return ret;
265}
266int Data_Node::merge_to_ctx(S_Data_Node source, int options, S_Context context) {
267 int ret;
268
269 if (!source) {
270 throw std::invalid_argument("Source can not be empty");
271 }
272
273 ret = lyd_merge_to_ctx(&node, source->node, options, context ? context->ctx : NULL);
274 if (ret) {
275 check_libyang_error(source->node->schema->module->ctx);
276 }
277 return ret;
278}
279int Data_Node::insert(S_Data_Node new_node) {
280 int ret;
281
282 if (!new_node) {
283 throw std::invalid_argument("New_node can not be empty");
284 }
285
286 ret = lyd_insert(node, new_node->node);
287 if (ret) {
288 check_libyang_error(node->schema->module->ctx);
289 }
290 return ret;
291}
292int Data_Node::insert_sibling(S_Data_Node new_node) {
293 struct lyd_node *dup_node;
294
295 if (!new_node) {
296 throw std::invalid_argument("New_node can not be empty");
297 }
298
299 /* because of memory handling in C++ the node is duplicated before insertion */
300 dup_node = lyd_dup(new_node->node, 1);
301 if (!dup_node) {
302 check_libyang_error(node->schema->module->ctx);
303 }
304
305 int ret = lyd_insert_sibling(&node, dup_node);
306 if (ret) {
307 check_libyang_error(node->schema->module->ctx);
308 }
309 return ret;
310}
311int Data_Node::insert_before(S_Data_Node new_node) {
312 struct lyd_node *dup_node;
313
314 if (!new_node) {
315 throw std::invalid_argument("New_node can not be empty");
316 }
317
318 /* because of memory handling in C++ the node is duplicated before insertion */
319 dup_node = lyd_dup(new_node->node, 1);
320 if (!dup_node) {
321 check_libyang_error(node->schema->module->ctx);
322 }
323
324 int ret = lyd_insert_before(node, dup_node);
325 if (ret) {
326 check_libyang_error(node->schema->module->ctx);
327 }
328 return ret;
329}
330int Data_Node::insert_after(S_Data_Node new_node) {
331 struct lyd_node *dup_node;
332
333 if (!new_node) {
334 throw std::invalid_argument("New_node can not be empty");
335 }
336
337 /* because of memory handling in C++ the node is duplicated before insertion */
338 dup_node = lyd_dup(new_node->node, 1);
339 if (!dup_node) {
340 check_libyang_error(node->schema->module->ctx);
341 }
342
343 int ret = lyd_insert_after(node, dup_node);
344 if (ret) {
345 check_libyang_error(node->schema->module->ctx);
346 }
347 return ret;
348}
349int Data_Node::schema_sort(int recursive) {
350 int ret = lyd_schema_sort(node, recursive);
351 if (ret) {
352 check_libyang_error(node->schema->module->ctx);
353 }
354 return ret;
355}
356S_Set Data_Node::find_path(const char *expr) {
357 struct ly_set *set = lyd_find_path(node, expr);
358 if (!set) {
359 check_libyang_error(node->schema->module->ctx);
360 }
361
362 return std::make_shared<Set>(set, std::make_shared<Deleter>(set, deleter));
363}
364S_Set Data_Node::find_instance(S_Schema_Node schema) {
365
366 if (!schema) {
367 throw std::invalid_argument("Schema can not be empty");
368 }
369
370 struct ly_set *set = lyd_find_instance(node, schema->node);
371 if (!set) {
372 check_libyang_error(node->schema->module->ctx);
373 }
374
375 return std::make_shared<Set>(set, std::make_shared<Deleter>(set, deleter));
376}
378 struct lyd_node *new_node = nullptr;
379
380 new_node = lyd_first_sibling(node);
381
382 return new_node ? std::make_shared<Data_Node>(new_node, deleter) : nullptr;
383}
384int Data_Node::validate(int options, S_Context var_arg) {
385 int ret = lyd_validate(&node, options, var_arg ? (void *) var_arg->ctx : node->schema->module->ctx);
386 if (ret) {
387 check_libyang_error(node ? node->schema->module->ctx : var_arg->ctx);
388 }
389 return ret;
390}
391int Data_Node::validate(int options, S_Data_Node var_arg) {
392 int ret;
393
394 if (!var_arg) {
395 throw std::invalid_argument("var_arg must be a data node");
396 }
397
398 ret = lyd_validate(&node, options, (void *) var_arg->node);
399 if (ret) {
400 check_libyang_error(node->schema->module->ctx);
401 }
402 return ret;
403}
404
405int Data_Node::validate_value(const char *value) {
406 int ret = lyd_validate_value(node->schema, value);
407 if (ret != EXIT_SUCCESS) {
408 check_libyang_error(node->schema->module->ctx);
409 }
410 return ret;
411}
412S_Difflist Data_Node::diff(S_Data_Node second, int options) {
413 struct lyd_difflist *diff;
414
415 if (!second) {
416 throw std::invalid_argument("Second can not be empty");
417 }
418
419 diff = lyd_diff(node, second->node, options);
420 if (!diff) {
421 check_libyang_error(node->schema->module->ctx);
422 }
423
424 return diff ? std::make_shared<Difflist>(diff, deleter) : nullptr;
425}
426S_Data_Node Data_Node::new_path(S_Context ctx, const char *path, const char *value, LYD_ANYDATA_VALUETYPE value_type, int options) {
427 struct lyd_node *new_node = nullptr;
428
429 new_node = lyd_new_path(node, ctx ? ctx->ctx : NULL, path, (void *)value, value_type, options);
430 if (!new_node) {
431 check_libyang_error(node->schema->module->ctx);
432 }
433
434 return new_node ? std::make_shared<Data_Node>(new_node, deleter) : nullptr;
435}
436S_Data_Node Data_Node::new_path(S_Context ctx, const char *path, S_Data_Node value, int options) {
437 struct lyd_node *new_node = nullptr;
438
439 if (!value) {
440 throw std::invalid_argument("Value can not be empty");
441 }
442
443 new_node = lyd_new_path(node, ctx ? ctx->ctx : NULL, path, (void *)value->node, LYD_ANYDATA_DATATREE, options);
444 if (!new_node) {
445 check_libyang_error(node->schema->module->ctx);
446 }
447
448 return new_node ? std::make_shared<Data_Node>(new_node, deleter) : nullptr;
449}
450S_Data_Node Data_Node::new_path(S_Context ctx, const char *path, S_Xml_Elem value, int options) {
451 struct lyd_node *new_node = nullptr;
452
453 if (!value) {
454 throw std::invalid_argument("Value can not be empty");
455 }
456
457 new_node = lyd_new_path(node, ctx ? ctx->ctx : NULL, path, (void *)value->elem, LYD_ANYDATA_XML, options);
458 if (!new_node) {
459 check_libyang_error(node->schema->module->ctx);
460 }
461
462 return new_node ? std::make_shared<Data_Node>(new_node, deleter) : nullptr;
463}
464unsigned int Data_Node::list_pos() {
465 unsigned int ret = lyd_list_pos(node);
466 if (!ret) {
467 check_libyang_error(node->schema->module->ctx);
468 }
469 return ret;
470}
472 int ret = lyd_unlink(node);
473 if (ret) {
474 check_libyang_error(node->schema->module->ctx);
475 }
476
477 /* change C++ memory handling after unlink */
478 if (deleter) {
479 deleter = std::make_shared<Deleter>(node, nullptr);
480 }
481
482 return ret;
483}
484S_Attr Data_Node::insert_attr(S_Module module, const char *name, const char *value) {
485 struct lyd_attr *attr = nullptr;
486
487 attr = lyd_insert_attr(node, module ? module->module : NULL, name, value);
488 if (!attr) {
489 check_libyang_error(node->schema->module->ctx);
490 }
491
492 return attr ? std::make_shared<Attr>(attr, deleter) : nullptr;
493}
495 struct lys_module *module = nullptr;
496
497 module = lyd_node_module(node);
498 if (!module) {
499 check_libyang_error(node->schema->module->ctx);
500 }
501
502 return module ? std::make_shared<Module>(module, deleter) : nullptr;
503}
504std::string Data_Node::print_mem(LYD_FORMAT format, int options) {
505 char *strp = nullptr;
506 int rc = 0;
507
508 rc = lyd_print_mem(&strp, node, format, options);
509 if (rc) {
510 check_libyang_error(node->schema->module->ctx);
511 return nullptr;
512 }
513
514 std::string s_strp = strp;
515 free(strp);
516 return s_strp;
517
518}
519std::vector<S_Data_Node> Data_Node::tree_for() {
520 std::vector<S_Data_Node> s_vector;
521
522 struct lyd_node *elem = nullptr;
523 LY_TREE_FOR(node, elem) {
524 s_vector.push_back(std::make_shared<Data_Node>(elem, deleter));
525 }
526
527 return s_vector;
528}
529std::vector<S_Data_Node> Data_Node::tree_dfs() {
530 std::vector<S_Data_Node> s_vector;
531
532 struct lyd_node *elem = nullptr, *next = nullptr;
533 LY_TREE_DFS_BEGIN(node, next, elem) {
534 s_vector.push_back(std::make_shared<Data_Node>(elem, deleter));
535 LY_TREE_DFS_END(node, next, elem)
536 }
537
538 return s_vector;
539}
540
542 Data_Node(derived->node, derived->deleter),
543 node(derived->node),
544 deleter(derived->deleter)
545{
546 if (derived->node->schema->nodetype != LYS_LEAFLIST && derived->node->schema->nodetype != LYS_LEAF) {
547 throw std::invalid_argument("Type must be LYS_LEAFLIST or LYS_LEAF");
548 }
549};
550Data_Node_Leaf_List::Data_Node_Leaf_List(struct lyd_node *node, S_Deleter deleter):
551 Data_Node(node, deleter),
552 node(node),
553 deleter(deleter)
554{};
557 struct lyd_node_leaf_list *leaf = (struct lyd_node_leaf_list *)node;
558 struct lys_type *type = (struct lys_type *)lyd_leaf_type(leaf);
559 return std::make_shared<Value>(leaf->value, &leaf->value_type, leaf->value_flags, type, deleter);
560}
561int Data_Node_Leaf_List::change_leaf(const char *val_str) {
562 int ret = lyd_change_leaf((struct lyd_node_leaf_list *) node, val_str);
563 if (ret < 0) {
564 check_libyang_error(node->schema->module->ctx);
565 }
566 return ret;
567}
569 return lyd_wd_default((struct lyd_node_leaf_list *)node);
570}
572 const struct lys_type *type = lyd_leaf_type((const struct lyd_node_leaf_list *) node);
573 if (!type) {
574 check_libyang_error(node->schema->module->ctx);
575 }
576
577 return std::make_shared<Type>((struct lys_type *) type, deleter);
578};
579
581 Data_Node(derived->node, derived->deleter),
582 node(derived->node),
583 deleter(derived->deleter)
584{
585 if (derived->node->schema->nodetype != LYS_ANYDATA && derived->node->schema->nodetype != LYS_ANYXML) {
586 throw std::invalid_argument("Type must be LYS_ANYDATA or LYS_ANYXML");
587 }
588};
589Data_Node_Anydata::Data_Node_Anydata(struct lyd_node *node, S_Deleter deleter):
590 Data_Node(node, deleter),
591 node(node),
592 deleter(deleter)
593{};
595
596Attr::Attr(struct lyd_attr *attr, S_Deleter deleter):
597 attr(attr),
598 deleter(deleter)
599{};
601S_Value Attr::value() {
602 struct lys_type *type = *((struct lys_type **)lys_ext_complex_get_substmt(LY_STMT_TYPE, attr->annotation, NULL));
603 return std::make_shared<Value>(attr->value, &attr->value_type, attr->value_flags, type, deleter);
604}
605S_Attr Attr::next() LY_NEW(attr, next, Attr);
606
607Difflist::Difflist(struct lyd_difflist *diff, S_Deleter deleter):
608 diff(diff)
609{
610 deleter = std::make_shared<Deleter>(diff, deleter);
611}
613std::vector<S_Data_Node> Difflist::first() {
614 std::vector<S_Data_Node> s_vector;
615 unsigned int i = 0;
616
617 if (!*diff->first) {
618 return s_vector;
619 }
620
621 for(i = 0; i < sizeof(*diff->first); i++) {
622 s_vector.push_back(std::make_shared<Data_Node>(*diff->first, deleter));
623 }
624
625 return s_vector;
626}
627std::vector<S_Data_Node> Difflist::second() {
628 std::vector<S_Data_Node> s_vector;
629 unsigned int i = 0;
630
631 if (!*diff->second) {
632 return s_vector;
633 }
634
635 for(i = 0; i < sizeof(*diff->second); i++) {
636 s_vector.push_back(std::make_shared<Data_Node>(*diff->second, deleter));
637 }
638
639 return s_vector;
640}
641
642S_Data_Node create_new_Data_Node(struct lyd_node *new_node) {
643 return new_node ? std::make_shared<Data_Node>(new_node, nullptr) : nullptr;
644}
645
646}
Class implementation for libyang C header libyang.h.
Class implementation for libyang C header tree_data.h.
Class implementation for libyang C header tree_schema.h.
Class implementation for libyang C header xml.h.
class for wrapping lyd_attr.
Definition: Tree_Data.hpp:292
S_Attr next()
Definition: Tree_Data.cpp:605
Attr(struct lyd_attr *attr, S_Deleter deleter=nullptr)
Definition: Tree_Data.cpp:596
S_Value value()
Definition: Tree_Data.cpp:601
int change_leaf(const char *val_str)
Definition: Tree_Data.cpp:561
classes for wrapping lyd_node.
Definition: Tree_Data.hpp:104
unsigned int list_pos()
Definition: Tree_Data.cpp:464
S_Data_Node first_sibling()
Definition: Tree_Data.cpp:377
std::string print_mem(LYD_FORMAT format, int options)
Definition: Tree_Data.cpp:504
S_Attr insert_attr(S_Module module, const char *name, const char *value)
Definition: Tree_Data.cpp:484
S_Set find_path(const char *expr)
Definition: Tree_Data.cpp:356
int insert(S_Data_Node new_node)
Definition: Tree_Data.cpp:279
Data_Node(struct lyd_node *node, S_Deleter deleter=nullptr)
Definition: Tree_Data.cpp:68
std::vector< S_Data_Node > tree_for()
Definition: Tree_Data.cpp:519
S_Data_Node new_path(S_Context ctx, const char *path, const char *value, LYD_ANYDATA_VALUETYPE value_type, int options)
Definition: Tree_Data.cpp:426
friend Data_Node_Anydata
Definition: Tree_Data.hpp:216
S_Data_Node next()
Definition: Tree_Data.hpp:142
int insert_after(S_Data_Node new_node)
Definition: Tree_Data.cpp:330
S_Data_Node parent()
Definition: Tree_Data.hpp:146
friend Data_Node_Leaf_List
Definition: Tree_Data.hpp:217
S_Data_Node dup_withsiblings(int recursive)
Definition: Tree_Data.cpp:230
S_Data_Node dup(int recursive)
Definition: Tree_Data.cpp:219
std::vector< S_Data_Node > tree_dfs()
Definition: Tree_Data.cpp:529
int insert_sibling(S_Data_Node new_node)
Definition: Tree_Data.cpp:292
int schema_sort(int recursive)
Definition: Tree_Data.cpp:349
int merge_to_ctx(S_Data_Node source, int options, S_Context context)
Definition: Tree_Data.cpp:266
int validate_value(const char *value)
Definition: Tree_Data.cpp:405
S_Schema_Node schema()
Definition: Tree_Data.hpp:132
int validate(int options, S_Context var_arg)
Definition: Tree_Data.cpp:384
S_Module node_module()
Definition: Tree_Data.cpp:494
S_Set find_instance(S_Schema_Node schema)
Definition: Tree_Data.cpp:364
S_Data_Node dup_to_ctx(int recursive, S_Context context)
Definition: Tree_Data.cpp:241
int merge(S_Data_Node source, int options)
Definition: Tree_Data.cpp:253
S_Difflist diff(S_Data_Node second, int options)
Definition: Tree_Data.cpp:412
virtual ~Data_Node()
Definition: Tree_Data.cpp:204
int insert_before(S_Data_Node new_node)
Definition: Tree_Data.cpp:311
std::string path()
Definition: Tree_Data.cpp:206
class for wrapping lyd_difflist.
Definition: Tree_Data.hpp:320
std::vector< S_Data_Node > second()
Definition: Tree_Data.cpp:627
std::vector< S_Data_Node > first()
Definition: Tree_Data.cpp:613
S_Data_Node instance()
Definition: Tree_Data.cpp:55
Value(lyd_val value, LY_DATA_TYPE *value_type, uint8_t value_flags, struct lys_type *type, S_Deleter deleter)
Definition: Tree_Data.cpp:33
std::vector< S_Type_Bit > bit()
Definition: Tree_Data.cpp:41
S_Data_Node leafref()
Definition: Tree_Data.cpp:61
S_Data_Node create_new_Data_Node(struct lyd_node *node)
Definition: Tree_Data.cpp:642
lyd_val value
Definition: tree_data.h:134
uint8_t value_flags
Definition: tree_data.h:247
struct lys_node * schema
Definition: tree_data.h:177
struct lyd_node * leafref
Definition: tree_data.h:109
struct lyd_node * instance
Definition: tree_data.h:102
struct lys_ext_instance_complex * annotation
Definition: tree_data.h:131
struct lyd_node ** first
Definition: tree_data.h:357
const char * name
Definition: tree_data.h:132
LY_DATA_TYPE _PACKED value_type
Definition: tree_data.h:246
struct lys_type_bit ** bit
Definition: tree_data.h:96
struct lyd_node ** second
Definition: tree_data.h:359
char * lyd_path(const struct lyd_node *node)
Build data path (usable as path, see XPath Addressing) of the data node.
int lyd_merge_to_ctx(struct lyd_node **trg, const struct lyd_node *src, int options, struct ly_ctx *ctx)
Same as lyd_merge(), but moves the resulting data into the specified context.
struct ly_set * lyd_find_path(const struct lyd_node *ctx_node, const char *path)
Search in the given data for instances of nodes matching the provided path.
struct lyd_node * lyd_dup(const struct lyd_node *node, int options)
Create a copy of the specified data tree node. Schema references are kept the same....
struct lyd_node * lyd_new(struct lyd_node *parent, const struct lys_module *module, const char *name)
Create a new container node in a data tree.
struct lyd_node * lyd_new_path(struct lyd_node *data_tree, const struct ly_ctx *ctx, const char *path, void *value, LYD_ANYDATA_VALUETYPE value_type, int options)
Create a new data node based on a simple XPath.
int lyd_insert_sibling(struct lyd_node **sibling, struct lyd_node *node)
Insert the node element as a last sibling of the specified sibling element.
int lyd_insert_before(struct lyd_node *sibling, struct lyd_node *node)
Insert the node element after the sibling element. If node and siblings are already siblings (just mo...
struct lyd_attr * lyd_insert_attr(struct lyd_node *parent, const struct lys_module *mod, const char *name, const char *value)
Insert attribute into the data node.
int lyd_validate_value(struct lys_node *node, const char *value)
Check restrictions applicable to the particular leaf/leaf-list on the given string value.
struct lyd_difflist * lyd_diff(struct lyd_node *first, struct lyd_node *second, int options)
Compare two data trees and provide list of differences.
int lyd_schema_sort(struct lyd_node *sibling, int recursive)
Order siblings according to the schema node ordering.
int lyd_print_mem(char **strp, const struct lyd_node *root, LYD_FORMAT format, int options)
Print data tree in the specified format.
int lyd_change_leaf(struct lyd_node_leaf_list *leaf, const char *val_str)
Change value of a leaf node.
LYD_ANYDATA_VALUETYPE
List of possible value types stored in lyd_node_anydata.
Definition: tree_data.h:50
struct ly_set * lyd_find_instance(const struct lyd_node *data, const struct lys_node *schema)
Search in the given data for instances of the provided schema node.
int lyd_unlink(struct lyd_node *node)
Unlink the specified data subtree. All referenced namespaces are copied.
struct lyd_node * lyd_first_sibling(struct lyd_node *node)
Get the first sibling of the given node.
struct lyd_node * lyd_new_anydata(struct lyd_node *parent, const struct lys_module *module, const char *name, void *value, LYD_ANYDATA_VALUETYPE value_type)
Create a new anydata or anyxml node in a data tree.
int lyd_validate(struct lyd_node **node, int options, void *var_arg,...)
Validate node data subtree.
LYD_FORMAT
Data input/output formats supported by libyang parser and printer functions.
Definition: tree_data.h:40
const struct lys_type * lyd_leaf_type(const struct lyd_node_leaf_list *leaf)
Get the type structure of a leaf.
unsigned int lyd_list_pos(const struct lyd_node *node)
Learn the relative instance position of a list or leaf-list within other instances of the same schema...
int lyd_insert(struct lyd_node *parent, struct lyd_node *node)
Insert the node element as child to the parent element. The node is inserted as a last child of the p...
struct lyd_node * lyd_new_leaf(struct lyd_node *parent, const struct lys_module *module, const char *name, const char *val_str)
Create a new leaf or leaflist node in a data tree with a string value that is converted to the actual...
struct lys_module * lyd_node_module(const struct lyd_node *node)
Return main module of the data tree node.
int lyd_insert_after(struct lyd_node *sibling, struct lyd_node *node)
Insert the node element after the sibling element. If node and siblings are already siblings (just mo...
int lyd_merge(struct lyd_node *target, const struct lyd_node *source, int options)
Merge a (sub)tree into a data tree.
#define LY_TREE_DFS_BEGIN(START, NEXT, ELEM)
Macro to iterate via all elements in a tree. This is the opening part to the LY_TREE_DFS_END - they a...
Definition: tree_schema.h:90
struct lyd_node * lyd_dup_withsiblings(const struct lyd_node *node, int options)
Create a copy of the specified data tree and all its siblings (preceding as well as following)....
struct lyd_node * lyd_dup_to_ctx(const struct lyd_node *node, int options, struct ly_ctx *ctx)
Create a copy of the specified data tree node in the different context. All the schema references and...
int lyd_wd_default(struct lyd_node_leaf_list *node)
Get know if the node contain (despite implicit or explicit) default value.
#define LY_TREE_FOR(START, ELEM)
Macro to iterate via all sibling elements without affecting the list itself.
Definition: tree_schema.h:40
@ LYD_ANYDATA_DATATREE
Definition: tree_data.h:78
@ LYD_ANYDATA_XML
Definition: tree_data.h:74
Attribute structure.
Definition: tree_data.h:128
Structure for the result of lyd_diff(), describing differences between two data trees.
Definition: tree_data.h:355
Generic structure for a data node, directly applicable to the data nodes defined as LYS_CONTAINER,...
Definition: tree_data.h:176
Structure for data nodes defined as LYS_LEAF or LYS_LEAFLIST.
Definition: tree_data.h:217
node's value representation
Definition: tree_data.h:94
void * lys_ext_complex_get_substmt(LY_STMT stmt, struct lys_ext_instance_complex *ext, struct lyext_substmt **info)
get pointer to the place where the specified extension's substatement is supposed to be stored in the...
@ LY_STMT_TYPE
Definition: tree_schema.h:345
union ly_set_set set
Definition: libyang.h:1711
Structure to hold a set of (not necessary somehow connected) lyd_node or lys_node objects....
Definition: libyang.h:1708
struct lys_module * module
Definition: tree_schema.h:1225
unsigned int count
Definition: tree_schema.h:841
union lys_type_info info
Definition: tree_schema.h:982
LY_DATA_TYPE _PACKED base
Definition: tree_schema.h:974
struct lys_type_info_bits bits
Definition: tree_schema.h:959
struct ly_ctx * ctx
Definition: tree_schema.h:667
LY_DATA_TYPE
YANG built-in types.
Definition: tree_schema.h:784
@ LY_TYPE_BITS
Definition: tree_schema.h:787
@ LY_TYPE_LEAFREF
Definition: tree_schema.h:794
@ LY_TYPE_INST
Definition: tree_schema.h:793
@ LYS_LEAF
Definition: tree_schema.h:233
@ LYS_ANYDATA
Definition: tree_schema.h:246
@ LYS_ANYXML
Definition: tree_schema.h:236
@ LYS_LEAFLIST
Definition: tree_schema.h:234
Main schema node structure representing YANG module.
Definition: tree_schema.h:666
YANG type structure providing information from the schema.
Definition: tree_schema.h:973
The main libyang public header.
libyang representation of data trees.
libyang representation of data model trees.
#define LY_TREE_DFS_END(START, NEXT, ELEM)
Definition: tree_schema.h:122