Zen API
 All Classes Files Functions Variables Typedefs Friends Macros Modules Pages
kList Class Reference

Description

Represents a doubly-linked list.

The kList class represents a doubly-linked list of objects or values. The kList 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 or inserted.

kStatus ListExample()
{
kList list = kNULL;
k32s values[] = { 1, 2, 3, 5, 7, 9 };
kSize i;
kListItem it = kNULL; //list iterator
{
//create a list that can store 32-bit integers
kTest(kList_Construct(&list, kTypeOf(k32s), 0, kNULL));
//add some initial items to the list
for (i = 0; i < kCountOf(values); ++i)
{
kTest(kList_AddT(list, &values[i], kNULL);
}
//print some information about the list and its items
printf("Item type: %s\n", kType_Name(kList_ItemType(list)));
printf("Count: %u\n", (k32u) kList_Count(list));
it = kList_First(list);
while (!kIsNull(it))
{
//get an item from the list
k32s value = kList_AsT(list, it, k32s);
it = kList_Next(list, it);
}
}
{
}
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.

kList supports the kObject_Clone, kObject_Dispose, and kObject_Size methods.

kList supports the kdat6 serialization protocol.

Inheritance diagram for kList:
Inheritance graph

Public Member Functions

kStatus kList_Add (kList list, const void *itemContent, kListItem *item)
 Adds a new item to the end of the list. More...
 
kStatus kList_Allocate (kList list, kType itemType, kSize initialCapacity)
 Reallocates the list. More...
 
kStatus kList_Assign (kList list, kList source)
 Performs a shallow copy of the source list. More...
 
void * kList_At (kList list, kListItem item)
 Returns a pointer to the content associated with a list item. More...
 
void * kList_AtIndex (kList list, kSize index)
 Returns a pointer to the content associated with a list item at the specified index. More...
 
kSize kList_Capacity (kList list)
 Returns the number of elements for which space has been allocated. More...
 
kStatus kList_Clear (kList list)
 Sets the count of list items to zero. More...
 
kStatus kList_Construct (kList *list, kType itemType, kSize initialCapacity, kAlloc allocator)
 Constructs a kList object. More...
 
kSize kList_Count (kList list)
 Returns the count of list elements. More...
 
kListItem kList_FindIndex (kList list, kSize index)
 Finds a reference to the list item at the specified index. More...
 
kListItem kList_First (kList list)
 Gets a reference to the first list item. More...
 
kStatus kList_Insert (kList list, kListItem before, const void *itemContent, kListItem *item)
 Inserts an item into the list before the specified list item. More...
 
kStatus kList_Item (kList list, kListItem item, void *content)
 Gets the content associated with a list item. More...
 
kType kList_ItemType (kList list)
 Returns the item type. More...
 
kListItem kList_Last (kList list)
 Gets a reference to the last list item. More...
 
kListItem kList_Next (kList list, kListItem item)
 Given a list item, gets a reference to the next list item. More...
 
kListItem kList_Previous (kList list, kListItem item)
 Given a list item, gets a reference to the previous list item. More...
 
kStatus kList_Purge (kList list)
 Disposes any elements in the list and sets the count of list items to zero. More...
 
kStatus kList_Remove (kList list, kListItem item)
 Removes the specified item from the list. More...
 
kStatus kList_Reserve (kList list, kSize capacity)
 Ensures that capacity is reserved for at least the specified number of list items. More...
 
kStatus kList_SetItem (kList list, kListItem item, const void *content)
 Sets the content associated with a list item. 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...
 
kBool kObject_HasForeignData (kObject object)
 Reports whether the object, including aggregated child elements, contains any foreign memory references. 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 kList_AddT(kList_list, TPtr_itemContent, kListItemPtr_item)
 Adds a new item to the end of the list. More...
 
#define kList_AsT(kList_list, kListItem_item, T)
 Gets the content associated with a list item. More...
 
#define kList_AtIndexT(kList_list, kSize_index, T)
 Returns a strongly-typed pointer to the content associated with a list item at the specified index. More...
 
#define kList_AtT(kList_list, kListItem_item, T)
 Returns a strongly-typed pointer to the content associated with a list item. More...
 
#define kList_InsertT(kList_list, kListItem_before, TPtr_itemContent, kListItemPtr_item)
 Inserts an item into the list before the specified list item. More...
 
#define kList_ItemT(kList_list, kListItem_item, TPtr_content)
 Gets the content associated with a list item. More...
 
#define kList_SetAsT(kList_list, kListItem_item, T_value, T)
 Sets the content associated with a list item. More...
 
#define kList_SetItemT(kList_list, kListItem_item, TPtr_content)
 Sets the content associated with a list item. More...
 
kPointer kListItem
 Represents a node within a kList object.
 

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...
 
kBool kObject_VHasForeignData (kObject object)
 Protected virtual method that reports whether the object, including aggregated child elements, contains any foreign memory references. 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: