15 #ifndef ECL_CONTAINERS_PUSH_AND_POP_DYNAMIC_HPP_
16 #define ECL_CONTAINERS_PUSH_AND_POP_DYNAMIC_HPP_
36 namespace formatters {
38 template <
typename Type,
size_t N>
class PushAndPopFormatter;
70 template<
typename Type>
74 typedef Type value_type;
75 typedef Type* iterator;
76 typedef const Type* const_iterator;
78 typedef const Type& const_reference;
93 : size_fifo(length+1), leader(0), follower(0)
96 data.resize( size_fifo );
99 PushAndPop(
const unsigned int length,
const Type & d ) :
105 data.resize( size_fifo );
134 const_iterator begin()
const {
152 const_iterator end()
const {
161 reverse_iterator rbegin() {
162 return reverse_iterator(end());
170 const_reverse_iterator rbegin()
const {
171 return const_reverse_iterator(end());
179 reverse_iterator rend() {
180 return reverse_iterator(begin());
188 const_reverse_iterator rend()
const {
189 return const_reverse_iterator(begin());
198 Type & operator[] (
int idx)
200 return data[ ((follower+idx)%size_fifo) ];
203 const Type & operator[] (
int idx)
const
205 return data[ ((follower+idx)%size_fifo) ];
212 for(
int i=0; i<size_fifo; i++ )
214 data[i] = otherOne.
data[i];
224 void push_back(
const Type & datum )
226 data[ leader++ ] = datum;
228 if( leader == follower )
231 follower %= size_fifo;
239 Type value = data[follower++];
240 follower %= size_fifo;
244 void fill(
const Type & d )
246 for(
unsigned int i=0; i<size_fifo; i++ ) data[i] = d;
249 void resize(
unsigned int length )
251 size_fifo = length+1;
253 data.resize( size_fifo );
268 unsigned int size()
const
270 if( leader > follower )
return leader - follower;
271 else if( leader < follower )
return size_fifo-follower+leader;
283 unsigned int size_fifo;