36 #ifndef CIRCULARMATRIXBUFFER_H
37 #define CIRCULARMATRIXBUFFER_H
66 #include <QSharedPointer>
83 using namespace Eigen;
92 template<
typename _Tp>
96 typedef QSharedPointer<CircularMatrixBuffer>
SPtr;
97 typedef QSharedPointer<const CircularMatrixBuffer>
ConstSPtr;
108 explicit CircularMatrixBuffer(
unsigned int uiMaxNumMatrices,
unsigned int uiRows,
unsigned int uiCols);
122 inline void push(
const Matrix<_Tp, Dynamic, Dynamic>* pMatrix);
130 inline Matrix<_Tp, Dynamic, Dynamic> pop();
142 inline quint32 size()
const;
148 inline quint32 rows()
const;
154 inline quint32 cols()
const;
160 inline void pause(
bool);
167 inline bool releaseFromPop();
174 inline bool releaseFromPush();
184 inline unsigned int mapIndex(
int& index);
186 unsigned int m_uiMaxNumMatrices;
187 unsigned int m_uiRows;
188 unsigned int m_uiCols;
189 unsigned int m_uiMaxNumElements;
191 int m_iCurrentReadIndex;
192 int m_iCurrentWriteIndex;
193 QSemaphore* m_pFreeElements;
194 QSemaphore* m_pUsedElements;
204 template<
typename _Tp>
206 :
Buffer(typeid(_Tp).name())
207 , m_uiMaxNumMatrices(uiMaxNumMatrices)
210 , m_uiMaxNumElements(m_uiMaxNumMatrices*m_uiRows*m_uiCols)
211 , m_pBuffer(new _Tp[m_uiMaxNumElements])
212 , m_iCurrentReadIndex(-1)
213 , m_iCurrentWriteIndex(-1)
214 , m_pFreeElements(new QSemaphore(m_uiMaxNumElements))
215 , m_pUsedElements(new QSemaphore(0))
224 template<
typename _Tp>
227 delete m_pFreeElements;
228 delete m_pUsedElements;
235 template<
typename _Tp>
240 unsigned int t_size = pMatrix->size();
241 if(t_size == m_uiRows*m_uiCols)
243 m_pFreeElements->acquire(t_size);
244 for(
unsigned int i = 0; i < t_size; ++i)
245 m_pBuffer[mapIndex(m_iCurrentWriteIndex)] = pMatrix->data()[i];
246 m_pUsedElements->release(t_size);
256 template<
typename _Tp>
259 Matrix<_Tp, Dynamic, Dynamic> matrix(m_uiRows, m_uiCols);
263 m_pUsedElements->acquire(m_uiRows*m_uiCols);
264 for(quint32 i = 0; i < m_uiRows*m_uiCols; ++i)
265 matrix.data()[i] = m_pBuffer[mapIndex(m_iCurrentReadIndex)];
266 m_pFreeElements->release(m_uiRows*m_uiCols);
277 template<
typename _Tp>
282 return index = AuxIndex % m_uiMaxNumElements;
289 template<
typename _Tp>
292 delete m_pFreeElements;
293 m_pFreeElements =
new QSemaphore(m_uiMaxNumElements);
294 delete m_pUsedElements;
295 m_pUsedElements =
new QSemaphore(0);
297 m_iCurrentReadIndex = -1;
298 m_iCurrentWriteIndex = -1;
304 template<
typename _Tp>
307 return m_uiMaxNumMatrices;
313 template<
typename _Tp>
322 template<
typename _Tp>
331 template<
typename _Tp>
340 template<
typename _Tp>
343 if((uint)m_pUsedElements->available() < m_uiRows*m_uiCols)
346 unsigned int t_size = m_uiRows*m_uiCols;
347 for(
unsigned int i = 0; i < t_size; ++i)
348 m_pBuffer[mapIndex(m_iCurrentWriteIndex)] = 0;
351 m_pUsedElements->release(m_uiRows*m_uiCols);
362 template<
typename _Tp>
365 if((uint)m_pFreeElements->available() < m_uiRows*m_uiCols)
368 unsigned int t_size = m_uiRows*m_uiCols;
369 for(
unsigned int i = 0; i < t_size; ++i)
370 m_pBuffer[mapIndex(m_iCurrentWriteIndex)] = 0;
373 m_pFreeElements->release(m_uiRows*m_uiCols);
398 #endif // CIRCULARMATRIXBUFFER_H
CircularMatrixBuffer(unsigned int uiMaxNumMatrices, unsigned int uiRows, unsigned int uiCols)
#define GENERICSSHARED_EXPORT
QSharedPointer< CircularMatrixBuffer > SPtr
The circular matrix buffer.
generics library export/import macros.
void push(const Matrix< _Tp, Dynamic, Dynamic > *pMatrix)
Matrix< _Tp, Dynamic, Dynamic > pop()
Contains the declaration of the Buffer base class.
The Buffer class provides a base class for buffers.
QSharedPointer< const CircularMatrixBuffer > ConstSPtr