Loading...
Searching...
No Matches
Trees - modification
Trees
Collaboration diagram for Trees - modification:

## Macros

#define | LY_ARRAY_CREATE(CTX, ARRAY, SIZE, EACTION)
| Allocate a (sized array) for the specified number of items. If the ARRAY already exists, it is resized (space for SIZE items is added and zeroed).
#define | LY_ARRAY_CREATE_GOTO(CTX, ARRAY, SIZE, RET, GOTO) LY_ARRAY_CREATE(CTX, ARRAY, SIZE, RET = LY_EMEM; goto GOTO)
| Allocate a (sized array) for the specified number of items. If the ARRAY already exists, it is resized (space for SIZE items is added).
#define | LY_ARRAY_CREATE_RET(CTX, ARRAY, SIZE, RETVAL) LY_ARRAY_CREATE(CTX, ARRAY, SIZE, return RETVAL)
| Allocate a (sized array) for the specified number of items. If the ARRAY already exists, it is resized (space for SIZE items is added and zeroed).
#define | LY_ARRAY_DECREMENT(ARRAY) --(*((LY_ARRAY_COUNT_TYPE*)(ARRAY) - 1))
| Decrement the items counter in a (sized array).
#define | LY_ARRAY_DECREMENT_FREE(ARRAY)
| Decrement the items counter in a (sized array) and free the whole array in case it was decremented to 0.
#define | LY_ARRAY_FREE(ARRAY) if (ARRAY){free((LY_ARRAY_COUNT_TYPE*)(ARRAY) - 1);}
| Free the space allocated for the (sized array).
#define | LY_ARRAY_INCREMENT(ARRAY) ++(*((LY_ARRAY_COUNT_TYPE*)(ARRAY) - 1))
| Increment the items counter in a (sized array).
#define | LY_ARRAY_NEW(CTX, ARRAY, EACTION)
| (Re-)Allocation of a (sized array).
#define | LY_ARRAY_NEW_GOTO(CTX, ARRAY, NEW_ITEM, RET, GOTO)
| (Re-)Allocation of a (sized array).
#define | LY_ARRAY_NEW_RET(CTX, ARRAY, NEW_ITEM, RETVAL)
| (Re-)Allocation of a (sized array).
#define | LY_ARRAY_REMOVE_VALUE(ARRAY, VALUE)
| Remove item from array based on value.
#define | LY_LIST_INSERT(LIST, NEW_ITEM, LINKER)
| Insert item into linked list.
#define | LY_LIST_NEW(CTX, LIST, NEW_ITEM, LINKER, EACTION)
| Allocate and insert new item into linked list, return in case of error.
#define | LY_LIST_NEW_GOTO(CTX, LIST, NEW_ITEM, LINKER, RET, LABEL) LY_LIST_NEW(CTX, LIST, NEW_ITEM, LINKER, RET = LY_EMEM; goto LABEL)
| Allocate and insert new item into linked list, goto specified label in case of error.
#define | LY_LIST_NEW_RET(CTX, LIST, NEW_ITEM, LINKER, RETVAL) LY_LIST_NEW(CTX, LIST, NEW_ITEM, LINKER, return RETVAL)
| Allocate and insert new item into linked list, return in case of error.

## Detailed Description

Generic macros, functions, etc. to modify schema and data trees.

## Macro Definition Documentation

## LY_ARRAY_CREATE

#define LY_ARRAY_CREATE | ( |  | CTX,
|  |  | ARRAY,
|  |  | SIZE,
|  |  | EACTION
| ) |  |

Value:
{ \
char *p__; \
if (ARRAY) { \
p__ = (char *)realloc(((LY_ARRAY_COUNT_TYPE*)(ARRAY) - 1), \
sizeof(LY_ARRAY_COUNT_TYPE) + ((*((LY_ARRAY_COUNT_TYPE*)(ARRAY) - 1) + (SIZE)) * sizeof *(ARRAY))); \
if (!p__) { \
LOGMEM(CTX); \
EACTION; \
} \
} else { \
p__ = (char *)calloc(1, sizeof(LY_ARRAY_COUNT_TYPE) + (SIZE) * sizeof *(ARRAY)); \
if (!p__) { \
LOGMEM(CTX); \
EACTION; \
} \
} \
p__ = (char *)((LY_ARRAY_COUNT_TYPE*)(p__) + 1); \
memcpy(&(ARRAY), &p__, sizeof p__); \
if ((ARRAY) && (SIZE > 0)) { \
memset(&(ARRAY)[*((LY_ARRAY_COUNT_TYPE*)(p__) - 1)], 0, (SIZE) * sizeof *(ARRAY)); \
} \
}
LY_ARRAY_COUNT_TYPE
#define LY_ARRAY_COUNT_TYPE
Type (i.e. size) of the sized array's size counter.
Definition tree.h:104

