20#ifndef __TLM_CORE_1_REQ_RSP_CHANNELS_FIFO_CIRCULAR_BUFFER_HH__
21#define __TLM_CORE_1_REQ_RSP_CHANNELS_FIFO_CIRCULAR_BUFFER_HH__
92 std::cout <<
"Buffer debug" << std::endl;
93 std::cout <<
"Size : " << size() << std::endl;
94 std::cout <<
"Free/Used " << free() <<
"/" << used() << std::endl;
95 std::cout <<
"Indices : r/w = " << m_ri <<
"/" << m_wi << std::endl;
98 std::cout <<
"empty" << std::endl;
102 std::cout <<
"full" << std::endl;
105 std::cout <<
"Data : " << std::endl;
106 for (
int i = 0; i < used(); i++) {
107 std::cout << peek_data( i ) << std::endl;
121 for (
int i = 0; i < used(); i++) {
122 buf_clear(m_buf, (m_ri + i) % m_size);
125 m_used = m_ri = m_wi = 0;
140 void *new_buf = buf_alloc(size);
142 for (i = 0; i < size && i < used(); i++) {
143 buf_write(new_buf, i, peek_data(i));
144 buf_clear(m_buf, (m_ri + i) % m_size);
153 m_free = m_size - m_used;
164 m_buf = buf_alloc(m_size);
179 buf_clear(m_buf, m_ri);
180 increment_read_pos();
189 buf_write(m_buf, m_wi, t);
190 increment_write_pos();
197 m_wi = (m_wi + i) % m_size;
206 m_ri = (m_ri + i) % m_size;
215 return new unsigned char [size *
sizeof(T)];
222 delete []
static_cast<unsigned char *
>(buf);
230 T *p =
static_cast<T *
>(buf) + n;
238 T *p =
static_cast<T *
>(buf) + n;
246 T *p =
static_cast<T *
>(buf) + n;
void buf_write(void *buf, int n, const T &t)
circular_buffer(const circular_buffer< T > &b)
void buf_free(void *&buf)
void increment_write_pos(int i=1)
T & buf_read(void *buf, int n) const
circular_buffer< T > & operator=(const circular_buffer< T > &)
const T & read_data() const
void increment_read_pos(int i=1)
const T & peek_data(int i) const
void buf_clear(void *buf, int n)
circular_buffer(int size=0)
void * buf_alloc(int size)