TwiceAsNice
2019-02-18
|
Circular buffer - a STL compliant container. More...
#include <base.hpp>
Public Types | |
typedef Alloc::value_type | value_type |
The type of elements stored in the circular_buffer . More... | |
typedef Alloc::pointer | pointer |
A pointer to an element. More... | |
typedef Alloc::const_pointer | const_pointer |
A const pointer to the element. More... | |
typedef Alloc::reference | reference |
A reference to an element. More... | |
typedef Alloc::const_reference | const_reference |
A const reference to an element. More... | |
typedef Alloc::difference_type | difference_type |
The distance type. More... | |
typedef Alloc::size_type | size_type |
The size type. More... | |
typedef Alloc | allocator_type |
The type of an allocator used in the circular_buffer . More... | |
typedef cb_details::iterator< circular_buffer< T, Alloc >, cb_details::const_traits< Alloc > > | const_iterator |
A const (random access) iterator used to iterate through the circular_buffer . More... | |
typedef cb_details::iterator< circular_buffer< T, Alloc >, cb_details::nonconst_traits< Alloc > > | iterator |
A (random access) iterator used to iterate through the circular_buffer . More... | |
typedef boost::reverse_iterator< const_iterator > | const_reverse_iterator |
A const iterator used to iterate backwards through a circular_buffer . More... | |
typedef boost::reverse_iterator< iterator > | reverse_iterator |
An iterator used to iterate backwards through a circular_buffer . More... | |
typedef std::pair< pointer, size_type > | array_range |
An array range. More... | |
typedef std::pair< const_pointer, size_type > | const_array_range |
A range of a const array. More... | |
typedef size_type | capacity_type |
The capacity type. More... | |
typedef call_traits< value_type >::param_type | param_value_type |
typedef call_traits< value_type >::param_type | return_value_type |
Public Member Functions | |
allocator_type | get_allocator () const |
Get the allocator. More... | |
allocator_type & | get_allocator () |
Get the allocator reference. More... | |
iterator | begin () |
Get the iterator pointing to the beginning of the circular_buffer . More... | |
iterator | end () |
Get the iterator pointing to the end of the circular_buffer . More... | |
const_iterator | begin () const |
Get the const iterator pointing to the beginning of the circular_buffer . More... | |
const_iterator | end () const |
Get the const iterator pointing to the end of the circular_buffer . More... | |
reverse_iterator | rbegin () |
Get the iterator pointing to the beginning of the "reversed" circular_buffer . More... | |
reverse_iterator | rend () |
Get the iterator pointing to the end of the "reversed" circular_buffer . More... | |
const_reverse_iterator | rbegin () const |
Get the const iterator pointing to the beginning of the "reversed" circular_buffer . More... | |
const_reverse_iterator | rend () const |
Get the const iterator pointing to the end of the "reversed" circular_buffer . More... | |
reference | operator[] (size_type index) |
Get the element at the index position. More... | |
return_value_type | operator[] (size_type index) const |
Get the element at the index position. More... | |
reference | at (size_type index) |
Get the element at the index position. More... | |
return_value_type | at (size_type index) const |
Get the element at the index position. More... | |
reference | front () |
Get the first element. More... | |
reference | back () |
Get the last element. More... | |
return_value_type | front () const |
Get the first element. More... | |
return_value_type | back () const |
Get the last element. More... | |
array_range | array_one () |
Get the first continuous array of the internal buffer. More... | |
array_range | array_two () |
Get the second continuous array of the internal buffer. More... | |
const_array_range | array_one () const |
Get the first continuous array of the internal buffer. More... | |
const_array_range | array_two () const |
Get the second continuous array of the internal buffer. More... | |
pointer | linearize () |
Linearize the internal buffer into a continuous array. More... | |
size_type | size () const |
Get the number of elements currently stored in the circular_buffer . More... | |
size_type | max_size () const |
Get the largest possible size or capacity of the circular_buffer . (It depends on allocator's max_size()). More... | |
bool | empty () const |
Is the circular_buffer empty? More... | |
bool | full () const |
Is the circular_buffer full? More... | |
size_type | reserve () const |
Get the maximum number of elements which can be inserted into the circular_buffer without overwriting any of already stored elements. More... | |
capacity_type | capacity () const |
Get the capacity of the circular_buffer . More... | |
void | set_capacity (capacity_type new_capacity) |
Change the capacity of the circular_buffer . More... | |
void | resize (size_type new_size, param_value_type item=value_type()) |
Change the size of the circular_buffer . More... | |
void | rset_capacity (capacity_type new_capacity) |
Change the capacity of the circular_buffer . More... | |
void | rresize (size_type new_size, param_value_type item=value_type()) |
Change the size of the circular_buffer . More... | |
circular_buffer (const allocator_type &alloc=allocator_type()) | |
Create an empty circular_buffer with a maximum capacity. More... | |
circular_buffer (capacity_type capacity, const allocator_type &alloc=allocator_type()) | |
Create an empty circular_buffer with the specified capacity. More... | |
circular_buffer (size_type n, param_value_type item, const allocator_type &alloc=allocator_type()) | |
Create a full circular_buffer with the specified capacity and filled with n copies of item . More... | |
circular_buffer (capacity_type capacity, size_type n, param_value_type item, const allocator_type &alloc=allocator_type()) | |
Create a circular_buffer with the specified capacity and filled with n copies of item . More... | |
circular_buffer (const circular_buffer< T, Alloc > &cb) | |
The copy constructor. More... | |
template<class InputIterator > | |
circular_buffer (InputIterator first, InputIterator last, const allocator_type &alloc=allocator_type()) | |
Create a full circular_buffer filled with a copy of the range. More... | |
template<class InputIterator > | |
circular_buffer (capacity_type capacity, InputIterator first, InputIterator last, const allocator_type &alloc=allocator_type()) | |
Create a circular_buffer with the specified capacity and filled with a copy of the range. More... | |
~circular_buffer () | |
The destructor. More... | |
circular_buffer< T, Alloc > & | operator= (const circular_buffer< T, Alloc > &cb) |
The assign operator. More... | |
void | assign (size_type n, param_value_type item) |
Assign n items into the circular_buffer . More... | |
void | assign (capacity_type capacity, size_type n, param_value_type item) |
Assign n items into the circular_buffer specifying the capacity. More... | |
template<class InputIterator > | |
void | assign (InputIterator first, InputIterator last) |
Assign a copy of the range into the circular_buffer . More... | |
template<class InputIterator > | |
void | assign (capacity_type capacity, InputIterator first, InputIterator last) |
Assign a copy of the range into the circular_buffer specifying the capacity. More... | |
void | swap (circular_buffer< T, Alloc > &cb) |
Swap the contents of two circular_buffer s. More... | |
void | push_back (param_value_type item=value_type()) |
Insert a new element at the end of the circular_buffer . More... | |
void | push_front (param_value_type item=value_type()) |
Insert a new element at the beginning of the circular_buffer . More... | |
void | pop_back () |
Remove the last element from the circular_buffer . More... | |
void | pop_front () |
Remove the first element from the circular_buffer . More... | |
iterator | insert (iterator pos, param_value_type item=value_type()) |
Insert an element at the specified position. More... | |
void | insert (iterator pos, size_type n, param_value_type item) |
Insert n copies of the item at the specified position. More... | |
template<class InputIterator > | |
void | insert (iterator pos, InputIterator first, InputIterator last) |
Insert the range [first, last) at the specified position. More... | |
iterator | rinsert (iterator pos, param_value_type item=value_type()) |
Insert an element before the specified position. More... | |
void | rinsert (iterator pos, size_type n, param_value_type item) |
Insert n copies of the item before the specified position. More... | |
template<class InputIterator > | |
void | rinsert (iterator pos, InputIterator first, InputIterator last) |
Insert the range [first, last) before the specified position. More... | |
iterator | erase (iterator pos) |
Remove an element at the specified position. More... | |
iterator | erase (iterator first, iterator last) |
Erase the range [first, last) . More... | |
iterator | rerase (iterator pos) |
Remove an element at the specified position. More... | |
iterator | rerase (iterator first, iterator last) |
Erase the range [first, last) . More... | |
void | clear () |
Remove all stored elements from the circular_buffer . More... | |
Private Member Functions | |
BOOST_CLASS_REQUIRE (T, boost, SGIAssignableConcept) | |
void | check_position (size_type index) const |
Check if the index is valid. More... | |
template<class Pointer > | |
void | increment (Pointer &p) const |
Increment the pointer. More... | |
template<class Pointer > | |
void | decrement (Pointer &p) const |
Decrement the pointer. More... | |
template<class Pointer > | |
Pointer | add (Pointer p, difference_type n) const |
Add n to the pointer. More... | |
template<class Pointer > | |
Pointer | sub (Pointer p, difference_type n) const |
Subtract n from the pointer. More... | |
pointer | map_pointer (pointer p) const |
Map the null pointer to virtual end of circular buffer. More... | |
pointer | allocate (size_type n) |
Allocate memory. More... | |
void | deallocate (pointer p, size_type n) |
Deallocate memory. More... | |
bool | is_uninitialized (const_pointer p) const |
Does the pointer point to the uninitialized memory? More... | |
void | replace (pointer pos, param_value_type item) |
Replace an element. More... | |
void | construct_or_replace (bool construct, pointer pos, param_value_type item) |
Construct or replace an element. More... | |
void | destroy_item (pointer p) |
Destroy an item. More... | |
void | destroy_if_constructed (pointer pos) |
Destroy an item only if it has been constructed. More... | |
void | destroy_content () |
Destroy the whole content of the circular buffer. More... | |
void | destroy () |
Destroy content and free allocated memory. More... | |
void | initialize (capacity_type capacity) |
Initialize the circular buffer. More... | |
void | initialize (capacity_type capacity, param_value_type item) |
Initialize the circular buffer. More... | |
template<class IntegralType > | |
void | initialize (IntegralType n, IntegralType item, const true_type &) |
Specialized initialize method. More... | |
template<class Iterator > | |
void | initialize (Iterator first, Iterator last, const false_type &) |
Specialized initialize method. More... | |
template<class InputIterator > | |
void | initialize (InputIterator first, InputIterator last, const std::input_iterator_tag &) |
Specialized initialize method. More... | |
template<class ForwardIterator > | |
void | initialize (ForwardIterator first, ForwardIterator last, const std::forward_iterator_tag &) |
Specialized initialize method. More... | |
template<class IntegralType > | |
void | initialize (capacity_type capacity, IntegralType n, IntegralType item, const true_type &) |
Specialized initialize method. More... | |
template<class Iterator > | |
void | initialize (capacity_type capacity, Iterator first, Iterator last, const false_type &) |
Specialized initialize method. More... | |
template<class InputIterator > | |
void | initialize (capacity_type capacity, InputIterator first, InputIterator last, const std::input_iterator_tag &) |
Specialized initialize method. More... | |
template<class ForwardIterator > | |
void | initialize (capacity_type capacity, ForwardIterator first, ForwardIterator last, const std::forward_iterator_tag &) |
Specialized initialize method. More... | |
template<class ForwardIterator > | |
void | initialize (capacity_type capacity, ForwardIterator first, ForwardIterator last, size_type distance) |
Helper initialize method. More... | |
void | reset (pointer buff, pointer last, capacity_type new_capacity) |
Reset the circular buffer. More... | |
void | swap_allocator (circular_buffer< T, Alloc > &cb, const true_type &) |
Specialized method for swapping the allocator. More... | |
void | swap_allocator (circular_buffer< T, Alloc > &cb, const false_type &) |
Specialized method for swapping the allocator. More... | |
template<class IntegralType > | |
void | assign (IntegralType n, IntegralType item, const true_type &) |
Specialized assign method. More... | |
template<class Iterator > | |
void | assign (Iterator first, Iterator last, const false_type &) |
Specialized assign method. More... | |
template<class InputIterator > | |
void | assign (InputIterator first, InputIterator last, const std::input_iterator_tag &) |
Specialized assign method. More... | |
template<class ForwardIterator > | |
void | assign (ForwardIterator first, ForwardIterator last, const std::forward_iterator_tag &) |
Specialized assign method. More... | |
template<class IntegralType > | |
void | assign (capacity_type new_capacity, IntegralType n, IntegralType item, const true_type &) |
Specialized assign method. More... | |
template<class Iterator > | |
void | assign (capacity_type new_capacity, Iterator first, Iterator last, const false_type &) |
Specialized assign method. More... | |
template<class InputIterator > | |
void | assign (capacity_type new_capacity, InputIterator first, InputIterator last, const std::input_iterator_tag &) |
Specialized assign method. More... | |
template<class ForwardIterator > | |
void | assign (capacity_type new_capacity, ForwardIterator first, ForwardIterator last, const std::forward_iterator_tag &) |
Specialized assign method. More... | |
template<class Functor > | |
void | assign_n (capacity_type new_capacity, size_type n, const Functor &fnc) |
Helper assign method. More... | |
iterator | insert_item (const iterator &pos, param_value_type item) |
Helper insert method. More... | |
template<class IntegralType > | |
void | insert (const iterator &pos, IntegralType n, IntegralType item, const true_type &) |
Specialized insert method. More... | |
template<class Iterator > | |
void | insert (const iterator &pos, Iterator first, Iterator last, const false_type &) |
Specialized insert method. More... | |
template<class InputIterator > | |
void | insert (iterator pos, InputIterator first, InputIterator last, const std::input_iterator_tag &) |
Specialized insert method. More... | |
template<class ForwardIterator > | |
void | insert (const iterator &pos, ForwardIterator first, ForwardIterator last, const std::forward_iterator_tag &) |
Specialized insert method. More... | |
template<class Wrapper > | |
void | insert_n (const iterator &pos, size_type n, const Wrapper &wrapper) |
Helper insert method. More... | |
template<class IntegralType > | |
void | rinsert (const iterator &pos, IntegralType n, IntegralType item, const true_type &) |
Specialized rinsert method. More... | |
template<class Iterator > | |
void | rinsert (const iterator &pos, Iterator first, Iterator last, const false_type &) |
Specialized rinsert method. More... | |
template<class InputIterator > | |
void | rinsert (iterator pos, InputIterator first, InputIterator last, const std::input_iterator_tag &) |
Specialized insert method. More... | |
template<class ForwardIterator > | |
void | rinsert (const iterator &pos, ForwardIterator first, ForwardIterator last, const std::forward_iterator_tag &) |
Specialized rinsert method. More... | |
template<class Wrapper > | |
void | rinsert_n (const iterator &pos, size_type n, const Wrapper &wrapper) |
Helper rinsert method. More... | |
Private Attributes | |
pointer | m_buff |
The internal buffer used for storing elements in the circular buffer. More... | |
pointer | m_end |
The internal buffer's end (end of the storage space). More... | |
pointer | m_first |
The virtual beginning of the circular buffer. More... | |
pointer | m_last |
The virtual end of the circular buffer (one behind the last element). More... | |
size_type | m_size |
The number of items currently stored in the circular buffer. More... | |
allocator_type | m_alloc |
The allocator. More... | |
Friends | |
template<class Buff , class Traits > | |
struct | cb_details::iterator |
Circular buffer - a STL compliant container.
T | The type of the elements stored in the circular_buffer . |
T
has to be SGIAssignable (SGI STL defined combination of Assignable and CopyConstructible). Moreover T
has to be DefaultConstructible if supplied as a default parameter when invoking some of the circular_buffer
's methods e.g. insert(iterator pos, const value_type& item = value_type())
. And EqualityComparable and/or LessThanComparable if the circular_buffer
will be compared with another container. Alloc | The allocator type used for all internal memory management. |
Alloc
has to meet the allocator requirements imposed by STL. For detailed documentation of the circular_buffer visit: http://www.boost.org/libs/circular_buffer/doc/circular_buffer.html
typedef Alloc boost::circular_buffer< T, Alloc >::allocator_type |
The type of an allocator used in the circular_buffer
.
typedef std::pair<pointer, size_type> boost::circular_buffer< T, Alloc >::array_range |
An array range.
(A typedef for the std::pair
where its first element is a pointer to a beginning of an array and its second element represents a size of the array.)
typedef size_type boost::circular_buffer< T, Alloc >::capacity_type |
The capacity type.
(Same as size_type
- defined for consistency with the circular_buffer_space_optimized
.)
typedef std::pair<const_pointer, size_type> boost::circular_buffer< T, Alloc >::const_array_range |
A range of a const array.
(A typedef for the std::pair
where its first element is a pointer to a beginning of a const array and its second element represents a size of the const array.)
typedef cb_details::iterator< circular_buffer<T, Alloc>, cb_details::const_traits<Alloc> > boost::circular_buffer< T, Alloc >::const_iterator |
A const (random access) iterator used to iterate through the circular_buffer
.
typedef Alloc::const_pointer boost::circular_buffer< T, Alloc >::const_pointer |
A const pointer to the element.
typedef Alloc::const_reference boost::circular_buffer< T, Alloc >::const_reference |
A const reference to an element.
typedef boost::reverse_iterator<const_iterator> boost::circular_buffer< T, Alloc >::const_reverse_iterator |
A const iterator used to iterate backwards through a circular_buffer
.
typedef Alloc::difference_type boost::circular_buffer< T, Alloc >::difference_type |
The distance type.
(A signed integral type used to represent the distance between two iterators.)
typedef cb_details::iterator< circular_buffer<T, Alloc>, cb_details::nonconst_traits<Alloc> > boost::circular_buffer< T, Alloc >::iterator |
A (random access) iterator used to iterate through the circular_buffer
.
typedef call_traits<value_type>::param_type boost::circular_buffer< T, Alloc >::param_value_type |
typedef Alloc::pointer boost::circular_buffer< T, Alloc >::pointer |
A pointer to an element.
typedef Alloc::reference boost::circular_buffer< T, Alloc >::reference |
A reference to an element.
typedef call_traits<value_type>::param_type boost::circular_buffer< T, Alloc >::return_value_type |
typedef boost::reverse_iterator<iterator> boost::circular_buffer< T, Alloc >::reverse_iterator |
An iterator used to iterate backwards through a circular_buffer
.
typedef Alloc::size_type boost::circular_buffer< T, Alloc >::size_type |
The size type.
(An unsigned integral type that can represent any non-negative value of the container's distance type.)
typedef Alloc::value_type boost::circular_buffer< T, Alloc >::value_type |
The type of elements stored in the circular_buffer
.
|
inlineexplicit |
Create an empty circular_buffer
with a maximum capacity.
capacity() == max_size() && size() == 0
alloc | The allocator. |
An allocation error | if memory is exhausted (std::bad_alloc if the standard allocator is used). |
|
inlineexplicit |
Create an empty circular_buffer
with the specified capacity.
capacity() == capacity && size() == 0
capacity | The maximum number of elements which can be stored in the circular_buffer . |
alloc | The allocator. |
An allocation error | if memory is exhausted (std::bad_alloc if the standard allocator is used). |
|
inline |
Create a full circular_buffer
with the specified capacity and filled with n
copies of item
.
capacity() == n && full() && (*this)[0] == item && (*this)[1] == item && ... && (*this)[n - 1] == item
n | The number of elements the created circular_buffer will be filled with. |
item | The element the created circular_buffer will be filled with. |
alloc | The allocator. |
An allocation error | if memory is exhausted (std::bad_alloc if the standard allocator is used). |
Whatever | T::T(const T&) throws. |
n
).
|
inline |
Create a circular_buffer
with the specified capacity and filled with n
copies of item
.
capacity >= n
capacity() == capacity && size() == n && (*this)[0] == item && (*this)[1] == item && ... && (*this)[n - 1] == item
capacity | The capacity of the created circular_buffer . |
n | The number of elements the created circular_buffer will be filled with. |
item | The element the created circular_buffer will be filled with. |
alloc | The allocator. |
An allocation error | if memory is exhausted (std::bad_alloc if the standard allocator is used). |
Whatever | T::T(const T&) throws. |
n
).
|
inline |
The copy constructor.
Creates a copy of the specified circular_buffer
.
*this == cb
cb | The circular_buffer to be copied. |
An allocation error | if memory is exhausted (std::bad_alloc if the standard allocator is used). |
Whatever | T::T(const T&) throws. |
cb
).
|
inline |
Create a full circular_buffer
filled with a copy of the range.
[first, last)
.first
and last
have to meet the requirements of InputIterator. capacity() == std::distance(first, last) && full() && (*this)[0]== *first && (*this)[1] == *(first + 1) && ... && (*this)[std::distance(first, last) - 1] == *(last - 1)
first | The beginning of the range to be copied. |
last | The end of the range to be copied. |
alloc | The allocator. |
An allocation error | if memory is exhausted (std::bad_alloc if the standard allocator is used). |
Whatever | T::T(const T&) throws. |
std::distance(first, last)
).
|
inline |
Create a circular_buffer
with the specified capacity and filled with a copy of the range.
[first, last)
.first
and last
have to meet the requirements of InputIterator. capacity() == capacity && size() <= std::distance(first, last) && (*this)[0]== *(last - capacity) && (*this)[1] == *(last - capacity + 1) && ... && (*this)[capacity - 1] == *(last - 1)
[first, last)
is greater than the specified capacity
then only elements from the range [last - capacity, last)
will be copied. capacity | The capacity of the created circular_buffer . |
first | The beginning of the range to be copied. |
last | The end of the range to be copied. |
alloc | The allocator. |
An allocation error | if memory is exhausted (std::bad_alloc if the standard allocator is used). |
Whatever | T::T(const T&) throws. |
std::distance(first, last)
; in min[capacity, std::distance(first, last)]
if the InputIterator
is a RandomAccessIterator).
|
inline |
The destructor.
Destroys the circular_buffer
.
Nothing. |
circular_buffer
(including iterators equal to end()
). circular_buffer
). clear()
|
inlineprivate |
Add n
to the pointer.
|
inlineprivate |
Allocate memory.
|
inline |
Get the first continuous array of the internal buffer.
This method in combination with array_two()
can be useful when passing the stored data into a legacy C API as an array. Suppose there is a circular_buffer
of capacity 10, containing 7 characters 'a', 'b', ..., 'g'
where buff[0] == 'a'
, buff[1] == 'b'
, ... and buff[6] == 'g'
:
circular_buffer<char> buff(10);
The internal representation is often not linear and the state of the internal buffer may look like this:
|e|f|g| | | |a|b|c|d|
end —^
begin ----—^
where |a|b|c|d|
represents the "array one", |e|f|g|
represents the "array two" and | | | |
is a free space.
Now consider a typical C style function for writing data into a file:
int write(int file_desc, char* buff, int num_bytes);
There are two ways how to write the content of the circular_buffer
into a file. Either relying on array_one()
and array_two()
methods and calling the write function twice:
array_range ar = buff.array_one();
write(file_desc, ar.first, ar.second);
ar = buff.array_two();
write(file_desc, ar.first, ar.second);
Or relying on the linearize()
method:
write(file_desc, buff.linearize(), buff.size());
Since the complexity of array_one()
and array_two()
methods is constant the first option is suitable when calling the write method is "cheap". On the other hand the second option is more suitable when calling the write method is more "expensive" than calling the linearize()
method whose complexity is linear.
circular_buffer
is empty the size of the returned array is 0
. Nothing. |
circular_buffer
). array_one()
and array_two()
(and their const versions). |a|b|c|d|e|f|g| | | |
the "array one" is represented by |a|b|c|d|e|f|g|
and the "array two" does not exist (the array_two()
method returns an array with the size 0
). array_two()
, linearize()
|
inline |
Get the first continuous array of the internal buffer.
This method in combination with array_two() const
can be useful when passing the stored data into a legacy C API as an array.
circular_buffer
is empty the size of the returned array is 0
. Nothing. |
circular_buffer
). array_two() const
; array_one()
for more details how to pass data into a legacy C hidapi API.
|
inline |
Get the second continuous array of the internal buffer.
This method in combination with array_one()
can be useful when passing the stored data into a legacy C API as an array.
circular_buffer
is empty the size of the returned array is 0
. Nothing. |
circular_buffer
). array_one()
|
inline |
Get the second continuous array of the internal buffer.
This method in combination with array_one() const
can be useful when passing the stored data into a legacy C API as an array.
circular_buffer
is empty the size of the returned array is 0
. Nothing. |
circular_buffer
). array_one() const
|
inline |
Assign n
items into the circular_buffer
.
The content of the circular_buffer
will be removed and replaced with n
copies of the item
.
capacity() == n && size() == n && (*this)[0] == item && (*this)[1] == item && ... && (*this) [n - 1] == item
n | The number of elements the circular_buffer will be filled with. |
item | The element the circular_buffer will be filled with. |
An allocation error | if memory is exhausted (std::bad_alloc if the standard allocator is used). |
Whatever | T::T(const T&) throws. |
circular_buffer
(except iterators equal to end()
). n
).
|
inline |
Assign n
items into the circular_buffer
specifying the capacity.
The capacity of the circular_buffer
will be set to the specified value and the content of the circular_buffer
will be removed and replaced with n
copies of the item
.
capacity >= n
capacity() == capacity && size() == n && (*this)[0] == item && (*this)[1] == item && ... && (*this) [n - 1] == item
capacity | The new capacity. |
n | The number of elements the circular_buffer will be filled with. |
item | The element the circular_buffer will be filled with. |
An allocation error | if memory is exhausted (std::bad_alloc if the standard allocator is used). |
Whatever | T::T(const T&) throws. |
circular_buffer
(except iterators equal to end()
). n
).
|
inline |
Assign a copy of the range into the circular_buffer
.
The content of the circular_buffer
will be removed and replaced with copies of elements from the specified range.
[first, last)
.first
and last
have to meet the requirements of InputIterator. capacity() == std::distance(first, last) && size() == std::distance(first, last) && (*this)[0]== *first && (*this)[1] == *(first + 1) && ... && (*this)[std::distance(first, last) - 1] == *(last - 1)
first | The beginning of the range to be copied. |
last | The end of the range to be copied. |
An allocation error | if memory is exhausted (std::bad_alloc if the standard allocator is used). |
Whatever | T::T(const T&) throws. |
circular_buffer
(except iterators equal to end()
). std::distance(first, last)
).
|
inline |
Assign a copy of the range into the circular_buffer
specifying the capacity.
The capacity of the circular_buffer
will be set to the specified value and the content of the circular_buffer
will be removed and replaced with copies of elements from the specified range.
[first, last)
.first
and last
have to meet the requirements of InputIterator. capacity() == capacity && size() <= std::distance(first, last) && (*this)[0]== *(last - capacity) && (*this)[1] == *(last - capacity + 1) && ... && (*this)[capacity - 1] == *(last - 1)
[first, last)
is greater than the specified capacity
then only elements from the range [last - capacity, last)
will be copied. capacity | The new capacity. |
first | The beginning of the range to be copied. |
last | The end of the range to be copied. |
An allocation error | if memory is exhausted (std::bad_alloc if the standard allocator is used). |
Whatever | T::T(const T&) throws. |
circular_buffer
(except iterators equal to end()
). std::distance(first, last)
; in min[capacity, std::distance(first, last)]
if the InputIterator
is a RandomAccessIterator).
|
inlineprivate |
Specialized assign method.
|
inlineprivate |
Specialized assign method.
|
inlineprivate |
Specialized assign method.
|
inlineprivate |
Specialized assign method.
|
inlineprivate |
Specialized assign method.
|
inlineprivate |
Specialized assign method.
|
inlineprivate |
Specialized assign method.
|
inlineprivate |
Specialized assign method.
|
inlineprivate |
Helper assign method.
|
inline |
Get the element at the index
position.
index | The position of the element. |
index
position. <code>std::out_of_range</code> | when the index is invalid (when index >= size() ). |
circular_buffer
). operator[]
|
inline |
Get the element at the index
position.
index | The position of the element. |
index
position. <code>std::out_of_range</code> | when the index is invalid (when index >= size() ). |
circular_buffer
). operator[] const
|
inline |
Get the last element.
!empty()
circular_buffer
. Nothing. |
circular_buffer
). front()
|
inline |
Get the last element.
!empty()
circular_buffer
. Nothing. |
circular_buffer
). front() const
|
inline |
Get the iterator pointing to the beginning of the circular_buffer
.
circular_buffer
. If the circular_buffer
is empty it returns an iterator equal to the one returned by end()
. Nothing. |
circular_buffer
).
|
inline |
Get the const iterator pointing to the beginning of the circular_buffer
.
circular_buffer
. If the circular_buffer
is empty it returns an iterator equal to the one returned by end() const
. Nothing. |
circular_buffer
). end() const
, rbegin() const
, rend() const
|
private |
|
inline |
Get the capacity of the circular_buffer
.
circular_buffer
. Nothing. |
circular_buffer
). reserve()
, size()
, max_size()
, set_capacity(capacity_type)
|
inlineprivate |
Check if the index
is valid.
|
inline |
Remove all stored elements from the circular_buffer
.
size() == 0
Nothing. |
circular_buffer
(except iterators equal to end()
). circular_buffer
).
|
inlineprivate |
Construct or replace an element.
construct
has to be set to true
if and only if pos
points to an uninitialized memory.
|
inlineprivate |
Deallocate memory.
|
inlineprivate |
Decrement the pointer.
|
inlineprivate |
Destroy content and free allocated memory.
|
inlineprivate |
Destroy the whole content of the circular buffer.
|
inlineprivate |
Destroy an item only if it has been constructed.
|
inlineprivate |
Destroy an item.
|
inline |
Is the circular_buffer
empty?
true
if there are no elements stored in the circular_buffer
; false
otherwise. Nothing. |
circular_buffer
). full()
|
inline |
Get the iterator pointing to the end of the circular_buffer
.
circular_buffer
. If the circular_buffer
is empty it returns an iterator equal to the one returned by begin()
. Nothing. |
circular_buffer
).
|
inline |
Get the const iterator pointing to the end of the circular_buffer
.
circular_buffer
. If the circular_buffer
is empty it returns an iterator equal to the one returned by begin() const
const. Nothing. |
circular_buffer
). begin() const
, rbegin() const
, rend() const
|
inline |
Remove an element at the specified position.
pos
is a valid iterator pointing to the circular_buffer
(but not an end()
). pos
is removed. pos | An iterator pointing at the element to be removed. |
end()
if no such element exists. Whatever | T::operator = (const T&) throws. |
end()
). std::distance(pos, end())
).
|
inline |
Erase the range [first, last)
.
[first, last)
. [first, last)
are removed. (If first == last
nothing is removed.) first | The beginning of the range to be removed. |
last | The end of the range to be removed. |
end()
if no such element exists. Whatever | T::operator = (const T&) throws. |
end()
). std::distance(first, end())
).
|
inline |
Get the first element.
!empty()
circular_buffer
. Nothing. |
circular_buffer
). back()
|
inline |
Get the first element.
!empty()
circular_buffer
. Nothing. |
circular_buffer
). back() const
|
inline |
Is the circular_buffer
full?
true
if the number of elements stored in the circular_buffer
equals the capacity of the circular_buffer
; false
otherwise. Nothing. |
circular_buffer
). empty()
|
inline |
Get the allocator.
Nothing. |
circular_buffer
). get_allocator()
for obtaining an allocator reference.
|
inline |
Get the allocator reference.
Nothing. |
circular_buffer
). get_allocator() const
|
inlineprivate |
Increment the pointer.
|
inlineprivate |
Initialize the circular buffer.
|
inlineprivate |
Initialize the circular buffer.
|
inlineprivate |
Specialized initialize method.
|
inlineprivate |
Specialized initialize method.
|
inlineprivate |
Specialized initialize method.
|
inlineprivate |
Specialized initialize method.
|
inlineprivate |
Specialized initialize method.
|
inlineprivate |
Specialized initialize method.
|
inlineprivate |
Specialized initialize method.
|
inlineprivate |
Specialized initialize method.
|
inlineprivate |
Helper initialize method.
|
inline |
Insert an element at the specified position.
pos
is a valid iterator pointing to the circular_buffer
or its end. item
will be inserted at the position pos
.circular_buffer
is full, the first element will be overwritten. If the circular_buffer
is full and the pos
points to begin()
, then the item
will not be inserted. If the capacity is 0
, nothing will be inserted. pos | An iterator specifying the position where the item will be inserted. |
item | The element to be inserted. |
begin()
if the item
is not inserted. (See the Effect.) Whatever | T::T(const T&) throws. |
Whatever | T::operator = (const T&) throws. |
pos
) and iterators behind the insertion point (towards the end; except iterators equal to end()
). It also invalidates iterators pointing to the overwritten element. std::distance(pos, end())
).
|
inline |
Insert n
copies of the item
at the specified position.
pos
is a valid iterator pointing to the circular_buffer
or its end. min[n, (pos - begin()) + reserve()]
elements will be inserted at the position pos
.min[pos - begin(), max[0, n - reserve()]]
elements will be overwritten at the beginning of the circular_buffer
.pos | An iterator specifying the position where the item s will be inserted. |
n | The number of item s the to be inserted. |
item | The element whose copies will be inserted. |
Whatever | T::T(const T&) throws. |
Whatever | T::operator = (const T&) throws. |
pos
) and iterators behind the insertion point (towards the end; except iterators equal to end()
). It also invalidates iterators pointing to the overwritten elements. min[capacity(), std::distance(pos, end()) + n]
). circular_buffer
with the capacity of 6 and the size of 4. Its internal buffer may look like the one below.|1|2|3|4| | |
p —^
p
:insert(p, (size_t)5, 0);
1
and 2
are overwritten. This is due to the fact the insert operation preserves the capacity. After insertion the internal buffer looks like this:|0|0|0|0|3|4|
|1|2|0|0|0|0|0|3|4|
.
|
inline |
Insert the range [first, last)
at the specified position.
pos
is a valid iterator pointing to the circular_buffer
or its end.[first, last)
where first
and last
meet the requirements of an InputIterator. [first + max[0, distance(first, last) - (pos - begin()) - reserve()], last)
will be inserted at the position pos
.min[pos - begin(), max[0, distance(first, last) - reserve()]]
elements will be overwritten at the beginning of the circular_buffer
.pos | An iterator specifying the position where the range will be inserted. |
first | The beginning of the range to be inserted. |
last | The end of the range to be inserted. |
Whatever | T::T(const T&) throws. |
Whatever | T::operator = (const T&) throws. |
pos
) and iterators behind the insertion point (towards the end; except iterators equal to end()
). It also invalidates iterators pointing to the overwritten elements. [std::distance(pos, end()) + std::distance(first, last)]
; in min[capacity(), std::distance(pos, end()) + std::distance(first, last)]
if the InputIterator
is a RandomAccessIterator). circular_buffer
with the capacity of 6 and the size of 4. Its internal buffer may look like the one below.|1|2|3|4| | |
p —^
p
:int array[] = { 5, 6, 7, 8, 9 };
insert(p, array, array + 5);
6
, 7
, 8
and 9
from the specified range get inserted and elements 1
and 2
are overwritten. This is due to the fact the insert operation preserves the capacity. After insertion the internal buffer looks like this:|6|7|8|9|3|4|
|1|2|5|6|7|8|9|3|4|
.
|
inlineprivate |
Specialized insert method.
|
inlineprivate |
Specialized insert method.
|
inlineprivate |
Specialized insert method.
|
inlineprivate |
Specialized insert method.
|
inlineprivate |
Helper insert method.
|
inlineprivate |
Helper insert method.
|
inlineprivate |
Does the pointer point to the uninitialized memory?
|
inline |
Linearize the internal buffer into a continuous array.
This method can be useful when passing the stored data into a legacy C API as an array.
&(*this)[0] < &(*this)[1] < ... < &(*this)[size() - 1]
0
if empty. Whatever | T::T(const T&) throws. |
Whatever | T::operator = (const T&) throws. |
circular_buffer
(except iterators equal to end()
); does not invalidate any iterators if the postcondition (the Effect) is already met prior calling this method. circular_buffer
); constant if the postcondition (the Effect) is already met. circular_buffer
may delinearize the internal buffer and invalidate the returned pointer. array_one()
and array_two()
for the other option how to pass data into a legacy C hidapi API.
|
inlineprivate |
Map the null pointer to virtual end of circular buffer.
|
inline |
Get the largest possible size or capacity of the circular_buffer
. (It depends on allocator's max_size()).
circular_buffer
can be set to. Nothing. |
circular_buffer
). size()
, capacity()
, reserve()
|
inline |
The assign operator.
Makes this circular_buffer
to become a copy of the specified circular_buffer
.
*this == cb
cb | The circular_buffer to be copied. |
An allocation error | if memory is exhausted (std::bad_alloc if the standard allocator is used). |
Whatever | T::T(const T&) throws. |
circular_buffer
(except iterators equal to end()
). cb
).
|
inline |
Get the element at the index
position.
0 <= index && index < size()
index | The position of the element. |
index
position. Nothing. |
circular_buffer
). at()
|
inline |
Get the element at the index
position.
0 <= index && index < size()
index | The position of the element. |
index
position. Nothing. |
circular_buffer
). at() const
|
inline |
Remove the last element from the circular_buffer
.
!empty()
circular_buffer
. Nothing. |
circular_buffer
).
|
inline |
Remove the first element from the circular_buffer
.
!empty()
circular_buffer
. Nothing. |
circular_buffer
).
|
inline |
Insert a new element at the end of the circular_buffer
.
capacity() > 0
then back() == item
circular_buffer
is full, the first element will be removed. If the capacity is 0
, nothing will be inserted. item | The element to be inserted. |
Whatever | T::T(const T&) throws. |
circular_buffer
). push_front(const_reference)
, pop_back()
, pop_front()
|
inline |
Insert a new element at the beginning of the circular_buffer
.
capacity() > 0
then front() == item
circular_buffer
is full, the last element will be removed. If the capacity is 0
, nothing will be inserted. item | The element to be inserted. |
Whatever | T::T(const T&) throws. |
circular_buffer
). push_back(const_reference)
, pop_back()
, pop_front()
|
inline |
Get the iterator pointing to the beginning of the "reversed" circular_buffer
.
circular_buffer
. If the circular_buffer
is empty it returns an iterator equal to the one returned by rend()
. Nothing. |
circular_buffer
).
|
inline |
Get the const iterator pointing to the beginning of the "reversed" circular_buffer
.
circular_buffer
. If the circular_buffer
is empty it returns an iterator equal to the one returned by rend() const
. Nothing. |
circular_buffer
). rend() const
, begin() const
, end() const
|
inline |
Get the iterator pointing to the end of the "reversed" circular_buffer
.
circular_buffer
. If the circular_buffer
is empty it returns an iterator equal to the one returned by rbegin()
. Nothing. |
circular_buffer
).
|
inline |
Get the const iterator pointing to the end of the "reversed" circular_buffer
.
circular_buffer
. If the circular_buffer
is empty it returns an iterator equal to the one returned by rbegin() const
. Nothing. |
circular_buffer
). rbegin() const
, begin() const
, end() const
|
inlineprivate |
Replace an element.
|
inline |
Remove an element at the specified position.
pos
is a valid iterator pointing to the circular_buffer
(but not an end()
). pos
is removed. pos | An iterator pointing at the element to be removed. |
begin()
if no such element exists. Whatever | T::operator = (const T&) throws. |
std::distance(begin(), pos)
). erase(iterator)
method and is more effective than erase(iterator)
if the iterator pos
is close to the beginning of the circular_buffer
. (See the Complexity.)
|
inline |
Erase the range [first, last)
.
[first, last)
. [first, last)
are removed. (If first == last
nothing is removed.) first | The beginning of the range to be removed. |
last | The end of the range to be removed. |
begin()
if no such element exists. Whatever | T::operator = (const T&) throws. |
std::distance(begin(), last)
). erase(iterator, iterator)
method and is more effective than erase(iterator, iterator)
if std::distance(begin(), first)
is lower that std::distance(last, end())
.
|
inline |
Get the maximum number of elements which can be inserted into the circular_buffer
without overwriting any of already stored elements.
capacity() - size()
Nothing. |
circular_buffer
). capacity()
, size()
, max_size()
|
inlineprivate |
Reset the circular buffer.
|
inline |
Change the size of the circular_buffer
.
size() == new_size && capacity() >= new_size
item
will be inserted at the back of the of the circular_buffer
in order to achieve the desired size. In the case the resulting size exceeds the current capacity the capacity will be set to new_size
.circular_buffer
is greater than the desired new size then number of [size() - new_size]
last elements will be removed. (The capacity will remain unchanged.) new_size | The new size. |
item | The element the circular_buffer will be filled with in order to gain the requested size. (See the Effect.) |
An allocation error | if memory is exhausted (std::bad_alloc if the standard allocator is used). |
Whatever | T::T(const T&) throws. |
circular_buffer
(except iterators equal to end()
) if the new size is greater than the current capacity. Invalidates iterators pointing to the removed elements if the new size is lower that the original size. Otherwise it does not invalidate any iterator. circular_buffer
).
|
inline |
Insert an element before the specified position.
pos
is a valid iterator pointing to the circular_buffer
or its end. item
will be inserted before the position pos
.circular_buffer
is full, the last element will be overwritten. If the circular_buffer
is full and the pos
points to end()
, then the item
will not be inserted. If the capacity is 0
, nothing will be inserted. pos | An iterator specifying the position before which the item will be inserted. |
item | The element to be inserted. |
end()
if the item
is not inserted. (See the Effect.) Whatever | T::T(const T&) throws. |
Whatever | T::operator = (const T&) throws. |
pos
). It also invalidates iterators pointing to the overwritten element. std::distance(begin(), pos)
).
|
inline |
Insert n
copies of the item
before the specified position.
pos
is a valid iterator pointing to the circular_buffer
or its end. min[n, (end() - pos) + reserve()]
elements will be inserted before the position pos
.min[end() - pos, max[0, n - reserve()]]
elements will be overwritten at the end of the circular_buffer
.pos | An iterator specifying the position where the item s will be inserted. |
n | The number of item s the to be inserted. |
item | The element whose copies will be inserted. |
Whatever | T::T(const T&) throws. |
Whatever | T::operator = (const T&) throws. |
pos
). It also invalidates iterators pointing to the overwritten elements. min[capacity(), std::distance(begin(), pos) + n]
). circular_buffer
with the capacity of 6 and the size of 4. Its internal buffer may look like the one below.|1|2|3|4| | |
p —^
p
:rinsert(p, (size_t)5, 0);
3
and 4
are overwritten. This is due to the fact the rinsert operation preserves the capacity. After insertion the internal buffer looks like this:|1|2|0|0|0|0|
|1|2|0|0|0|0|0|3|4|
.
|
inline |
Insert the range [first, last)
before the specified position.
pos
is a valid iterator pointing to the circular_buffer
or its end.[first, last)
where first
and last
meet the requirements of an InputIterator. [first, last - max[0, distance(first, last) - (end() - pos) - reserve()])
will be inserted before the position pos
.min[end() - pos, max[0, distance(first, last) - reserve()]]
elements will be overwritten at the end of the circular_buffer
.pos | An iterator specifying the position where the range will be inserted. |
first | The beginning of the range to be inserted. |
last | The end of the range to be inserted. |
Whatever | T::T(const T&) throws. |
Whatever | T::operator = (const T&) throws. |
pos
). It also invalidates iterators pointing to the overwritten elements. [std::distance(begin(), pos) + std::distance(first, last)]
; in min[capacity(), std::distance(begin(), pos) + std::distance(first, last)]
if the InputIterator
is a RandomAccessIterator). circular_buffer
with the capacity of 6 and the size of 4. Its internal buffer may look like the one below.|1|2|3|4| | |
p —^
p
:int array[] = { 5, 6, 7, 8, 9 };
insert(p, array, array + 5);
5
, 6
, 7
and 8
from the specified range get inserted and elements 3
and 4
are overwritten. This is due to the fact the rinsert operation preserves the capacity. After insertion the internal buffer looks like this:|1|2|5|6|7|8|
|1|2|5|6|7|8|9|3|4|
.
|
inlineprivate |
Specialized rinsert method.
|
inlineprivate |
Specialized rinsert method.
|
inlineprivate |
Specialized insert method.
|
inlineprivate |
Specialized rinsert method.
|
inlineprivate |
Helper rinsert method.
|
inline |
Change the size of the circular_buffer
.
size() == new_size && capacity() >= new_size
item
will be inserted at the front of the of the circular_buffer
in order to achieve the desired size. In the case the resulting size exceeds the current capacity the capacity will be set to new_size
.circular_buffer
is greater than the desired new size then number of [size() - new_size]
first elements will be removed. (The capacity will remain unchanged.) new_size | The new size. |
item | The element the circular_buffer will be filled with in order to gain the requested size. (See the Effect.) |
An allocation error | if memory is exhausted (std::bad_alloc if the standard allocator is used). |
Whatever | T::T(const T&) throws. |
circular_buffer
(except iterators equal to end()
) if the new size is greater than the current capacity. Invalidates iterators pointing to the removed elements if the new size is lower that the original size. Otherwise it does not invalidate any iterator. circular_buffer
).
|
inline |
Change the capacity of the circular_buffer
.
capacity() == new_capacity && size() <= new_capacity
circular_buffer
is greater than the desired new capacity then number of [size() - new_capacity]
first elements will be removed and the new size will be equal to new_capacity
. new_capacity | The new capacity. |
An allocation error | if memory is exhausted (std::bad_alloc if the standard allocator is used). |
Whatever | T::T(const T&) throws. |
circular_buffer
(except iterators equal to end()
) if the new capacity is different from the original. min[size(), new_capacity]
).
|
inline |
Change the capacity of the circular_buffer
.
capacity() == new_capacity && size() <= new_capacity
circular_buffer
is greater than the desired new capacity then number of [size() - new_capacity]
last elements will be removed and the new size will be equal to new_capacity
. new_capacity | The new capacity. |
An allocation error | if memory is exhausted (std::bad_alloc if the standard allocator is used). |
Whatever | T::T(const T&) throws. |
circular_buffer
(except iterators equal to end()
) if the new capacity is different from the original. min[size(), new_capacity]
).
|
inline |
Get the number of elements currently stored in the circular_buffer
.
circular_buffer
. Nothing. |
circular_buffer
).
|
inlineprivate |
Subtract n
from the pointer.
|
inline |
Swap the contents of two circular_buffer
s.
this
contains elements of cb
and vice versa; the capacity of this
equals to the capacity of cb
and vice versa. cb | The circular_buffer whose content will be swapped. |
Nothing. |
circular_buffer
s. (On the other hand the iterators still point to the same elements but within another container. If you want to rely on this feature you have to turn the Debug Support off otherwise an assertion will report an error if such invalidated iterator is used.) circular_buffer
).
|
inlineprivate |
Specialized method for swapping the allocator.
|
inlineprivate |
Specialized method for swapping the allocator.
|
friend |
|
private |
The allocator.
|
private |
The internal buffer used for storing elements in the circular buffer.
|
private |
The internal buffer's end (end of the storage space).
|
private |
The virtual beginning of the circular buffer.
|
private |
The virtual end of the circular buffer (one behind the last element).
|
private |
The number of items currently stored in the circular buffer.