libyang  6.4.7
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
Sized Array API

Macros

#define LYA_ADD(ARRAY, EACTION)
 Allocate memory for a new item in a sized array. More...
 
#define LYA_ADD_ITEM(ARRAY, NEW_ITEM, EACTION)
 Allocate memory for a new item in a sized array. More...
 
#define LYA_COUNT(ARRAY)   (ARRAY ? LYA_COUNT_(ARRAY) : 0)
 Get the number of records in the ARRAY. More...
 
#define LYA_COUNT_(ARRAY)   (*((LYA_COUNT_T *)(ARRAY) - 1))
 Internal macro, do not use. More...
 
#define LYA_COUNT_T   uint64_t
 Type (i.e. size) of the sized array's size counter. More...
 
#define LYA_DECREMENT(ARRAY)   --LYA_COUNT_(ARRAY)
 Decrement the items counter of a sized array. More...
 
#define LYA_DECREMENT_FREE(ARRAY)
 Decrement the items counter of a sized array. Free and zero the whole array in case the count was decremented to 0. More...
 
#define LYA_FOR(ARRAY, INDEX)
 Helper macro to go through sized-arrays with a numeric iterator. More...
 
#define LYA_FOR_EACH(ARRAY, ITER)
 Helper macro to go through sized-arrays with a pointer iterator. More...
 
#define LYA_FREE(ARRAY)
 Free the space allocated for a sized array. More...
 
#define LYA_INCREMENT(ARRAY)   ++LYA_COUNT_(ARRAY)
 Increment the items counter of a sized array. More...
 
#define LYA_NEW(ARRAY, COUNT, EACTION)
 Allocate memory of a sized array or resize an existing array. More...
 
#define LYA_PREALLOC(ARRAY, COUNT, EACTION)
 Allocate memory of a sized array or resize an existing array. More...
 
#define LYA_PRI_COUNT_T   PRIu64
 Printing format specifier macro for LYA_COUNT_T values. More...
 
#define LYA_REMOVE_VALUE(ARRAY, VALUE)
 Remove a specific value from a sized array. More...
 

Detailed Description

Generic macros for LY array handling that includes the information about its size.

Macro Definition Documentation

#define LYA_ADD (   ARRAY,
  EACTION 
)
Value:
LYA_PREALLOC(ARRAY, LYA_COUNT(ARRAY) + 1, EACTION); \
#define LYA_COUNT(ARRAY)
Get the number of records in the ARRAY.
Definition: ly_array.h:78
#define LYA_INCREMENT(ARRAY)
Increment the items counter of a sized array.
Definition: ly_array.h:166
#define LYA_PREALLOC(ARRAY, COUNT, EACTION)
Allocate memory of a sized array or resize an existing array.
Definition: ly_array.h:97

Allocate memory for a new item in a sized array.

Updates the size information.

New item is zeroed.

Parameters
[in,out]ARRAYSized array to manipulate.
[in]EACTIONError action on memory allocation error, must include 'return' or 'goto' commands.

Definition at line 140 of file ly_array.h.

#define LYA_ADD_ITEM (   ARRAY,
  NEW_ITEM,
  EACTION 
)
Value:
LYA_ADD(ARRAY, EACTION); \
(NEW_ITEM) = &(ARRAY)[LYA_COUNT_(ARRAY) - 1]
#define LYA_ADD(ARRAY, EACTION)
Allocate memory for a new item in a sized array.
Definition: ly_array.h:140
#define LYA_COUNT_(ARRAY)
Internal macro, do not use.
Definition: ly_array.h:83

Allocate memory for a new item in a sized array.

Updates the size information.

New item is zeroed.

Parameters
[in,out]ARRAYSized array to manipulate.
[out]NEW_ITEMPointer to the new item.
[in]EACTIONError action on memory allocation error, must include 'return' or 'goto' commands.

Definition at line 155 of file ly_array.h.

#define LYA_COUNT (   ARRAY)    (ARRAY ? LYA_COUNT_(ARRAY) : 0)

Get the number of records in the ARRAY.

Parameters
[in]ARRAYSized array to manipulate.

Definition at line 78 of file ly_array.h.

