Zen API

- Home
- Topics
- Types
- Files

All Classes Files Functions Variables Typedefs Friends Macros Modules Pages
kArrayList.h
Go to the documentation of this file.
1
10 #ifndef K_API_ARRAY_LIST_H
11 #define K_API_ARRAY_LIST_H
12
13 #include <kApi/kApiDef.h>
14 #include <kApi/Data/kArrayList.x.h>
15
77 //typedef kObject kArrayList; --forward-declared in kApiDef.x.h
78
89 kFx(kStatus) kArrayList_Construct(kArrayList* list, kType itemType, kSize initialCapacity, kAlloc allocator);
90
100 kFx(kStatus) kArrayList_Allocate(kArrayList list, kType itemType, kSize initialCapacity);
101
114 kFx(kStatus) kArrayList_Attach(kArrayList list, void* items, kType itemType, kSize capacity);
115
131 #define kArrayList_AttachT(kArrayList_list, TPtr_items, kType_itemType, kSize_capacity) \
132 xkArrayList_AttachT(kArrayList_list, TPtr_items, kType_itemType, kSize_capacity, sizeof(*TPtr_items))
133
146 kFx(kStatus) kArrayList_Import(kArrayList list, const void* items, kType itemType, kSize count);
147
163 #define kArrayList_ImportT(kArrayList_list, TPtr_items, kType_itemType, kSize_count) \
164 xkArrayList_ImportT(kArrayList_list, TPtr_items, kType_itemType, kSize_count, sizeof(*TPtr_items))
165
175 kFx(kStatus) kArrayList_Append(kArrayList list, const void* items, kSize count);
176
189 #define kArrayList_AppendT(kArrayList_list, TPtr_items, kSize_count) \
190 xkArrayList_AppendT(kArrayList_list, TPtr_items, kSize_count, sizeof(*TPtr_items))
191
203 kFx(kStatus) kArrayList_Assign(kArrayList list, kArrayList source);
204
212 kInlineFx(kStatus) kArrayList_Clear(kArrayList list)
213 {
214 kObj(kArrayList, list);
215
216 obj->count = 0;
217
218 return kOK;
219 }
220
228 kFx(kStatus) kArrayList_Purge(kArrayList list);
229
237 kFx(kStatus) kArrayList_Zero(kArrayList list);
238
247 kFx(kStatus) kArrayList_Add(kArrayList list, const void* item);
248
260 #define kArrayList_AddT(kArrayList_list, TPtr_item) \
261 xkArrayList_AddT(kArrayList_list, TPtr_item, sizeof(*TPtr_item))
262
274 kFx(kStatus) kArrayList_Insert(kArrayList list, kSize before, const void* item);
275
290 #define kArrayList_InsertT(kArrayList_list, kSize_before, TPtr_item) \
291 xkArrayList_InsertT(kArrayList_list, kSize_before, TPtr_item, sizeof(*TPtr_item))
292
302 kFx(kStatus) kArrayList_Remove(kArrayList list, kSize index, void* item);
303
316 #define kArrayList_RemoveT(kArrayList_list, kSize_index, TPtr_item) \
317 xkArrayList_RemoveT(kArrayList_list, kSize_index, TPtr_item, sizeof(*TPtr_item))
318
330 kInlineFx(kStatus) kArrayList_Discard(kArrayList list, kSize index)
331 {
332 return kArrayList_Remove(list, index, kNULL);
333 }
334
344 kFx(kStatus) kArrayList_SetItem(kArrayList list, kSize index, const void* item);
345
358 #define kArrayList_SetItemT(kArrayList_list, kSize_index, TPtr_item) \
359 xkArrayList_SetItemT(kArrayList_list, kSize_index, TPtr_item, sizeof(*TPtr_item))
360
370 kFx(kStatus) kArrayList_Item(kArrayList list, kSize index, void* item);
371
384 #define kArrayList_ItemT(kArrayList_list, kSize_index, TPtr_item) \
385 xkArrayList_ItemT(kArrayList_list, kSize_index, TPtr_item, sizeof(*TPtr_item))
386
401 #define kArrayList_SetAsT(kArrayList_list, kSize_index, T_value, T) \
402 (kPointer_WriteAs(xkArrayList_AsT(kArrayList_list, kSize_index, sizeof(T)), T_value, T), (void)0)
403
417 #define kArrayList_AsT(kArrayList_list, kSize_index, T) \
418 kPointer_ReadAs(xkArrayList_AsT(kArrayList_list, kSize_index, sizeof(T)), T)
419
430 kFx(kStatus) kArrayList_Resize(kArrayList list, kSize count);
431
443 kInlineFx(kStatus) kArrayList_AddCount(kArrayList list, kSize count)
444 {
445 kObj(kArrayList, list);
446
447 if ((obj->count + count) > obj->capacity)
448 {
449 kCheck(kArrayList_Reserve(list, obj->count + count));
450 }
451
452 obj->count += count;
453
454 return kOK;
455 }
456
465 kInlineFx(kStatus) kArrayList_RemoveCount(kArrayList list, kSize count)
466 {
467 kObj(kArrayList, list);
468
469 if (count > obj->count)
470 {
471 return kERROR_STATE;
472 }
473
474 obj->count -= count;
475
476 return kOK;
477 }
478
489 kFx(kStatus) kArrayList_Reserve(kArrayList list, kSize capacity);
490
498 kInlineFx(void*) kArrayList_Data(kArrayList list)
499 {
500 kObj(kArrayList, list);
501
502 return obj->items;
503 }
504
516 #define kArrayList_DataT(kArrayList_list, T) \
517 kCast(T*, xkArrayList_DataT(kArrayList_list, sizeof(T)))
518
529 kInlineFx(void*) kArrayList_DataAt(kArrayList list, kSSize index)
530 {
531 kObj(kArrayList, list);
532
533 return kPointer_ItemOffset(obj->items, index, obj->itemSize);
534 }
535
548 #define kArrayList_DataAtT(kArrayList_list, kSSize_index, T) \
549 kCast(T*, xkArrayList_DataAtT(kArrayList_list, kSSize_index, sizeof(T)))
550
558 kInlineFx(kSize) kArrayList_DataSize(kArrayList list)
559 {
560 kObj(kArrayList, list);
561
562 return obj->count * obj->itemSize;
563 }
564
576 kInlineFx(void*) kArrayList_At(kArrayList list, kSize index)
577 {
578 # if !defined(K_FSS_912_DISABLE_BOUNDS_CHECK)
579 {
580 kAssert(index < kArrayList_Count(list));
581 }
582 # endif
583
584 return kArrayList_DataAt(list, (kSSize)index);
585 }
586
600 #define kArrayList_AtT(kArrayList_list, kSize_index, T) \
601 kCast(T*, xkArrayList_AtT(kArrayList_list, kSize_index, sizeof(T)))
602
610 kInlineFx(kType) kArrayList_ItemType(kArrayList list)
611 {
612 kObj(kArrayList, list);
613
614 return obj->itemType;
615 }
616
624 kInlineFx(kSize) kArrayList_ItemSize(kArrayList list)
625 {
626 kObj(kArrayList, list);
627
628 return obj->itemSize;
629 }
630
638 kInlineFx(kSize) kArrayList_Count(kArrayList list)
639 {
640 kObj(kArrayList, list);
641
642 return obj->count;
643 }
644
652 kInlineFx(kSize) kArrayList_Capacity(kArrayList list)
653 {
654 kObj(kArrayList, list);
655
656 return obj->capacity;
657 }
658
666 kInlineFx(void*) kArrayList_First(kArrayList list)
667 {
668 return kArrayList_Begin(list);
669 }
670
682 #define kArrayList_FirstT(kArrayList_list, T) \
683 kCast(T*, xkArrayList_FirstT(kArrayList_list, sizeof(T)))
684
692 kInlineFx(void*) kArrayList_Last(kArrayList list)
693 {
694 return kArrayList_RBegin(list);
695 }
696
708 #define kArrayList_LastT(kArrayList_list, T) \
709 kCast(T*, xkArrayList_LastT(kArrayList_list, sizeof(T)))
710
718 kInlineFx(void*) kArrayList_Begin(kArrayList list)
719 {
720 kObj(kArrayList, list);
721
722 return obj->items;
723 }
724
736 #define kArrayList_BeginT(kArrayList_list, T) \
737 kCast(T*, xkArrayList_BeginT(kArrayList_list, sizeof(T)))
738
746 kInlineFx(void*) kArrayList_End(kArrayList list)
747 {
748 kObj(kArrayList, list);
749
750 return kPointer_ItemOffset(obj->items, (kSSize)obj->count, obj->itemSize);
751 }
752
764 #define kArrayList_EndT(kArrayList_list, T) \
765 kCast(T*, xkArrayList_EndT(kArrayList_list, sizeof(T)))
766
774 kInlineFx(void*) kArrayList_RBegin(kArrayList list)
775 {
776 kObj(kArrayList, list);
777
778 return kPointer_ItemOffset(obj->items, (kSSize)obj->count-1, obj->itemSize);
779 }
780
792 #define kArrayList_RBeginT(kArrayList_list, T) \
793 kCast(T*, xkArrayList_RBeginT(kArrayList_list, sizeof(T)))
794
802 kInlineFx(void*) kArrayList_REnd(kArrayList list)
803 {
804 kObj(kArrayList, list);
805
806 return kPointer_ItemOffset(obj->items, (kSSize)-1, obj->itemSize);
807 }
808
820 #define kArrayList_REndT(kArrayList_list, T) \
821 kCast(T*, xkArrayList_REndT(kArrayList_list, sizeof(T)))
822
823 #endif
kArrayList::kArrayList_Resize
kStatus kArrayList_Resize(kArrayList list, kSize count)
Sets the current count of list items to the specified value.
kArrayList::kArrayList_Insert
kStatus kArrayList_Insert(kArrayList list, kSize before, const void *item)
Inserts an item into the list at the specified position.
kArrayList::kArrayList_DataSize
kSize kArrayList_DataSize(kArrayList list)
Returns the total size of list data (Count x ItemSize), in bytes.
Definition: kArrayList.h:558
kArrayList::kArrayList_Attach
kStatus kArrayList_Attach(kArrayList list, void *items, kType itemType, kSize capacity)
Attaches the list object to an external buffer.
kArrayList::kArrayList_Purge
kStatus kArrayList_Purge(kArrayList list)
Disposes any elements in the list and sets the count of list items to zero.
kArrayList::kArrayList_Append
kStatus kArrayList_Append(kArrayList list, const void *items, kSize count)
Appends the specified items to the list.
kArrayList::kArrayList_Data
void * kArrayList_Data(kArrayList list)
Returns a pointer to the list item buffer.
Definition: kArrayList.h:498
kArrayList::kArrayList_Add
kStatus kArrayList_Add(kArrayList list, const void *item)
Adds the specified item to the end of the list.
kArrayList::kArrayList_Reserve
kStatus kArrayList_Reserve(kArrayList list, kSize capacity)
Ensures that capacity is reserved for at least the specified number of list items.
kSize
Represents an unsigned integer that can store a pointer address.
kAlloc
Abstract base class for memory allocator types.
kArrayList::kArrayList_Remove
kStatus kArrayList_Remove(kArrayList list, kSize index, void *item)
Removes an item from the list at the specified index, optionally returning the value.
kArrayList::kArrayList_ItemType
kType kArrayList_ItemType(kArrayList list)
Returns the list element type.
Definition: kArrayList.h:610
kPointer::kPointer_ItemOffset
void * kPointer_ItemOffset(const void *pointer, kSSize itemIndex, kSize itemSize)
Gets a pointer to the Nth element of an array.
Definition: kApiDef.h:292
kCheck
#define kCheck(EXPRESSION)
Executes a return statement if the given expression is not kOK.
Definition: kApiDef.h:559
kArrayList::kArrayList_SetItem
kStatus kArrayList_SetItem(kArrayList list, kSize index, const void *item)
Sets the value of an item.
kArrayList::kArrayList_Begin
void * kArrayList_Begin(kArrayList list)
Returns a pointer to the first item for forward iteration.
Definition: kArrayList.h:718
kArrayList::kArrayList_Last
void * kArrayList_Last(kArrayList list)
Returns a pointer to the last item in the list.
Definition: kArrayList.h:692
kInlineFx
#define kInlineFx(TYPE)
Inline method declaration helper.
Definition: kApiDef.h:26
kSSize
Represents a signed integer that can store a pointer address.
kArrayList::kArrayList_Allocate
kStatus kArrayList_Allocate(kArrayList list, kType itemType, kSize initialCapacity)
Reallocates the list item buffer.
kArrayList::kArrayList_RBegin
void * kArrayList_RBegin(kArrayList list)
Returns a pointer to the first item for reverse iteration.
Definition: kArrayList.h:774
kArrayList::kArrayList_Construct
kStatus kArrayList_Construct(kArrayList *list, kType itemType, kSize initialCapacity, kAlloc allocator)
Constructs a kArrayList object.
kObj
#define kObj(TypeName_T, T_object)
Declares a local "obj" (this-pointer) variable and initializes it from a type-checked object handle...
Definition: kApiDef.h:2892
kArrayList::kArrayList_Capacity
kSize kArrayList_Capacity(kArrayList list)
Returns the number of elements for which space has been allocated.
Definition: kArrayList.h:652
kArrayList::kArrayList_ItemSize
kSize kArrayList_ItemSize(kArrayList list)
Returns the list element size.
Definition: kArrayList.h:624
kApiDef.h
Core Zen type declarations.
kArrayList::kArrayList_AddCount
kStatus kArrayList_AddCount(kArrayList list, kSize count)
Increases the list count by the specified amount.
Definition: kArrayList.h:443
kArrayList::kArrayList_Count
kSize kArrayList_Count(kArrayList list)
Returns the current count of items in the list.
Definition: kArrayList.h:638
kArrayList::kArrayList_REnd
void * kArrayList_REnd(kArrayList list)
Returns a pointer to one past the last item for reverse iteration.
Definition: kArrayList.h:802
kStatus::kERROR_STATE
#define kERROR_STATE
Invalid state.
Definition: kApiDef.h:488
kArrayList::kArrayList_Clear
kStatus kArrayList_Clear(kArrayList list)
Sets the count of list items to zero.
Definition: kArrayList.h:212
kArrayList::kArrayList_Item
kStatus kArrayList_Item(kArrayList list, kSize index, void *item)
Gets the value of an item.
kArrayList::kArrayList_Discard
kStatus kArrayList_Discard(kArrayList list, kSize index)
Removes an item from the list at the specified index.
Definition: kArrayList.h:330
kType
Represents metadata about a type (class, interface, or value).
kArrayList::kArrayList_Zero
kStatus kArrayList_Zero(kArrayList list)
Sets the memory for all list elements to zero.
kArrayList
Represents a list implemented with a dynamic array.
kAssert
#define kAssert(EXPRESSION)
Aborts execution if EXPRESSION is kFALSE.
Definition: kApiDef.h:749
kArrayList::kArrayList_Assign
kStatus kArrayList_Assign(kArrayList list, kArrayList source)
Performs a shallow copy of the source list.
kStatus::kOK
#define kOK
Operation successful.
Definition: kApiDef.h:513
kStatus
Represents an error code.
kArrayList::kArrayList_First
void * kArrayList_First(kArrayList list)
Returns a pointer to the first item in the list.
Definition: kArrayList.h:666
kNULL
#define kNULL
Null pointer.
Definition: kApiDef.h:267
kArrayList::kArrayList_DataAt
void * kArrayList_DataAt(kArrayList list, kSSize index)
Calculates an address relative to the start of the buffer.
Definition: kArrayList.h:529
kArrayList::kArrayList_Import
kStatus kArrayList_Import(kArrayList list, const void *items, kType itemType, kSize count)
Copies the specified items into the list, replacing existing contents.
kArrayList::kArrayList_End
void * kArrayList_End(kArrayList list)
Returns a pointer to one past the last item for forward iteration.
Definition: kArrayList.h:746
kArrayList::kArrayList_RemoveCount
kStatus kArrayList_RemoveCount(kArrayList list, kSize count)
Decreases the list count by the specified amount.
Definition: kArrayList.h:465
kArrayList::kArrayList_At
void * kArrayList_At(kArrayList list, kSize index)
Returns a pointer to the specified item in the list buffer.
Definition: kArrayList.h:576