35 value_type(*value_type),
36 value_flags(value_flags),
45 std::vector<S_Type_Bit> vec(type->info.bits.count);
47 for (
unsigned int i = 0; i < type->info.bits.count; ++i) {
49 vec[i] = std::make_shared<Type_Bit>(value.bit[i], deleter);
59 return value.instance ? std::make_shared<Data_Node>(value.instance, deleter) :
nullptr;
65 return value.leafref ? std::make_shared<Data_Node>(value.leafref, deleter) :
nullptr;
76 throw std::invalid_argument(
"At least one of module or parent parameters must be set");
81 check_libyang_error(module ? module->module->ctx :
parent->node->schema->module->ctx);
85 deleter = !
parent ? std::make_shared<Deleter>(node, module->deleter) :
parent->deleter;
91 throw std::invalid_argument(
"At least one of module or parent parameters must be set");
96 check_libyang_error(module ? module->module->ctx :
parent->node->schema->module->ctx);
100 deleter = !
parent ? std::make_shared<Deleter>(node, module->deleter) :
parent->deleter;
106 throw std::invalid_argument(
"At least one of module or parent parameters must be set");
111 check_libyang_error(module ? module->module->ctx :
parent->node->schema->module->ctx);
115 deleter = !
parent ? std::make_shared<Deleter>(node, module->deleter) :
parent->deleter;
121 throw std::invalid_argument(
"At least one of module or parent parameters must be set");
127 check_libyang_error(module ? module->module->ctx :
parent->node->schema->module->ctx);
131 deleter = !
parent ? std::make_shared<Deleter>(node, module->deleter) :
parent->deleter;
137 throw std::invalid_argument(
"At least one of module or parent parameters must be set");
143 check_libyang_error(module ? module->module->ctx :
parent->node->schema->module->ctx);
147 deleter = !
parent ? std::make_shared<Deleter>(node, module->deleter) :
parent->deleter;
153 throw std::invalid_argument(
"Context can not be empty");
156 throw std::invalid_argument(
"Path can not be empty");
159 new_node =
lyd_new_path(NULL, context->ctx,
path, (
void *) value, value_type, options);
161 check_libyang_error(context->ctx);
165 deleter = std::make_shared<Deleter>(node, context->deleter);
171 throw std::invalid_argument(
"Context can not be empty");
174 throw std::invalid_argument(
"Path can not be empty");
179 check_libyang_error(context->ctx);
183 deleter = context->deleter;
189 throw std::invalid_argument(
"Context can not be empty");
192 throw std::invalid_argument(
"Path can not be empty");
197 check_libyang_error(context->ctx);
201 deleter = context->deleter;
207 char *
path =
nullptr;
211 check_libyang_error(node->schema->module->ctx);
215 std::string s_path =
path;
220 struct lyd_node *new_node =
nullptr;
222 new_node =
lyd_dup(node, recursive);
227 S_Deleter new_deleter = std::make_shared<Deleter>(new_node, deleter);
228 return std::make_shared<Data_Node>(new_node, new_deleter);
231 struct lyd_node *new_node =
nullptr;
238 S_Deleter new_deleter = std::make_shared<Deleter>(new_node, deleter);
239 return std::make_shared<Data_Node>(new_node, new_deleter);
242 struct lyd_node *new_node =
nullptr;
245 throw std::invalid_argument(
"Context can not be empty");
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;
257 throw std::invalid_argument(
"Source can not be empty");
260 ret =
lyd_merge(node, source->node, options);
262 check_libyang_error(source->node->schema->module->ctx);
270 throw std::invalid_argument(
"Source can not be empty");
273 ret =
lyd_merge_to_ctx(&node, source->node, options, context ? context->ctx : NULL);
275 check_libyang_error(source->node->schema->module->ctx);
283 throw std::invalid_argument(
"New_node can not be empty");
288 check_libyang_error(node->schema->module->ctx);
296 throw std::invalid_argument(
"New_node can not be empty");
300 dup_node =
lyd_dup(new_node->node, 1);
302 check_libyang_error(node->schema->module->ctx);
307 check_libyang_error(node->schema->module->ctx);
315 throw std::invalid_argument(
"New_node can not be empty");
319 dup_node =
lyd_dup(new_node->node, 1);
321 check_libyang_error(node->schema->module->ctx);
326 check_libyang_error(node->schema->module->ctx);
334 throw std::invalid_argument(
"New_node can not be empty");
338 dup_node =
lyd_dup(new_node->node, 1);
340 check_libyang_error(node->schema->module->ctx);
345 check_libyang_error(node->schema->module->ctx);
352 check_libyang_error(node->schema->module->ctx);
359 check_libyang_error(node->schema->module->ctx);
362 return std::make_shared<Set>(set, std::make_shared<Deleter>(set, deleter));
367 throw std::invalid_argument(
"Schema can not be empty");
372 check_libyang_error(node->schema->module->ctx);
375 return std::make_shared<Set>(set, std::make_shared<Deleter>(set, deleter));
378 struct lyd_node *new_node =
nullptr;
382 return new_node ? std::make_shared<Data_Node>(new_node, deleter) :
nullptr;
385 int ret =
lyd_validate(&node, options, var_arg ? (
void *) var_arg->ctx : node->schema->module->ctx);
387 check_libyang_error(node ? node->schema->module->ctx : var_arg->ctx);
395 throw std::invalid_argument(
"var_arg must be a data node");
398 ret =
lyd_validate(&node, options, (
void *) var_arg->node);
400 check_libyang_error(node->schema->module->ctx);
407 if (ret != EXIT_SUCCESS) {
408 check_libyang_error(node->schema->module->ctx);
416 throw std::invalid_argument(
"Second can not be empty");
421 check_libyang_error(node->schema->module->ctx);
424 return diff ? std::make_shared<Difflist>(
diff, deleter) :
nullptr;
427 struct lyd_node *new_node =
nullptr;
429 new_node =
lyd_new_path(node, ctx ? ctx->ctx : NULL,
path, (
void *)value, value_type, options);
431 check_libyang_error(node->schema->module->ctx);
434 return new_node ? std::make_shared<Data_Node>(new_node, deleter) :
nullptr;
437 struct lyd_node *new_node =
nullptr;
440 throw std::invalid_argument(
"Value can not be empty");
445 check_libyang_error(node->schema->module->ctx);
448 return new_node ? std::make_shared<Data_Node>(new_node, deleter) :
nullptr;
451 struct lyd_node *new_node =
nullptr;
454 throw std::invalid_argument(
"Value can not be empty");
459 check_libyang_error(node->schema->module->ctx);
462 return new_node ? std::make_shared<Data_Node>(new_node, deleter) :
nullptr;
467 check_libyang_error(node->schema->module->ctx);
474 check_libyang_error(node->schema->module->ctx);
479 deleter = std::make_shared<Deleter>(node,
nullptr);
489 check_libyang_error(node->schema->module->ctx);
492 return attr ? std::make_shared<Attr>(
attr, deleter) :
nullptr;
497 module = lyd_node_module(node);
499 check_libyang_error(node->schema->module->ctx);
502 return module ? std::make_shared<Module>(module, deleter) : nullptr;
505 char *strp =
nullptr;
510 check_libyang_error(node->schema->module->ctx);
514 std::string s_strp = strp;
520 std::vector<S_Data_Node> s_vector;
524 s_vector.push_back(std::make_shared<Data_Node>(elem, deleter));
530 std::vector<S_Data_Node> s_vector;
534 s_vector.push_back(std::make_shared<Data_Node>(elem, deleter));
542 Data_Node(derived->node, derived->deleter),
544 deleter(derived->deleter)
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");
559 return std::make_shared<Value>(leaf->
value, &leaf->value_type, leaf->
value_flags, type, deleter);
564 check_libyang_error(node->schema->module->ctx);
574 check_libyang_error(node->schema->module->ctx);
577 return std::make_shared<Type>((
struct lys_type *) type, deleter);
581 Data_Node(derived->node, derived->deleter),
583 deleter(derived->deleter)
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");
603 return std::make_shared<Value>(attr->value, &attr->value_type, attr->value_flags, type, deleter);
610 deleter = std::make_shared<Deleter>(diff, deleter);
614 std::vector<S_Data_Node> s_vector;
621 for(i = 0; i <
sizeof(*diff->first); i++) {
622 s_vector.push_back(std::make_shared<Data_Node>(*diff->first, deleter));
628 std::vector<S_Data_Node> s_vector;
631 if (!*diff->second) {
635 for(i = 0; i <
sizeof(*diff->second); i++) {
636 s_vector.push_back(std::make_shared<Data_Node>(*diff->second, deleter));
643 return new_node ? std::make_shared<Data_Node>(new_node,
nullptr) :
nullptr;
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.
Attr(struct lyd_attr *attr, S_Deleter deleter=nullptr)
int change_leaf(const char *val_str)
S_Data_Node first_sibling()
std::string print_mem(LYD_FORMAT format, int options)
S_Attr insert_attr(S_Module module, const char *name, const char *value)
S_Set find_path(const char *expr)
int insert(S_Data_Node new_node)
Data_Node(struct lyd_node *node, S_Deleter deleter=nullptr)
std::vector< S_Data_Node > tree_for()
S_Data_Node new_path(S_Context ctx, const char *path, const char *value, LYD_ANYDATA_VALUETYPE value_type, int options)
int insert_after(S_Data_Node new_node)
friend Data_Node_Leaf_List
S_Data_Node dup_withsiblings(int recursive)
S_Data_Node dup(int recursive)
std::vector< S_Data_Node > tree_dfs()
int insert_sibling(S_Data_Node new_node)
int schema_sort(int recursive)
int merge_to_ctx(S_Data_Node source, int options, S_Context context)
int validate_value(const char *value)
int validate(int options, S_Context var_arg)
S_Set find_instance(S_Schema_Node schema)
S_Data_Node dup_to_ctx(int recursive, S_Context context)
int merge(S_Data_Node source, int options)
S_Difflist diff(S_Data_Node second, int options)
int insert_before(S_Data_Node new_node)
std::vector< S_Data_Node > second()
std::vector< S_Data_Node > first()
Difflist(struct lyd_difflist *diff, S_Deleter deleter)
Value(lyd_val value, LY_DATA_TYPE *value_type, uint8_t value_flags, struct lys_type *type, S_Deleter deleter)
std::vector< S_Type_Bit > bit()
S_Data_Node create_new_Data_Node(struct lyd_node *node)
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....
union lyd_value_u lyd_val
node's value representation
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.
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.
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...
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...
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.
Structure for the result of lyd_diff(), describing differences between two data trees.
Generic structure for a data node, directly applicable to the data nodes defined as LYS_CONTAINER,...
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...
Structure to hold a set of (not necessary somehow connected) lyd_node or lys_node objects....
LY_DATA_TYPE
YANG built-in types.
Main schema node structure representing YANG module.
YANG type structure providing information from the schema.
The main libyang public header.
Structure for data nodes defined as LYS_LEAF or LYS_LEAFLIST.
libyang representation of data trees.
libyang representation of data model trees.
#define LY_TREE_DFS_END(START, NEXT, ELEM)