Acoustic Research Tool (ART)
v0.10
|
A generic buffer which may be either used as a simple vector or ring buffer.
The implementation of this class is based on the STL vector and behaves exactly like it in case it is used as an array. Only the methods referenced by the muParser have been implemented - some missing parts like iterators are not available but can still be implemented.
Public Types | |
typedef _Type & | reference |
Reference type of the data being stored in the vector. | |
typedef const _Type & | const_reference |
Constant reference type of the data being stored in the vector. | |
typedef _Type * | pointer |
Pointer type of the data being stored in the vector. | |
typedef const _Type * | const_pointer |
Constant pointer type of the data being stored in the vector. | |
typedef int | size_type |
The standard size type is int to allow negative indices for access. | |
typedef _Type | value_type |
Data type of the data being stored. | |
typedef _Alloc | allocator_type |
Allocator type for the used data type. |
Public Member Functions | |
mpBuffer (const allocator_type &a=allocator_type()) | |
Creates a new buffer object with no elements. | |
mpBuffer (size_type n, bool rb=false, const value_type &v=value_type(), const allocator_type &a=allocator_type()) | |
Creates a new buffer object with the specified number of elements and the specified type. | |
mpBuffer (const mpBuffer< value_type, allocator_type > &buf) | |
Creates a new buffer by copying all elements of the specified buffer object. | |
virtual mpBuffer & | operator= (const mpBuffer< value_type, allocator_type > &buf) |
Assignment operator - deallocates all currently saved object in the buffer and creates a copy of the specified buffer. | |
virtual | ~mpBuffer () |
The destructor of the mpBuffer class. | |
virtual size_type | size () const |
Returns the current size of the buffer. | |
virtual size_type | max_size () const |
Returns the maximum number of elements which can be saved in a the buffer class. | |
virtual void | resize (size_type sz, value_type c=value_type()) |
Resizes the current buffer to the given size. | |
virtual size_type | capacity () const |
Returns the capacity of the current buffer which is equal to the size. | |
virtual bool | empty () const |
Returns true if the current amount of saved elements is zero. | |
virtual reference | at (size_type n) |
Returns the element currently saved at the specified position. | |
virtual const_reference | at (size_type n) const |
Returns the element currently saved at the specified position. | |
virtual reference | operator[] (size_type n) |
Returns the element currently saved at the specified position, but uses a modulo operation in case of a ring buffer. | |
virtual const_reference | operator[] (size_type n) const |
Returns the element currently saved at the specified position, but uses a modulo operation in case of a ring buffer. | |
virtual reference | front () |
Returns the first element of the current buffer. | |
virtual const_reference | front () const |
Returns the first element of the current buffer. | |
virtual reference | back () |
Returns the last element of the current buffer. | |
virtual const_reference | back () const |
Returns the last element of the current buffer. | |
virtual allocator_type | get_allocator () const |
Returns the allocator type of the current buffer. | |
virtual void | setCurrentIdx (size_type n) |
Sets the current index of the ring buffer to the given value and adapts internal pointers to the first and last element of the ring buffer. | |
virtual size_type | getFirst () const |
Returns the first element saved in the current buffer. | |
virtual size_type | getLast () const |
Returns the last element saved in the current buffer. | |
virtual size_type | getUsedBufferSize () const |
Returns the number of accessed elements of the ring buffer which is equivalent to the actually used buffer size. | |
virtual bool | isRingBuffer () const |
Returns true if the current buffer behaves like a a ring buffer, false otherwise. | |
virtual void | setRingBuffer () |
Sets the current buffer to behave like a ring buffer. | |
virtual void | setVector () |
Sets the current buffer to behave like a vector. |
Protected Member Functions | |
virtual void | clean () |
Releases all elements by calling the destructor of the saved elements and deallocating all needed memory. |
Protected Attributes | |
size_type | _size |
Current number of elements in use. | |
allocator_type | _allocator |
Allocator of current element type. | |
pointer | _fields |
Pointer to all elements of buffer. | |
bool | _is_ringbuffer |
Attribute deciding whether the current buffer implements a ringbuffer. | |
size_type | _first |
In case of a ring buffer, this is the index to the first valid element. | |
size_type | _last |
In case of a ring buffer, this is the index to the last valid element. | |
size_type | _used_elements |
Saves the number of currently used elements for a ring buffer. |
typedef _Alloc mpBuffer< _Type, _Alloc >::allocator_type |
Allocator type for the used data type.
typedef const _Type* mpBuffer< _Type, _Alloc >::const_pointer |
Constant pointer type of the data being stored in the vector.
typedef const _Type& mpBuffer< _Type, _Alloc >::const_reference |
Constant reference type of the data being stored in the vector.
typedef _Type* mpBuffer< _Type, _Alloc >::pointer |
Pointer type of the data being stored in the vector.
typedef _Type& mpBuffer< _Type, _Alloc >::reference |
Reference type of the data being stored in the vector.
typedef int mpBuffer< _Type, _Alloc >::size_type |
The standard size type is int to allow negative indices for access.
typedef _Type mpBuffer< _Type, _Alloc >::value_type |
Data type of the data being stored.
|
inlineexplicit |
Creates a new buffer object with no elements.
The default buffer type is array.
[in] | a | Defines the allocator type for the class which shall be saved in the buffer. Defaults to the standard allocator. |
|
inlineexplicit |
Creates a new buffer object with the specified number of elements and the specified type.
[in] | n | Initial size of the array. |
[in] | rb | Defines the type of the array: If set to true, the buffer is a ring buffer, otherwise, it will be an array. |
[in] | v | Defines the class type which shall be saved in the buffer. |
[in] | a | Defines the allocator type for the class which shall be saved in the buffer. Defaults to the standard allocator. |
|
inline |
Creates a new buffer by copying all elements of the specified buffer object.
[in] | buf | The buffer to copy. |
|
inlinevirtual |
Returns the element currently saved at the specified position.
This function behaves the same for the array and ring buffer implementation and does not change the _used_elements field.
[in] | n | The position of the element saved in the buffer. |
std::out_of_range | If the specified position is not within 0 <= n < size. |
|
inlinevirtual |
Returns the element currently saved at the specified position.
This function behaves the same for the array and ring buffer implementation and does not change the _used_elements field.
[in] | n | The index of the element saved in the buffer. |
std::out_of_range | If the specified position is not within 0 <= n < size. |
|
inlinevirtual |
Assignment operator - deallocates all currently saved object in the buffer and creates a copy of the specified buffer.
[in] | buf | The buffer to copy. |
|
inlinevirtual |
Returns the element currently saved at the specified position, but uses a modulo operation in case of a ring buffer.
[in] | n | The index of the element saved in the buffer. |
std::out_of_range | If the current buffer is an array and the index is not within 0 <= n < size or the number of used elements in the ring buffer is greater than the current size. |
|
inlinevirtual |
Returns the element currently saved at the specified position, but uses a modulo operation in case of a ring buffer.
[in] | n | The index of the element saved in the buffer. |
std::out_of_range | If the current buffer is an array and the index is not within 0 <= n < size or the number of used elements in the ring buffer is greater than the current size. |
|
inlinevirtual |
Resizes the current buffer to the given size.
[in] | sz | The size of the new buffer. |
[in] | c | The class type of the elements to save in the buffer. |
std::length_error | If the new size of a ring buffer will be less than the current number of elements in use. |
|
protected |
Allocator of current element type.
|
protected |
Pointer to all elements of buffer.
|
protected |
In case of a ring buffer, this is the index to the first valid element.
Initial value is -1.
|
protected |
Attribute deciding whether the current buffer implements a ringbuffer.
|
mutableprotected |
In case of a ring buffer, this is the index to the last valid element.
Initial value is -1.
|
protected |
Current number of elements in use.