libyang  3.4.2
libyang is YANG data modelling language parser and toolkit written (and providing API) in C.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Trees - modification
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). More...
 
#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). More...
 
#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). More...
 
#define LY_ARRAY_DECREMENT(ARRAY)   --(*((LY_ARRAY_COUNT_TYPE*)(ARRAY) - 1))
 Decrement the items counter in a (sized array). More...
 
#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. More...
 
#define LY_ARRAY_FREE(ARRAY)   if (ARRAY){free((LY_ARRAY_COUNT_TYPE*)(ARRAY) - 1);}
 Free the space allocated for the (sized array). More...
 
#define LY_ARRAY_INCREMENT(ARRAY)   ++(*((LY_ARRAY_COUNT_TYPE*)(ARRAY) - 1))
 Increment the items counter in a (sized array). More...
 
#define LY_ARRAY_NEW(CTX, ARRAY, EACTION)
 (Re-)Allocation of a (sized array). More...
 
#define LY_ARRAY_NEW_GOTO(CTX, ARRAY, NEW_ITEM, RET, GOTO)
 (Re-)Allocation of a (sized array). More...
 
#define LY_ARRAY_NEW_RET(CTX, ARRAY, NEW_ITEM, RETVAL)
 (Re-)Allocation of a (sized array). More...
 
#define LY_ARRAY_REMOVE_VALUE(ARRAY, VALUE)
 Remove item from array based on value. More...
 
#define LY_LIST_INSERT(LIST, NEW_ITEM, LINKER)
 Insert item into linked list. More...
 
#define LY_LIST_NEW(CTX, LIST, NEW_ITEM, LINKER, EACTION)
 Allocate and insert new item into linked list, return in case of error. More...
 
#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. More...
 
#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. More...
 

Detailed Description

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

Macro Definition Documentation

#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) { \
memset(&(ARRAY)[*((LY_ARRAY_COUNT_TYPE*)(p__) - 1)], 0, (SIZE) * sizeof *(ARRAY)); \
} \
}
memset(value->fixed_mem, 0, LYD_VALUE_FIXED_MEM_SIZE)
#define LOGMEM(CTX)
Definition: tree_edit.h:22
#define LY_ARRAY_COUNT_TYPE
Type (i.e. size) of the sized array's size counter.
Definition: tree.h:104
if((v1->size!=v2->size)||memcmp(v1->data, v2->data, v1->size))
Definition: binary.c:349

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]CTXlibyang context for logging.
[in,out]ARRAYPointer to the array to create.
[in]SIZENumber 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]EACTIONAction to perform in case of error (memory allocation failure).

Definition at line 132 of file tree_edit.h.

#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]CTXlibyang context for logging.
[in,out]ARRAYPointer to the array to create.
[in]SIZENumber 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]RETVariable to store error code.
[in]GOTOLabel to go in case of error (memory allocation failure).

Definition at line 186 of file tree_edit.h.

#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]CTXlibyang context for logging.
[in,out]ARRAYPointer to the array to create.
[in]SIZENumber 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]RETVALReturn value for the case of error (memory allocation failure).

Definition at line 169 of file tree_edit.h.

#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]ARRAYPointer to the array to affect.

Definition at line 208 of file tree_edit.h.

#define LY_ARRAY_DECREMENT_FREE (   ARRAY)
Value:
--(*((LY_ARRAY_COUNT_TYPE*)(ARRAY) - 1)); \
if (!LY_ARRAY_COUNT(ARRAY)) { \
LY_ARRAY_FREE(ARRAY); \
(ARRAY) = NULL; \
}
#define LY_ARRAY_FREE(ARRAY)
Free the space allocated for the (sized array).
Definition: tree_edit.h:231
#define LY_ARRAY_COUNT(ARRAY)
Get the number of records in the ARRAY.
Definition: tree.h:148
#define LY_ARRAY_COUNT_TYPE
Type (i.e. size) of the sized array's size counter.
Definition: tree.h:104
if((v1->size!=v2->size)||memcmp(v1->data, v2->data, v1->size))
Definition: binary.c:349

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

Parameters
[in]ARRAYPointer to the array to affect.

Definition at line 217 of file tree_edit.h.

#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]ARRAYA (sized array) to be freed.

Definition at line 231 of file tree_edit.h.

#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]ARRAYPointer to the array to affect.

Definition at line 197 of file tree_edit.h.

