Libftpp
A modern C++ library
ring_buffer.hpp
Go to the documentation of this file.
1 #ifndef RING_BUFFER_HPP
2 #define RING_BUFFER_HPP
3 
4 #include <stddef.h>
5 
6 #include <iostream>
7 #include <stdexcept>
8 #include <vector>
9 
10 #define MAX_BUFFER_SIZE 65550 // 16 KB
11 
43 {
44 private:
45  std::vector<unsigned char> _buffer;
46  size_t _head;
47  size_t _tail;
48  size_t _size;
49 
50 public:
51  RingBuffer();
52  RingBuffer(const size_t& size_buffer);
53 
54  void push(const unsigned char& byte);
55  void push(const std::string& line);
56  void push(const std::vector<unsigned char>& bytes);
57  void pushInto(const void* data, const size_t& size);
58 
59  unsigned char pop();
60  std::vector<unsigned char> pop(const size_t& size);
61  void popInto(void* data, const size_t& size);
62 
63  unsigned char peek() const;
64  std::vector<unsigned char> peek(const size_t& size) const;
65 
66  void clear();
67 
68  bool isEmpty() const;
69  bool isFull() const;
70  size_t size() const;
71  size_t capacity() const;
72  size_t capacityAvailable() const;
73 };
74 
75 #endif
RingBuffer class for managing a circular buffer of bytes. It provides methods to push and pop bytes,...
Definition: ring_buffer.hpp:43
bool isEmpty() const
void push(const unsigned char &byte)
Definition: ring_buffer.cpp:18
size_t size() const
bool isFull() const
unsigned char peek() const
void clear()
unsigned char pop()
Definition: ring_buffer.cpp:44
void popInto(void *data, const size_t &size)
Definition: ring_buffer.cpp:87
size_t capacity() const
void pushInto(const void *data, const size_t &size)
Definition: ring_buffer.cpp:73
size_t capacityAvailable() const