No more need to specify each types for ringBuffer

This commit is contained in:
Geoffrey Merck 2020-05-09 13:33:05 +02:00
parent 7302dc8bd7
commit 6c3dd265ab
2 changed files with 7 additions and 12 deletions

View File

@ -53,9 +53,9 @@ public:
uint16_t getData() const; uint16_t getData() const;
bool put(TDATATYPE sample); bool put(const TDATATYPE item);
bool get(TDATATYPE& sample); bool get(TDATATYPE& item);
TDATATYPE peek() const; TDATATYPE peek() const;
@ -72,6 +72,6 @@ private:
bool m_overflow; bool m_overflow;
}; };
#include "RingBuffer.impl.h"
#endif #endif

View File

@ -56,7 +56,7 @@ template <typename TDATATYPE> uint16_t CRingBuffer<TDATATYPE>::getData() const
return m_length - m_tail + m_head; return m_length - m_tail + m_head;
} }
template <typename TDATATYPE> bool CRingBuffer<TDATATYPE>::put(TDATATYPE sample) template <typename TDATATYPE> bool CRingBuffer<TDATATYPE>::put(const TDATATYPE sample)
{ {
if (m_full) { if (m_full) {
m_overflow = true; m_overflow = true;
@ -80,12 +80,12 @@ template <typename TDATATYPE> TDATATYPE CRingBuffer<TDATATYPE>::peek() const
return m_buffer[m_tail]; return m_buffer[m_tail];
} }
template <typename TDATATYPE> bool CRingBuffer<TDATATYPE>::get(TDATATYPE& sample) template <typename TDATATYPE> bool CRingBuffer<TDATATYPE>::get(TDATATYPE& item)
{ {
if (m_head == m_tail && !m_full) if (m_head == m_tail && !m_full)
return false; return false;
sample = m_buffer[m_tail]; item = m_buffer[m_tail];
m_full = false; m_full = false;
@ -111,9 +111,4 @@ template <typename TDATATYPE> void CRingBuffer<TDATATYPE>::reset()
m_tail = 0U; m_tail = 0U;
m_full = false; m_full = false;
m_overflow = false; m_overflow = false;
} }
//Add here any declarations you need
template class CRingBuffer<uint8_t>;
template class CRingBuffer<q15_t>;
template class CRingBuffer<uint16_t>;