Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 1 | /** |
Radek Krejci | aa429e4 | 2015-10-09 15:52:37 +0200 | [diff] [blame] | 2 | * @file tree_data.h |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 3 | * @author Radek Krejci <rkrejci@cesnet.cz> |
Radek Krejci | aa429e4 | 2015-10-09 15:52:37 +0200 | [diff] [blame] | 4 | * @brief libyang representation of data trees. |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 5 | * |
| 6 | * Copyright (c) 2015 CESNET, z.s.p.o. |
| 7 | * |
| 8 | * Redistribution and use in source and binary forms, with or without |
| 9 | * modification, are permitted provided that the following conditions |
| 10 | * are met: |
| 11 | * 1. Redistributions of source code must retain the above copyright |
| 12 | * notice, this list of conditions and the following disclaimer. |
| 13 | * 2. Redistributions in binary form must reproduce the above copyright |
| 14 | * notice, this list of conditions and the following disclaimer in |
| 15 | * the documentation and/or other materials provided with the |
| 16 | * distribution. |
| 17 | * 3. Neither the name of the Company nor the names of its contributors |
| 18 | * may be used to endorse or promote products derived from this |
| 19 | * software without specific prior written permission. |
| 20 | */ |
| 21 | |
| 22 | #ifndef LY_TREE_DATA_H_ |
| 23 | #define LY_TREE_DATA_H_ |
| 24 | |
| 25 | #include <stddef.h> |
| 26 | #include <stdint.h> |
| 27 | |
Mislav Novakovic | e251a65 | 2015-09-29 08:40:12 +0200 | [diff] [blame] | 28 | #include "tree_schema.h" |
| 29 | |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 30 | #ifdef __cplusplus |
| 31 | extern "C" { |
| 32 | #endif |
| 33 | |
| 34 | /** |
| 35 | * @addtogroup datatree |
| 36 | * @{ |
| 37 | */ |
| 38 | |
| 39 | /** |
| 40 | * @brief Data input/output formats supported by libyang [parser](@ref parsers) and [printer](@ref printers) functions. |
| 41 | */ |
| 42 | typedef enum { |
| 43 | LYD_UNKNOWN, /**< unknown format, used as return value in case of error */ |
| 44 | LYD_XML, /**< XML format of the instance data */ |
Radek Krejci | 452fb95 | 2015-10-02 16:07:46 +0200 | [diff] [blame] | 45 | LYD_XML_FORMAT, /**< For input data, it is interchangeable with #LYD_XML, for output it formats XML with indentantion */ |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 46 | LYD_JSON, /**< JSON format of the instance data */ |
| 47 | } LYD_FORMAT; |
| 48 | |
| 49 | /** |
| 50 | * @brief Data attribute's type to distinguish between a standard (XML) attribute and namespace definition |
| 51 | */ |
| 52 | typedef enum lyd_attr_type { |
| 53 | LYD_ATTR_STD = 1, /**< standard attribute, see ::lyd_attr structure */ |
| 54 | LYD_ATTR_NS = 2 /**< namespace definition, see ::lyd_ns structure */ |
| 55 | } LYD_ATTR_TYPE; |
| 56 | |
| 57 | /** |
| 58 | * @brief Namespace definition structure. |
| 59 | * |
| 60 | * Usually, the object is provided as ::lyd_attr structure. The structure is compatible with |
| 61 | * ::lyd_attr within the first two members (#type and #next) to allow passing through and type |
| 62 | * detection interchangeably. When the type member is set to #LYD_ATTR_NS, the ::lyd_attr |
| 63 | * structure should be cast to ::lyd_ns to access the rest of members. |
| 64 | */ |
| 65 | struct lyd_ns { |
| 66 | LYD_ATTR_TYPE type; /**< always #LYD_ATTR_NS, compatible with ::lyd_attr */ |
| 67 | struct lyd_attr *next; /**< pointer to the next attribute or namespace definition of an element, |
| 68 | compatible with ::lyd_attr */ |
| 69 | struct lyd_node *parent; /**< pointer to the element where the namespace definition is placed */ |
| 70 | const char *prefix; /**< namespace prefix value */ |
| 71 | const char *value; /**< namespace value */ |
| 72 | }; |
| 73 | |
| 74 | /** |
| 75 | * @brief Attribute structure. |
| 76 | * |
| 77 | * The structure provides information about attributes of a data element and covers not only |
| 78 | * attributes but also namespace definitions. Therefore, the first two members (#type and #next) |
| 79 | * can be safely accessed to pass through the attributes list and type detection. When the #type |
| 80 | * member has #LYD_ATTR_STD value, the rest of the members can be used. Otherwise, the object |
| 81 | * should be cast to the appropriate structure according to #LYD_ATTR_TYPE enumeration. |
| 82 | */ |
| 83 | struct lyd_attr { |
| 84 | LYD_ATTR_TYPE type; /**< type of the attribute, to access the last three members, the value |
| 85 | must be ::LYD_ATTR_STD */ |
| 86 | struct lyd_attr *next; /**< pointer to the next attribute or namespace definition of an element */ |
| 87 | struct lyd_ns *ns; /**< pointer to the definition of the namespace of the attribute */ |
| 88 | const char *name; /**< attribute name */ |
| 89 | const char *value; /**< attribute value */ |
| 90 | }; |
| 91 | |
| 92 | /** |
| 93 | * @brief node's value representation |
| 94 | */ |
| 95 | typedef union lyd_value_u { |
| 96 | const char *binary; /**< base64 encoded, NULL terminated string */ |
Michal Vasko | 8ea2b7f | 2015-09-29 14:30:53 +0200 | [diff] [blame] | 97 | struct lys_type_bit **bit; /**< bitmap of pointers to the schema definition of the bit value that are set, |
| 98 | its size is always the number of defined bits in the schema */ |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 99 | int8_t bool; /**< 0 as false, 1 as true */ |
| 100 | int64_t dec64; /**< decimal64: value = dec64 / 10^fraction-digits */ |
| 101 | struct lys_type_enum *enm; /**< pointer to the schema definition of the enumeration value */ |
Michal Vasko | 8ea2b7f | 2015-09-29 14:30:53 +0200 | [diff] [blame] | 102 | struct lys_ident *ident; /**< pointer to the schema definition of the identityref value */ |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 103 | struct lyd_node *instance; /**< instance-identifier, pointer to the referenced data tree node */ |
| 104 | int8_t int8; /**< 8-bit signed integer */ |
| 105 | int16_t int16; /**< 16-bit signed integer */ |
| 106 | int32_t int32; /**< 32-bit signed integer */ |
| 107 | int64_t int64; /**< 64-bit signed integer */ |
| 108 | struct lyd_node *leafref; /**< pointer to the referenced leaf/leaflist instance in data tree */ |
| 109 | const char *string; /**< string */ |
| 110 | uint8_t uint8; /**< 8-bit unsigned integer */ |
| 111 | uint16_t uint16; /**< 16-bit signed integer */ |
| 112 | uint32_t uint32; /**< 32-bit signed integer */ |
| 113 | uint64_t uint64; /**< 64-bit signed integer */ |
| 114 | } lyd_val; |
| 115 | |
| 116 | /** |
| 117 | * @brief Generic structure for a data node, directly applicable to the data nodes defined as #LYS_CONTAINER, #LYS_LIST |
| 118 | * and #LYS_CHOICE. |
| 119 | * |
| 120 | * Completely fits to containers and choices and is compatible (can be used interchangeably except the #child member) |
| 121 | * with all other lyd_node_* structures. All data nodes are provides as ::lyd_node structure by default. |
| 122 | * According to the schema's ::lys_node#nodetype member, the specific object is supposed to be cast to |
Radek Krejci | ee36089 | 2015-10-06 11:23:14 +0200 | [diff] [blame] | 123 | * ::lyd_node_leaf_list or ::lyd_node_anyxml structures. This structure fits only to |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 124 | * #LYS_CONTAINER and #LYS_CHOICE values. |
| 125 | * |
| 126 | * To traverse through all the child elements or attributes, use #LY_TREE_FOR or #LY_TREE_FOR_SAFE macro. |
| 127 | */ |
| 128 | struct lyd_node { |
| 129 | struct lys_node *schema; /**< pointer to the schema definition of this node */ |
| 130 | |
| 131 | struct lyd_attr *attr; /**< pointer to the list of attributes of this node */ |
| 132 | struct lyd_node *next; /**< pointer to the next sibling node (NULL if there is no one) */ |
| 133 | struct lyd_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is |
| 134 | never NULL. If there is no sibling node, pointer points to the node |
| 135 | itself. In case of the first node, this pointer points to the last |
| 136 | node in the list. */ |
| 137 | struct lyd_node *parent; /**< pointer to the parent node, NULL in case of root node */ |
| 138 | struct lyd_node *child; /**< pointer to the first child node \note Since other lyd_node_* |
Radek Krejci | ee36089 | 2015-10-06 11:23:14 +0200 | [diff] [blame] | 139 | structures represent end nodes, this member |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 140 | is replaced in those structures. Therefore, be careful with accessing |
| 141 | this member without having information about the node type from the schema's |
| 142 | ::lys_node#nodetype member. */ |
| 143 | }; |
| 144 | |
| 145 | /** |
Michal Vasko | 4c18331 | 2015-09-25 10:41:47 +0200 | [diff] [blame] | 146 | * @brief Structure for data nodes defined as #LYS_LEAF or #LYS_LEAFLIST. |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 147 | * |
Michal Vasko | 4c18331 | 2015-09-25 10:41:47 +0200 | [diff] [blame] | 148 | * Extension for ::lyd_node structure. It replaces the ::lyd_node#child member by |
| 149 | * three new members (#value, #value_str and #value_type) to provide |
| 150 | * information about the value. The first five members (#schema, #attr, #next, |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 151 | * #prev and #parent) are compatible with the ::lyd_node's members. |
| 152 | * |
| 153 | * To traverse through all the child elements or attributes, use #LY_TREE_FOR or #LY_TREE_FOR_SAFE macro. |
| 154 | */ |
Michal Vasko | 4c18331 | 2015-09-25 10:41:47 +0200 | [diff] [blame] | 155 | struct lyd_node_leaf_list { |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 156 | struct lys_node *schema; /**< pointer to the schema definition of this node which is ::lys_node_leaflist |
| 157 | structure */ |
| 158 | |
| 159 | struct lyd_attr *attr; /**< pointer to the list of attributes of this node */ |
| 160 | struct lyd_node *next; /**< pointer to the next sibling node (NULL if there is no one) */ |
| 161 | struct lyd_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is |
| 162 | never NULL. If there is no sibling node, pointer points to the node |
| 163 | itself. In case of the first node, this pointer points to the last |
| 164 | node in the list. */ |
| 165 | struct lyd_node *parent; /**< pointer to the parent node, NULL in case of root node */ |
| 166 | |
| 167 | /* struct lyd_node *child; should be here, but is not */ |
| 168 | |
| 169 | /* leaflist's specific members */ |
| 170 | lyd_val value; /**< node's value representation */ |
| 171 | const char *value_str; /**< string representation of value (for comparison, printing,...) */ |
| 172 | LY_DATA_TYPE value_type; /**< type of the value in the node, mainly for union to avoid repeating of type detection */ |
| 173 | }; |
| 174 | |
| 175 | /** |
| 176 | * @brief Structure for data nodes defined as #LYS_ANYXML. |
| 177 | * |
| 178 | * Extension for ::lyd_node structure - replaces the ::lyd_node#child member by new #value member. The first five |
| 179 | * members (#schema, #attr, #next, #prev and #parent) are compatible with the ::lyd_node's members. |
| 180 | * |
| 181 | * To traverse through all the child elements or attributes, use #LY_TREE_FOR or #LY_TREE_FOR_SAFE macro. |
| 182 | */ |
| 183 | struct lyd_node_anyxml { |
| 184 | struct lys_node *schema; /**< pointer to the schema definition of this node which is ::lys_node_anyxml |
| 185 | structure */ |
| 186 | |
| 187 | struct lyd_attr *attr; /**< pointer to the list of attributes of this node */ |
| 188 | struct lyd_node *next; /**< pointer to the next sibling node (NULL if there is no one) */ |
| 189 | struct lyd_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is |
| 190 | never NULL. If there is no sibling node, pointer points to the node |
| 191 | itself. In case of the first node, this pointer points to the last |
| 192 | node in the list. */ |
| 193 | struct lyd_node *parent; /**< pointer to the parent node, NULL in case of root node */ |
| 194 | |
| 195 | /* struct lyd_node *child; should be here, but is not */ |
| 196 | |
| 197 | /* anyxml's specific members */ |
| 198 | struct lyxml_elem *value; /**< anyxml name is the root element of value! */ |
| 199 | }; |
| 200 | |
| 201 | /** |
Michal Vasko | 8ea2b7f | 2015-09-29 14:30:53 +0200 | [diff] [blame] | 202 | * @brief Create a new container node in a data tree. |
| 203 | * |
| 204 | * @param[in] parent Parent node for the node being created. NULL in case of creating top level element. |
Radek Krejci | ee36089 | 2015-10-06 11:23:14 +0200 | [diff] [blame] | 205 | * @param[in] module Module with the node being created. |
Michal Vasko | 8ea2b7f | 2015-09-29 14:30:53 +0200 | [diff] [blame] | 206 | * @param[in] name Schema node name of the new data node. The node can be #LYS_CONTAINER, #LYS_LIST, |
| 207 | * #LYS_INPUT, #LYS_OUTPUT, #LYS_NOTIF, or #LYS_RPC. |
| 208 | */ |
| 209 | struct lyd_node *lyd_new(struct lyd_node *parent, struct lys_module *module, const char *name); |
| 210 | |
| 211 | /** |
| 212 | * @brief Create a new leaf or leaflist node in a data tree with a specific value. |
| 213 | * |
| 214 | * @param[in] parent Parent node for the node being created. NULL in case of creating top level element. |
Radek Krejci | ee36089 | 2015-10-06 11:23:14 +0200 | [diff] [blame] | 215 | * @param[in] module Module with the node being created. |
| 216 | * @param[in] name Schema node name of the new data node. |
Michal Vasko | 8ea2b7f | 2015-09-29 14:30:53 +0200 | [diff] [blame] | 217 | * @param[in] type Type of the value provided in the \p value parameter. Cannot be #LY_TYPE_DER, #LY_TYPE_UNION, |
| 218 | * or #LY_TYPE_INST. |
Michal Vasko | 81eef2c | 2015-10-02 15:37:25 +0200 | [diff] [blame] | 219 | * @param[in] value Value of the node being created. Can be NULL only if \p type is #LY_TYPE_EMPTY. |
Michal Vasko | 8ea2b7f | 2015-09-29 14:30:53 +0200 | [diff] [blame] | 220 | */ |
| 221 | struct lyd_node *lyd_new_leaf_val(struct lyd_node *parent, struct lys_module *module, const char *name, |
Michal Vasko | 0e3c872 | 2015-09-29 16:06:08 +0200 | [diff] [blame] | 222 | LY_DATA_TYPE type, lyd_val value); |
Michal Vasko | 8ea2b7f | 2015-09-29 14:30:53 +0200 | [diff] [blame] | 223 | |
| 224 | /** |
| 225 | * @brief Create a new leaf or leaflist node in a data tree with a string value that is converted to |
| 226 | * the actual value. |
| 227 | * |
| 228 | * @param[in] parent Parent node for the node being created. NULL in case of creating top level element. |
Radek Krejci | ee36089 | 2015-10-06 11:23:14 +0200 | [diff] [blame] | 229 | * @param[in] module Module with the node being created. |
| 230 | * @param[in] name Schema node name of the new data node. |
Michal Vasko | 8ea2b7f | 2015-09-29 14:30:53 +0200 | [diff] [blame] | 231 | * @param[in] type Interpretation of the string provided in the \p val_str parameter. After appropriate |
| 232 | * conversion this will be the resulting type of the value in the node. Cannot be #LY_TYPE_DER or #LY_TYPE_UNION. |
| 233 | * @param[in] val_str String form of the value of the node being created. Can be NULL only if \p type is |
| 234 | * #LY_TYPE_EMPTY. |
| 235 | */ |
| 236 | struct lyd_node *lyd_new_leaf_str(struct lyd_node *parent, struct lys_module *module, const char *name, |
| 237 | LY_DATA_TYPE type, const char *val_str); |
| 238 | |
| 239 | /** |
| 240 | * @brief Create a new anyxml node in a data tree. |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 241 | * |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 242 | * @param[in] parent Parent node for the node being created. NULL in case of creating top level element. |
Radek Krejci | ee36089 | 2015-10-06 11:23:14 +0200 | [diff] [blame] | 243 | * @param[in] module Module with the node being created. |
| 244 | * @param[in] name Schema node name of the new data node. |
Michal Vasko | 8ea2b7f | 2015-09-29 14:30:53 +0200 | [diff] [blame] | 245 | * @param[in] val_xml Value of the node being created. Must be a well-formed XML. |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 246 | */ |
Michal Vasko | 8ea2b7f | 2015-09-29 14:30:53 +0200 | [diff] [blame] | 247 | struct lyd_node *lyd_new_anyxml(struct lyd_node *parent, struct lys_module *module, const char *name, |
| 248 | const char *val_xml); |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 249 | |
| 250 | /** |
Michal Vasko | c0797f8 | 2015-10-14 15:51:25 +0200 | [diff] [blame] | 251 | * @brief Create a copy of the specified data tree \p node. Namespaces are copied as needed, |
| 252 | * schema references are kept the same. |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 253 | * |
| 254 | * @param[in] node Data tree node to be duplicated. |
| 255 | * @param[in] recursive 1 if all children are supposed to be also duplicated. |
| 256 | * @return Created copy of the provided data \p node. |
| 257 | */ |
| 258 | struct lyd_node *lyd_dup(struct lyd_node *node, int recursive); |
| 259 | |
| 260 | /** |
| 261 | * @brief Insert the \p node element as child to the \p parent element. The \p node is inserted as a last child of the |
| 262 | * \p parent. |
| 263 | * |
| 264 | * If the node is part of some other tree, it is automatically unlinked. |
| 265 | * If the node is the first node of a node list (with no parent), all |
| 266 | * the subsequent nodes are also inserted. |
| 267 | * |
| 268 | * @param[in] parent Parent node for the \p node being inserted. |
| 269 | * @param[in] node The node being inserted. |
| 270 | * @param[in] options Options for the inserting data to the target data tree options, see @ref parseroptions. |
| 271 | * @return 0 fo success, nonzero in case of error, e.g. when the node is being inserted to an inappropriate place |
| 272 | * in the data tree. |
| 273 | */ |
| 274 | int lyd_insert(struct lyd_node *parent, struct lyd_node *node, int options); |
| 275 | |
| 276 | /** |
| 277 | * @brief Insert the \p node element after the \p sibling element. |
| 278 | * |
| 279 | * TODO not implemented |
| 280 | * |
| 281 | * @param[in] sibling The data tree node before which the \p node will be inserted. |
| 282 | * @param[in] node The data tree node to be inserted. |
| 283 | * @return 0 fo success, nonzero in case of error, e.g. when the node is being inserted to an inappropriate place |
| 284 | * in the data tree. |
| 285 | */ |
| 286 | int lyd_insert_before(struct lyd_node *sibling, struct lyd_node *node); |
| 287 | |
| 288 | /** |
| 289 | * @brief Insert the \p node element after the \p sibling element. |
| 290 | * |
| 291 | * @param[in] sibling The data tree node before which the \p node will be inserted. |
| 292 | * @param[in] node The data tree node to be inserted. |
| 293 | * @param[in] options Options for the inserting data to the target data tree options, see @ref parseroptions. |
| 294 | * @return 0 fo success, nonzero in case of error, e.g. when the node is being inserted to an inappropriate place |
| 295 | * in the data tree. |
| 296 | */ |
| 297 | int lyd_insert_after(struct lyd_node *sibling, struct lyd_node *node, int options); |
| 298 | |
| 299 | /** |
| 300 | * @brief Move the data tree \p node before the specified \p sibling node |
| 301 | * |
| 302 | * Both the data nodes must be in the same children list, i.e. they have the same parent. |
| 303 | * |
| 304 | * TODO not implemented |
| 305 | * |
| 306 | * @param[in] sibling The data tree node before which the \p node will be moved. |
| 307 | * @param[in] node The data tree node to be moved. |
| 308 | * @return 0 for success, nonzero in case of error |
| 309 | */ |
| 310 | int lyd_move_before(struct lyd_node *sibling, struct lyd_node *node); |
| 311 | |
| 312 | /** |
| 313 | * @brief Move the data tree \p node after the specified \p sibling node |
| 314 | * |
| 315 | * Both the data nodes must be in the same children list, i.e. they have the same parent. |
| 316 | * |
| 317 | * TODO not implemented |
| 318 | * |
| 319 | * @param[in] sibling The data tree node after which the \p node will be moved. |
| 320 | * @param[in] node The data tree node to be moved. |
| 321 | * @return 0 for success, nonzero in case of error |
| 322 | */ |
| 323 | int lyd_move_after(struct lyd_node *sibling, struct lyd_node *node); |
| 324 | |
| 325 | /** |
Michal Vasko | 55f60be | 2015-10-14 13:12:58 +0200 | [diff] [blame] | 326 | * @brief Unlink the specified data subtree. All referenced namespaces are copied. |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 327 | * |
| 328 | * Note, that the node's connection with the schema tree is kept. Therefore, in case of |
| 329 | * reconnecting the node to a data tree using lyd_paste() it is necessary to paste it |
| 330 | * to the appropriate place in the data tree following the schema. |
| 331 | * |
| 332 | * @param[in] node Data tree node to be unlinked (together with all children). |
| 333 | * @return 0 for success, nonzero for error |
| 334 | */ |
| 335 | int lyd_unlink(struct lyd_node *node); |
| 336 | |
| 337 | /** |
| 338 | * @brief Free (and unlink) the specified data (sub)tree. |
| 339 | * |
| 340 | * @param[in] node Root of the (sub)tree to be freed. |
| 341 | */ |
| 342 | void lyd_free(struct lyd_node *node); |
| 343 | |
| 344 | /** |
| 345 | * @brief Opaque internal structure, do not access it from outside. |
| 346 | */ |
| 347 | struct lyxml_elem; |
| 348 | |
| 349 | /** |
| 350 | * @brief Serialize anyxml content for further processing. |
| 351 | * |
| 352 | * TODO not implemented |
| 353 | * |
| 354 | * @param[in] anyxml Anyxml content from ::lyd_node_anyxml#value to serialize ax XML string |
| 355 | * @return Serialized content of the anyxml or NULL in case of error |
| 356 | */ |
| 357 | char *lyxml_serialize(struct lyxml_elem *anyxml); |
| 358 | |
| 359 | /** |
| 360 | * @brief Structure to hold a set of (not necessary somehow connected) ::lyd_node objects. |
| 361 | * |
| 362 | * To free the structure, use lyd_set_free() function, to manipulate with the structure, use other |
| 363 | * lyd_set_* functions. |
| 364 | */ |
| 365 | struct lyd_set { |
| 366 | unsigned int size; /**< allocated size of the set array */ |
| 367 | unsigned int number; /**< number of elements in (used size of) the set array */ |
| 368 | struct lyd_node **set; /**< array of pointers to a ::lyd_node objects */ |
| 369 | }; |
| 370 | |
| 371 | /** |
| 372 | * @brief Create and initiate new ::lyd_set structure. |
| 373 | * |
| 374 | * @return Created ::lyd_set structure or NULL in case of error. |
| 375 | */ |
| 376 | struct lyd_set *lyd_set_new(void); |
| 377 | |
| 378 | /** |
| 379 | * @brief Add a ::lyd_node object into the set |
| 380 | * |
| 381 | * @param[in] set Set where the \p node will be added. |
| 382 | * @param[in] node The ::lyd_node object to be added into the \p set; |
| 383 | * @return 0 on success |
| 384 | */ |
| 385 | int lyd_set_add(struct lyd_set *set, struct lyd_node *node); |
| 386 | |
| 387 | /** |
| 388 | * @brief Free the ::lyd_set data. Frees only the set structure content, not the referred data. |
| 389 | * |
| 390 | * @param[in] set The set to be freed. |
| 391 | */ |
| 392 | void lyd_set_free(struct lyd_set *set); |
| 393 | |
| 394 | /**@} */ |
| 395 | |
| 396 | #ifdef __cplusplus |
| 397 | } |
| 398 | #endif |
| 399 | |
| 400 | #endif /* LY_TREE_DATA_H_ */ |