kzc_dynamic_array.hpp File Reference

Automatically growing array of arbitrary data. More...

Classes

struct  KzcDynamicArray
 Structure of a DynamicArray. More...
 
struct  KzcDynamicArrayIterator
 Read-only iterator for dynamic array. More...
 
struct  KzcDynamicArrayMutableIterator
 Mutable iterator for dynamic array. More...
 

Macros

#define kzcDynamicArrayIterate(iterator_param)
 Finds the next entry in the attached dynamic array. More...
 
#define kzcDynamicArrayMutableIterate(iterator_param)
 Finds the next entry in the iterated dynamic array. More...
 
#define kzcDynamicArrayMutableIteratorRemove(iterator_param)
 Removes the entry pointed by the iterator from the dynamic array. More...
 

Functions

KANZI_API kzsError kzcDynamicArrayCreate (const struct KzcMemoryManager *memoryManager, struct KzcDynamicArray **out_dynamicArray)
 Creates a new initially empty dynamic array with initial capacity of 10. More...
 
KANZI_API kzsError kzcDynamicArrayCreateWithCapacity (const struct KzcMemoryManager *memoryManager, kzUint capacity, struct KzcDynamicArray **out_dynamicArray)
 Creates a new initially empty dynamic array. More...
 
KANZI_API kzsError kzcDynamicArrayDelete (struct KzcDynamicArray *dynamicArray)
 Frees the memory allocated for the dynamic array. More...
 
KANZI_API kzsError kzcDynamicArrayCopy (const struct KzcMemoryManager *memoryManager, const struct KzcDynamicArray *original, struct KzcDynamicArray **out_copy)
 Creates a copy of a dynamic array. More...
 
KANZI_API void kzcDynamicArrayClear (struct KzcDynamicArray *dynamicArray)
 Removes all the elements from the dynamic array. More...
 
KANZI_API kzsError kzcDynamicArrayRemoveByIndex (struct KzcDynamicArray *dynamicArray, const kzUint index)
 Removes the index'th element from the dynamic array. More...
 
KANZI_API void kzcDynamicArraySort (const struct KzcDynamicArray *dynamicArray, KzcComparatorFunction comparator)
 Sorts the given dynamic array according to the given comparator function. More...
 
KANZI_API void kzcDynamicArraySortWithContext (const struct KzcDynamicArray *dynamicArray, KzcComparatorWithContextFunction comparator, const void *context)
 Sorts the given dynamic array according to the given comparator function. More...
 
KANZI_API void kzcDynamicArraySwap (const struct KzcDynamicArray *dynamicArray, kzUint indexA, kzUint indexB)
 Swaps places of two elements of a dynamic array with each other. More...
 
KANZI_API void kzcDynamicArrayReverse (const struct KzcDynamicArray *dynamicArray)
 Reverses the order of a dynamic array. More...
 
KANZI_API kzUint kzcDynamicArrayGetSize (const struct KzcDynamicArray *dynamicArray)
 Returns the number of elements in the dynamic array. More...
 
KANZI_API kzBool kzcDynamicArrayIsEmpty (const struct KzcDynamicArray *dynamicArray)
 Checks if the dynamic array is empty or not. More...
 
KANZI_API struct KzcDynamicArrayIterator kzcDynamicArrayGetIterator (const struct KzcDynamicArray *dynamicArray)
 Returns an iterator for the dynamic array. More...
 
KANZI_API struct KzcDynamicArrayMutableIterator kzcDynamicArrayGetMutableIterator (struct KzcDynamicArray *dynamicArray)
 Returns a mutable iterator for the dynamic array. More...
 
KZ_INLINE kzBool kzcDynamicArrayIterate_private (struct KzcDynamicArrayIterator *iterator)
 
KZ_INLINE kzBool kzcDynamicArrayMutableIterate_private (struct KzcDynamicArrayMutableIterator *iterator)
 
KANZI_API kzsError kzcDynamicArrayMutableIteratorRemove_private (struct KzcDynamicArrayMutableIterator *iterator)
 
void * kzcDynamicArrayPointerGet (const struct KzcDynamicArray *dynamicArray, kzUint index)
 Retrieves an element from the pointer dynamic array from the given index. More...
 

Variables

KANZI_API const struct KzcDynamicArrayIterator KZC_DYNAMIC_ARRAY_EMPTY_ITERATOR
 Dynamic array iterator that can be used for an empty iteration result e.g. More...
 

Detailed Description

Automatically growing array of arbitrary data.

The data type of the elements is determined when the first element is added with kzcDynamicArrayPointerAdd(), kzcDynamicArrayIntAdd(), kzcDynamicArrayUintAdd(), kzcDynamicArrayFloatAdd() or kzcDynamicArrayStringAdd(). It is the caller's responsibility to use accessor functions of the right type.

Copyright 2008-2017 by Rightware. All rights reserved.

Macro Definition Documentation

#define kzcDynamicArrayIterate (   iterator_param)

Finds the next entry in the attached dynamic array.

Returns
KZ_TRUE if the next entry is found, otherwise KZ_FALSE.
#define kzcDynamicArrayMutableIterate (   iterator_param)

Finds the next entry in the iterated dynamic array.

Returns
KZ_TRUE if the next entry is found, otherwise KZ_FALSE.
#define kzcDynamicArrayMutableIteratorRemove (   iterator_param)

Removes the entry pointed by the iterator from the dynamic array.