Allocate a (sized array) for the specified number of items. If the ARRAY already exists, it is resized (space for SIZE items is added and zeroed).

Does not set the size information, it is supposed to be incremented via LY_ARRAY_INCREMENT when the items are filled.

This is a generic macro for LY_ARRAY_CREATE_RET and LY_ARRAY_CREATE_GOTO.

Parameters

  [in] | CTX | libyang context for logging.
  [in,out] | ARRAY | Pointer to the array to create.
  [in] | SIZE | Number of the new items the array is supposed to hold. The size of the allocated space is then counted from the type of the ARRAY, so do not provide placeholder void pointers.
  [in] | EACTION | Action to perform in case of error (memory allocation failure).

Definition at line 132 of file tree_edit.h.

## LY_ARRAY_CREATE_GOTO

#define LY_ARRAY_CREATE_GOTO | ( |  | CTX,
|  |  | ARRAY,
|  |  | SIZE,
|  |  | RET,
|  |  | GOTO
| ) |  | LY_ARRAY_CREATE(CTX, ARRAY, SIZE, RET = LY_EMEM; goto GOTO)

Allocate a (sized array) for the specified number of items. If the ARRAY already exists, it is resized (space for SIZE items is added).

Does not set the count information, it is supposed to be incremented via LY_ARRAY_INCREMENT when the items are filled.

Parameters

  [in] | CTX | libyang context for logging.
  [in,out] | ARRAY | Pointer to the array to create.
  [in] | SIZE | Number of the new items the array is supposed to hold. The size of the allocated space is then counted from the type of the ARRAY, so do not provide placeholder void pointers.
  [out] | RET | Variable to store error code.
  [in] | GOTO | Label to go in case of error (memory allocation failure).

Definition at line 186 of file tree_edit.h.

## LY_ARRAY_CREATE_RET

#define LY_ARRAY_CREATE_RET | ( |  | CTX,
|  |  | ARRAY,
|  |  | SIZE,
|  |  | RETVAL
| ) |  | LY_ARRAY_CREATE(CTX, ARRAY, SIZE, return RETVAL)

Allocate a (sized array) for the specified number of items. If the ARRAY already exists, it is resized (space for SIZE items is added and zeroed).

Does not set the size information, it is supposed to be incremented via LY_ARRAY_INCREMENT when the items are filled.

Parameters

  [in] | CTX | libyang context for logging.
  [in,out] | ARRAY | Pointer to the array to create.
  [in] | SIZE | Number of the new items the array is supposed to hold. The size of the allocated space is then counted from the type of the ARRAY, so do not provide placeholder void pointers.
  [in] | RETVAL | Return value for the case of error (memory allocation failure).

Definition at line 169 of file tree_edit.h.

## LY_ARRAY_DECREMENT

#define LY_ARRAY_DECREMENT | ( |  | ARRAY | ) | --(*((LY_ARRAY_COUNT_TYPE*)(ARRAY) - 1))

Decrement the items counter in a (sized array).

Does not change the allocated memory used by the ARRAY. To do so, use LY_ARRAY_CREATE_RET, LY_ARRAY_CREATE_GOTO or LY_ARRAY_RESIZE_ERR_RET.

Parameters

  [in] | ARRAY | Pointer to the array to affect.

Definition at line 208 of file tree_edit.h.

## LY_ARRAY_DECREMENT_FREE

#define LY_ARRAY_DECREMENT_FREE | ( |  | ARRAY | ) |

Value:
--(*((LY_ARRAY_COUNT_TYPE*)(ARRAY) - 1)); \
if (!LY_ARRAY_COUNT(ARRAY)) { \
LY_ARRAY_FREE(ARRAY); \
(ARRAY) = NULL; \
}
LY_ARRAY_COUNT
#define LY_ARRAY_COUNT(ARRAY)
Get the number of records in the ARRAY.
Definition tree.h:148

Decrement the items counter in a (sized array) and free the whole array in case it was decremented to 0.

Parameters

  [in] | ARRAY | Pointer to the array to affect.

Definition at line 217 of file tree_edit.h.

## LY_ARRAY_FREE

#define LY_ARRAY_FREE | ( |  | ARRAY | ) | if (ARRAY){free((LY_ARRAY_COUNT_TYPE*)(ARRAY) - 1);}

Free the space allocated for the (sized array).

The items inside the array are not freed.

Parameters

  [in] | ARRAY | A (sized array) to be freed.

Definition at line 231 of file tree_edit.h.

## LY_ARRAY_INCREMENT

