libdacav 0.9.0
Circular buffers

This module provides a trivial implementation of fixed size circular buffers. More...

Typedefs

typedef struct dcirc dcirc_t
 Opaque type for circular buffer.

Enumerations

enum  dcirc_result_t { DCIRC_SUCCESS = 0, DCIRC_EMPTY = 1 }
 Return value for the getter function. More...

Functions

dcirc_tdcirc_new (size_t size, const dcprm_t *cprm)
 Constructor for a circular buffer.
dcirc_result_t dcirc_get (dcirc_t *cb, void **item)
 Getter for the oldest item.
void dcirc_put (dcirc_t *cb, const void *item)
 Insert an item, possibly overwriting the oldest stored item.
void dcirc_flush (dcirc_t *cb)
 Flush the circular buffer.
void dcirc_free (dcirc_t *cb)
 Destructor for a circular buffer.

Detailed Description

This module provides a trivial implementation of fixed size circular buffers.


Typedef Documentation

typedef struct dcirc dcirc_t

Opaque type for circular buffer.


Enumeration Type Documentation

Return value for the getter function.

See also:
dcirc_get.
Enumerator:
DCIRC_SUCCESS 

Object retrieved.

DCIRC_EMPTY 

Empty circular buffer.


Function Documentation

void dcirc_flush ( dcirc_t cb)

Flush the circular buffer.

All internal items are removed according to the given remotion semantics.

Parameters:
[in]cbThe circular buffer to be freed.
void dcirc_free ( dcirc_t cb)

Destructor for a circular buffer.

The buffer is automatically flushed before getting freed.

Parameters:
[in]cbThe circular buffer to destroy.
dcirc_result_t dcirc_get ( dcirc_t cb,
void **  item 
)

Getter for the oldest item.

The oldest item (if any) gets removed from the circualr buffer, and its ownership gets trasferred to the caller.

Parameters:
[in]cbThe circular buffer;
[out]itemThe retrieved item.
Warning:
This function yields the internal copy of the item: freeing it is up to you.
Return values:
dcirc_result_t::DCIRC_SUCCESSon success;
dcirc_result_t::DCIRC_EMPTYif nothing is stored into the buffer.
dcirc_t* dcirc_new ( size_t  size,
const dcprm_t cprm 
)

Constructor for a circular buffer.

Parameters:
[in]sizeThe number of consecutive elements stored into the circular buffer;
[in]cprmThe copy-constructor/destructor pair for items. You may provide NULL in order to avoid a copying semantics.
See also:
dcprm_t.
Returns:
A pointer to the allocated circular buffer
void dcirc_put ( dcirc_t cb,
const void *  item 
)

Insert an item, possibly overwriting the oldest stored item.

The inserted item gets copied through the provided copy semantics. The overwritten item, if any, gets freed through the provided remotion semantics.

Parameters:
[in]cbThe circular buffer;
[in]itemThe item to be inserted.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator