ESyS-Particle
2.3.4
RingBuffer.hpp
Go to the documentation of this file.
1
// //
3
// Copyright (c) 2003-2017 by The University of Queensland //
4
// Centre for Geoscience Computing //
5
// http://earth.uq.edu.au/centre-geoscience-computing //
6
// //
7
// Primary Business: Brisbane, Queensland, Australia //
8
// Licensed under the Open Software License version 3.0 //
9
// http://www.apache.org/licenses/LICENSE-2.0 //
10
// //
12
13
template
<
typename
T>
14
RingBuffer<T>::RingBuffer
(
int
s)
15
{
16
m_buffer=vector<T>(s);
17
m_idx=0;
18
m_size=s;
19
}
20
21
template
<
typename
T>
22
T&
RingBuffer<T>::operator[]
(
int
i)
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
}
RingBuffer::operator[]
T & operator[](int)
Definition:
RingBuffer.hpp:22
RingBuffer::RingBuffer
RingBuffer(int)
Definition:
RingBuffer.hpp:14
RingBuffer::insert
void insert(const T &)
Definition:
RingBuffer.hpp:36
Foundation
RingBuffer.hpp
Generated by
1.8.20