qb  2.0.0.0
C++17 Actor Framework
qb Issue Watch Star Fork Follow @isndev
Loading...
Searching...
No Matches
qb::allocator::base_pipe< T > Class Template Reference

Base class for the extensible buffer. More...

#include <pipe.h>

Inheritance diagram for qb::allocator::base_pipe< T >:
Collaboration diagram for qb::allocator::base_pipe< T >:

Public Member Functions

 base_pipe ()
 Default constructor.
 base_pipe (base_pipe const &rhs)
 Copy constructor.
 base_pipe (base_pipe &&rhs) noexcept
 Move constructor.
base_pipeoperator= (base_pipe const &rhs)
 Copy assignment operator.
base_pipeoperator= (base_pipe &&rhs) noexcept
 Move assignment operator.
 ~base_pipe ()
 Destructor.
std::size_t capacity () const noexcept
 Returns the total capacity of the buffer.
T * data () const noexcept
 Returns a pointer to the buffer data.
T * begin () const noexcept
 Returns a pointer to the first valid element.
T * end () const noexcept
 Returns a pointer just after the last valid element.
const T * cbegin () const noexcept
 Returns a constant pointer to the first valid element.
const T * cend () const noexcept
 Returns a constant pointer just after the last valid element.
std::size_t size () const noexcept
 Returns the number of valid elements in the buffer.
void resize (std::size_t new_size)
 Resizes the buffer.
void free_front (std::size_t const size) noexcept
 Frees elements at the beginning of the buffer.
void free_back (std::size_t const size) noexcept
 Frees elements at the end of the buffer.
void reset (std::size_t const begin) noexcept
 Resets the buffer to a specific position.
void reset () noexcept
 Completely resets the buffer.
void clear () noexcept
 Clears the buffer content (alias for reset)
bool empty () const noexcept
 Checks if the buffer is empty.
void free (std::size_t const size) noexcept
 Frees a specified number of elements.
auto * allocate_back (std::size_t const size)
 Allocates space at the end of the buffer.
template<typename U, typename... _Init>
U & allocate_back (_Init &&...init)
 Allocates and constructs an object of type U at the end of the buffer.
template<typename U, typename... _Init>
U & allocate_size (std::size_t const size, _Init &&...init)
 Allocates space with a custom size and constructs an object.
auto allocate (std::size_t const size)
 Allocates space at the beginning or end of the buffer.
template<typename U, typename... _Init>
U & allocate (_Init &&...init)
 Allocates space and constructs an object.
template<typename U>
U & recycle_back (U const &data)
 Copies an object to the end of the buffer.
template<typename U>
U & recycle_back (U const &data, std::size_t const size)
 Copies data to the end of the buffer.
template<typename U>
U & recycle (U const &data)
 Copies an object to the beginning or end of the buffer.
template<typename U>
U & recycle (U const &data, std::size_t const size)
 Copies data to the beginning or end of the buffer.
void reorder () noexcept
 Reorganizes the buffer to consolidate free space.
void flush () const noexcept
 Flushes the buffer (synchronization operation, no-op in this class)
void reserve (std::size_t const size)
 Reserves space in the buffer.

Protected Attributes

std::size_t _begin
 Index of first valid element.
std::size_t _end
 Index just after the last valid element.
bool _flag_front
 Indicates if the last allocation was at the beginning.
std::size_t _capacity
 Total buffer capacity.
std::size_t _factor
 Buffer expansion factor.
T * _data
 Buffer data.

Detailed Description

template<typename T>
class qb::allocator::base_pipe< T >

Base class for the extensible buffer.

Implements the fundamental functionalities of an extensible buffer:

  • Automatic memory allocation and deallocation
  • Capacity management with automatic resizing
  • Efficient data access for reading and writing
  • Methods for allocating space at the beginning or end of the buffer
Template Parameters
TType of elements stored in the buffer

Constructor & Destructor Documentation

◆ base_pipe() [1/3]

