Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
StaticCircularBuffer< T, Allocator > Class Template Reference

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 ()
 
VectorTypegetBuffer ()
 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_
 

Detailed Description

template<typename T, typename Allocator = std::allocator<T>>
class StaticCircularBuffer< T, Allocator >

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.

Member Typedef Documentation

◆ VectorType

template<typename T , typename Allocator = std::allocator<T>>
typedef std::vector<T, Allocator> StaticCircularBuffer< T, Allocator >::VectorType

Definition at line 44 of file static_circular_buffer.h.

Constructor & Destructor Documentation

◆ StaticCircularBuffer() [1/2]

template<typename T , typename Allocator = std::allocator<T>>
StaticCircularBuffer< T, Allocator >::StaticCircularBuffer ( size_t  max_size,
const T &  val,
const Allocator &  alloc = Allocator() 
)
inline

Definition at line 46 of file static_circular_buffer.h.

◆ StaticCircularBuffer() [2/2]

template<typename T , typename Allocator = std::allocator<T>>
StaticCircularBuffer< T, Allocator >::StaticCircularBuffer ( )
inline

Definition at line 52 of file static_circular_buffer.h.

Member Function Documentation

◆ advance()

template<typename T , typename Allocator = std::allocator<T>>
void StaticCircularBuffer< T, Allocator >::advance ( typename VectorType::iterator &  it,
size_t  distance = 1 
)
inlineprivate

Definition at line 147 of file static_circular_buffer.h.

◆ capacity()

template<typename T , typename Allocator = std::allocator<T>>
size_t StaticCircularBuffer< T, Allocator >::capacity ( ) const
inline

Definition at line 81 of file static_circular_buffer.h.

◆ clear()

template<typename T , typename Allocator = std::allocator<T>>
void StaticCircularBuffer< T, Allocator >::clear ( )
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.

◆ front()

template<typename T , typename Allocator = std::allocator<T>>
T& StaticCircularBuffer< T, Allocator >::front ( )
inline

Definition at line 96 of file static_circular_buffer.h.

◆ getBuffer()

template<typename T , typename Allocator = std::allocator<T>>
VectorType& StaticCircularBuffer< T, Allocator >::getBuffer ( )
inline

getBuffer Provides a reference to the internal data structure, use at your own risk.

Returns

Definition at line 141 of file static_circular_buffer.h.

◆ pop_front()

template<typename T , typename Allocator = std::allocator<T>>
void StaticCircularBuffer< T, Allocator >::pop_front ( )
inline

pop_front Reduces buffer size by one, advancing the begin iterator

Definition at line 128 of file static_circular_buffer.h.

◆ push_back()

template<typename T , typename Allocator = std::allocator<T>>
T& StaticCircularBuffer< T, Allocator >::push_back ( )
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.

◆ set_capacity()

template<typename T , typename Allocator = std::allocator<T>>
void StaticCircularBuffer< T, Allocator >::set_capacity ( size_t  max_size,
const T &  val 
)
inline

set_capacity Allocates memory for max_size copies of val

Parameters
Resetsthe beginning and end iterators, which reduces the size of the buffer to zero

Definition at line 74 of file static_circular_buffer.h.

◆ size()

template<typename T , typename Allocator = std::allocator<T>>
size_t StaticCircularBuffer< T, Allocator >::size ( ) const
inline

Definition at line 86 of file static_circular_buffer.h.

Member Data Documentation

◆ begin_iterator_

template<typename T , typename Allocator = std::allocator<T>>
VectorType::iterator StaticCircularBuffer< T, Allocator >::begin_iterator_
private

Definition at line 157 of file static_circular_buffer.h.

◆ buffer_

template<typename T , typename Allocator = std::allocator<T>>
VectorType StaticCircularBuffer< T, Allocator >::buffer_
private

Definition at line 156 of file static_circular_buffer.h.

◆ end_iterator_

template<typename T , typename Allocator = std::allocator<T>>
VectorType::iterator StaticCircularBuffer< T, Allocator >::end_iterator_
private

Definition at line 158 of file static_circular_buffer.h.

◆ full_

template<typename T , typename Allocator = std::allocator<T>>
bool StaticCircularBuffer< T, Allocator >::full_
private

Definition at line 159 of file static_circular_buffer.h.


The documentation for this class was generated from the following file:


pal_statistics
Author(s):
autogenerated on Fri Aug 2 2024 08:29:35