Click
Loading...
Searching...
No Matches
circularbuffer.hh
1/*
2 * circularbuffer.hh - Class used to represent a circular buffer with a dynamic size.
3 * The operations on it are O(1) and the buffer automatically grows to be able to store
4 * the data.
5 *
6 * Romain Gaillard.
7 */
8
9#ifndef MIDDLEBOX_CIRCULARBUFFER_HH
10#define MIDDLEBOX_CIRCULARBUFFER_HH
11
12#include <click/vector.hh>
13#include <click/bufferpool.hh>
14#include <click/bufferpoolnode.hh>
15
16CLICK_DECLS
17
24{
25public:
29 CircularBuffer(BufferPool* bufferPool);
30
35
39 uint32_t getSize();
40
44 uint32_t getCapacity();
45
51 uint32_t getStartOffset();
52
58 void setStartOffset(uint32_t startOffset);
59
63 bool isBlank();
64
69 void removeDataAtBeginning(uint32_t newStart);
70
75 void addDataAtEnd(const unsigned char* data, uint32_t length);
76
82 void getData(uint32_t start, uint32_t length, Vector<unsigned char> &getBuffer);
83
84private:
85 BufferPool* bufferPool;
86 BufferPoolNode* bufferNode;
87 uint32_t bufferStart; // Position in the buffer of the beginning of the data
88 uint32_t bufferEnd; // Position in the buffer of the end of the data
89 uint32_t startOffset;
90 uint32_t size; // Current size of the circular buffer (not necessarily the size of the
91 // buffer in the BufferPoolNode, which is the capacity instead).
92 bool blank;
93 bool useStartOffset; // Indicates whether we use the start offset or not
94
98 void increaseBufferSize(uint32_t addSize);
99};
100
101CLICK_ENDDECLS
102
103#endif
Class used to provide a pool of buffers that can have a dynamic size and be resized at any moment.
Definition bufferpool.hh:25
Class used to manage a buffer obtained via a BufferPool.
Definition bufferpoolnode.hh:21
Represents a ring buffer that automatically grows to be able to store the data and provides O(1) oper...
Definition circularbuffer.hh:24
uint32_t getSize()
Return the size of the circular buffer (the size of the data in it)
Definition circularbuffer.cc:65
void addDataAtEnd(const unsigned char *data, uint32_t length)
Add data at the end of the buffer.
Definition circularbuffer.cc:101
void getData(uint32_t start, uint32_t length, Vector< unsigned char > &getBuffer)
Retrieve data from the buffer.
Definition circularbuffer.cc:160
void setStartOffset(uint32_t startOffset)
Set the start offset. Offset of the first byte in the buffer. Used to be able to manipulate sequence ...
Definition circularbuffer.cc:143
uint32_t getStartOffset()
Return the start offset. Offset of the first byte in the buffer. Used to be able to manipulate sequen...
Definition circularbuffer.cc:149
uint32_t getCapacity()
Return the capacity of the circular buffer (the size of the memory chunk it uses)
Definition circularbuffer.cc:70
~CircularBuffer()
Destruct a CircularBuffer Put the buffer back into the BufferPool.
Definition circularbuffer.cc:29
void removeDataAtBeginning(uint32_t newStart)
Remove data at the beginning of the buffer.
Definition circularbuffer.cc:75
bool isBlank()
Indicate whether the buffer is blank.
Definition circularbuffer.cc:154
Vector template.
Definition vector.hh:111
Click's vector container template.