Main Page | Class List | File List | Class Members | File Members | Related Pages

gi_array.h File Reference

Simple data structure abstraction to provide a growable C-like array. More...

#include "gi_buffer.h"

Go to the source code of this file.

Classes

struct  GiArray

Defines

#define GI_ARRAY_HEAD(array)   gi_buffer_head(&((array)->buf))
#define gi_array_head(array)   GI_ARRAY_HEAD(array)
#define gi_array_length(array)   ((array)->nmemb)
#define GI_ARRAY_FOREACH(foreachfn)   ((GiArrayForeachFn)(foreachfn))

Typedefs

typedef void(* GiArrayForeachFn )(void *data, void *udata)

Functions

EXTERN_C_BEGIN LIBGIFT_EXPORT
void 
gi_array_init (GiArray *array, size_t elemsize)
LIBGIFT_EXPORT void gi_array_finish (GiArray *array)
LIBGIFT_EXPORT GiArraygi_array_new (size_t elemsize)
LIBGIFT_EXPORT void gi_array_free (GiArray *array)
LIBGIFT_EXPORT GiArraygi_array_copy (GiArray *array)
LIBGIFT_EXPORT bool gi_array_index (GiArray *array, void *buf, size_t index)
LIBGIFT_EXPORT bool gi_array_push (GiArray *array, const void *buf)
LIBGIFT_EXPORT bool gi_array_pop (GiArray *array, void *buf)
LIBGIFT_EXPORT bool gi_array_unshift (GiArray *array, const void *buf)
LIBGIFT_EXPORT bool gi_array_shift (GiArray *array, void *buf)
LIBGIFT_EXPORT bool gi_array_splice (GiArray *array, void *removed, size_t offset, size_t length, const void *inserted, size_t nmemb)
LIBGIFT_EXPORT void gi_array_foreach (GiArray *array, GiArrayForeachFn foreachfn, const void *udata)


Detailed Description

Simple data structure abstraction to provide a growable C-like array.


Define Documentation

#define GI_ARRAY_HEAD array   )     gi_buffer_head(&((array)->buf))
 

Accessor macro to simplify receiving a pointer to the first element in the array.


Function Documentation

LIBGIFT_EXPORT GiArray* gi_array_copy GiArray array  ) 
 

Deepy copy the input array. Produces a new dynamically allocated array object with the same element structure.

LIBGIFT_EXPORT void gi_array_finish GiArray array  ) 
 

Destroy any internally allocated array data.

LIBGIFT_EXPORT void gi_array_free GiArray array  ) 
 

Free dynamically allocated array storage (as with gi_array_new) and clean up internal array data (as with gi_array_finish).

LIBGIFT_EXPORT bool gi_array_index GiArray array,
void *  buf,
size_t  index
 

Access an individual array element.

Parameters:
array 
buf Storage location for the array element. Must be at least as large as the initialized element size (see gi_array_init).
index Offset in the array to access. It is safe (that is, non-fatal) to provide an index outside of the current range of the array.
Returns:
If `buf' has been successfully filled, true is returned; otherwise, false.

EXTERN_C_BEGIN LIBGIFT_EXPORT void gi_array_init GiArray array,
size_t  elemsize
 

Initialize a new array object.

LIBGIFT_EXPORT GiArray* gi_array_new size_t  elemsize  ) 
 

Dynamically allocate storage for a new array object and implicitly initialize.

LIBGIFT_EXPORT bool gi_array_pop GiArray array,
void *  buf
 

Remove a single element from the end of the array and store it at `buf'.

LIBGIFT_EXPORT bool gi_array_push GiArray array,
const void *  buf
 

Push a single element to the end of the array. The storage provided by `buf' will be copied into the array object.

LIBGIFT_EXPORT bool gi_array_shift GiArray array,
void *  buf
 

Remove a single element from the beginning of the array. See gi_array_pop for exact semantics of the removal operation.

LIBGIFT_EXPORT bool gi_array_splice GiArray array,
void *  removed,
size_t  offset,
size_t  length,
const void *  inserted,
size_t  nmemb
 

Splice the array. Simply put, the splice operation will remove `length' elements from the position beginning at `offset', storing them in `removed', and insert the `nmemb' elements stored at `inserted' in their place.

It's probably best to lookup `perldoc -f splice' if you wish to see the inspiration for this insane interface.

Parameters:
array 
removed Storage location for the removed elements. If NULL, the removed elements will be discarded.
offset Array index to begin the splice.
length Number of elements to remove following `offset'.
inserted Storage location for the items to be inserted. If NULL ( and `nmemb' is 0), no insertion operation will be performed following the removal.
nmemb Number of elements to insert following `offset'.
Returns:
If all input conditions have been met (successful removal and storage), true is returned; otherwise, false.

LIBGIFT_EXPORT bool gi_array_unshift GiArray array,
const void *  buf
 

Add a single element to the beginning of the array. See gi_array_push for exact semantics of the insert operation.


Generated on Sun Aug 22 07:56:40 2004 by doxygen 1.3.7