#define LYA_COUNT_ (   ARRAY)    (*((LYA_COUNT_T *)(ARRAY) - 1))

Internal macro, do not use.

Definition at line 83 of file ly_array.h.

#define LYA_COUNT_T   uint64_t

Type (i.e. size) of the sized array's size counter.

To print the value via a print format, use LYA_PRI_COUNT_T specifier.

Definition at line 38 of file ly_array.h.

#define LYA_DECREMENT (   ARRAY)    --LYA_COUNT_(ARRAY)

Decrement the items counter of a sized array.

Does not change the allocated memory used by the ARRAY. To do so, use LYA_PREALLOC.

Parameters
[in,out]ARRAYSized array to manipulate.

Definition at line 176 of file ly_array.h.

#define LYA_DECREMENT_FREE (   ARRAY)
Value:
if (!LYA_COUNT(ARRAY)) { \
LYA_FREE(ARRAY); \
(ARRAY) = NULL; \
}
#define LYA_FREE(ARRAY)
Free the space allocated for a sized array.
Definition: ly_array.h:199
#define LYA_COUNT(ARRAY)
Get the number of records in the ARRAY.
Definition: ly_array.h:78
if((v1->size!=v2->size)||memcmp(v1->data, v2->data, v1->size))
Definition: binary.c:382
#define LYA_DECREMENT(ARRAY)
Decrement the items counter of a sized array.
Definition: ly_array.h:176

Decrement the items counter of a sized array. Free and zero the whole array in case the count was decremented to 0.

Parameters
[in,out]ARRAYSized array to manipulate.

Definition at line 185 of file ly_array.h.

#define LYA_FOR (   ARRAY,
  INDEX 
)
Value:
for (INDEX = 0; \
INDEX < LYA_COUNT(ARRAY); \
++INDEX)
#define LYA_COUNT(ARRAY)
Get the number of records in the ARRAY.
Definition: ly_array.h:78

Helper macro to go through sized-arrays with a numeric iterator.

Use with opening curly bracket ({).

The item on the current INDEX in the ARRAY can be accessed in a standard C way as ARRAY[INDEX].

Parameters
[in]ARRAYSized array to manipulate.
[out]INDEXVariable for the iterating index of the item being processed in each loop.

Definition at line 55 of file ly_array.h.

#define LYA_FOR_EACH (   ARRAY,
  ITER 
)
Value:
for (ITER = ARRAY; \
(ARRAY) && ((LYA_COUNT_T)(ITER - ARRAY) < LYA_COUNT(ARRAY)); \
++ITER)
#define LYA_COUNT_T
Type (i.e. size) of the sized array&#39;s size counter.
Definition: ly_array.h:38
#define LYA_COUNT(ARRAY)
Get the number of records in the ARRAY.
Definition: ly_array.h:78

Helper macro to go through sized-arrays with a pointer iterator.

Use with opening curly bracket ({).

Parameters
[in]ARRAYSized array to manipulate.
[out]ITERIterating pointer to the item being processed in each loop.

Definition at line 68 of file ly_array.h.

#define LYA_FREE (   ARRAY)
Value:
if (ARRAY) { \
free((LYA_COUNT_T *)(ARRAY) - 1); \
}
#define LYA_COUNT_T
Type (i.e. size) of the sized array&#39;s size counter.
Definition: ly_array.h:38

Free the space allocated for a sized array.

The items inside the array are not freed.

Parameters
[in,out]ARRAYSized array to manipulate.

Definition at line 199 of file ly_array.h.

#define LYA_INCREMENT (   ARRAY)    ++LYA_COUNT_(ARRAY)

Increment the items counter of a sized array.

Does not change the allocated memory used by the ARRAY. To do so, use LYA_PREALLOC.

Parameters
[in,out]ARRAYSized array to manipulate.

Definition at line 166 of file ly_array.h.

#define LYA_NEW (   ARRAY,
  COUNT,
  EACTION 
)
Value:
LYA_PREALLOC(ARRAY, COUNT, EACTION); \
LYA_COUNT_(ARRAY) = (COUNT)
#define LYA_PREALLOC(ARRAY, COUNT, EACTION)
Allocate memory of a sized array or resize an existing array.
Definition: ly_array.h:97
#define LYA_COUNT_(ARRAY)
Internal macro, do not use.
Definition: ly_array.h:83

