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