QVisu
Qt-based visualization for smart homes
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
vlc_arrays.h File Reference

Go to the source code of this file.

Classes

struct  vlc_array_t
 
struct  vlc_dictionary_entry_t
 
struct  vlc_dictionary_t
 

Macros

#define INSERT_ELEM(p_ar, i_oldsize, i_pos, elem)
 
#define REMOVE_ELEM(p_ar, i_size, i_pos)
 
#define TAB_INIT(count, tab)
 
#define TAB_CLEAN(count, tab)
 
#define TAB_APPEND_CAST(cast, count, tab, p)
 
#define TAB_APPEND(count, tab, p)   TAB_APPEND_CAST( , count, tab, p )
 
#define TAB_FIND(count, tab, p, idx)
 
#define TAB_REMOVE(count, tab, p)
 
#define TAB_INSERT_CAST(cast, count, tab, p, index)
 
#define TAB_INSERT(count, tab, p, index)   TAB_INSERT_CAST( , count, tab, p, index )
 
#define BSEARCH(entries, count, elem, zetype, key, answer)
 
#define _ARRAY_ALLOC(array, newsize)
 
#define _ARRAY_GROW1(array)
 
#define ARRAY_SIZE(x)   (sizeof(x) / sizeof((x)[0]))
 
#define DECL_ARRAY(type)
 
#define TYPEDEF_ARRAY(type, name)   typedef DECL_ARRAY(type) name;
 
#define ARRAY_INIT(array)
 
#define ARRAY_RESET(array)
 
#define ARRAY_APPEND(array, elem)
 
#define ARRAY_INSERT(array, elem, pos)
 
#define _ARRAY_SHRINK(array)
 
#define ARRAY_REMOVE(array, pos)
 
#define ARRAY_VAL(array, pos)   array.p_elems[pos]
 
#define ARRAY_BSEARCH(array, elem, zetype, key, answer)   BSEARCH( (array).p_elems, (array).i_size, elem, zetype, key, answer)
 
#define FOREACH_ARRAY(item, array)
 
#define FOREACH_END()   } }
 

Typedefs

typedef struct vlc_array_t vlc_array_t
 
typedef struct
vlc_dictionary_entry_t 
vlc_dictionary_entry_t
 
typedef struct vlc_dictionary_t vlc_dictionary_t
 

Detailed Description

This file defines functions, structures and macros for handling arrays in vlc

Macro Definition Documentation

#define _ARRAY_ALLOC (   array,
  newsize 
)
Value:
{ \
(array).i_alloc = newsize; \
(array).p_elems = realloc( (array).p_elems, (array).i_alloc * \
sizeof(*(array).p_elems) ); \
if( !(array).p_elems ) abort(); \
}
#define _ARRAY_GROW1 (   array)
Value:
{ \
if( (array).i_alloc < 10 ) \
_ARRAY_ALLOC(array, 10 ) \
else if( (array).i_alloc == (array).i_size ) \
_ARRAY_ALLOC(array, (int)(array.i_alloc * 1.5) ) \
}
#define _ARRAY_SHRINK (   array)
Value:
{ \
if( (array).i_size > 10 && (array).i_size < (int)((array).i_alloc / 1.5) ) { \
_ARRAY_ALLOC(array, (array).i_size + 5); \
} \
}
#define ARRAY_APPEND (   array,
  elem 
)
Value:
do { \
_ARRAY_GROW1(array); \
(array).p_elems[(array).i_size] = elem; \
(array).i_size++; \
} while(0)
#define ARRAY_INIT (   array)
Value:
do { \
(array).i_alloc = 0; \
(array).i_size = 0; \
(array).p_elems = NULL; \
} while(0)
#define ARRAY_INSERT (   array,
  elem,
  pos 
)
Value:
do { \
_ARRAY_GROW1(array); \
if( (array).i_size - pos ) { \
memmove( (array).p_elems + pos + 1, (array).p_elems + pos, \
((array).i_size-pos) * sizeof(*(array).p_elems) ); \
} \
(array).p_elems[pos] = elem; \
(array).i_size++; \
} while(0)
#define ARRAY_REMOVE (   array,
  pos 
)
Value:
do { \
if( (array).i_size - (pos) - 1 ) \
{ \
memmove( (array).p_elems + pos, (array).p_elems + pos + 1, \
( (array).i_size - pos - 1 ) *sizeof(*(array).p_elems) ); \
} \
(array).i_size--; \
_ARRAY_SHRINK(array); \
} while(0)
#define ARRAY_RESET (   array)
Value:
do { \
(array).i_alloc = 0; \
(array).i_size = 0; \
free( (array).p_elems ); (array).p_elems = NULL; \
} while(0)
#define BSEARCH (   entries,
  count,
  elem,
  zetype,
  key,
  answer 
)
Value:
do { \
int low = 0, high = count - 1; \
answer = -1; \
while( low <= high ) {\
int mid = (low + high ) / 2; /* Just don't care about 2^30 tables */ \
zetype mid_val = entries[mid] elem;\
if( mid_val < key ) \
low = mid + 1; \
else if ( mid_val > key ) \
high = mid -1; \
else \
{ \
answer = mid; break; \
}\
} \
} while(0)

