Zen API

- Home
- Topics
- Types
- Files

All Classes Files Functions Variables Typedefs Friends Macros Modules Pages
kQueue.h
Go to the documentation of this file.
1
10 #ifndef K_API_QUEUE_H
11 #define K_API_QUEUE_H
12
13 #include <kApi/kApiDef.h>
14 #include <kApi/Data/kQueue.x.h>
15
78 //typedef kObject kQueue; --forward-declared in kApiDef.x.h
79
90 kFx(kStatus) kQueue_Construct(kQueue* queue, kType itemType, kSize initialCapacity, kAlloc allocator);
91
101 kFx(kStatus) kQueue_Allocate(kQueue queue, kType itemType, kSize initialCapacity);
102
114 kFx(kStatus) kQueue_Assign(kQueue queue, kQueue source);
115
123 kInlineFx(kStatus) kQueue_Clear(kQueue queue)
124 {
125 kObj(kQueue, queue);
126
127 obj->count = 0;
128 obj->head = 0;
129
130 return kOK;
131 }
132
140 kFx(kStatus) kQueue_Purge(kQueue queue);
141
152 kFx(kStatus) kQueue_Reserve(kQueue queue, kSize capacity);
153
162 kFx(kStatus) kQueue_Add(kQueue queue, const void* item);
163
175 #define kQueue_AddT(kQueue_queue, TPtr_item) \
176 xkQueue_AddT(kQueue_queue, TPtr_item, sizeof(*TPtr_item))
177
186 kFx(kStatus) kQueue_Remove(kQueue queue, void* item);
187
197 kFx(kStatus) kQueue_SetItem(kQueue queue, kSize index, const void* item);
198
211 #define kQueue_SetItemT(kQueue_queue, kSize_index, TPtr_item) \
212 xkQueue_SetItemT(kQueue_queue, kSize_index, TPtr_item, sizeof(*TPtr_item))
213
223 kFx(kStatus) kQueue_Item(kQueue queue, kSize index, void* item);
224
237 #define kQueue_ItemT(kQueue_queue, kSize_index, TPtr_item) \
238 xkQueue_ItemT(kQueue_queue, kSize_index, TPtr_item, sizeof(*TPtr_item))
239
253 #define kQueue_SetAsT(kQueue_queue, kSize_index, T_value, T) \
254 (kPointer_WriteAs(xkQueue_AsT(kQueue_queue, kSize_index, sizeof(T)), T_value, T), (void)0)
255
268 #define kQueue_AsT(kQueue_queue, kSize_index, T) \
269 kPointer_ReadAs(xkQueue_AsT(kQueue_queue, kSize_index, sizeof(T)), T)
270
282 kInlineFx(kStatus) kQueue_AddCount(kQueue queue, kSize count)
283 {
284 kObj(kQueue, queue);
285
286 if ((obj->count + count) > obj->capacity)
287 {
288 kCheck(kQueue_Reserve(queue, obj->count + count));
289 }
290
291 obj->count += count;
292
293 return kOK;
294 }
295
304 kInlineFx(kStatus) kQueue_RemoveCount(kQueue queue, kSize count)
305 {
306 kObj(kQueue, queue);
307
308 if (count > obj->count)
309 {
310 return kERROR_STATE;
311 }
312
313 obj->count -= count;
314 obj->head += count;
315
316 if (obj->head >= obj->capacity)
317 {
318 obj->head -= obj->capacity;
319 }
320
321 return kOK;
322 }
323
334 kInlineFx(void*) kQueue_DataAt(kQueue queue, kSize index)
335 {
336 kObj(kQueue, queue);
337
338 if ((obj->head + index) >= obj->capacity)
339 {
340 return kPointer_ItemOffset(obj->items, (kSSize)(obj->head + index - obj->capacity), obj->itemSize);
341 }
342 else
343 {
344 return kPointer_ItemOffset(obj->items, (kSSize)(obj->head + index), obj->itemSize);
345 }
346 }
347
362 #define kQueue_DataAtT(kQueue_queue, kSize_index, T) \
363 kCast(T*, xkQueue_DataAtT(kQueue_queue, kSize_index, sizeof(T)))
364
376 kInlineFx(void*) kQueue_At(kQueue queue, kSize index)
377 {
378 # if !defined(K_FSS_912_DISABLE_BOUNDS_CHECK)
379 {
380 kAssert(index < kQueue_Count(queue));
381 }
382 # endif
383
384 return kQueue_DataAt(queue, index);
385 }
386
400 #define kQueue_AtT(kQueue_queue, kSize_index, T) \
401 kCast(T*, xkQueue_AtT(kQueue_queue, kSize_index, sizeof(T)))
402
410 kInlineFx(kType) kQueue_ItemType(kQueue queue)
411 {
412 kObj(kQueue, queue);
413
414 return obj->itemType;
415 }
416
424 kInlineFx(kSize) kQueue_ItemSize(kQueue queue)
425 {
426 kObj(kQueue, queue);
427
428 return obj->itemSize;
429 }
430
438 kInlineFx(kSize) kQueue_Count(kQueue queue)
439 {
440 kObj(kQueue, queue);
441
442 return obj->count;
443 }
444
452 kInlineFx(kSize) kQueue_Capacity(kQueue queue)
453 {
454 kObj(kQueue, queue);
455
456 return obj->capacity;
457 }
458
459 #endif
kQueue::kQueue_Remove
kStatus kQueue_Remove(kQueue queue, void *item)
Removes the item at the head of the queue.
kQueue::kQueue_SetItem
kStatus kQueue_SetItem(kQueue queue, kSize index, const void *item)
Sets the value of an item.
kQueue::kQueue_DataAt
void * kQueue_DataAt(kQueue queue, kSize index)
Calculates an element address.
Definition: kQueue.h:334
kQueue::kQueue_ItemSize
kSize kQueue_ItemSize(kQueue queue)
Returns the queue element size.
Definition: kQueue.h:424
kSize
Represents an unsigned integer that can store a pointer address.
kAlloc
Abstract base class for memory allocator types.
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
kInlineFx
#define kInlineFx(TYPE)
Inline method declaration helper.
Definition: kApiDef.h:26
kQueue::kQueue_Reserve
kStatus kQueue_Reserve(kQueue queue, kSize capacity)
Ensures that capacity is reserved for at least the specified number of queue items.
kSSize
Represents a signed integer that can store a pointer address.
kQueue::kQueue_RemoveCount
kStatus kQueue_RemoveCount(kQueue queue, kSize count)
Decreases the queue count by the specified amount.
Definition: kQueue.h:304
kQueue::kQueue_Construct
kStatus kQueue_Construct(kQueue *queue, kType itemType, kSize initialCapacity, kAlloc allocator)
Constructs a kQueue object.
kQueue::kQueue_ItemType
kType kQueue_ItemType(kQueue queue)
Returns the queue element type.
Definition: kQueue.h:410
kQueue::kQueue_Allocate
kStatus kQueue_Allocate(kQueue queue, kType itemType, kSize initialCapacity)
Reallocates the queue item buffer.
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
kQueue::kQueue_Item
kStatus kQueue_Item(kQueue queue, kSize index, void *item)
Gets the value of an item.
kQueue::kQueue_Assign
kStatus kQueue_Assign(kQueue queue, kQueue source)
Performs a shallow copy of the source queue.
kApiDef.h
Core Zen type declarations.
kMsgQueue
Represents a synchronized FIFO queue with an optional maximum content size and/or item capacity...
kStatus::kERROR_STATE
#define kERROR_STATE
Invalid state.
Definition: kApiDef.h:488
kQueue::kQueue_Count
kSize kQueue_Count(kQueue queue)
Returns the current count of items in the queue.
Definition: kQueue.h:438
kType
Represents metadata about a type (class, interface, or value).
kQueue
Represents a FIFO queue implemented with a dynamic array.
kAssert
#define kAssert(EXPRESSION)
Aborts execution if EXPRESSION is kFALSE.
Definition: kApiDef.h:749
kStatus::kOK
#define kOK
Operation successful.
Definition: kApiDef.h:513
kStatus
Represents an error code.
kQueue::kQueue_At
void * kQueue_At(kQueue queue, kSize index)
Returns a pointer to the specified item in the queue buffer.
Definition: kQueue.h:376
kQueue::kQueue_Add
kStatus kQueue_Add(kQueue queue, const void *item)
Adds the specified item to the end of the queue.
kQueue::kQueue_Capacity
kSize kQueue_Capacity(kQueue queue)
Returns the number of elements for which space has been allocated.
Definition: kQueue.h:452
kQueue::kQueue_Purge
kStatus kQueue_Purge(kQueue queue)
Disposes any elements in the queue and sets the count of queue items to zero.
kQueue::kQueue_Clear
kStatus kQueue_Clear(kQueue queue)
Sets the count of queue items to zero.
Definition: kQueue.h:123
kQueue::kQueue_AddCount
kStatus kQueue_AddCount(kQueue queue, kSize count)
Increases the queue count by the specified amount.
Definition: kQueue.h:282