Leosac  0.8.0
Open Source Access Control
circularbuffer.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014-2016 Leosac
3 
4  This file is part of Leosac.
5 
6  Leosac is free software: you can redistribute it and/or modify
7  it under the terms of the GNU Affero General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Leosac is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Affero General Public License for more details.
15 
16  You should have received a copy of the GNU Affero General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
26 #ifndef CIRCULARBUFFER_HPP
27 #define CIRCULARBUFFER_HPP
28 
29 #include <string>
30 #include <vector>
31 
32 #include "tools/bufferutils.hpp"
33 
34 namespace Leosac
35 {
36 namespace Module
37 {
38 namespace Rpleth
39 {
44 {
45  static const std::size_t DefaultSize = 8192;
46 
47  public:
48  CircularBuffer(std::size_t size = DefaultSize);
49 
50  ~CircularBuffer() = default;
51 
52  public:
53  std::size_t read(Byte *data, std::size_t size);
54 
55  std::size_t write(const Byte *data, std::size_t size);
56 
57  Byte operator[](int idx) const;
58 
59  void fastForward(std::size_t offset);
60 
61  void reset();
62 
63  std::size_t getSize() const;
64 
65  std::size_t toRead() const;
66 
67  bool isEmpty() const;
68 
69  private:
70  std::vector<Byte> _buffer;
71  std::size_t _size;
72  std::size_t _rIdx;
73  std::size_t _wIdx;
74  std::size_t _toRead;
75 };
76 }
77 }
78 }
79 #endif // CIRCULARBUFFER_HPP
Leosac::Module::Rpleth::CircularBuffer::CircularBuffer
CircularBuffer(std::size_t size=DefaultSize)
Definition: circularbuffer.cpp:32
Leosac::Module::Rpleth::CircularBuffer::operator[]
Byte operator[](int idx) const
Definition: circularbuffer.cpp:76
Leosac::Module::Rpleth::CircularBuffer::read
std::size_t read(Byte *data, std::size_t size)
Definition: circularbuffer.cpp:41
Leosac::Module::Rpleth::CircularBuffer::isEmpty
bool isEmpty() const
Definition: circularbuffer.cpp:106
Leosac::Module::Rpleth::CircularBuffer::~CircularBuffer
~CircularBuffer()=default
Leosac
This is the header file for a generated source file, GitSHA1.cpp.
Definition: APIStatusCode.hpp:22
Leosac::Module::Rpleth::CircularBuffer::fastForward
void fastForward(std::size_t offset)
Definition: circularbuffer.cpp:81
Leosac::Module::Rpleth::CircularBuffer::_size
std::size_t _size
Definition: circularbuffer.hpp:71
Leosac::Module::Rpleth::CircularBuffer::_toRead
std::size_t _toRead
Definition: circularbuffer.hpp:74
Leosac::Module::Rpleth::CircularBuffer::reset
void reset()
Definition: circularbuffer.cpp:89
Leosac::Module::Rpleth::CircularBuffer::_wIdx
std::size_t _wIdx
Definition: circularbuffer.hpp:73
Leosac::Module::Rpleth::CircularBuffer::toRead
std::size_t toRead() const
Definition: circularbuffer.cpp:101
Leosac::Module::Rpleth::CircularBuffer::DefaultSize
static const std::size_t DefaultSize
Definition: circularbuffer.hpp:45
bufferutils.hpp
buffer-related helper functions
Leosac::Module::Rpleth::CircularBuffer
Implementation of a ring buffer.
Definition: circularbuffer.hpp:43
Leosac::Module::Rpleth::CircularBuffer::_buffer
std::vector< Byte > _buffer
Definition: circularbuffer.hpp:70
Leosac::Module::Rpleth::CircularBuffer::write
std::size_t write(const Byte *data, std::size_t size)
Definition: circularbuffer.cpp:61
Leosac::Module::Rpleth::CircularBuffer::getSize
std::size_t getSize() const
Definition: circularbuffer.cpp:96
Byte
std::uint8_t Byte
Definition: bufferutils.hpp:31
Leosac::Module::Rpleth::CircularBuffer::_rIdx
std::size_t _rIdx
Definition: circularbuffer.hpp:72