srs-control
0.2.2
Toggle main menu visibility
Loading...
Searching...
No Matches
LargeBuffer.hpp
Go to the documentation of this file.
1
#pragma once
2
3
#include "
srs/utils/CommonAlias.hpp
"
4
#include <cstddef>
5
#include <fmt/base.h>
6
#include <span>
7
#include <string_view>
8
9
namespace
srs
10
{
22
class
LargeBuffer
23
{
24
public
:
29
LargeBuffer
() =
default
;
30
38
explicit
LargeBuffer
(std::size_t buffer_size) {
data_
.resize(buffer_size); }
39
43
explicit
LargeBuffer
(
const
LargeBuffer
& other) =
delete
;
44
52
explicit
LargeBuffer
(
LargeBuffer
&& other)
noexcept
=
default
;
53
57
auto
operator=
(
const
LargeBuffer
& other) ->
LargeBuffer
& =
delete
;
58
66
auto
operator=
(
LargeBuffer
&& other)
noexcept
->
LargeBuffer
& =
default
;
67
71
~LargeBuffer
() =
default
;
72
79
auto
operator==
(std::span<char> msg)
const
->
bool
{
return
std::string_view{ msg } ==
data
(); }
80
87
auto
operator==
(std::string_view msg)
const
->
bool
{
return
msg ==
data
(); }
88
94
[[nodiscard]]
auto
data
() const -> std::string_view {
return
std::string_view{
data_
.data(),
size_
}; }
95
[[nodiscard]]
auto
empty
() const ->
bool
{
return
data_
.empty(); }
96
103
void
resize
(std::size_t size)
104
{
105
size_
= size;
106
data_
.resize(
size_
>=
data_
.size() ?
size_
:
data_
.size());
107
}
108
// void set_buffer_size(std::size_t capacity) { data_.resize(capacity); }
109
115
[[nodiscard]]
auto
get_buffer_size
() const -> std::
size_t
{
return
data_
.size(); }
116
122
[[nodiscard]]
auto
get_size
() const -> std::
size_t
{
return
size_
; }
123
129
// INFO: Do not return the reference to the underlying vector, as it's not thread safe.
130
auto
get_all_data
() -> std::span<char> {
return
std::span{
data_
}; }
131
132
auto
is_empty
() ->
bool
{
return
data_
.size() == 0 and
data_
.capacity() == 0; }
133
134
private
:
135
std::size_t
size_
= 0;
136
BinaryData
data_
;
137
};
138
139
}
// namespace srs
CommonAlias.hpp
srs::LargeBuffer::~LargeBuffer
~LargeBuffer()=default
Default destructor.
srs::LargeBuffer::is_empty
auto is_empty() -> bool
Definition
LargeBuffer.hpp:132
srs::LargeBuffer::LargeBuffer
LargeBuffer()=default
Default constructor for an empty buffer. This does not allocate any memory.
srs::LargeBuffer::data
auto data() const -> std::string_view
Return a string_view with the underlying data and current size.
Definition
LargeBuffer.hpp:94
srs::LargeBuffer::size_
std::size_t size_
Definition
LargeBuffer.hpp:135
srs::LargeBuffer::operator==
auto operator==(std::span< char > msg) const -> bool
Comparison with a span.
Definition
LargeBuffer.hpp:79
srs::LargeBuffer::get_size
auto get_size() const -> std::size_t
Getter for the size.
Definition
LargeBuffer.hpp:122
srs::LargeBuffer::LargeBuffer
LargeBuffer(LargeBuffer &&other) noexcept=default
Move constructor via swapping.
srs::LargeBuffer::operator=
auto operator=(const LargeBuffer &other) -> LargeBuffer &=delete
Default copy assignment. Very slow and should be avoided.
srs::LargeBuffer::empty
auto empty() const -> bool
Definition
LargeBuffer.hpp:95
srs::LargeBuffer::data_
BinaryData data_
Definition
LargeBuffer.hpp:136
srs::LargeBuffer::LargeBuffer
LargeBuffer(std::size_t buffer_size)
Constructor with a buffer size.
Definition
LargeBuffer.hpp:38
srs::LargeBuffer::resize
void resize(std::size_t size)
Change the size of this buffer.
Definition
LargeBuffer.hpp:103
srs::LargeBuffer::operator==
auto operator==(std::string_view msg) const -> bool
Comparison with a string_view.
Definition
LargeBuffer.hpp:87
srs::LargeBuffer::LargeBuffer
LargeBuffer(const LargeBuffer &other)=delete
Default copy constructor. Very slow and should be avoided.
srs::LargeBuffer::operator=
auto operator=(LargeBuffer &&other) noexcept -> LargeBuffer &=default
Move assignment via swapping.
srs::LargeBuffer::get_buffer_size
auto get_buffer_size() const -> std::size_t
Getter for the buffer size.
Definition
LargeBuffer.hpp:115
srs::LargeBuffer::get_all_data
auto get_all_data() -> std::span< char >
Return the total underlying data.
Definition
LargeBuffer.hpp:130
srs
Definition
Application.cpp:45
srs::BinaryData
std::vector< BufferElementType > BinaryData
Definition
CommonAlias.hpp:16
backend
srs
data
LargeBuffer.hpp
Impressum
Datenschutzerklärung
Generated by
1.17.0