#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__); \
}
#define LOGMEM(CTX)
Definition: tree_edit.h:22
#define LY_ARRAY_COUNT_TYPE
Type (i.e. size) of the sized array's size counter.
Definition: tree.h:104
if((v1->size!=v2->size)||memcmp(v1->data, v2->data, v1->size))
Definition: binary.c:349

(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]CTXlibyang context for logging.
[in,out]ARRAYPointer 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]EACTIONAction to perform in case of error (memory allocation failure).

Definition at line 60 of file tree_edit.h.

#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))
memset(value->fixed_mem, 0, LYD_VALUE_FIXED_MEM_SIZE)
Definition: log.h:242
#define LY_ARRAY_NEW(CTX, ARRAY, EACTION)
(Re-)Allocation of a (sized array).
Definition: tree_edit.h:60
#define LY_ARRAY_COUNT_TYPE
Type (i.e. size) of the sized array's size counter.
Definition: tree.h:104

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

Increases the size information.

Parameters
[in]CTXlibyang context for logging.
[in,out]ARRAYPointer 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_ITEMReturning pointer to the newly allocated record in the ARRAY.
[out]RETVariable to store error code.
[in]GOTOLabel to go in case of error (memory allocation failure).

Definition at line 112 of file tree_edit.h.

#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))
memset(value->fixed_mem, 0, LYD_VALUE_FIXED_MEM_SIZE)
#define LY_ARRAY_NEW(CTX, ARRAY, EACTION)
(Re-)Allocation of a (sized array).
Definition: tree_edit.h:60
#define LY_ARRAY_COUNT_TYPE
Type (i.e. size) of the sized array's size counter.
Definition: tree.h:104

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

Increases the size information.

Parameters
[in]CTXlibyang context for logging.
[in,out]ARRAYPointer 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_ITEMReturning pointer to the newly allocated record in the ARRAY.
[in]RETVALReturn value for the case of error (memory allocation failure).

Definition at line 95 of file tree_edit.h.

#define LY_ARRAY_REMOVE_VALUE (   ARRAY,
  VALUE 
)
Value:
{ \
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)); \
} \
break; \
} \
} \
}
#define LY_ARRAY_DECREMENT(ARRAY)
Decrement the items counter in a (sized array).
Definition: tree_edit.h:208
#define LY_ARRAY_COUNT(ARRAY)
Get the number of records in the ARRAY.
Definition: tree.h:148
#define LY_ARRAY_FOR(ARRAY,...)
Sized-array iterator (for-loop).
Definition: tree.h:167
#define LY_ARRAY_COUNT_TYPE
Type (i.e. size) of the sized array's size counter.
Definition: tree.h:104
if((v1->size!=v2->size)||memcmp(v1->data, v2->data, v1->size))
Definition: binary.c:349

Remove item from array based on value.

Parameters
[in,out]ARRAYA (sized array) to be modified.
[in]VALUEThe item value to be removed. Only the first occurence will be removed.

Definition at line 240 of file tree_edit.h.

#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]LISTLinked list to add to.
[in]NEW_ITEMNew item, that will be appended to the list, must be already allocated.
[in]LINKERname of structuring member that is used to connect items together.

Definition at line 261 of file tree_edit.h.

#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); \
}
#define LOGMEM(CTX)
Definition: tree_edit.h:22
#define LY_LIST_INSERT(LIST, NEW_ITEM, LINKER)
Insert item into linked list.
Definition: tree_edit.h:261
if((v1->size!=v2->size)||memcmp(v1->data, v2->data, v1->size))
Definition: binary.c:349

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]CTXused for logging.
[in,out]LISTLinked list to add to.
[out]NEW_ITEMNew item that is appended to the list.
[in]LINKERname of structure member that is used to connect items together.
[in]EACTIONAction to perform in case of error (memory allocation failure).

Definition at line 284 of file tree_edit.h.

#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]CTXused for logging.
[in,out]LISTLinked list to add to.
[out]NEW_ITEMNew item that is appended to the list.
[in]LINKERname of structure member that is used to connect items together.
[in]RETvariable to store returned error type.
[in]LABELlabel to goto in case of error.

Definition at line 317 of file tree_edit.h.

#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]CTXused for logging.
[in,out]LISTLinked list to add to.
[out]NEW_ITEMNew item that is appended to the list.
[in]LINKERname of structure member that is used to connect items together.
[in]RETVALReturn value for the case of error (memory allocation failure).

Definition at line 304 of file tree_edit.h.