Back to index

lightning-sunbird  0.9+nobinonly
Classes | Typedefs | Functions
icalarray.h File Reference

An array of arbitrarily-sized elements which grows dynamically as elements are added. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _icalarray

Typedefs

typedef struct _icalarray

Functions

icalarray * icalarray_new (int element_size, int increment_size)
 Constructor.
void icalarray_free (icalarray *array)
 Destructor.
void icalarray_append (icalarray *array, void *element)
void icalarray_remove_element_at (icalarray *array, int position)
voidicalarray_element_at (icalarray *array, int position)
void icalarray_sort (icalarray *array, int(*compare)(const void *, const void *))

Detailed Description

An array of arbitrarily-sized elements which grows dynamically as elements are added.

Definition in file icalarray.h.


Class Documentation

struct _icalarray

Definition at line 2521 of file ical.h.

Collaboration diagram for _icalarray:
Class Members
void * data
unsigned int element_size
int element_size
unsigned int increment_size
int increment_size
unsigned int num_elements
int num_elements
unsigned int space_allocated
int space_allocated

Typedef Documentation

typedef struct _icalarray

Definition at line 36 of file icalarray.h.


Function Documentation

void icalarray_append ( icalarray *  array,
void element 
)

Definition at line 82 of file icalarray.c.

{
    if (array->num_elements >= array->space_allocated)
       icalarray_expand (array, 1);

    memcpy ((char *)(array->data) + ( array->num_elements * array->element_size ), element,
           array->element_size);
    array->num_elements++;
}

Here is the call graph for this function:

void* icalarray_element_at ( icalarray *  array,
int  position 
)

Definition at line 95 of file icalarray.c.

{
    assert (position >= 0);
    assert (position < array->num_elements);

    return (char *)(array->data) + (position * array->element_size);
}
void icalarray_free ( icalarray *  array)

Destructor.

Definition at line 73 of file icalarray.c.

{
    if (array->data)
       free (array->data);
    free (array);
}
icalarray* icalarray_new ( int  element_size,
int  increment_size 
)

Constructor.

Definition at line 49 of file icalarray.c.

{
    icalarray *array;

    array = (icalarray*) malloc (sizeof (icalarray));
    if (!array) {
       icalerror_set_errno(ICAL_NEWFAILED_ERROR);
       return NULL;
    }

    array->element_size = element_size;
    array->increment_size = increment_size;
    array->num_elements = 0;
    array->space_allocated = 0;
    array->data = NULL;

    return array;
}

Here is the call graph for this function:

void icalarray_remove_element_at ( icalarray *  array,
int  position 
)

Definition at line 106 of file icalarray.c.

{
    void *dest;
    int elements_to_move;

    assert (position >= 0);
    assert (position < array->num_elements);

    dest = (char *)array->data + (position * array->element_size);
    elements_to_move = array->num_elements - position - 1;

    if (elements_to_move > 0)
       memmove (dest, (char *)dest + array->element_size,
               elements_to_move * array->element_size);

    array->num_elements--;
}

Here is the call graph for this function:

void icalarray_sort ( icalarray *  array,
int(*)(const void *, const void *)  compare 
)

Definition at line 127 of file icalarray.c.

{
    qsort (array->data, array->num_elements, array->element_size, compare);
}

Here is the call graph for this function: