Files Classes Functions Hierarchy
#include <cirbuffarr.h>
Public Member Functions | |
| void | operator++ () |
| Move the current pointer forward. | |
| void | operator-- () |
| Move the current pointer back. | |
| cirbuffarr (uintc nstates_, uintc W_) | |
| Hold n states, each with W T objects. | |
| ~cirbuffarr () | |
| Free memory. | |
| T * | operator[] (uintc k) |
| Access the states, 0 is the most recent. | |
| T const * | operator[] (uintc k) const |
| Access the states, 0 is the most recent. | |
| template<typename Z > | |
| void | operator= (Z const &x) |
| Copy array x to the current state. | |
| template<typename Z > | |
| void | copyto (Z &x, uintc i=0) const |
| Copy the i'th state to array x. | |
| template<typename Z > | |
| void | push (Z const &x) |
| Push array x into the front. | |
| void | dup () |
| Duplicate the current state. | |
| ostream & | print (ostream &os) const |
| Print the circular buffer from first to last states. | |
Public Attributes | |
| uintc | nstates |
| The number of states the circular buffer has. | |
| uintc | W |
| The number of elements of each state. | |
The client pushes the new state into the current position by using push or they can directly write to the memory area themselves and increment with ++ afterwards.
popping is done by the -- operator. There is no deletion only a change in the pointers. The memory is allocated upfront and released when the object dies.
The copy routines allow you to save a state in another memory location, and restore it. Hence this class can be used in another way.
Definition at line 29 of file cirbuffarr.h.
| cirbuffarr< T >::cirbuffarr | ( | uintc | nstates_, | |
| uintc | W_ | |||
| ) | [inline] |
Hold n states, each with W T objects.
Definition at line 162 of file cirbuffarr.h.
References cirbuffarr< T >::nstates, and cirbuffarr< T >::W.
00163 : nstates(nstates_), W(W_) 00164 { 00165 assert(nstates>0); 00166 current=0; 00167 state = new T[nstates*W]; 00168 }
| cirbuffarr< T >::~cirbuffarr | ( | ) | [inline] |
| void cirbuffarr< T >::copyto | ( | Z & | x, | |
| uintc | i = 0 | |||
| ) | const [inline] |
Copy the i'th state to array x.
Definition at line 137 of file cirbuffarr.h.
References cirbuffarr< T >::operator[](), and cirbuffarr< T >::W.
Referenced by cirbuffarrtest01(), and cirbuffarrtest02().
00138 { 00139 T const * c = operator[](i); 00140 00141 for (uint i=0; i<W; ++i) 00142 x[i] = c[i]; 00143 }
| void cirbuffarr< T >::dup | ( | ) | [inline] |
Duplicate the current state.
Definition at line 111 of file cirbuffarr.h.
References cirbuffarr< T >::operator[](), and cirbuffarr< T >::push().
Referenced by cirbuffarrtest02().
00112 { 00113 T * prev = operator[](0); //accessState(); 00114 push(prev); 00115 }
| void cirbuffarr< T >::operator++ | ( | ) | [inline] |
Move the current pointer forward.
Definition at line 47 of file cirbuffarr.h.
Referenced by cirbuffarr< T >::push().
00048 { ++current; current %= nstates; }
| void cirbuffarr< T >::operator-- | ( | ) | [inline] |
| void cirbuffarr< T >::operator= | ( | Z const & | x | ) | [inline] |
Copy array x to the current state.
Definition at line 119 of file cirbuffarr.h.
References cirbuffarr< T >::operator[](), and cirbuffarr< T >::W.
00120 { 00121 T * c = operator[](0); //accessState(); 00122 00123 for (uint i=0; i<W; ++i) 00124 c[i] = x[i]; 00125 }
| T const * cirbuffarr< T >::operator[] | ( | uintc | k | ) | const [inline] |
Access the states, 0 is the most recent.
Definition at line 154 of file cirbuffarr.h.
References cirbuffarr< T >::nstates, and cirbuffarr< T >::W.
00155 { 00156 //assert(k<nstates); 00157 assert(nstates!=0); 00158 return state + ((current+(nstates-k))%nstates)*W; 00159 }
| T * cirbuffarr< T >::operator[] | ( | uintc | k | ) | [inline] |
Access the states, 0 is the most recent.
Definition at line 146 of file cirbuffarr.h.
References cirbuffarr< T >::nstates, and cirbuffarr< T >::W.
Referenced by cirbuffarr< T >::copyto(), cirbuffarr< T >::dup(), cirbuffarr< T >::operator=(), and cirbuffarr< T >::print().
00147 { 00148 assert(k<nstates); 00149 assert(nstates!=0); 00150 return state + ((current+(nstates-k))%nstates)*W; 00151 }
| ostream & cirbuffarr< T >::print | ( | ostream & | os | ) | const [inline] |
Print the circular buffer from first to last states.
Definition at line 92 of file cirbuffarr.h.
References cirbuffarr< T >::nstates, cirbuffarr< T >::operator[](), and cirbuffarr< T >::W.
00093 { 00094 T const * s; 00095 uint i; 00096 uint k; 00097 for (i=0; i<nstates; ++i) 00098 { 00099 s = operator[](i); 00100 os << i << ": "; 00101 for (k=0; k<W; ++k) 00102 os << s[k] << " "; 00103 os << endl; 00104 } 00105 00106 return os; 00107 }
Push array x into the front.
Definition at line 129 of file cirbuffarr.h.
References cirbuffarr< T >::operator++().
Referenced by cirbuffarrtest01(), cirbuffarrtest02(), and cirbuffarr< T >::dup().
00130 { 00131 operator ++(); 00132 *this = x; 00133 }
| uintc cirbuffarr< T >::nstates |
The number of states the circular buffer has.
Definition at line 41 of file cirbuffarr.h.
Referenced by cirbuffarr< T >::cirbuffarr(), cirbuffarr< arc >::operator++(), cirbuffarr< arc >::operator--(), cirbuffarr< T >::operator[](), and cirbuffarr< T >::print().
| uintc cirbuffarr< T >::W |
The number of elements of each state.
Definition at line 44 of file cirbuffarr.h.
Referenced by cirbuffarr< T >::cirbuffarr(), cirbuffarr< T >::copyto(), cirbuffarr< T >::operator=(), cirbuffarr< T >::operator[](), and cirbuffarr< T >::print().
1.5.8