CObject
CCArrayQueue Struct Reference

Array implementation of CIQueue interface. More...

#include <CCArrayQueue.h>

+ Inheritance diagram for CCArrayQueue:

Public Member Functions

const struct CCArrayQueue_VTableCCArrayQueue_GetVTable ()
 
CError CCArrayQueue (struct CCArrayQueue *self, size_t element_size, size_t queue_size)
 
CError CCArrayQueueStatic (struct CCArrayQueue *self, void *memory, size_t element_size, size_t queue_size)
 
size_t CCThreadedQueue_Size (struct CCThreadedQueue *self)
 
CIQueueError CIQueue_Insert (struct CIQueue *self, const void *element)
 
CIQueueError CIQueue_Remove (struct CIQueue *self, void *element)
 
CIQueueError CIQueue_Peek (struct CIQueue *self, void *element)
 
size_t CIQueue_Size (struct CIQueue *self)
 
size_t CIQueue_MaxSize (struct CIQueue *self)
 
void CIQueue_Clear (struct CIQueue *self)
 

Data Fields

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
 

Detailed Description

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.

struct CCArrayQueue queue;
CCArrayQueue(&queue, sizeof(char), 3);
char test = 'h'
CIQueue_Insert(&queue.cIQueue, &test);
char test_peek;
CIQueue_Peek(&queue.cIQueue, &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.

Constructor & Destructor Documentation

CError CCArrayQueue ( struct CCArrayQueue self,
size_t  element_size,
size_t  queue_size 
)
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
selfThe instance of struct CCArrayQueue to construct.
element_sizeThe size of an element in the queue in bytes.
queue_sizeThe maximum number of elements which can be put in the queue.
Returns
CIQUEUE_OK on successful construction.

Member Function Documentation

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
selfThe instance of struct CCArrayQueue to construct.
memoryA pointer to memory to use for the queue. The memory pointed to must be at least element_size * queue_size bytes long.
element_sizeThe size of an element in the queue in bytes.
queue_sizeThe maximum number of elements which can be put in the queue.
Returns
CIQUEUE_OK on successful construction.
size_t CCThreadedQueue_Size ( struct CCThreadedQueue self)
inherited

Get the number of elements currently in the queue. This is an unreliable method and should only be used for logging purposes.

Parameters
selfThe queue.
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
selfThe queue.
CIQueueError CIQueue_Insert ( struct CIQueue self,
const void *  element 
)
inherited

Insert an element into the tail of the queue by copy.

Parameters
selfThe queue.
elementPointer 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
selfThe queue.
Returns
The maximum number of elements allowed in the queue.
CIQueueError CIQueue_Peek ( struct CIQueue self,
void *  element 
)
inherited

Peek at the element in the head of the queue by copy. This does not remove the head.

Parameters
selfThe queue.
elementData in the head of the queue will be copied to the location pointed to by this.
Returns
An error code.
CIQueueError CIQueue_Remove ( struct CIQueue self,
void *  element 
)
inherited

Remove an element from the head of the queue by copy.

Parameters
selfThe queue
elementData 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
selfThe queue.
Returns
Number of elements currently in the queue.

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