CircularBuffer implementation that does not perform allocations/deallocations outside of the constructor, destructor and resize methods. More...
#include <static_circular_buffer.h>
Public Types | |
typedef std::vector< T, Allocator > | VectorType |
Public Member Functions | |
size_t | capacity () const |
void | clear () |
clear Change the size of the buffer to 0 (not capacity) Only modifies internal iterators More... | |
T & | front () |
VectorType & | getBuffer () |
getBuffer Provides a reference to the internal data structure, use at your own risk. More... | |
void | pop_front () |
pop_front Reduces buffer size by one, advancing the begin iterator More... | |
T & | push_back () |
push_back Increases the buffer size (not capacity) by one, and returns a reference to the last item in the buffer. This item may have been used in the past More... | |
void | set_capacity (size_t max_size, const T &val) |
set_capacity Allocates memory for max_size copies of val More... | |
size_t | size () const |
StaticCircularBuffer () | |
StaticCircularBuffer (size_t max_size, const T &val, const Allocator &alloc=Allocator()) | |
Private Member Functions | |
void | advance (typename VectorType::iterator &it, size_t distance=1) |
Private Attributes | |
VectorType::iterator | begin_iterator_ |
VectorType | buffer_ |
VectorType::iterator | end_iterator_ |
bool | full_ |
CircularBuffer implementation that does not perform allocations/deallocations outside of the constructor, destructor and resize methods.
MIT License
Copyright (c) 2019 PAL Robotics S.L.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. The Buffer can only be used by reading/writing to the existing elements
Cannot use boost::circular_buffer because popping a vector destroys it and deallocates memory
Definition at line 41 of file static_circular_buffer.h.
typedef std::vector<T, Allocator> StaticCircularBuffer< T, Allocator >::VectorType |
Definition at line 44 of file static_circular_buffer.h.
|
inline |
Definition at line 46 of file static_circular_buffer.h.
|
inline |
Definition at line 52 of file static_circular_buffer.h.
|
inlineprivate |
Definition at line 147 of file static_circular_buffer.h.
|
inline |
Definition at line 81 of file static_circular_buffer.h.
|
inline |
clear Change the size of the buffer to 0 (not capacity) Only modifies internal iterators
Definition at line 62 of file static_circular_buffer.h.
|
inline |
Definition at line 96 of file static_circular_buffer.h.
|
inline |
getBuffer Provides a reference to the internal data structure, use at your own risk.
Definition at line 141 of file static_circular_buffer.h.
|
inline |
pop_front Reduces buffer size by one, advancing the begin iterator
Definition at line 128 of file static_circular_buffer.h.
|
inline |
push_back Increases the buffer size (not capacity) by one, and returns a reference to the last item in the buffer. This item may have been used in the past
If the buffer becomes full, the returned reference already contains an item
Definition at line 109 of file static_circular_buffer.h.
|
inline |
set_capacity Allocates memory for max_size copies of val
Resets | the beginning and end iterators, which reduces the size of the buffer to zero |
Definition at line 74 of file static_circular_buffer.h.
|
inline |
Definition at line 86 of file static_circular_buffer.h.
|
private |
Definition at line 157 of file static_circular_buffer.h.
|
private |
Definition at line 156 of file static_circular_buffer.h.
|
private |
Definition at line 158 of file static_circular_buffer.h.
|
private |
Definition at line 159 of file static_circular_buffer.h.