Binary search in a sorted array. The key must be comparable by < and >

Parameters
entriesarray of entries
countnumber of entries
elemkey to check within an entry (like .id, or ->i_id)
zetypetype of the key
keyvalue of the key
answerindex of answer within the array. -1 if not found
#define DECL_ARRAY (   type)
Value:
struct { \
int i_alloc; \
int i_size; \
type *p_elems; \
}
#define FOREACH_ARRAY (   item,
  array 
)
Value:
{ \
int fe_idx; \
for( fe_idx = 0 ; fe_idx < (array).i_size ; fe_idx++ ) \
{ \
item = (array).p_elems[fe_idx];
#define INSERT_ELEM (   p_ar,
  i_oldsize,
  i_pos,
  elem 
)
Value:
do \
{ \
if( !(i_oldsize) ) (p_ar) = NULL; \
(p_ar) = realloc( p_ar, ((i_oldsize) + 1) * sizeof(*(p_ar)) ); \
if( !(p_ar) ) abort(); \
if( (i_oldsize) - (i_pos) ) \
{ \
memmove( (p_ar) + (i_pos) + 1, (p_ar) + (i_pos), \
((i_oldsize) - (i_pos)) * sizeof( *(p_ar) ) ); \
} \
(p_ar)[(i_pos)] = elem; \
(i_oldsize)++; \
} \
while( 0 )

Simple dynamic array handling. Array is realloced at each insert/removal

#define REMOVE_ELEM (   p_ar,
  i_size,
  i_pos 
)
Value:
do \
{ \
if( (i_size) - (i_pos) - 1 ) \
{ \
memmove( (p_ar) + (i_pos), \
(p_ar) + (i_pos) + 1, \
((i_size) - (i_pos) - 1) * sizeof( *(p_ar) ) ); \
} \
if( i_size > 1 ) \
(p_ar) = realloc_down( p_ar, ((i_size) - 1) * sizeof( *(p_ar) ) );\
else \
{ \
free( p_ar ); \
(p_ar) = NULL; \
} \
(i_size)--; \
} \
while( 0 )
#define TAB_APPEND_CAST (   cast,
  count,
  tab,
 
)
Value:
do { \
if( (count) > 0 ) \
(tab) = cast realloc( tab, sizeof( void ** ) * ( (count) + 1 ) ); \
else \
(tab) = cast malloc( sizeof( void ** ) ); \
if( !(tab) ) abort(); \
(tab)[count] = (p); \
(count)++; \
} while(0)
#define TAB_CLEAN (   count,
  tab 
)
Value:
do { \
free( tab ); \
(count)= 0; \
(tab)= NULL; \
} while(0)
#define TAB_FIND (   count,
  tab,
  p,
  idx 
)
Value:
do { \
for( (idx) = 0; (idx) < (count); (idx)++ ) \
if( (tab)[(idx)] == (p) ) \
break; \
if( (idx) >= (count) ) \
(idx) = -1; \
} while(0)
#define TAB_INIT (   count,
  tab 
)
Value:
do { \
(count) = 0; \
(tab) = NULL; \
} while(0)
#define TAB_INSERT_CAST (   cast,
  count,
  tab,
  p,
  index 
)
Value:
do { \
if( (count) > 0 ) \
(tab) = cast realloc( tab, sizeof( void ** ) * ( (count) + 1 ) ); \
else \
(tab) = cast malloc( sizeof( void ** ) ); \
if( !(tab) ) abort(); \
if( (count) - (index) > 0 ) \
memmove( (void**)(tab) + (index) + 1, \
(void**)(tab) + (index), \
((count) - (index)) * sizeof(*(tab)) );\
(tab)[(index)] = (p); \
(count)++; \
} while(0)
#define TAB_REMOVE (   count,
  tab,
 
)
Value:
do { \
int i_index; \
TAB_FIND( count, tab, p, i_index ); \
if( i_index >= 0 ) \
{ \
if( (count) > 1 ) \
{ \
memmove( ((void**)(tab) + i_index), \
((void**)(tab) + i_index+1), \
( (count) - i_index - 1 ) * sizeof( void* ) );\
} \
(count)--; \
if( (count) == 0 ) \
{ \
free( tab ); \
(tab) = NULL; \
} \
} \
} while(0)