template<typename T>
qb::allocator::base_pipe< T >::base_pipe ( )
inline

Default constructor.

Initializes an empty buffer with default capacity

◆ base_pipe() [2/3]

template<typename T>
qb::allocator::base_pipe< T >::base_pipe ( base_pipe< T > const & rhs)
inline

Copy constructor.

Copies data from another buffer

Parameters
rhsBuffer to copy from

◆ base_pipe() [3/3]

template<typename T>
qb::allocator::base_pipe< T >::base_pipe ( base_pipe< T > && rhs)
inlinenoexcept

Move constructor.

Transfers ownership of data from another buffer

Parameters
rhsBuffer to move from

◆ ~base_pipe()

template<typename T>
qb::allocator::base_pipe< T >::~base_pipe ( )
inline

Destructor.

Frees memory allocated by the buffer

Member Function Documentation

◆ operator=()

template<typename T>
base_pipe & qb::allocator::base_pipe< T >::operator= ( base_pipe< T > && rhs)
inlinenoexcept

Move assignment operator.

Parameters
rhsBuffer to move from
Returns
Reference to this buffer after move

◆ capacity()

template<typename T>
std::size_t qb::allocator::base_pipe< T >::capacity ( ) const
inlinenodiscardnoexcept

Returns the total capacity of the buffer.

Returns
Capacity in number of elements

◆ data()

template<typename T>
T * qb::allocator::base_pipe< T >::data ( ) const
inlinenodiscardnoexcept

Returns a pointer to the buffer data.

Returns
Pointer to the data

◆ begin()

template<typename T>
T * qb::allocator::base_pipe< T >::begin ( ) const
inlinenodiscardnoexcept

Returns a pointer to the first valid element.

Returns
Pointer to the beginning of valid data

◆ end()

template<typename T>
T * qb::allocator::base_pipe< T >::end ( ) const
inlinenodiscardnoexcept

Returns a pointer just after the last valid element.

Returns
Pointer to the end of valid data

◆ cbegin()

template<typename T>
const T * qb::allocator::base_pipe< T >::cbegin ( ) const
inlinenodiscardnoexcept

Returns a constant pointer to the first valid element.

Returns
Constant pointer to the beginning of valid data

◆ cend()

template<typename T>
const T * qb::allocator::base_pipe< T >::cend ( ) const
inlinenodiscardnoexcept

Returns a constant pointer just after the last valid element.

Returns
Constant pointer to the end of valid data

◆ size()

template<typename T>
std::size_t qb::allocator::base_pipe< T >::size ( ) const
inlinenodiscardnoexcept

Returns the number of valid elements in the buffer.

Returns
Number of elements

◆ resize()

template<typename T>
void qb::allocator::base_pipe< T >::resize ( std::size_t new_size)
inline

Resizes the buffer.

If the new size is smaller than the current size, excess elements are removed. If the new size is larger, space is allocated at the end of the buffer.

Parameters
new_sizeDesired new size

◆ free_front()

template<typename T>
void qb::allocator::base_pipe< T >::free_front ( std::size_t const size)
inlinenoexcept

Frees elements at the beginning of the buffer.

Parameters
sizeNumber of elements to free

◆ free_back()

template<typename T>
void qb::allocator::base_pipe< T >::free_back ( std::size_t const size)
inlinenoexcept

Frees elements at the end of the buffer.

Parameters
sizeNumber of elements to free

◆ reset() [1/2]

template<typename T>
void qb::allocator::base_pipe< T >::reset ( std::size_t const begin)
inlinenoexcept

Resets the buffer to a specific position.

If the specified position is not the end, sets the beginning to this position. Otherwise, completely resets the buffer.

Parameters
beginNew beginning position

◆ reset() [2/2]

template<typename T>
void qb::allocator::base_pipe< T >::reset ( )
inlinenoexcept

Completely resets the buffer.

Data remains in memory but is marked as invalid

◆ empty()

template<typename T>
bool qb::allocator::base_pipe< T >::empty ( ) const
inlinenoexcept

