Zen API

- Home
- Topics
- Types
- Files

All Classes Files Functions Variables Typedefs Friends Macros Modules Pages
Public Member Functions | Related
kArrayList Class Reference
kApi/Data

## Description

Represents a list implemented with a dynamic array.

The kArrayList class represents a dynamic, array-based list of objects or values. The kArrayList constructor accepts a kType value that determines the type of items that will be stored in the list. The list will automatically grow as new items are added.

kStatus ArrayListExample()
{
kArrayList list = kNULL;
k32s values[] = { 1, 2, 3, 5, 7, 9 };
kSize i;
kTry
{
//create a list that can store 32-bit integers
kTest(kArrayList_Construct(&list, kTypeOf(k32s), 0, kNULL));
//add some initial items to the list
for (i = 0; i < kCountOf(values); ++i)
{
kTest(kArrayList_AddT(list, &values[i]);
}
//print some information about the list and its items
printf("Item type: %s\n", kType_Name(kArrayList_ItemType(list)));
printf("Count: %u\n", (k32u) kArrayList_Count(list));
for (i = 0; i < kArrayList_Count(list); ++i)
{
//get an item from the list
k32s value = kArrayList_AsT(list, i, k32s);
printf("Item %u: %d\n", (k32u)i, value);
}
}
kFinally
{
kObject_Destroy(list);
kEndFinally();
}
return kOK;
}

For lists that contain objects (e.g. kImage) as opposed to values (e.g. k32s), the objects are not automatically destroyed when the list is destroyed. To recursively destroy both the list and the list items, use kObject_Dispose.

kArrayList supports the kObject_Clone, kObject_Dispose, and kObject_Size methods.

kArrayList supports the kdat5 and kdat6 serialization protocols.

Inheritance diagram for kArrayList:

## Public Member Functions
kStatus | kArrayList_Add (kArrayList list, const void *item)
| Adds the specified item to the end of the list. More...
kStatus | kArrayList_AddCount (kArrayList list, kSize count)
| Increases the list count by the specified amount. More...
kStatus | kArrayList_Allocate (kArrayList list, kType itemType, kSize initialCapacity)
| Reallocates the list item buffer. More...
kStatus | kArrayList_Append (kArrayList list, const void *items, kSize count)
| Appends the specified items to the list. More...
kStatus | kArrayList_Assign (kArrayList list, kArrayList source)
| Performs a shallow copy of the source list. More...
void * | kArrayList_At (kArrayList list, kSize index)
| Returns a pointer to the specified item in the list buffer. More...
kStatus | kArrayList_Attach (kArrayList list, void *items, kType itemType, kSize capacity)
| Attaches the list object to an external buffer. More...
void * | kArrayList_Begin (kArrayList list)
| Returns a pointer to the first item for forward iteration. More...
kSize | kArrayList_Capacity (kArrayList list)
| Returns the number of elements for which space has been allocated. More...
kStatus | kArrayList_Clear (kArrayList list)
| Sets the count of list items to zero. More...
kStatus | kArrayList_Construct (kArrayList *list, kType itemType, kSize initialCapacity, kAlloc allocator)
| Constructs a kArrayList object. More...
kSize | kArrayList_Count (kArrayList list)
| Returns the current count of items in the list. More...
void * | kArrayList_Data (kArrayList list)
| Returns a pointer to the list item buffer. More...
void * | kArrayList_DataAt (kArrayList list, kSSize index)
| Calculates an address relative to the start of the buffer. More...
kSize | kArrayList_DataSize (kArrayList list)
| Returns the total size of list data (Count x ItemSize), in bytes. More...
kStatus | kArrayList_Discard (kArrayList list, kSize index)
| Removes an item from the list at the specified index. More...
void * | kArrayList_End (kArrayList list)
| Returns a pointer to one past the last item for forward iteration. More...
void * | kArrayList_First (kArrayList list)
| Returns a pointer to the first item in the list. More...
kStatus | kArrayList_Import (kArrayList list, const void *items, kType itemType, kSize count)
| Copies the specified items into the list, replacing existing contents. More...
kStatus | kArrayList_Insert (kArrayList list, kSize before, const void *item)
| Inserts an item into the list at the specified position. More...
kStatus | kArrayList_Item (kArrayList list, kSize index, void *item)
| Gets the value of an item. More...
kSize | kArrayList_ItemSize (kArrayList list)
| Returns the list element size. More...
kType | kArrayList_ItemType (kArrayList list)
| Returns the list element type. More...
void * | kArrayList_Last (kArrayList list)
| Returns a pointer to the last item in the list. More...
kStatus | kArrayList_Purge (kArrayList list)
| Disposes any elements in the list and sets the count of list items to zero. More...
void * | kArrayList_RBegin (kArrayList list)
| Returns a pointer to the first item for reverse iteration. More...
kStatus | kArrayList_Remove (kArrayList list, kSize index, void *item)
| Removes an item from the list at the specified index, optionally returning the value. More...
kStatus | kArrayList_RemoveCount (kArrayList list, kSize count)
| Decreases the list count by the specified amount. More...
void * | kArrayList_REnd (kArrayList list)
| Returns a pointer to one past the last item for reverse iteration. More...
kStatus | kArrayList_Reserve (kArrayList list, kSize capacity)
| Ensures that capacity is reserved for at least the specified number of list items. More...
kStatus | kArrayList_Resize (kArrayList list, kSize count)
| Sets the current count of list items to the specified value. More...
kStatus | kArrayList_SetItem (kArrayList list, kSize index, const void *item)
| Sets the value of an item. More...
kStatus | kArrayList_Zero (kArrayList list)
| Sets the memory for all list elements to zero. More...
Public Member Functions inherited from kObject
kAlloc | kObject_Alloc (kObject object)
| Gets the memory allocator associated with this object. More...
kStatus | kObject_Clone (kObject *object, kObject source, kAlloc allocator)
| Constructs a new object by copying an existing object, including any aggregated child elements. More...
kStatus | kObject_Destroy (kObject object)
| Destroys the object. More...
kStatus | kObject_Dispose (kObject object)
| Destroys the object and any aggregated child elements. More...
kBool | kObject_Equals (kObject object, kObject other)
| Determines whether the object is equal to another object. More...
kSize | kObject_HashCode (kObject object)
| Gets a hash code representing the state of this object. More...
kBool | kObject_Is (kObject object, kType type)
| Determines whether this object is an instance of the specified type. More...
kBool | kObject_IsShared (kObject object)
| Reports whether the object is currently shared (reference count greater than one). More...
kStatus | kObject_SetPool (kObject object, kObjectPool pool)
| Sets the object pool associated with this object. More...
kStatus | kObject_Share (kObject object)
| Increments the reference count associated with this object. More...
kSize | kObject_Size (kObject object)
| Estimates the memory consumed by this object, including any aggregated child elements. More...
kType | kObject_Type (kObject object)
| Returns the type of the object. More...
Public Member Functions inherited from kCollection
kSize | kCollection_Count (kCollection collection)
| Gets the collection element count. More...
kIterator | kCollection_GetIterator (kCollection collection)
| Returns an iterator to the first element in the collection. More...
kBool | kCollection_HasNext (kCollection collection, kIterator iterator)
| Determines whether a collection has another item. More...
kType | kCollection_ItemType (kCollection collection)
| Gets the collection element type. More...
void * | kCollection_Next (kCollection collection, kIterator *iterator)
| Gets a pointer to the next collection element and then advances the iterator. More...

## Related
#define | kArrayList_AddT(kArrayList_list, TPtr_item)
| Adds the specified item to the end of the list. More...
#define | kArrayList_AppendT(kArrayList_list, TPtr_items, kSize_count)
| Appends the specified items to the list. More...
#define | kArrayList_AsT(kArrayList_list, kSize_index, T)
| Gets the value of an item. More...
#define | kArrayList_AtT(kArrayList_list, kSize_index, T)
| Returns a strongly-typed pointer to the specified item in the list buffer. More...
#define | kArrayList_AttachT(kArrayList_list, TPtr_items, kType_itemType, kSize_capacity)
| Attaches the list object to an external buffer. More...
#define | kArrayList_BeginT(kArrayList_list, T)
| Returns a strongly-typed pointer to the first item for forward iteration. More...
#define | kArrayList_DataAtT(kArrayList_list, kSSize_index, T)
| Returns a strongly-typed pointer address relative to the start of the buffer. More...
#define | kArrayList_DataT(kArrayList_list, T)
| Returns a strongly-typed pointer to the list item buffer. More...
#define | kArrayList_EndT(kArrayList_list, T)
| Returns a strongly-typed pointer to one past the last item for forward iteration. More...
#define | kArrayList_FirstT(kArrayList_list, T)
| Returns a strongly-typed pointer to the first item in the list. More...
#define | kArrayList_ImportT(kArrayList_list, TPtr_items, kType_itemType, kSize_count)
| Copies the specified items into the list, replacing existing contents. More...
#define | kArrayList_InsertT(kArrayList_list, kSize_before, TPtr_item)
| Inserts an item into the list at the specified position. More...
#define | kArrayList_ItemT(kArrayList_list, kSize_index, TPtr_item)
| Gets the value of an item. More...
#define | kArrayList_LastT(kArrayList_list, T)
| Returns a strongly-typed pointer to the last item in the list. More...
#define | kArrayList_RBeginT(kArrayList_list, T)
| Returns a strongly-typed pointer to the first item for reverse iteration. More...
#define | kArrayList_RemoveT(kArrayList_list, kSize_index, TPtr_item)
| Removes an item from the list at the specified index. More...
#define | kArrayList_REndT(kArrayList_list, T)
| Returns a strongly-typed pointer to one past the last item for reverse iteration. More...
#define | kArrayList_SetAsT(kArrayList_list, kSize_index, T_value, T)
| Sets the value of an item. More...
#define | kArrayList_SetItemT(kArrayList_list, kSize_index, TPtr_item)
| Sets the value of an item. More...
Related inherited from kCollection
#define | kCollection_NextT(kCollection_collection, kIteratorPtr_iterator, T)
| Gets a strongly-typd pointer to next collection element and then advances the iterator. More...

## Additional Inherited Members
Protected Member Functions inherited from kObject
kStatus | kObject_FreeMem (kObject object, void *mem)
| Protected method called by derived classes to free memory using the object's allocator. More...
kStatus | kObject_FreeMemRef (kObject object, void *mem)
| Protected method called by derived classes to free memory (and reset the provided memory pointer to kNULL) using the object's allocator. More...
kStatus | kObject_GetMem (kObject object, kSize size, void *mem)
| Protected method called by derived classes to allocate memory using the object's allocator. More...
kStatus | kObject_GetMemZero (kObject object, kSize size, void *mem)
| Protected method called by derived classes to allocate and zero memory using the object's allocator. More...
kStatus | kObject_Init (kObject object, kType type, kAlloc alloc)
| Protected method called by derived classes to initialize the kObject base class. More...
kStatus | kObject_VDisposeItems (kObject object)
| Protected virtual method that destroys any aggregated child objects associated with a collection. More...
kBool | kObject_VEquals (kObject object, kObject other)
| Protected virtual method that compares two objects for equality. More...
kSize | kObject_VHashCode (kObject object)
| Protected virtual method that calculates a hash code representing the object instance. More...
kStatus | kObject_VInitClone (kObject object, kObject source, kAlloc allocator)
| Protected virtual method that clones (makes a deep copy of) the specified source object. More...
kStatus | kObject_VRelease (kObject object)
| Protected virtual method that deallocates any resources owned by the object. More...
kSize | kObject_VSize (kObject object)
| Protected virtual method that calculates the total size (in bytes) of the object instance. More...

The documentation for this class was generated from the following file:

- Data/kArrayList.h