Public Member Functions | Private Attributes | List of all members
Buffer< T > Class Template Reference

#include <Buffer.h>

Public Member Functions

uint32_t available (void)
 
 Buffer (uint32_t size=0x100)
 
void clear (void)
 
get (void)
 
uint32_t getSize ()
 
T * head (void)
 
 operator int (void)
 
Bufferoperator= (T data)
 
uint32_t peek (char c)
 
void put (T data)
 
 ~Buffer ()
 

Private Attributes

T * _buf
 
volatile uint32_t _rloc
 
uint32_t _size
 
volatile uint32_t _wloc
 

Detailed Description

template<typename T>
class Buffer< T >

A templated software ring buffer

Example:

#include "mbed.h"
#include "Buffer.h"
int main()
{
buf = 'a';
buf.put('b');
char *head = buf.head();
puts(head);
char whats_in_there[2] = {0};
int pos = 0;
while(buf.available())
{
whats_in_there[pos++] = buf;
}
printf("%c %c\n", whats_in_there[0], whats_in_there[1]);
buf.clear();
error("done\n\n\n");
}

Definition at line 61 of file Buffer.h.

Constructor & Destructor Documentation

template<class T >
Buffer< T >::Buffer ( uint32_t  size = 0x100)

Create a Buffer and allocate memory for it

Parameters
sizeThe size of the buffer

Definition at line 27 of file Buffer.cpp.

template<class T >
Buffer< T >::~Buffer ( )

Destry a Buffer and release it's allocated memory

Definition at line 37 of file Buffer.cpp.

Member Function Documentation

template<class T >
uint32_t Buffer< T >::available ( void  )
inline

Determine if anything is readable in the buffer

Returns
1 if something can be read, 0 otherwise

Definition at line 157 of file Buffer.h.

template<class T >
void Buffer< T >::clear ( void  )

Reset the buffer to 0. Useful if using head() to parse packeted data

Definition at line 51 of file Buffer.cpp.

template<class T >
T Buffer< T >::get ( void  )
inline

Remove a data element from the buffer

Returns
Pull the oldest element from the buffer

Definition at line 140 of file Buffer.h.

template<class T >
uint32_t Buffer< T >::getSize ( )

Get the size of the ring buffer

Returns
the size of the ring buffer

Definition at line 45 of file Buffer.cpp.

template<class T >
T * Buffer< T >::head ( void  )
inline

Get the address to the head of the buffer

Returns
The address of element 0 in the buffer

Definition at line 149 of file Buffer.h.

template<typename T>
Buffer< T >::operator int ( void  )
inline

Overloaded operator for reading from the buffer

Returns
Pull the oldest element from the buffer

Definition at line 121 of file Buffer.h.

template<typename T>
Buffer& Buffer< T >::operator= ( data)
inline

Overloaded operator for writing to the buffer

Parameters
dataSomething to put in the buffer
Returns

Definition at line 112 of file Buffer.h.

template<class T >
uint32_t Buffer< T >::peek ( char  c)

Definition at line 61 of file Buffer.cpp.

template<class T>
void Buffer< T >::put ( data)
inline

Add a data element into the buffer

Parameters
dataSomething to add to the buffer

Definition at line 131 of file Buffer.h.

Member Data Documentation

template<typename T>
T* Buffer< T >::_buf
private

Definition at line 64 of file Buffer.h.

template<typename T>
volatile uint32_t Buffer< T >::_rloc
private

Definition at line 66 of file Buffer.h.

template<typename T>
uint32_t Buffer< T >::_size
private

Definition at line 67 of file Buffer.h.

template<typename T>
volatile uint32_t Buffer< T >::_wloc
private

Definition at line 65 of file Buffer.h.


The documentation for this class was generated from the following files:


rosserial_mbed
Author(s): Gary Servin
autogenerated on Mon Jun 10 2019 14:53:26