OS  v1.7.5
Documentation
Loading...
Searching...
No Matches
bytebuffer.hpp
1#ifndef QOS_BYTE_BUFFER
2#define QOS_BYTE_BUFFER
3
4#include "include/types.hpp"
5
6
7namespace qOS {
8
17 class byteBuffer {
18 private:
19 volatile byte_t *buffer{ nullptr };
20 volatile index_t tail{ 0U };
21 volatile index_t head{ 0U };
22 size_t length{ 0U };
23 static size_t checkValidPowerOfTwo( size_t k ) noexcept;
24 byteBuffer( byteBuffer const& ) = delete;
25 void operator=( byteBuffer const& ) = delete;
26 public:
28 virtual ~byteBuffer() {}
35 byteBuffer( volatile byte_t *pBuffer, const size_t bLength )
36 {
37 (void)setup( pBuffer, bLength );
38 }
39 template <size_t numberOfBytes>
40 byteBuffer( volatile byte_t (&area)[numberOfBytes] ) noexcept
41 {
42 (void)setup( area, numberOfBytes );
43 }
50 bool setup( volatile byte_t *pBuffer, const size_t bLength ) noexcept;
51 template <size_t numberOfBytes>
52 bool setup( volatile byte_t (&area)[numberOfBytes] ) noexcept // skipcq : CXX-W2066
53 {
54 return setup( area, numberOfBytes );
55 }
61 bool put( const byte_t bData ) noexcept;
68 bool read( void *dst, const size_t n ) noexcept;
75 bool get( byte_t *dst ) noexcept;
81 byte_t peek( void ) const noexcept;
87 bool isEmpty( void ) const noexcept;
93 bool isFull( void ) const noexcept;
98 size_t count( void ) const noexcept;
99 };
100
102}
103
104
105#endif /*QOS_BYTE_BUFFER*/
A Byte-sized buffer object.
Definition bytebuffer.hpp:17
bool isFull(void) const noexcept
Query the full status of the Byte-sized buffer.
bool setup(volatile byte_t(&area)[numberOfBytes]) noexcept
Definition bytebuffer.hpp:52
bool read(void *dst, const size_t n) noexcept
Gets n data from the Byte-sized buffer and removes them.
bool setup(volatile byte_t *pBuffer, const size_t bLength) noexcept
Initialize the Byte-sized buffer.
bool get(byte_t *dst) noexcept
Gets one data-byte from the front of the Byte-sized buffer, and removes it.
bool isEmpty(void) const noexcept
Query the empty status of the Byte-sized buffer.
bool put(const byte_t bData) noexcept
Adds an element of data to the Byte-sized buffer.
byteBuffer(volatile byte_t *pBuffer, const size_t bLength)
Initialize the Byte-sized buffer instance.
Definition bytebuffer.hpp:35
byteBuffer(volatile byte_t(&area)[numberOfBytes]) noexcept
Definition bytebuffer.hpp:40
byte_t peek(void) const noexcept
Looks for one byte from the head of the Byte-sized buffer without removing it.
size_t count(void) const noexcept
Query the number of elements in the Byte-sized buffer.
STD_TYPE_SIZE_T index_t
A type to instantiate an OS index variable. Can store the maximum size of a theoretically possible ob...
Definition types.hpp:94
STD_TYPE_UINT8_T byte_t
A type to instantiate a byte variable.
Definition types.hpp:67
OS/Kernel interfaces.
Definition bytebuffer.hpp:7