gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
CircleBuf< T > Class Template Reference

Circular buffer backed by a vector. More...

#include <circlebuf.hh>

Public Types

typedef T value_type
 

Public Member Functions

 CircleBuf (size_t size)
 
bool empty () const
 Is the buffer empty? More...
 
size_t capacity () const
 Return the maximum number of elements that can be stored in the buffer at any one time. More...
 
size_t size () const
 Return the number of elements stored in the buffer. More...
 
void flush ()
 Remove all the elements in the buffer. More...
 
template<class OutputIterator >
void peek (OutputIterator out, size_t len) const
 Copy buffer contents without advancing the read pointer. More...
 
template<class OutputIterator >
void peek (OutputIterator out, off_t offset, size_t len) const
 Copy buffer contents without advancing the read pointer. More...
 
template<class OutputIterator >
void read (OutputIterator out, size_t len)
 Copy buffer contents and advance the read pointer. More...
 
template<class InputIterator >
void write (InputIterator in, size_t len)
 Add elements to the end of the ring buffers and advance. More...
 

Protected Member Functions

void normalize ()
 Normalize the start and stop pointers to ensure that pointer invariants hold after updates. More...
 

Protected Attributes

std::vector< value_typebuf
 
size_t _start
 
size_t _stop
 

Detailed Description

template<typename T>
class CircleBuf< T >

Circular buffer backed by a vector.

The data in the cricular buffer is stored in a standard vector. _start designates the first element in the buffer and _stop points to the last element + 1 (i.e., the position of the next insertion). The _stop index may be outside the range of the backing store, which means that the actual index must be calculated as _stop % capacity.

Invariants:

Definition at line 68 of file circlebuf.hh.

Member Typedef Documentation

template<typename T>
typedef T CircleBuf< T >::value_type

Definition at line 71 of file circlebuf.hh.

Constructor & Destructor Documentation

template<typename T>
CircleBuf< T >::CircleBuf ( size_t  size)
inlineexplicit

Definition at line 74 of file circlebuf.hh.

Member Function Documentation

template<typename T>
size_t CircleBuf< T >::capacity ( ) const
inline

Return the maximum number of elements that can be stored in the buffer at any one time.

Definition at line 83 of file circlebuf.hh.

Referenced by Fifo< uint8_t >::capacity().

template<typename T>
bool CircleBuf< T >::empty ( ) const
inline

Is the buffer empty?

Definition at line 78 of file circlebuf.hh.

Referenced by Terminal::console_in(), Terminal::dataAvailable(), Fifo< uint8_t >::empty(), and Terminal::in().

template<typename T>
void CircleBuf< T >::flush ( )
inline

Remove all the elements in the buffer.

Note: This does not actually remove elements from the backing store.

Definition at line 93 of file circlebuf.hh.

Referenced by arrayParamIn(), and Fifo< uint8_t >::flush().

template<typename T>
void CircleBuf< T >::normalize ( )
inlineprotected

Normalize the start and stop pointers to ensure that pointer invariants hold after updates.

Definition at line 186 of file circlebuf.hh.

Referenced by CircleBuf< char >::read(), and CircleBuf< char >::write().

template<typename T>
template<class OutputIterator >
void CircleBuf< T >::peek ( OutputIterator  out,
size_t  len 
) const
inline

Copy buffer contents without advancing the read pointer.

Parameters
outOutput iterator/pointer
lenNumber of elements to copy

Definition at line 105 of file circlebuf.hh.

Referenced by Terminal::accept(), arrayParamOut(), main(), CircleBuf< char >::peek(), Fifo< uint8_t >::peek(), and CircleBuf< char >::read().

template<typename T>
template<class OutputIterator >
void CircleBuf< T >::peek ( OutputIterator  out,
off_t  offset,
size_t  len 
) const
inline

Copy buffer contents without advancing the read pointer.

Parameters
outOutput iterator/pointer
offsetOffset into the ring buffer
lenNumber of elements to copy

Definition at line 117 of file circlebuf.hh.

template<typename T>
template<class OutputIterator >
void CircleBuf< T >::read ( OutputIterator  out,
size_t  len 
)
inline

Copy buffer contents and advance the read pointer.

Parameters
outOutput iterator/pointer
lenNumber of elements to read

Definition at line 143 of file circlebuf.hh.

Referenced by Terminal::in(), main(), and Fifo< uint8_t >::read().

template<typename T>
size_t CircleBuf< T >::size ( ) const
inline

Return the number of elements stored in the buffer.

Definition at line 85 of file circlebuf.hh.

Referenced by Terminal::accept(), arrayParamOut(), main(), CircleBuf< char >::peek(), Fifo< uint8_t >::size(), and CircleBuf< char >::write().

template<typename T>
template<class InputIterator >
void CircleBuf< T >::write ( InputIterator  in,
size_t  len 
)
inline

Add elements to the end of the ring buffers and advance.

Parameters
inInput iterator/pointer
lenNumber of elements to read

Definition at line 157 of file circlebuf.hh.

Referenced by arrayParamIn(), Terminal::data(), main(), Terminal::out(), and Fifo< uint8_t >::write().

Member Data Documentation

template<typename T>
size_t CircleBuf< T >::_start
protected
template<typename T>
size_t CircleBuf< T >::_stop
protected
template<typename T>
std::vector<value_type> CircleBuf< T >::buf
protected

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

Generated on Fri Jun 9 2017 13:04:05 for gem5 by doxygen 1.8.6