Added support for WNC M14A2A Cellular LTE Data Module.

Dependencies:   WNC14A2AInterface

Dependents:   http-example-wnc http-example-wnc-modified

Embed: (wiki syntax)

« Back to documentation index

MyBuffer< T > Class Template Reference

MyBuffer< T > Class Template Reference

A templated software ring buffer. More...

#include <MyBuffer.h>

Public Member Functions

 MyBuffer (uint32_t size=0x100)
 Create a Buffer and allocate memory for it.
uint32_t getSize ()
 Get the size of the ring buffer.
 ~MyBuffer ()
 Destry a Buffer and release it's allocated memory.
void put (T data)
 Add a data element into the buffer.
get (void)
 Remove a data element from the buffer.
T * head (void)
 Get the address to the head of the buffer.
void clear (void)
 Reset the buffer to 0.
uint32_t available (void)
 Determine if anything is readable in the buffer.
MyBufferoperator= (T data)
 Overloaded operator for writing to the buffer.
 operator int (void)
 Overloaded operator for reading from the buffer.

Detailed Description

template<typename T>
class MyBuffer< T >

A templated software ring buffer.

Example:

  #include "mbed.h"
  #include "MyBuffer.h"

  MyBuffer <char>  buf;

  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 MyBuffer.h.


Constructor & Destructor Documentation

MyBuffer ( uint32_t  size = 0x100 )

Create a Buffer and allocate memory for it.

Parameters:
sizeThe size of the buffer

Definition at line 27 of file MyBuffer.cpp.

~MyBuffer (  )

Destry a Buffer and release it's allocated memory.

Definition at line 37 of file MyBuffer.cpp.


Member Function Documentation

uint32_t available ( void   )

Determine if anything is readable in the buffer.

Returns:
1 if something can be read, 0 otherwise

Definition at line 157 of file MyBuffer.h.

void clear ( void   )

Reset the buffer to 0.

Useful if using head() to parse packeted data

Definition at line 51 of file MyBuffer.cpp.

T get ( void   )

Remove a data element from the buffer.

Returns:
Pull the oldest element from the buffer

Definition at line 140 of file MyBuffer.h.

uint32_t getSize (  )

Get the size of the ring buffer.

Returns:
the size of the ring buffer

Definition at line 45 of file MyBuffer.cpp.

T * head ( void   )

Get the address to the head of the buffer.

Returns:
The address of element 0 in the buffer

Definition at line 149 of file MyBuffer.h.

operator int ( void   )

Overloaded operator for reading from the buffer.

Returns:
Pull the oldest element from the buffer

Definition at line 121 of file MyBuffer.h.

MyBuffer& operator= ( data )

Overloaded operator for writing to the buffer.

Parameters:
dataSomething to put in the buffer
Returns:

Definition at line 112 of file MyBuffer.h.

void put ( data )

Add a data element into the buffer.

Parameters:
dataSomething to add to the buffer

Definition at line 131 of file MyBuffer.h.