#define LY_ARRAY_INCREMENT | ( |  | ARRAY | ) | ++(*((LY_ARRAY_COUNT_TYPE*)(ARRAY) - 1))

Increment the items counter in a (sized array).

Does not change the allocated memory used by the ARRAY. To do so, use LY_ARRAY_CREATE_RET, LY_ARRAY_CREATE_GOTO or LY_ARRAY_RESIZE_ERR_RET.

Parameters

  [in] | ARRAY | Pointer to the array to affect.

Definition at line 197 of file tree_edit.h.

## LY_ARRAY_NEW

#define LY_ARRAY_NEW | ( |  | CTX,
|  |  | ARRAY,
|  |  | EACTION
| ) |  |

Value:
{ \
char *p__; \
if (ARRAY) { \
++(*((LY_ARRAY_COUNT_TYPE*)(ARRAY) - 1)); \
p__ = (char *)realloc(((LY_ARRAY_COUNT_TYPE*)(ARRAY) - 1), \
sizeof(LY_ARRAY_COUNT_TYPE) + (*((LY_ARRAY_COUNT_TYPE*)(ARRAY) - 1) * sizeof *(ARRAY))); \
if (!p__) { \
--(*((LY_ARRAY_COUNT_TYPE*)(ARRAY) - 1)); \
LOGMEM(CTX); \
EACTION; \
} \
} else { \
p__ = (char *)malloc(sizeof(LY_ARRAY_COUNT_TYPE) + sizeof *(ARRAY)); \
if (!p__) { \
LOGMEM(CTX); \
EACTION; \
} \
*((LY_ARRAY_COUNT_TYPE*)(p__)) = 1; \
} \
p__ = (char *)((LY_ARRAY_COUNT_TYPE*)(p__) + 1); \
memcpy(&(ARRAY), &p__, sizeof p__); \
}

(Re-)Allocation of a (sized array).

Increases the size information.

This is a generic macro for LY_ARRAY_NEW_RET and LY_ARRAY_NEW_GOTO.

Parameters

  [in] | CTX | libyang context for logging.
  [in,out] | ARRAY | Pointer to the array to allocate/resize. The size of the allocated space is counted from the type of the ARRAY, so do not provide placeholder void pointers.
  [in] | EACTION | Action to perform in case of error (memory allocation failure).

Definition at line 60 of file tree_edit.h.

## LY_ARRAY_NEW_GOTO

#define LY_ARRAY_NEW_GOTO | ( |  | CTX,
|  |  | ARRAY,
|  |  | NEW_ITEM,
|  |  | RET,
|  |  | GOTO
| ) |  |

Value:
LY_ARRAY_NEW(CTX, ARRAY, RET = LY_EMEM; goto GOTO); \
(NEW_ITEM) = &(ARRAY)[*((LY_ARRAY_COUNT_TYPE*)(ARRAY) - 1) - 1]; \
memset(NEW_ITEM, 0, sizeof *(NEW_ITEM))
LY_EMEM
@ LY_EMEM
Definition log.h:239
LY_ARRAY_NEW
#define LY_ARRAY_NEW(CTX, ARRAY, EACTION)
(Re-)Allocation of a (sized array).
Definition tree_edit.h:60

(Re-)Allocation of a (sized array).

Increases the size information.

Parameters

  [in] | CTX | libyang context for logging.
  [in,out] | ARRAY | Pointer to the array to allocate/resize. The size of the allocated space is counted from the type of the ARRAY, so do not provide placeholder void pointers.
  [out] | NEW_ITEM | Returning pointer to the newly allocated record in the ARRAY.
  [out] | RET | Variable to store error code.
  [in] | GOTO | Label to go in case of error (memory allocation failure).

Definition at line 112 of file tree_edit.h.

## LY_ARRAY_NEW_RET

#define LY_ARRAY_NEW_RET | ( |  | CTX,
|  |  | ARRAY,
|  |  | NEW_ITEM,
|  |  | RETVAL
| ) |  |

Value:
LY_ARRAY_NEW(CTX, ARRAY, return RETVAL); \
(NEW_ITEM) = &(ARRAY)[*((LY_ARRAY_COUNT_TYPE*)(ARRAY) - 1) - 1]; \
memset(NEW_ITEM, 0, sizeof *(NEW_ITEM))

(Re-)Allocation of a (sized array).

Increases the size information.

Parameters

  [in] | CTX | libyang context for logging.
  [in,out] | ARRAY | Pointer to the array to allocate/resize. The size of the allocated space is counted from the type of the ARRAY, so do not provide placeholder void pointers.
  [out] | NEW_ITEM | Returning pointer to the newly allocated record in the ARRAY.
  [in] | RETVAL | Return value for the case of error (memory allocation failure).

