@@ -174,16 +174,127 @@ template <class T, U32 N> struct fixed_queue
174174 U32 _last;
175175 T _buffer[N + 1 ];
176176
177- void reset ();
178- void front ();
179- void pop_front ();
180- void push_front (const T& element);
177+ void reset ()
178+ {
179+ clear ();
180+ }
181+ void clear ()
182+ {
183+ _last = 0 ;
184+ _first = 0 ;
185+ }
186+ T& front ()
187+ {
188+ fixed_queue<T, N>::iterator it = begin ();
189+ return *it;
190+ }
191+ void pop_front ()
192+ {
193+ _first = (_first + 1 ) & N;
194+ }
195+ void push_front ()
196+ {
197+ _first = (_first + N) & N;
198+ }
199+ void push_front (const T& data)
200+ {
201+ push_front ();
202+ T& new_front = front ();
203+ new_front = data;
204+ }
181205 void push_back ();
182- bool full () const ;
183- void back ();
184- void pop_back ();
185- bool empty () const ;
186- U32 size () const ;
206+ U32 max_size () const
207+ {
208+ return N;
209+ }
210+ bool full () const
211+ {
212+ return size () == max_size ();
213+ }
214+ T& back ()
215+ {
216+ fixed_queue<T, N>::iterator it = end () - 1 ;
217+ return *it;
218+ }
219+ void pop_back ()
220+ {
221+ _last = (_last + N) & N;
222+ }
223+ bool empty () const
224+ {
225+ return _last == _first;
226+ }
227+ U32 size () const
228+ {
229+ return _last - _first;
230+ }
231+
232+ struct iterator {
233+ U32 _it;
234+ fixed_queue<T, N>* _owner;
235+
236+ T& operator *() const
237+ {
238+ return _owner->_buffer [_it];
239+ }
240+
241+ bool operator !=(const iterator& other) const
242+ {
243+ return _it != other._it ;
244+ }
245+
246+ iterator* operator +=(S32 value)
247+ {
248+ value += _it;
249+ _it = (value + N) & N;
250+ return this ;
251+ }
252+
253+ iterator* operator -=(S32 value)
254+ {
255+ iterator* tmp = operator +=(-value);
256+ return tmp;
257+ }
258+
259+ iterator* operator --()
260+ {
261+ *this -= 1 ;
262+ return this ;
263+ }
264+
265+ iterator operator -(S32 value) const
266+ {
267+ iterator tmp;
268+ tmp._it = _it;
269+ tmp._owner = _owner;
270+ tmp -= value;
271+ return tmp;
272+ }
273+
274+ iterator* operator ++()
275+ {
276+ *this += 1 ;
277+ return this ;
278+ }
279+ };
280+
281+ iterator create_iterator (u32 initial_location) const
282+ {
283+ iterator it;
284+ it._it = initial_location;
285+ it._owner = const_cast <fixed_queue<T, N>*>(this );
286+ return it;
287+ }
288+
289+ iterator begin () const
290+ {
291+ return create_iterator (_first);
292+ }
293+
294+ iterator end () const
295+ {
296+ return create_iterator (_last);
297+ }
187298};
188299
189300#endif
0 commit comments