diff --git a/inc/Logger.h b/inc/Logger.h new file mode 100644 index 0000000..cdc57d0 --- /dev/null +++ b/inc/Logger.h @@ -0,0 +1,6 @@ +#pragma once +#include "cstdio" + +#define write_log(format,args...) do { \ + printf(format, ## args); \ + } while(0) diff --git a/src/RingBuffer.cpp b/src/RingBuffer.cpp index 41619fe..d081a0b 100644 --- a/src/RingBuffer.cpp +++ b/src/RingBuffer.cpp @@ -1,4 +1,5 @@ #include "RingBuffer.h" +#include "Logger.h" template RingBuffer::RingBuffer(std::size_t size) { @@ -24,7 +25,7 @@ template void RingBuffer::Reset() template void RingBuffer::advance_pointer() { - if(m_is_full) { + if (m_is_full) { m_tail++; if (m_tail == m_size) { m_tail = 0; @@ -50,11 +51,10 @@ template void RingBuffer::retreat_pointer() template void RingBuffer::Write(T* data, std::size_t count) { if (m_is_full || m_head + count > m_size) { - //todo: implement - // write_log("[WARN] Trying to overfill the ring buffer: \n\tIsFull:%d\n\tHead:%zu\n\tCount:%zu\n\t", - // m_is_full, - // m_head, - // count); + write_log("[WARN] Trying to overfill the ring buffer: \n\tIsFull:%d\n\tHead:%zu\n\tCount:%zu\n\t", + m_is_full, + m_head, + count); return; } m_is_empty = 0; @@ -69,8 +69,7 @@ template void RingBuffer::Write(T* data, std::size_t count) template bool RingBuffer::Read(T* output, std::size_t count) { if (m_is_empty) { - //todo: implement - //write_log("[WARN] Trying to read empty buffer"); + write_log("[WARN] Trying to read empty buffer"); return 0; } @@ -97,11 +96,11 @@ template std::size_t RingBuffer::GetSize() return p_size; } -template void RingBuffer::Print() { - //todo: implement - // write_log("[INFO] The ring buffer: \n\tIsFull:%d\n\tIsEmpty:%d\n\tHead:%zu\n\tTail:%zu\n\t", - // me->m_is_full, - // me->m_is_empty, - // me->m_head, - // me->m_tail); +template void RingBuffer::Print() +{ + write_log("[INFO] The ring buffer: \n\tIsFull:%d\n\tIsEmpty:%d\n\tHead:%zu\n\tTail:%zu\n\t", + m_is_full, + m_is_empty, + m_head, + m_tail); } \ No newline at end of file