Array implementation of CIQueue interface.
More...
#include <CCArrayQueue.h>
|
struct CObject | cobject |
|
struct CIQueue | ciqueue |
|
struct { |
size_t size |
|
size_t max_size |
|
size_t element_size |
|
size_t head |
|
size_t tail |
|
unsigned char is_static |
|
unsigned char * queueBase |
|
} | _ |
|
struct CInterface | interface |
|
Implements the struct CIQueue interface using an array as the underlying data structure. This is a copy by value queue. Below is an example of creating a new queue of size three to hold chars, then, adding an element and peeking at the added element. Note, error checking should be done, but is ommitted in this example.
char test = 'h'
char test_peek;
if( test_peek == 'h' ) {
printf("success!");
}
CDestroy(&queue);
- Attention
- All functions inherited from the CIQueue interface can be called using the CCArrayQueue::cIQueue as their first argument.
- Class Constructor
- See also
-
Constructor for class struct CCArrayQueue. This method uses CMalloc defined in Class.h to allocate space for the queue. Calling the destructor, CDestructor( ), will free this memory with the free method, CFree, defined in Class.h.
- Parameters
-
self | The instance of struct CCArrayQueue to construct. |
element_size | The size of an element in the queue in bytes. |
queue_size | The maximum number of elements which can be put in the queue. |
- Returns
- CIQUEUE_OK on successful construction.
CError CCArrayQueueStatic |
( |
struct CCArrayQueue * |
self, |
|
|
void * |
memory, |
|
|
size_t |
element_size, |
|
|
size_t |
queue_size |
|
) |
| |
- Class Constructor
Constructor for class struct CCArrayQueue. Allows application code to define memory region to use for the queue's array back end.
- Parameters
-
self | The instance of struct CCArrayQueue to construct. |
memory | A pointer to memory to use for the queue. The memory pointed to must be at least element_size * queue_size bytes long. |
element_size | The size of an element in the queue in bytes. |
queue_size | The maximum number of elements which can be put in the queue. |
- Returns
- CIQUEUE_OK on successful construction.
Get the number of elements currently in the queue. This is an unreliable method and should only be used for logging purposes.
- Parameters
-
- Returns
- Number of elements currently in the queue.
void CIQueue_Clear |
( |
struct CIQueue * |
self | ) |
|
|
inherited |
Reset the queue to having zero elements in it. All data copied into the queue is lost.
- Parameters
-
Insert an element into the tail of the queue by copy.
- Parameters
-
self | The queue. |
element | Pointer to data to copy into queue. |
- Returns
- Error code.
size_t CIQueue_MaxSize |
( |
struct CIQueue * |
self | ) |
|
|
inherited |
Get the maximum number of elements allowed in the queue.
- Parameters
-
- Returns
- The maximum number of elements allowed in the queue.
Peek at the element in the head of the queue by copy. This does not remove the head.
- Parameters
-
self | The queue. |
element | Data in the head of the queue will be copied to the location pointed to by this. |
- Returns
- An error code.
Remove an element from the head of the queue by copy.
- Parameters
-
self | The queue |
element | Data in the head of the queue will be copied into the location pointed to by this. Pass in NULL to remove the the head of the queue without copying out the data. |
- Returns
- An error code.
size_t CIQueue_Size |
( |
struct CIQueue * |
self | ) |
|
|
inherited |
Get the number of elements currently in the queue.
- Parameters
-
- Returns
- Number of elements currently in the queue.
The documentation for this struct was generated from the following file: