ESyS-Particle  4.0.1
RingBuffer.hpp
1 
2 // //
3 // Copyright (c) 2003-2011 by The University of Queensland //
4 // Earth Systems Science Computational Centre (ESSCC) //
5 // http://www.uq.edu.au/esscc //
6 // //
7 // Primary Business: Brisbane, Queensland, Australia //
8 // Licensed under the Open Software License version 3.0 //
9 // http://www.opensource.org/licenses/osl-3.0.php //
10 // //
12 
13 template< typename T>
15 {
16  m_buffer=vector<T>(s);
17  m_idx=0;
18  m_size=s;
19 }
20 
21 template< typename T>
23 {
24  int real_idx=(m_idx+i)%m_size;
25  return m_buffer[real_idx];
26 }
27 
28 template< typename T>
29 T RingBuffer<T>::operator[] (int i) const
30 {
31  int real_idx=(m_idx+i)%m_size;
32  return m_buffer[real_idx];
33 }
34 
35 template< typename T>
36 void RingBuffer<T>::insert(const T& data)
37 {
38  m_idx=(m_idx+1)%m_size;
39  m_buffer[m_idx]=data;
40 }