#include <itpp/base/circular_buffer.h>
Public Member Functions | |
Circular_Buffer () | |
Default constructor. | |
Circular_Buffer (int n) | |
Create a Circular_Buffer of size n . | |
Circular_Buffer (const Circular_Buffer< T > &s) | |
Create a copy of s . | |
virtual | ~Circular_Buffer () |
Default destructor. | |
void | put (const T &in) |
Write the element in to the buffer. | |
void | put (const Vec< T > &in) |
Write the vector of elements in to the circular buffer. | |
void | put (const Array< T > &in) |
Write the vector of elements in to the circular buffer. | |
void | get (T &out) |
Get the oldest element in the circular buffer. | |
T | get () |
Get the oldest element in the circular buffer. | |
void | get (Vec< T > &out, const int N=-1) |
Get the N oldest element in the circular buffer. N=-1 returns all elements in the buffer. | |
void | get (Array< T > &out, const int N=-1) |
Get the N oldest element in the circular buffer. N=-1 returns all elements in the buffer. | |
void | peek (T &out) const |
Peek at the oldest element in the circular buffer, without removing it. | |
T | peek () const |
Peek at the oldest element in the circular buffer, without removing it. | |
void | peek (const int index, T &out) const |
Peek at the element with index index in the circular buffer, without removing it. | |
void | peek (Vec< T > &out, const int N=-1) const |
Peek at the N first elements of the circular buffer, without removing them. N=-1 peeks all elements in the buffer. | |
void | peek (const ivec &index, Vec< T > &out) const |
Peek at the elements with index index in the circular buffer, without removing them. | |
void | peek (Array< T > &out, const int N=-1) const |
Peek at the N first elements of the circular buffer, without removing them. N=-1 peeks all elements in the buffer. | |
void | peek (const ivec &index, Array< T > &out) const |
Peek at the elements with index index in the circular buffer, without removing them. | |
void | peek_reverse (T &out) const |
Peek at the latest element in the circular buffer, without removing it. | |
T | peek_reverse () const |
Peek at the latest element in the circular buffer, without removing it. | |
void | peek_reverse (Vec< T > &out, const int N=-1) const |
Peek at the N latest elements of the circular buffer in reverse order, without removing them. N=-1 returns all elements in the buffer. | |
void | peek_reverse (Array< T > &out, const int N=-1) const |
Peek at the N latest elements of the circular buffer in reverse order, without removing them. N=-1 returns all elements in the buffer. | |
void | clear () |
Empty the circular buffer. | |
void | operator= (const Circular_Buffer< T > &s) |
Assignment operator. | |
int | size () const |
Returns the maximum number of data elements the circular buffer can store. | |
int | nrof_elements () const |
Returns the number of data elements currently stored in the circular buffer. | |
void | set_size (int n, bool copy=false) |
Resizing a Circular_Buffer<T>. | |
Protected Member Functions | |
void | alloc (int n) |
void | free () |
Protected Attributes | |
int | _write |
int | _read |
int | _ndata |
int | _rw_dist |
T * | _data |
This class is a general circular buffer class for arbitrary types.
For rarely used types you will need to instantiate the class by
template class Circular_Buffer<type>;
The following example shows how to define a Circular_Buffer of doubles:
vec a = randn(3); vec b = randn(8); vec out_vec; Array <double> out_array; Circular_Buffer<double> cb1(10); //Put the elements of a to the buffer cb1.put(a); //Vector output: Peek at the two oldest elements of the buffer (the two first extracted) cb1.peek(out_vec,2); cout << "peek(out_vec,2) = " << out_vec << ": display 2 first elements of the buffer, without affecting the content" << endl; //Vector output: Peek at all elements of the buffer in reverse order cb1.peek_reverse(out_vec); cout << "peek_reverse(out_vec,-1) = " << out_vec << ": display buffer, without affecting the content" << endl; //Array output: Peek at all elements of the buffer in reverse order cb1.peek_reverse(out_array); cout << "peek_reverse(out_array,-1) = " << out_array << ": display buffer, without affecting the content" << endl; //Put the elements of \c b to the buffer cb1.put(b); //Extract the oldest element of the buffer cb1.get(out_vec,1); cout << "get(out_vec,1) = " << out_vec << endl ; //Extract all element of the buffer cb1.get(out_vec); cout << "get(out_vec) = " << out_vec << endl ;
Definition at line 95 of file circular_buffer.h.
itpp::Circular_Buffer< T >::Circular_Buffer | ( | ) |
Default constructor.
Definition at line 194 of file circular_buffer.h.
References itpp::Circular_Buffer< T >::_data, itpp::Circular_Buffer< T >::_ndata, itpp::Circular_Buffer< T >::_read, itpp::Circular_Buffer< T >::_rw_dist, and itpp::Circular_Buffer< T >::_write.
itpp::Circular_Buffer< T >::Circular_Buffer | ( | int | n | ) |
Create a Circular_Buffer of size n
.
Definition at line 204 of file circular_buffer.h.
References itpp::Circular_Buffer< T >::_read, itpp::Circular_Buffer< T >::_rw_dist, itpp::Circular_Buffer< T >::_write, and itpp::Circular_Buffer< T >::alloc().
itpp::Circular_Buffer< T >::Circular_Buffer | ( | const Circular_Buffer< T > & | s | ) |
Create a copy of s
.
Definition at line 213 of file circular_buffer.h.
References itpp::Circular_Buffer< T >::_data, itpp::Circular_Buffer< T >::_ndata, itpp::Circular_Buffer< T >::_read, itpp::Circular_Buffer< T >::_rw_dist, itpp::Circular_Buffer< T >::_write, and itpp::Circular_Buffer< T >::alloc().
itpp::Circular_Buffer< T >::~Circular_Buffer | ( | ) | [virtual] |
Default destructor.
Definition at line 226 of file circular_buffer.h.
References itpp::Circular_Buffer< T >::free().
void itpp::Circular_Buffer< T >::put | ( | const T & | in | ) |
Write the element in to the buffer.
Definition at line 473 of file circular_buffer.h.
References itpp::Circular_Buffer< T >::_data, itpp::Circular_Buffer< T >::_ndata, itpp::Circular_Buffer< T >::_rw_dist, itpp::Circular_Buffer< T >::_write, and itpp::Circular_Buffer< T >::get().
Referenced by itpp::Circular_Buffer< T >::set_size().
void itpp::Circular_Buffer< T >::put | ( | const Vec< T > & | in | ) |
Write the vector of elements in to the circular buffer.
Definition at line 494 of file circular_buffer.h.
References itpp::Circular_Buffer< T >::_data, itpp::Circular_Buffer< T >::_ndata, itpp::Circular_Buffer< T >::_rw_dist, itpp::Circular_Buffer< T >::_write, itpp::Circular_Buffer< T >::get(), and itpp::Vec< Num_T >::size().
void itpp::Circular_Buffer< T >::put | ( | const Array< T > & | in | ) |
Write the vector of elements in to the circular buffer.
Definition at line 518 of file circular_buffer.h.
References itpp::Circular_Buffer< T >::_data, itpp::Circular_Buffer< T >::_ndata, itpp::Circular_Buffer< T >::_rw_dist, itpp::Circular_Buffer< T >::_write, itpp::Circular_Buffer< T >::get(), and itpp::Array< T >::size().
void itpp::Circular_Buffer< T >::get | ( | T & | out | ) |
Get the oldest element in the circular buffer.
Definition at line 232 of file circular_buffer.h.
References itpp::Circular_Buffer< T >::_data, itpp::Circular_Buffer< T >::_ndata, itpp::Circular_Buffer< T >::_read, itpp::Circular_Buffer< T >::_rw_dist, and it_assert0.
T itpp::Circular_Buffer< T >::get | ( | ) |
Get the oldest element in the circular buffer.
Definition at line 243 of file circular_buffer.h.
Referenced by itpp::Circular_Buffer< T >::put().
void itpp::Circular_Buffer< T >::get | ( | Vec< T > & | out, | |
const int | N = -1 | |||
) |
Get the N oldest element in the circular buffer. N=-1
returns all elements in the buffer.
Definition at line 252 of file circular_buffer.h.
References itpp::Circular_Buffer< T >::_data, itpp::Circular_Buffer< T >::_ndata, itpp::Circular_Buffer< T >::_read, itpp::Circular_Buffer< T >::_rw_dist, it_assert0, and itpp::Vec< Num_T >::set_size().
void itpp::Circular_Buffer< T >::get | ( | Array< T > & | out, | |
const int | N = -1 | |||
) |
Get the N oldest element in the circular buffer. N=-1
returns all elements in the buffer.
Definition at line 276 of file circular_buffer.h.
References itpp::Circular_Buffer< T >::_data, itpp::Circular_Buffer< T >::_ndata, itpp::Circular_Buffer< T >::_read, itpp::Circular_Buffer< T >::_rw_dist, it_assert0, and itpp::Array< T >::set_size().
void itpp::Circular_Buffer< T >::peek | ( | T & | out | ) | const |
Peek at the oldest element in the circular buffer, without removing it.
Definition at line 300 of file circular_buffer.h.
References itpp::Circular_Buffer< T >::_data, itpp::Circular_Buffer< T >::_read, itpp::Circular_Buffer< T >::_rw_dist, and it_assert0.
T itpp::Circular_Buffer< T >::peek | ( | ) | const |
Peek at the oldest element in the circular buffer, without removing it.
Definition at line 307 of file circular_buffer.h.
void itpp::Circular_Buffer< T >::peek | ( | const int | index, | |
T & | out | |||
) | const |
Peek at the element with index index in the circular buffer, without removing it.
Definition at line 316 of file circular_buffer.h.
References itpp::Circular_Buffer< T >::_data, itpp::Circular_Buffer< T >::_ndata, itpp::Circular_Buffer< T >::_read, itpp::Circular_Buffer< T >::_rw_dist, and it_assert0.
void itpp::Circular_Buffer< T >::peek | ( | Vec< T > & | out, | |
const int | N = -1 | |||
) | const |
Peek at the N first elements of the circular buffer, without removing them. N=-1
peeks all elements in the buffer.
Definition at line 323 of file circular_buffer.h.
References itpp::Circular_Buffer< T >::_data, itpp::Circular_Buffer< T >::_ndata, itpp::Circular_Buffer< T >::_read, itpp::Circular_Buffer< T >::_rw_dist, it_assert0, and itpp::Vec< Num_T >::set_size().
void itpp::Circular_Buffer< T >::peek | ( | const ivec & | index, | |
Vec< T > & | out | |||
) | const |
Peek at the elements with index index in the circular buffer, without removing them.
Definition at line 346 of file circular_buffer.h.
References itpp::Circular_Buffer< T >::_data, itpp::Circular_Buffer< T >::_ndata, itpp::Circular_Buffer< T >::_read, itpp::Circular_Buffer< T >::_rw_dist, it_assert0, and itpp::Vec< Num_T >::set_size().
void itpp::Circular_Buffer< T >::peek | ( | Array< T > & | out, | |
const int | N = -1 | |||
) | const |
Peek at the N first elements of the circular buffer, without removing them. N=-1
peeks all elements in the buffer.
Definition at line 358 of file circular_buffer.h.
References itpp::Circular_Buffer< T >::_data, itpp::Circular_Buffer< T >::_ndata, itpp::Circular_Buffer< T >::_read, itpp::Circular_Buffer< T >::_rw_dist, it_assert0, and itpp::Array< T >::set_size().
void itpp::Circular_Buffer< T >::peek | ( | const ivec & | index, | |
Array< T > & | out | |||
) | const |
Peek at the elements with index index in the circular buffer, without removing them.
Definition at line 381 of file circular_buffer.h.
References itpp::Circular_Buffer< T >::_data, itpp::Circular_Buffer< T >::_ndata, itpp::Circular_Buffer< T >::_read, itpp::Circular_Buffer< T >::_rw_dist, it_assert0, and itpp::Array< T >::set_size().
void itpp::Circular_Buffer< T >::peek_reverse | ( | T & | out | ) | const |
Peek at the latest element in the circular buffer, without removing it.
Definition at line 393 of file circular_buffer.h.
References itpp::Circular_Buffer< T >::_data, itpp::Circular_Buffer< T >::_ndata, itpp::Circular_Buffer< T >::_rw_dist, itpp::Circular_Buffer< T >::_write, and it_assert0.
T itpp::Circular_Buffer< T >::peek_reverse | ( | ) | const |
Peek at the latest element in the circular buffer, without removing it.
Definition at line 408 of file circular_buffer.h.
Referenced by itpp::Circular_Buffer< T >::set_size().
void itpp::Circular_Buffer< T >::peek_reverse | ( | Vec< T > & | out, | |
const int | N = -1 | |||
) | const |
Peek at the N latest elements of the circular buffer in reverse order, without removing them. N=-1
returns all elements in the buffer.
Definition at line 417 of file circular_buffer.h.
References itpp::Circular_Buffer< T >::_data, itpp::Circular_Buffer< T >::_ndata, itpp::Circular_Buffer< T >::_rw_dist, itpp::Circular_Buffer< T >::_write, it_assert0, and itpp::Vec< Num_T >::set_size().
void itpp::Circular_Buffer< T >::peek_reverse | ( | Array< T > & | out, | |
const int | N = -1 | |||
) | const |
Peek at the N latest elements of the circular buffer in reverse order, without removing them. N=-1
returns all elements in the buffer.
Definition at line 445 of file circular_buffer.h.
References itpp::Circular_Buffer< T >::_data, itpp::Circular_Buffer< T >::_ndata, itpp::Circular_Buffer< T >::_rw_dist, itpp::Circular_Buffer< T >::_write, it_assert0, and itpp::Array< T >::set_size().
void itpp::Circular_Buffer< T >::clear | ( | ) |
Empty the circular buffer.
Definition at line 541 of file circular_buffer.h.
References itpp::Circular_Buffer< T >::_read, itpp::Circular_Buffer< T >::_rw_dist, and itpp::Circular_Buffer< T >::_write.
Referenced by itpp::Circular_Buffer< T >::set_size().
void itpp::Circular_Buffer< T >::operator= | ( | const Circular_Buffer< T > & | s | ) |
Assignment operator.
Definition at line 578 of file circular_buffer.h.
References itpp::Circular_Buffer< T >::_data, itpp::Circular_Buffer< T >::_ndata, itpp::Circular_Buffer< T >::_read, itpp::Circular_Buffer< T >::_rw_dist, itpp::Circular_Buffer< T >::_write, and itpp::Circular_Buffer< T >::set_size().
int itpp::Circular_Buffer< T >::size | ( | ) | const [inline] |
Returns the maximum number of data elements the circular buffer can store.
Definition at line 170 of file circular_buffer.h.
References itpp::Circular_Buffer< T >::_ndata.
int itpp::Circular_Buffer< T >::nrof_elements | ( | ) | const [inline] |
Returns the number of data elements currently stored in the circular buffer.
Definition at line 173 of file circular_buffer.h.
References itpp::Circular_Buffer< T >::_rw_dist.
void itpp::Circular_Buffer< T >::set_size | ( | int | n, | |
bool | copy = false | |||
) |
Resizing a Circular_Buffer<T>.
Definition at line 589 of file circular_buffer.h.
References itpp::Circular_Buffer< T >::_ndata, itpp::Circular_Buffer< T >::_rw_dist, itpp::Circular_Buffer< T >::alloc(), itpp::Circular_Buffer< T >::clear(), itpp::Circular_Buffer< T >::free(), itpp::Circular_Buffer< T >::peek_reverse(), and itpp::Circular_Buffer< T >::put().
Referenced by itpp::Circular_Buffer< T >::operator=().
Generated on Thu Apr 19 14:18:37 2007 for IT++ by Doxygen 1.5.1