Checks if the buffer is empty.

Returns
true if the buffer is empty, false otherwise

◆ free()

template<typename T>
void qb::allocator::base_pipe< T >::free ( std::size_t const size)
inlinenoexcept

Frees a specified number of elements.

Depending on the _flag_front flag, frees at the beginning or end of the buffer

Parameters
sizeNumber of elements to free

◆ allocate_back() [1/2]

template<typename T>
auto * qb::allocator::base_pipe< T >::allocate_back ( std::size_t const size)
inline

Allocates space at the end of the buffer.

Automatically increases capacity if necessary.

Parameters
sizeNumber of elements to allocate
Returns
Pointer to the beginning of the allocated space

◆ allocate_back() [2/2]

template<typename T>
template<typename U, typename... _Init>
U & qb::allocator::base_pipe< T >::allocate_back ( _Init &&... init)
inline

Allocates and constructs an object of type U at the end of the buffer.

Template Parameters
UType of object to construct
_InitTypes of arguments for construction
Parameters
initArguments for construction
Returns
Reference to the constructed object

◆ allocate_size()

template<typename T>
template<typename U, typename... _Init>
U & qb::allocator::base_pipe< T >::allocate_size ( std::size_t const size,
_Init &&... init )
inline

Allocates space with a custom size and constructs an object.

Template Parameters
UType of object to construct
_InitTypes of arguments for construction
Parameters
sizeAdditional size to allocate after the object
initArguments for construction
Returns
Reference to the constructed object

◆ allocate() [1/2]

template<typename T>
auto qb::allocator::base_pipe< T >::allocate ( std::size_t const size)
inline

Allocates space at the beginning or end of the buffer.

Chooses the location based on available space

Parameters
sizeNumber of elements to allocate
Returns
Pointer to the beginning of the allocated space

◆ allocate() [2/2]

template<typename T>
template<typename U, typename... _Init>
U & qb::allocator::base_pipe< T >::allocate ( _Init &&... init)
inline

Allocates space and constructs an object.

Template Parameters
UType of object to construct
_InitTypes of arguments for construction
Parameters
initArguments for construction
Returns
Reference to the constructed object

◆ recycle_back() [1/2]

template<typename T>
template<typename U>
U & qb::allocator::base_pipe< T >::recycle_back ( U const & data)
inline

Copies an object to the end of the buffer.

Template Parameters
UType of object to copy
Parameters
dataObject to copy
Returns
Reference to the copy of the object

◆ recycle_back() [2/2]

template<typename T>
template<typename U>
U & qb::allocator::base_pipe< T >::recycle_back ( U const & data,
std::size_t const size )
inline

Copies data to the end of the buffer.

Template Parameters
UType of data to copy
Parameters
dataData to copy
sizeNumber of elements to copy
Returns
Reference to the copy of the data

◆ recycle() [1/2]

template<typename T>
template<typename U>
U & qb::allocator::base_pipe< T >::recycle ( U const & data)
inline

Copies an object to the beginning or end of the buffer.

Template Parameters
UType of object to copy
Parameters
dataObject to copy
Returns
Reference to the copy of the object

◆ recycle() [2/2]

template<typename T>
template<typename U>
U & qb::allocator::base_pipe< T >::recycle ( U const & data,
std::size_t const size )
inline

Copies data to the beginning or end of the buffer.

Template Parameters
UType of data to copy
Parameters
dataData to copy
sizeNumber of elements to copy
Returns
Reference to the copy of the data

◆ reorder()

template<typename T>
void qb::allocator::base_pipe< T >::reorder ( )
inlinenoexcept

Reorganizes the buffer to consolidate free space.

Moves data to the beginning of the buffer

◆ reserve()

template<typename T>
void qb::allocator::base_pipe< T >::reserve ( std::size_t const size)
inline

Reserves space in the buffer.

Allocates space without marking it as used

Parameters
sizeNumber of elements to reserve