#pragma once #include #include class DoubleBuffer { public: DoubleBuffer() : m_write_buffer(&m_buffer1) , m_read_buffer(&m_buffer2) { } ssize_t write(const byte*, size_t); ssize_t read(byte*, size_t); bool is_empty() const { return m_read_buffer_index >= m_read_buffer->size() && m_write_buffer->is_empty(); } private: void flip(); Vector* m_write_buffer { nullptr }; Vector* m_read_buffer { nullptr }; Vector m_buffer1; Vector m_buffer2; size_t m_read_buffer_index { 0 }; };