Definition at line 95 of file tree_edit.h.

## LY_ARRAY_REMOVE_VALUE

#define LY_ARRAY_REMOVE_VALUE | ( |  | ARRAY,
|  |  | VALUE
| ) |  |

Value:
{ \
LY_ARRAY_COUNT_TYPE index__; \
LY_ARRAY_FOR(ARRAY, index__) { \
if ((ARRAY)[index__] == VALUE) { \
if (index__ != LY_ARRAY_COUNT(ARRAY) - 1) { \
memmove(&((ARRAY)[index__]), &((ARRAY)[LY_ARRAY_COUNT(ARRAY) - 1]), sizeof *(ARRAY)); \
} \
LY_ARRAY_DECREMENT(ARRAY); \
break; \
} \
} \
}

Remove item from array based on value.

Parameters

  [in,out] | ARRAY | A (sized array) to be modified.
  [in] | VALUE | The item value to be removed. Only the first occurence will be removed.

Definition at line 240 of file tree_edit.h.

## LY_LIST_INSERT

#define LY_LIST_INSERT | ( |  | LIST,
|  |  | NEW_ITEM,
|  |  | LINKER
| ) |  |

Value:
if (!(*LIST)) { \
memcpy(LIST, &(NEW_ITEM), sizeof NEW_ITEM); \
} else { \
size_t offset__ = (char *)&(*LIST)->LINKER - (char *)(*LIST); \
char **iter__ = (char **)((size_t)(*LIST) + offset__); \
while (*iter__) { \
iter__ = (char **)((size_t)(*iter__) + offset__); \
} \
memcpy(iter__, &(NEW_ITEM), sizeof NEW_ITEM); \
}

Insert item into linked list.

Parameters

  [in,out] | LIST | Linked list to add to.
  [in] | NEW_ITEM | New item, that will be appended to the list, must be already allocated.
  [in] | LINKER | name of structuring member that is used to connect items together.

Definition at line 261 of file tree_edit.h.

## LY_LIST_NEW

#define LY_LIST_NEW | ( |  | CTX,
|  |  | LIST,
|  |  | NEW_ITEM,
|  |  | LINKER,
|  |  | EACTION
| ) |  |

Value:
{ \
char *p__ = (char *)calloc(1, sizeof *NEW_ITEM); \
if (!p__) { \
LOGMEM(CTX); \
EACTION; \
} \
memcpy(&(NEW_ITEM), &p__, sizeof p__); \
LY_LIST_INSERT(LIST, NEW_ITEM, LINKER); \
}

Allocate and insert new item into linked list, return in case of error.

This is a generic macro for LY_LIST_NEW_RET and LY_LIST_NEW_GOTO.

Parameters

  [in] | CTX | used for logging.
  [in,out] | LIST | Linked list to add to.
  [out] | NEW_ITEM | New item that is appended to the list.
  [in] | LINKER | name of structure member that is used to connect items together.
  [in] | EACTION | Action to perform in case of error (memory allocation failure).

Definition at line 284 of file tree_edit.h.

## LY_LIST_NEW_GOTO

#define LY_LIST_NEW_GOTO | ( |  | CTX,
|  |  | LIST,
|  |  | NEW_ITEM,
|  |  | LINKER,
|  |  | RET,
|  |  | LABEL
| ) |  | LY_LIST_NEW(CTX, LIST, NEW_ITEM, LINKER, RET = LY_EMEM; goto LABEL)

Allocate and insert new item into linked list, goto specified label in case of error.

Parameters

  [in] | CTX | used for logging.
  [in,out] | LIST | Linked list to add to.
  [out] | NEW_ITEM | New item that is appended to the list.
  [in] | LINKER | name of structure member that is used to connect items together.
  [in] | RET | variable to store returned error type.
  [in] | LABEL | label to goto in case of error.

Definition at line 317 of file tree_edit.h.

## LY_LIST_NEW_RET

#define LY_LIST_NEW_RET | ( |  | CTX,
|  |  | LIST,
|  |  | NEW_ITEM,
|  |  | LINKER,
|  |  | RETVAL
| ) |  | LY_LIST_NEW(CTX, LIST, NEW_ITEM, LINKER, return RETVAL)

Allocate and insert new item into linked list, return in case of error.

Parameters

  [in] | CTX | used for logging.
  [in,out] | LIST | Linked list to add to.
  [out] | NEW_ITEM | New item that is appended to the list.
  [in] | LINKER | name of structure member that is used to connect items together.
  [in] | RETVAL | Return value for the case of error (memory allocation failure).

Definition at line 304 of file tree_edit.h.