Function Documentation

KANZI_API kzsError kzcDynamicArrayCreate ( const struct KzcMemoryManager memoryManager,
struct KzcDynamicArray **  out_dynamicArray 
)

Creates a new initially empty dynamic array with initial capacity of 10.

Parameters
memoryManagerThe memory manager to use.
out_dynamicArrayA pointer that is set to point to the new dynamic array on success.
Returns
KZS_SUCCESS on success.
KANZI_API kzsError kzcDynamicArrayCreateWithCapacity ( const struct KzcMemoryManager memoryManager,
kzUint  capacity,
struct KzcDynamicArray **  out_dynamicArray 
)

Creates a new initially empty dynamic array.

Initial capacity is given as a parameter.

Parameters
memoryManagerThe memory manager to use.
capacityThe initial capacity of the array. I.e. the number of elements that can be added to the array before more memory needs to be allocated.
out_dynamicArrayA pointer that is set to point to the new dynamic array on success.
Returns
KZS_SUCCESS on success.
KANZI_API kzsError kzcDynamicArrayDelete ( struct KzcDynamicArray dynamicArray)

Frees the memory allocated for the dynamic array.

Returns
KZS_SUCCESS on success.
KANZI_API kzsError kzcDynamicArrayCopy ( const struct KzcMemoryManager memoryManager,
const struct KzcDynamicArray original,
struct KzcDynamicArray **  out_copy 
)

Creates a copy of a dynamic array.

Parameters
memoryManagerThe memory manager to use for allocating the copy.
originalA valid dynamic array.
out_copyA pointer that is set to point to the copy on success.
Returns
KZS_SUCCESS on success.
KANZI_API void kzcDynamicArrayClear ( struct KzcDynamicArray dynamicArray)

Removes all the elements from the dynamic array.

KANZI_API kzsError kzcDynamicArrayRemoveByIndex ( struct KzcDynamicArray dynamicArray,
const kzUint  index 
)

Removes the index'th element from the dynamic array.

Parameters
dynamicArrayA valid dynamic array.
indexThe index of the element.
Returns
KZS_ERROR_ARRAY_OUT_OF_BOUNDS if the index is out of bounds, KZS_SUCCESS on success.
KANZI_API void kzcDynamicArraySort ( const struct KzcDynamicArray dynamicArray,
KzcComparatorFunction  comparator 
)

Sorts the given dynamic array according to the given comparator function.

Parameters
dynamicArrayA valid dynamic array.
comparatorThe comparator function to use for sorting.
KANZI_API void kzcDynamicArraySortWithContext ( const struct KzcDynamicArray dynamicArray,
KzcComparatorWithContextFunction  comparator,
const void *  context 
)

Sorts the given dynamic array according to the given comparator function.

The given arbitrary context is passed to the comparator.

Parameters
dynamicArrayA valid dynamic array.
comparatorThe comparator function to use for sorting.
contextAn arbitrary pointer passed to the comparator function.
KANZI_API void kzcDynamicArraySwap ( const struct KzcDynamicArray dynamicArray,
kzUint  indexA,
kzUint  indexB 
)

Swaps places of two elements of a dynamic array with each other.

Parameters
dynamicArrayA valid dynamic array.
indexAIndex of the first element.
indexBIndex of the second element.
KANZI_API void kzcDynamicArrayReverse ( const struct KzcDynamicArray dynamicArray)

Reverses the order of a dynamic array.

Parameters
dynamicArrayA valid dynamic array.
kzUint kzcDynamicArrayGetSize ( const struct KzcDynamicArray dynamicArray)
inline

Returns the number of elements in the dynamic array.

Parameters
dynamicArrayA valid dynamic array.
Returns
The number of elements in the dynamic array.
kzBool kzcDynamicArrayIsEmpty ( const struct KzcDynamicArray dynamicArray)
inline

Checks if the dynamic array is empty or not.

Parameters
dynamicArrayA valid dynamic array.
Returns
KZ_TRUE if the dynamic array is empty, otherwise KZ_FALSE.
struct KzcDynamicArrayIterator kzcDynamicArrayGetIterator ( const struct KzcDynamicArray dynamicArray)

Returns an iterator for the dynamic array.

Parameters
dynamicArrayA valid dynamic array.
struct KzcDynamicArrayMutableIterator kzcDynamicArrayGetMutableIterator ( struct KzcDynamicArray dynamicArray)

Returns a mutable iterator for the dynamic array.

Parameters
dynamicArrayA valid dynamic array.
KZ_INLINE kzBool kzcDynamicArrayIterate_private ( struct KzcDynamicArrayIterator iterator)
KZ_INLINE kzBool kzcDynamicArrayMutableIterate_private ( struct KzcDynamicArrayMutableIterator iterator)
KANZI_API kzsError kzcDynamicArrayMutableIteratorRemove_private ( struct KzcDynamicArrayMutableIterator iterator)
void* kzcDynamicArrayPointerGet ( const struct KzcDynamicArray dynamicArray,
kzUint  index 
)
inline

Retrieves an element from the pointer dynamic array from the given index.

The index must not be out of bounds.

Variable Documentation

KANZI_API const struct KzcDynamicArrayIterator KZC_DYNAMIC_ARRAY_EMPTY_ITERATOR

Dynamic array iterator that can be used for an empty iteration result e.g.

when an actual empty dynamic array doesn't exist.