/** * @file * @brief FIFO buffer type. */ #ifndef STA_CORE_FIFO_BUFFER_HPP #define STA_CORE_FIFO_BUFFER_HPP namespace sta { /** * @brief FIFO buffer. * * @tparam Size Size type * @tparam N Buffer size * * @ingroup sta_core */ template class FifoBuffer { public: /** * @brief FIFO size type. */ using size_type = Size; /** * @brief Max number of bytes in FIFO. */ static constexpr size_type MAX_SIZE = N; public: /** * @brief Construct empty FIFO buffer. */ FifoBuffer(); /** * @brief Construct FIFO buffer with initial data. * * @param buffer Source buffer * @param size Buffer size */ FifoBuffer(const uint8_t * buffer, Size size); /** * @brief Clear buffer content. */ void clear(); /** * @brief Set data in buffer. * * @param buffer Source buffer * @param size Number of bytes to write */ void set(const uint8_t * buffer, size_type size); /** * @brief Append value to end of buffer. * * @param value Value */ void pushBack(uint8_t value); /** * @brief Append data to end of buffer. * * @param buffer Source buffer * @param size Number of bytes to write */ void pushBack(const uint8_t * buffer, size_type size); /** * @brief Append value repeatedly to end of buffer. * * @param value Fill value * @param count Repeat count */ void pushBack(uint8_t value, size_type count); /** * @brief Take data from start of buffer. * * @param buffer Destination buffer * @param size Number of bytes to read */ void popFront(uint8_t * buffer, size_type size); /** * @brief Get size of data in buffer. * * @return Data size */ size_type size() const; /** * @brief Check if buffer is full. * * @return True if buffer is full */ bool isFull() const; /** * @brief Check if buffer is empty. * * @return True if buffer is empty */ bool isEmpty() const; private: uint8_t * head_; /**< Read position */ uint8_t * tail_; /**< Write position */ uint8_t buffer_[N]; /**< Buffer data */ }; } // namespace sta #include #endif // STA_CORE_FIFO_BUFFER_HPP