libyang  0.16.105
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 
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, S_Deleter deleter):
34  value(value),
35  type(*value_type),
36  flags(value_flags),
37  deleter(deleter)
38 {};
40 S_Data_Node Value::instance() {
41  if (LY_TYPE_INST != type) {
42  return nullptr;
43  }
44  return value.instance ? std::make_shared<Data_Node>(value.instance, deleter) : nullptr;
45 }
46 S_Data_Node Value::leafref() {
47  if (LY_TYPE_LEAFREF != type) {
48  return nullptr;
49  }
50  return value.leafref ? std::make_shared<Data_Node>(value.leafref, deleter) : nullptr;
51 }
52 
53 Data_Node::Data_Node(struct lyd_node *node, S_Deleter deleter):
54  node(node),
55  deleter(deleter)
56 {};
57 Data_Node::Data_Node(S_Data_Node parent, S_Module module, const char *name) {
58  lyd_node *new_node = nullptr;
59 
60  if (!module) {
61  throw std::invalid_argument("Module can not be empty");
62  }
63 
64  new_node = lyd_new(parent ? parent->node : nullptr, module->module, name);
65  if (!new_node) {
66  check_libyang_error(module->module->ctx);
67  }
68 
69  node = new_node;
70  deleter = !parent ? std::make_shared<Deleter>(node, module->deleter) : parent->deleter;
71 };
72 Data_Node::Data_Node(S_Data_Node parent, S_Module module, const char *name, const char *val_str) {
73  lyd_node *new_node = nullptr;
74 
75  if (!module) {
76  throw std::invalid_argument("Module can not be empty");
77  }
78 
79  new_node = lyd_new_leaf(parent ? parent->node : nullptr, module->module, name, val_str);
80  if (!new_node) {
81  check_libyang_error(module->module->ctx);
82  }
83 
84  node = new_node;
85  deleter = !parent ? std::make_shared<Deleter>(node, module->deleter) : parent->deleter;
86 };
87 Data_Node::Data_Node(S_Data_Node parent, S_Module module, const char *name, const char *value, LYD_ANYDATA_VALUETYPE value_type) {
88  lyd_node *new_node = nullptr;
89 
90  if (!module) {
91  throw std::invalid_argument("Module can not be empty");
92  }
93 
94  new_node = lyd_new_anydata(parent ? parent->node : NULL, module->module, name, (void *) value, value_type);
95  if (!new_node) {
96  check_libyang_error(module->module->ctx);
97  }
98 
99  node = new_node;
100  deleter = !parent ? std::make_shared<Deleter>(node, module->deleter) : parent->deleter;
101 };
102 Data_Node::Data_Node(S_Data_Node parent, S_Module module, const char *name, S_Data_Node value) {
103  lyd_node *new_node = nullptr;
104 
105  if (!module) {
106  throw std::invalid_argument("Module can not be empty");
107  }
108 
109  new_node = lyd_new_anydata(parent ? parent->node : NULL, module->module, name, (void *) value->node, LYD_ANYDATA_DATATREE);
110  if (!new_node) {
111  check_libyang_error(module->module->ctx);
112  }
113 
114  node = new_node;
115  deleter = !parent ? std::make_shared<Deleter>(node, module->deleter) : parent->deleter;
116 };
117 Data_Node::Data_Node(S_Data_Node parent, S_Module module, const char *name, S_Xml_Elem value) {
118  lyd_node *new_node = nullptr;
119 
120  if (!module) {
121  throw std::invalid_argument("Module can not be empty");
122  }
123 
124  new_node = lyd_new_anydata(parent ? parent->node : NULL, module->module, name, (void *) value->elem, LYD_ANYDATA_XML);
125  if (!new_node) {
126  check_libyang_error(module->module->ctx);
127  }
128 
129  node = new_node;
130  deleter = !parent ? std::make_shared<Deleter>(node, module->deleter) : parent->deleter;
131 }
132 Data_Node::Data_Node(S_Context context, const char *path, const char *value, LYD_ANYDATA_VALUETYPE value_type, int options) {
133  lyd_node *new_node = nullptr;
134 
135  if (!context) {
136  throw std::invalid_argument("Context can not be empty");
137  }
138  if (!path) {
139  throw std::invalid_argument("Path can not be empty");
140  }
141 
142  new_node = lyd_new_path(NULL, context->ctx, path, (void *) value, value_type, options);
143  if (!new_node) {
144  check_libyang_error(context->ctx);
145  }
146 
147  node = new_node;
148  deleter = std::make_shared<Deleter>(node, context->deleter);
149 }
150 Data_Node::Data_Node(S_Context context, const char *path, S_Data_Node value, int options) {
151  lyd_node *new_node = nullptr;
152 
153  if (!context) {
154  throw std::invalid_argument("Context can not be empty");
155  }
156  if (!path) {
157  throw std::invalid_argument("Path can not be empty");
158  }
159 
160  new_node = lyd_new_path(NULL, context->ctx, path, (void *) value->node, LYD_ANYDATA_DATATREE, options);
161  if (!new_node) {
162  check_libyang_error(context->ctx);
163  }
164 
165  node = new_node;
166  deleter = context->deleter;
167 }
168 Data_Node::Data_Node(S_Context context, const char *path, S_Xml_Elem value, int options) {
169  lyd_node *new_node = nullptr;
170 
171  if (!context) {
172  throw std::invalid_argument("Context can not be empty");
173  }
174  if (!path) {
175  throw std::invalid_argument("Path can not be empty");
176  }
177 
178  new_node = lyd_new_path(NULL, context->ctx, path, (void *) value->elem, LYD_ANYDATA_XML, options);
179  if (!new_node) {
180  check_libyang_error(context->ctx);
181  }
182 
183  node = new_node;
184  deleter = context->deleter;
185 }
186 
188 S_Attr Data_Node::attr() LY_NEW(node, attr, Attr);
189 std::string Data_Node::path() {
190  char *path = nullptr;
191 
192  path = lyd_path(node);
193  if (!path) {
194  check_libyang_error(node->schema->module->ctx);
195  return nullptr;
196  }
197 
198  std::string s_path = path;
199  free(path);
200  return s_path;
201 }
202 S_Data_Node Data_Node::dup(int recursive) {
203  struct lyd_node *new_node = nullptr;
204 
205  new_node = lyd_dup(node, recursive);
206  if (!new_node) {
207  return nullptr;
208  }
209 
210  S_Deleter new_deleter = std::make_shared<Deleter>(new_node, deleter);
211  return std::make_shared<Data_Node>(new_node, new_deleter);
212 }
213 S_Data_Node Data_Node::dup_withsiblings(int recursive) {
214  struct lyd_node *new_node = nullptr;
215 
216  new_node = lyd_dup_withsiblings(node, recursive);
217  if (!new_node) {
218  return nullptr;
219  }
220 
221  S_Deleter new_deleter = std::make_shared<Deleter>(new_node, deleter);
222  return std::make_shared<Data_Node>(new_node, new_deleter);
223 }
224 S_Data_Node Data_Node::dup_to_ctx(int recursive, S_Context context) {
225  struct lyd_node *new_node = nullptr;
226 
227  new_node = lyd_dup_to_ctx(node, recursive, context->ctx);
228 
229  S_Deleter new_deleter = std::make_shared<Deleter>(new_node, context->deleter);
230  return new_node ? std::make_shared<Data_Node>(new_node, new_deleter) : nullptr;
231 }
232 int Data_Node::merge(S_Data_Node source, int options) {
233  int ret = lyd_merge(node, source->node, options);
234  if (ret) {
235  check_libyang_error(source->node->schema->module->ctx);
236  }
237  return ret;
238 }
239 int Data_Node::merge_to_ctx(S_Data_Node source, int options, S_Context context) {
240  int ret = lyd_merge_to_ctx(&node, source->node, options, context->ctx);
241  if (ret) {
242  check_libyang_error(context->ctx);
243  }
244  return ret;
245 }
246 int Data_Node::insert(S_Data_Node new_node) {
247  int ret = lyd_insert(node, new_node->node);
248  if (ret) {
249  check_libyang_error(node->schema->module->ctx);
250  }
251  return ret;
252 }
253 int Data_Node::insert_sibling(S_Data_Node new_node) {
254  /* because of memory handling in C++ the node is duplicated before insertion */
255  struct lyd_node *dup_node = lyd_dup(new_node->node, 1);
256  if (!dup_node) {
257  check_libyang_error(node->schema->module->ctx);
258  }
259 
260  int ret = lyd_insert_sibling(&node, dup_node);
261  if (ret) {
262  check_libyang_error(node->schema->module->ctx);
263  }
264  return ret;
265 }
266 int Data_Node::insert_before(S_Data_Node new_node) {
267  /* because of memory handling in C++ the node is duplicated before insertion */
268  struct lyd_node *dup_node = lyd_dup(new_node->node, 1);
269  if (!dup_node) {
270  check_libyang_error(node->schema->module->ctx);
271  }
272 
273  int ret = lyd_insert_before(node, dup_node);
274  if (ret) {
275  check_libyang_error(node->schema->module->ctx);
276  }
277  return ret;
278 }
279 int Data_Node::insert_after(S_Data_Node new_node) {
280  /* because of memory handling in C++ the node is duplicated before insertion */
281  struct lyd_node *dup_node = lyd_dup(new_node->node, 1);
282  if (!dup_node) {
283  check_libyang_error(node->schema->module->ctx);
284  }
285 
286  int ret = lyd_insert_after(node, dup_node);
287  if (ret) {
288  check_libyang_error(node->schema->module->ctx);
289  }
290  return ret;
291 }
292 int Data_Node::schema_sort(int recursive) {
293  int ret = lyd_schema_sort(node, recursive);
294  if (ret) {
295  check_libyang_error(node->schema->module->ctx);
296  }
297  return ret;
298 }
299 S_Set Data_Node::find_path(const char *expr) {
300  struct ly_set *set = lyd_find_path(node, expr);
301  if (!set) {
302  check_libyang_error(node->schema->module->ctx);
303  }
304 
305  return std::make_shared<Set>(set, std::make_shared<Deleter>(set, deleter));
306 }
307 S_Set Data_Node::find_instance(S_Schema_Node schema) {
308  struct ly_set *set = lyd_find_instance(node, schema->node);
309  if (!set) {
310  check_libyang_error(node->schema->module->ctx);
311  }
312 
313  return std::make_shared<Set>(set, std::make_shared<Deleter>(set, deleter));
314 }
316  struct lyd_node *new_node = nullptr;
317 
318  new_node = lyd_first_sibling(node);
319 
320  return new_node ? std::make_shared<Data_Node>(new_node, deleter) : nullptr;
321 }
322 int Data_Node::validate(int options, S_Context var_arg) {
323  int ret = lyd_validate(&node, options, (void *) var_arg->ctx);
324  if (ret) {
325  check_libyang_error(node ? node->schema->module->ctx : var_arg->ctx);
326  }
327  return ret;
328 }
329 int Data_Node::validate(int options, S_Data_Node var_arg) {
330  int ret = lyd_validate(&node, options, (void *) var_arg->node);
331  if (ret) {
332  check_libyang_error(node->schema->module->ctx);
333  }
334  return ret;
335 }
336 
337 int Data_Node::validate_value(const char *value) {
338  int ret = lyd_validate_value(node->schema, value);
339  if (ret != EXIT_SUCCESS) {
340  check_libyang_error(node->schema->module->ctx);
341  }
342  return ret;
343 }
344 S_Difflist Data_Node::diff(S_Data_Node second, int options) {
345  struct lyd_difflist *diff;
346 
347  diff = lyd_diff(node, second->node, options);
348  if (!diff) {
349  check_libyang_error(node->schema->module->ctx);
350  }
351 
352  return diff ? std::make_shared<Difflist>(diff, deleter) : nullptr;
353 }
354 S_Data_Node Data_Node::new_path(S_Context ctx, const char *path, const char *value, LYD_ANYDATA_VALUETYPE value_type, int options) {
355  struct lyd_node *new_node = nullptr;
356 
357  new_node = lyd_new_path(node, ctx->ctx, path, (void *)value, value_type, options);
358  if (!new_node) {
359  check_libyang_error(node->schema->module->ctx);
360  }
361 
362  return new_node ? std::make_shared<Data_Node>(new_node, deleter) : nullptr;
363 }
364 S_Data_Node Data_Node::new_path(S_Context ctx, const char *path, S_Data_Node value, int options) {
365  struct lyd_node *new_node = nullptr;
366 
367  new_node = lyd_new_path(node, ctx->ctx, path, (void *)value->node, LYD_ANYDATA_DATATREE, options);
368  if (!new_node) {
369  check_libyang_error(node->schema->module->ctx);
370  }
371 
372  return new_node ? std::make_shared<Data_Node>(new_node, deleter) : nullptr;
373 }
374 S_Data_Node Data_Node::new_path(S_Context ctx, const char *path, S_Xml_Elem value, int options) {
375  struct lyd_node *new_node = nullptr;
376 
377  new_node = lyd_new_path(node, ctx->ctx, path, (void *)value->elem, LYD_ANYDATA_XML, options);
378  if (!new_node) {
379  check_libyang_error(node->schema->module->ctx);
380  }
381 
382  return new_node ? std::make_shared<Data_Node>(new_node, deleter) : nullptr;
383 }
384 unsigned int Data_Node::list_pos() {
385  unsigned int ret = lyd_list_pos(node);
386  if (!ret) {
387  check_libyang_error(node->schema->module->ctx);
388  }
389  return ret;
390 }
392  int ret = lyd_unlink(node);
393  if (ret) {
394  check_libyang_error(node->schema->module->ctx);
395  }
396 
397  /* change C++ memory handling after unlink */
398  if (deleter) {
399  deleter = std::make_shared<Deleter>(node, nullptr);
400  }
401 
402  return ret;
403 }
404 S_Attr Data_Node::insert_attr(S_Module module, const char *name, const char *value) {
405  struct lyd_attr *attr = nullptr;
406 
407  attr = lyd_insert_attr(node, module ? module->module : NULL, name, value);
408  if (!attr) {
409  check_libyang_error(node->schema->module->ctx);
410  }
411 
412  return attr ? std::make_shared<Attr>(attr, deleter) : nullptr;
413 }
415  struct lys_module *module = nullptr;
416 
417  module = lyd_node_module(node);
418  if (!module) {
419  check_libyang_error(node->schema->module->ctx);
420  }
421 
422  return module ? std::make_shared<Module>(module, deleter) : nullptr;
423 }
424 std::string Data_Node::print_mem(LYD_FORMAT format, int options) {
425  char *strp = nullptr;
426  int rc = 0;
427 
428  rc = lyd_print_mem(&strp, node, format, options);
429  if (rc) {
430  check_libyang_error(node->schema->module->ctx);
431  return nullptr;
432  }
433 
434  std::string s_strp = strp;
435  free(strp);
436  return s_strp;
437 
438 }
439 std::vector<S_Data_Node> Data_Node::tree_for() {
440  std::vector<S_Data_Node> s_vector;
441 
442  struct lyd_node *elem = nullptr;
443  LY_TREE_FOR(node, elem) {
444  s_vector.push_back(std::make_shared<Data_Node>(elem, deleter));
445  }
446 
447  return s_vector;
448 }
449 std::vector<S_Data_Node> Data_Node::tree_dfs() {
450  std::vector<S_Data_Node> s_vector;
451 
452  struct lyd_node *elem = nullptr, *next = nullptr;
453  LY_TREE_DFS_BEGIN(node, next, elem) {
454  s_vector.push_back(std::make_shared<Data_Node>(elem, deleter));
455  LY_TREE_DFS_END(node, next, elem)
456  }
457 
458  return s_vector;
459 }
460 
462  Data_Node(derived->node, derived->deleter),
463  node(derived->node),
464  deleter(derived->deleter)
465 {
466  if (derived->node->schema->nodetype != LYS_LEAFLIST && derived->node->schema->nodetype != LYS_LEAF) {
467  throw std::invalid_argument("Type must be LYS_LEAFLIST or LYS_LEAF");
468  }
469 };
470 Data_Node_Leaf_List::Data_Node_Leaf_List(struct lyd_node *node, S_Deleter deleter):
471  Data_Node(node, deleter),
472  node(node),
473  deleter(deleter)
474 {};
477  struct lyd_node_leaf_list *leaf = (struct lyd_node_leaf_list *) node;
478  return std::make_shared<Value>(leaf->value, &leaf->value_type, leaf->value_flags, deleter);
479 }
480 int Data_Node_Leaf_List::change_leaf(const char *val_str) {
481  int ret = lyd_change_leaf((struct lyd_node_leaf_list *) node, val_str);
482  if (ret < 0) {
483  check_libyang_error(node->schema->module->ctx);
484  }
485  return ret;
486 }
488  return lyd_wd_default((struct lyd_node_leaf_list *)node);
489 }
491  const struct lys_type *type = lyd_leaf_type((const struct lyd_node_leaf_list *) node);
492  if (!type) {
493  check_libyang_error(node->schema->module->ctx);
494  }
495 
496  return std::make_shared<Type>((struct lys_type *) type, deleter);
497 };
498 
500  Data_Node(derived->node, derived->deleter),
501  node(derived->node),
502  deleter(derived->deleter)
503 {
504  if (derived->node->schema->nodetype != LYS_ANYDATA && derived->node->schema->nodetype != LYS_ANYXML) {
505  throw std::invalid_argument("Type must be LYS_ANYDATA or LYS_ANYXML");
506  }
507 };
508 Data_Node_Anydata::Data_Node_Anydata(struct lyd_node *node, S_Deleter deleter):
509  Data_Node(node, deleter),
510  node(node),
511  deleter(deleter)
512 {};
514 
515 Attr::Attr(struct lyd_attr *attr, S_Deleter deleter):
516  attr(attr),
517  deleter(deleter)
518 {};
520 S_Value Attr::value() {
521  struct lyd_node_leaf_list *leaf = (struct lyd_node_leaf_list *) attr;
522  return std::make_shared<Value>(leaf->value, &leaf->value_type, leaf->value_flags, deleter);
523 }
524 S_Attr Attr::next() LY_NEW(attr, next, Attr);
525 
526 Difflist::Difflist(struct lyd_difflist *diff, S_Deleter deleter) {
527  diff = diff;
528  deleter = std::make_shared<Deleter>(diff, deleter);
529 }
531 std::vector<S_Data_Node> Difflist::first() {
532  std::vector<S_Data_Node> s_vector;
533  unsigned int i = 0;
534 
535  if (!*diff->first) {
536  return s_vector;
537  }
538 
539  for(i = 0; i < sizeof(*diff->first); i++) {
540  s_vector.push_back(std::make_shared<Data_Node>(*diff->first, deleter));
541  }
542 
543  return s_vector;
544 }
545 std::vector<S_Data_Node> Difflist::second() {
546  std::vector<S_Data_Node> s_vector;
547  unsigned int i = 0;
548 
549  if (!*diff->second) {
550  return s_vector;
551  }
552 
553  for(i = 0; i < sizeof(*diff->second); i++) {
554  s_vector.push_back(std::make_shared<Data_Node>(*diff->second, deleter));
555  }
556 
557  return s_vector;
558 }
559 
560 S_Data_Node create_new_Data_Node(struct lyd_node *new_node) {
561  return new_node ? std::make_shared<Data_Node>(new_node, nullptr) : nullptr;
562 }
563 
564 }
int insert(S_Data_Node new_node)
Definition: Tree_Data.cpp:246
S_Value value()
Definition: Tree_Data.cpp:520
int insert_before(S_Data_Node new_node)
Definition: Tree_Data.cpp:266
struct lys_module * module
Definition: tree_schema.h:1245
const char * name
Definition: tree_data.h:132
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.
struct lyd_node * next
Definition: tree_data.h:236
int schema_sort(int recursive)
Definition: Tree_Data.cpp:292
int change_leaf(const char *val_str)
Definition: Tree_Data.cpp:480
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:239
std::string path()
Definition: Tree_Data.cpp:189
int validate(int options, S_Context var_arg)
Definition: Tree_Data.cpp:322
struct lys_node * schema
Definition: tree_data.h:187
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 XPath Addressing) 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 lyd_attr * attr
Definition: tree_data.h:235
S_Data_Node create_new_Data_Node(struct lyd_node *node)
Definition: Tree_Data.cpp:560
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:202
node's value representation
Definition: tree_data.h:94
union ly_set_set set
Definition: libyang.h:1719
S_Data_Node parent()
Definition: Tree_Data.hpp:140
S_Data_Node first_sibling()
Definition: Tree_Data.cpp:315
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:232
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...
LY_DATA_TYPE _PACKED value_type
Definition: tree_data.h:256
S_Data_Node leafref()
Definition: Tree_Data.cpp:46
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....
Data_Node_Anydata(S_Data_Node derived)
Definition: Tree_Data.cpp:499
unsigned int list_pos()
Definition: Tree_Data.cpp:384
S_Attr next()
Definition: Tree_Data.cpp:524
Data_Node(struct lyd_node *node, S_Deleter deleter=nullptr)
Definition: Tree_Data.cpp:53
struct lyd_node * lyd_new_path(struct lyd_node *data_tree, 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:299
libyang representation of data trees.
The main libyang public header.
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:531
Structure to hold a set of (not necessary somehow connected) lyd_node or lys_node objects....
Definition: libyang.h:1716
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:404
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:515
S_Data_Node dup_withsiblings(int recursive)
Definition: Tree_Data.cpp:213
#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:98
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:545
S_Difflist diff(S_Data_Node second, int options)
Definition: Tree_Data.cpp:344
Structure for data nodes defined as LYS_LEAF or LYS_LEAFLIST.
Definition: tree_data.h:227
struct lyd_node * leafref
Definition: tree_data.h:109
Attribute structure.
Definition: tree_data.h:128
S_Data_Node next()
Definition: Tree_Data.hpp:136
#define LY_TREE_DFS_END(START, NEXT, ELEM)
Definition: tree_schema.h:130
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:97
S_Schema_Node schema()
Definition: Tree_Data.hpp:126
class for wrapping lyd_difflist.
Definition: Tree_Data.hpp:312
struct lyd_node ** second
Definition: tree_data.h:364
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:360
int validate_value(const char *value)
Definition: Tree_Data.cpp:337
Main schema node structure representing YANG module.
Definition: tree_schema.h:674
Data_Node_Leaf_List(S_Data_Node derived)
Definition: Tree_Data.cpp:461
int lyd_print_mem(char **strp, const struct lyd_node *root, LYD_FORMAT format, int options)
Print data tree in the specified format.
lyd_val value
Definition: tree_data.h:134
std::string print_mem(LYD_FORMAT format, int options)
Definition: Tree_Data.cpp:424
#define LY_TREE_FOR(START, ELEM)
Macro to iterate via all sibling elements without affecting the list itself.
Definition: tree_schema.h:48
class for wrapping lyd_attr.
Definition: Tree_Data.hpp:284
int insert_sibling(S_Data_Node new_node)
Definition: Tree_Data.cpp:253
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
YANG built-in types.
Definition: tree_schema.h:792
struct lyd_node * instance
Definition: tree_data.h:102
std::vector< S_Data_Node > tree_dfs()
Definition: Tree_Data.cpp:449
YANG type structure providing information from the schema.
Definition: tree_schema.h:981
struct lyd_node ** first
Definition: tree_data.h:362
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.
const struct lys_type * lyd_leaf_type(const struct lyd_node_leaf_list *leaf)
Get the type structure of a leaf.
Value(lyd_val value, LY_DATA_TYPE *value_type, uint8_t value_flags, S_Deleter deleter)
Definition: Tree_Data.cpp:33
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:354
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:186
std::vector< S_Data_Node > tree_for()
Definition: Tree_Data.cpp:439
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:40
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:414
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:675
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:279
uint8_t value_flags
Definition: tree_data.h:257
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:224
S_Set find_instance(S_Schema_Node schema)
Definition: Tree_Data.cpp:307