Allocate memory of a sized array or resize an existing array.

Updates the size information unlike LYA_PREALLOC.

Any new memory is zeroed.

Parameters
[in,out]ARRAYSized array to manipulate.
[in]COUNTNew count (size) of the items in the array.
[in]EACTIONError action on memory allocation error, must include 'return' or 'goto' commands.

Definition at line 126 of file ly_array.h.

#define LYA_PREALLOC (   ARRAY,
  COUNT,
  EACTION 
)
Value:
{ \
LYA_COUNT_T lya_prealloc_orig = LYA_COUNT(ARRAY); \
LYA_COUNT_T lya_prealloc_count = (COUNT); \
if (lya_prealloc_count < lya_prealloc_orig) { \
lya_prealloc_count = lya_prealloc_orig; \
} \
void *lya_prealloc_mem = realloc((ARRAY) ? (LYA_COUNT_T *)(ARRAY) - 1 : NULL, \
sizeof(LYA_COUNT_T) + lya_prealloc_count * sizeof *(ARRAY)); \
if (!lya_prealloc_mem) { \
EACTION; \
} \
void *lya_prealloc_array = (LYA_COUNT_T *)lya_prealloc_mem + 1; \
memcpy(&(ARRAY), &lya_prealloc_array, sizeof(ARRAY)); \
LYA_COUNT_(ARRAY) = lya_prealloc_orig; \
memset((ARRAY) + lya_prealloc_orig, 0, (lya_prealloc_count - lya_prealloc_orig) * sizeof *(ARRAY)); \
}
#define LYA_COUNT_T
Type (i.e. size) of the sized array&#39;s size counter.
Definition: ly_array.h:38
memset(value->fixed_mem, 0, LYD_VALUE_FIXED_MEM_SIZE)
#define LYA_COUNT(ARRAY)
Get the number of records in the ARRAY.
Definition: ly_array.h:78
if((v1->size!=v2->size)||memcmp(v1->data, v2->data, v1->size))
Definition: binary.c:382
#define LYA_COUNT_(ARRAY)
Internal macro, do not use.
Definition: ly_array.h:83

Allocate memory of a sized array or resize an existing array.

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

Any new memory is zeroed. The array is never shrunk below its current count.

Parameters
[in,out]ARRAYSized array to manipulate.
[in]COUNTNew count (size) of the items in the array.
[in]EACTIONError action on memory allocation error, must include 'return' or 'goto' commands.

Definition at line 97 of file ly_array.h.

#define LYA_PRI_COUNT_T   PRIu64

Printing format specifier macro for LYA_COUNT_T values.

Definition at line 43 of file ly_array.h.

#define LYA_REMOVE_VALUE (   ARRAY,
  VALUE 
)
Value:
{ \
LYA_FOR(ARRAY, u) { \
if ((ARRAY)[u] == VALUE) { \
if (u < LYA_COUNT(ARRAY) - 1) { \
memmove(&((ARRAY)[u]), &((ARRAY)[LYA_COUNT(ARRAY) - 1]), sizeof *(ARRAY)); \
} \
LYA_DECREMENT(ARRAY); \
break; \
} \
} \
}
#define LYA_COUNT_T
Type (i.e. size) of the sized array&#39;s size counter.
Definition: ly_array.h:38
#define LYA_FOR(ARRAY, INDEX)
Helper macro to go through sized-arrays with a numeric iterator.
Definition: ly_array.h:55
#define LYA_COUNT(ARRAY)
Get the number of records in the ARRAY.
Definition: ly_array.h:78
if((v1->size!=v2->size)||memcmp(v1->data, v2->data, v1->size))
Definition: binary.c:382
#define LYA_DECREMENT(ARRAY)
Decrement the items counter of a sized array.
Definition: ly_array.h:176

Remove a specific value from a sized array.

Parameters
[in,out]ARRAYSized array to manipulate.
[in]VALUEValue to remove, only the first occurence is removed.

Definition at line 210 of file ly_array.h.