Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals   Examples  

cyclic_buffer.h File Reference

Go to the source code of this file.

Data Structures

struct  s_cyclic_buffer
 Basic structure that defines the cyclic buffer. More...


Typedefs

typedef s_cyclic_buffercyclic_buffer

Functions

cyclic_buffer create_cyclic_buffer (unsigned long size)
 Create a new cyclic buffer.

void destroy_cyclic_buffer (cyclic_buffer buffer)
 Destroy a cyclic buffer (free all allocated memory).

void * cyclic_buffer_add_element (cyclic_buffer buffer, void *element, unsigned element_size)
 Add a new element to the cyclic buffer.

void rewind_cyclic_buffer (cyclic_buffer buffer)
 Reset the current buffer's pointer (used to extract element from the buffer).

void * cyclic_buffer_get_element (cyclic_buffer buffer)
 Returns the current element of the cyclic buffer.

unsigned long cyclic_buffer_get_start (cyclic_buffer buffer)
 Return the index of the first element in the buffer.

unsigned long cyclic_buffer_get_stop (cyclic_buffer buffer)
 Return the index of the last element in the buffer.

unsigned long cyclic_buffer_get_current_size (cyclic_buffer buffer)
 Return the number of elements in the cyclic buffer.


Detailed Description

Header file for cyclic_buffer.c

Definition in file cyclic_buffer.h.


Function Documentation

cyclic_buffer create_cyclic_buffer unsigned long    size
 

Create a new cyclic buffer.

Parameters:
size Maximum number of elements of the buffer.
Returns:
The function return a handle on the newly vreated cyclic buffer, or NULL if an error occured (out of memory).
Warning:
The function create_cyclic_buffer() allocates memory (using malloc()). Therefore, when you don't need the buffer anymore, you should destry it using destroy_cyclic_buffer().

Definition at line 15 of file cyclic_buffer.c.

References s_cyclic_buffer::buffer, s_cyclic_buffer::current, s_cyclic_buffer::current_size, s_cyclic_buffer::n, s_cyclic_buffer::size, s_cyclic_buffer::start, and s_cyclic_buffer::stop.

void* cyclic_buffer_add_element cyclic_buffer    buffer,
void *    element,
unsigned    element_size
 

Add a new element to the cyclic buffer.

Parameters:
buffer Handle to the cyclic buffer that will be used to receive the new element.
element Pointer to the element to add to the cyclic buffer.
element_size Size (in bytes) of the element to add.
Returns:
If succees, the function returns a pointer to the element in the cyclic buffer. Otherwise, if an error occured, the function returns NULL.
Warning:
Please note that the element is copied into the cyclic buffer. This implies that memory is allocated.

Definition at line 87 of file cyclic_buffer.c.

References s_cyclic_buffer::buffer, s_cyclic_buffer::current_size, s_cyclic_buffer::size, s_cyclic_buffer::start, and s_cyclic_buffer::stop.

unsigned long cyclic_buffer_get_current_size cyclic_buffer    buffer
 

Return the number of elements in the cyclic buffer.

Parameters:
buffer Handle to the cyclic buffer.
Returns:
The function returns the number of elements in the cyclic buffer.

Definition at line 201 of file cyclic_buffer.c.

References s_cyclic_buffer::current_size.

void* cyclic_buffer_get_element cyclic_buffer    buffer
 

Returns the current element of the cyclic buffer.

Parameters:
buffer Handle to the cyclic buffer.
Returns:
The function returns a pointer to the current buffer's element, or NULL if the buffer's pointer reached the end of the buffer.
Warning:
Before calling get_element(), you should call rewind_cyclic_buffer() first.

Definition at line 157 of file cyclic_buffer.c.

References s_cyclic_buffer::buffer, s_cyclic_buffer::current, s_cyclic_buffer::current_size, s_cyclic_buffer::n, and s_cyclic_buffer::size.

unsigned long cyclic_buffer_get_start cyclic_buffer    buffer
 

Return the index of the first element in the buffer.

Parameters:
buffer Handle to the cyclic buffer.
Returns:
The function returns the index of the first element in the buffer.

Definition at line 179 of file cyclic_buffer.c.

References s_cyclic_buffer::start.

unsigned long cyclic_buffer_get_stop cyclic_buffer    buffer
 

Return the index of the last element in the buffer.

Parameters:
buffer Handle to the cyclic buffer.
Returns:
The function returns the index of the last element in the buffer.

Definition at line 190 of file cyclic_buffer.c.

References s_cyclic_buffer::stop.

void destroy_cyclic_buffer cyclic_buffer    buffer
 

Destroy a cyclic buffer (free all allocated memory).

Parameters:
buffer Handle to the cyclic buffer to destroy.

Definition at line 57 of file cyclic_buffer.c.

References s_cyclic_buffer::buffer, and s_cyclic_buffer::size.

void rewind_cyclic_buffer cyclic_buffer    buffer
 

Reset the current buffer's pointer (used to extract element from the buffer).

Parameters:
buffer Handle to the cyclic buffer.

Definition at line 140 of file cyclic_buffer.c.

References s_cyclic_buffer::current, s_cyclic_buffer::n, and s_cyclic_buffer::start.


Generated on Thu Apr 3 16:23:45 2003 for Common_C_libraries by doxygen1.3-rc1