Commit c08fa1c2 authored by Pierre d'Herbemont's avatar Pierre d'Herbemont

include/vlc_arrays.h: Export a static inlined array API.

parent c1012538
...@@ -117,6 +117,7 @@ ...@@ -117,6 +117,7 @@
} \ } \
} while(0) } while(0)
#define TAB_REMOVE( count, tab, p ) \ #define TAB_REMOVE( count, tab, p ) \
do { \ do { \
int _i_index_; \ int _i_index_; \
...@@ -278,6 +279,74 @@ ...@@ -278,6 +279,74 @@
#define FOREACH_END() } } #define FOREACH_END() } }
/************************************************************************
* Dynamic arrays with progressive allocation (Prefered API)
************************************************************************/
typedef struct vlc_array_t
{
int i_count;
void ** pp_elems;
} vlc_array_t;
static inline void vlc_array_init( vlc_array_t * p_array )
{
memset( p_array, 0, sizeof(vlc_array_t) );
}
static inline void vlc_array_clear( vlc_array_t * p_array )
{
free( p_array->pp_elems );
memset( p_array, 0, sizeof(vlc_array_t) );
}
/* Read */
static inline int
vlc_array_count( vlc_array_t * p_array )
{
return p_array->i_count;
}
static inline void *
vlc_array_object_at_index( vlc_array_t * p_array, int i_index )
{
return p_array->pp_elems[i_index];
}
/* Write */
static inline void
vlc_array_insert( vlc_array_t * p_array, void * p_elem, int i_index )
{
TAB_INSERT( p_array->i_count, p_array->pp_elems, p_elem, i_index );
}
static inline void
vlc_array_append( vlc_array_t * p_array, void * p_elem )
{
vlc_array_insert( p_array, p_elem, p_array->i_count );
}
static inline void
vlc_array_remove( vlc_array_t * p_array, int i_index )
{
if( i_index >= 0 )
{
if( p_array->i_count > 1 )
{
memmove( p_array->pp_elems + i_index,
p_array->pp_elems + i_index+1,
( p_array->i_count - i_index - 1 ) * sizeof( void* ) );
}
p_array->i_count--;
if( p_array->i_count == 0 )
{
free( p_array->pp_elems );
p_array->pp_elems = NULL;
}
}
}
/************************************************************************ /************************************************************************
* Dictionaries * Dictionaries
************************************************************************/ ************************************************************************/
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment