srs-control 0.2.2
Loading...
Searching...
No Matches
srs::LargeBuffer Class Reference

Class for buffer for storing large data. More...

#include <LargeBuffer.hpp>

Collaboration diagram for srs::LargeBuffer:

Public Member Functions

 LargeBuffer ()=default
 Default constructor for an empty buffer. This does not allocate any memory.
 LargeBuffer (std::size_t buffer_size)
 Constructor with a buffer size.
 LargeBuffer (const LargeBuffer &other)=delete
 Default copy constructor. Very slow and should be avoided.
 LargeBuffer (LargeBuffer &&other) noexcept=default
 Move constructor via swapping.
auto operator= (const LargeBuffer &other) -> LargeBuffer &=delete
 Default copy assignment. Very slow and should be avoided.
auto operator= (LargeBuffer &&other) noexcept -> LargeBuffer &=default
 Move assignment via swapping.
 ~LargeBuffer ()=default
 Default destructor.
auto operator== (std::span< char > msg) const -> bool
 Comparison with a span.
auto operator== (std::string_view msg) const -> bool
 Comparison with a string_view.
auto data () const -> std::string_view
 Return a string_view with the underlying data and current size.
auto empty () const -> bool
void resize (std::size_t size)
 Change the size of this buffer.
auto get_buffer_size () const -> std::size_t
 Getter for the buffer size.
auto get_size () const -> std::size_t
 Getter for the size.
auto get_all_data () -> std::span< char >
 Return the total underlying data.
auto is_empty () -> bool

Private Attributes

std::size_t size_ = 0
BinaryData data_

Detailed Description

Class for buffer for storing large data.

It has two different length indicators: size and buffer size (capacity). Similar to std::vector, size represents the current amount of valid values and buffer size represents the memory allocated for the buffer. The reason to use LargeBuffer instead of simply std::vector is because the std::vector::resize() also initialize the values when vector grows, while LargeBuffer::resize() just change the size value, without furthering operations. The LargeBuffer is not supposed to grow or reallocated and all the memory should be allocated up front via the constructor LargeBuffer(std::size_t).

Definition at line 22 of file LargeBuffer.hpp.

Constructor & Destructor Documentation

◆ LargeBuffer() [1/4]

srs::LargeBuffer::LargeBuffer ( )
default

Default constructor for an empty buffer. This does not allocate any memory.

◆ LargeBuffer() [2/4]

srs::LargeBuffer::LargeBuffer ( std::size_t buffer_size)
inlineexplicit

Constructor with a buffer size.

The number of the elements pre-allocated is equal to the buffer_size.

Parameters
buffer_sizeNumber of element whose memory pre-allocated to the buffer.

Definition at line 38 of file LargeBuffer.hpp.

◆ LargeBuffer() [3/4]

srs::LargeBuffer::LargeBuffer ( const LargeBuffer & other)
explicitdelete

Default copy constructor. Very slow and should be avoided.

◆ LargeBuffer() [4/4]

srs::LargeBuffer::LargeBuffer ( LargeBuffer && other)
explicitdefaultnoexcept

Move constructor via swapping.

This "move" constructor does not move the data of the other, but rather perform the swap action with other object.

Parameters
otherOther LargeBuffer object to be swapped.

◆ ~LargeBuffer()

srs::LargeBuffer::~LargeBuffer ( )
default

Default destructor.

Member Function Documentation

◆ data()

auto srs::LargeBuffer::data ( ) const -> std::string_view
inlinenodiscard

Return a string_view with the underlying data and current size.

Returns
string_view data

Definition at line 94 of file LargeBuffer.hpp.

◆ empty()

auto srs::LargeBuffer::empty ( ) const -> bool
inlinenodiscard

Definition at line 95 of file LargeBuffer.hpp.

◆ get_all_data()

auto srs::LargeBuffer::get_all_data ( ) -> std::span< char >
inline

Return the total underlying data.

Returns
Span of the underlying data.

Definition at line 130 of file LargeBuffer.hpp.

◆ get_buffer_size()

auto srs::LargeBuffer::get_buffer_size ( ) const -> std::size_t
inlinenodiscard

Getter for the buffer size.

Returns
Buffer size

Definition at line 115 of file LargeBuffer.hpp.

◆ get_size()

auto srs::LargeBuffer::get_size ( ) const -> std::size_t
inlinenodiscard

Getter for the size.

Returns
Size of elements in the buffer

Definition at line 122 of file LargeBuffer.hpp.

◆ is_empty()

auto srs::LargeBuffer::is_empty ( ) -> bool
inline

Definition at line 132 of file LargeBuffer.hpp.

◆ operator=() [1/2]

auto srs::LargeBuffer::operator= ( const LargeBuffer & other) -> LargeBuffer &=delete
delete

Default copy assignment. Very slow and should be avoided.

◆ operator=() [2/2]

auto srs::LargeBuffer::operator= ( LargeBuffer && other) -> LargeBuffer &=default
defaultnoexcept

Move assignment via swapping.

This "move" assignment does not move the data of the other, but rather perform the swap action with other object.

Parameters
otherOther LargeBuffer object to be swapped.

◆ operator==() [1/2]

auto srs::LargeBuffer::operator== ( std::span< char > msg) const -> bool
inline

Comparison with a span.

Parameters
msgSpan data.
Returns
True if equal

Definition at line 79 of file LargeBuffer.hpp.

◆ operator==() [2/2]

auto srs::LargeBuffer::operator== ( std::string_view msg) const -> bool
inline

Comparison with a string_view.

Parameters
msgstring_view data.
Returns
True if equal

Definition at line 87 of file LargeBuffer.hpp.

◆ resize()

void srs::LargeBuffer::resize ( std::size_t size)
inline

Change the size of this buffer.

Changing the size to the new size value, without assigning or changing the old data values.

Parameters
sizeNew size value.

Definition at line 103 of file LargeBuffer.hpp.

Member Data Documentation

◆ data_

BinaryData srs::LargeBuffer::data_
private

Definition at line 136 of file LargeBuffer.hpp.

◆ size_

std::size_t srs::LargeBuffer::size_ = 0
private

Definition at line 135 of file LargeBuffer.hpp.


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