A piece of raw data. More...
#include <Buffer.h>
Public Types | |
Member types | |
using | value_type = unsigned char |
using | size_type = uint32_t |
using | iterator = value_type * |
using | const_iterator = const value_type * |
Public Member Functions | |
Construction and destruction | |
Buffer ()=default | |
Create an empty buffer. More... | |
Buffer (size_type size) | |
Create a buffer with size bytes allocated. More... | |
Buffer (uint64_t size) | |
Create a buffer with size bytes allocated. More... | |
template<typename T > | |
Buffer (const T &source) | |
Copy source into this buffer. Allocates the necessary memory. More... | |
Buffer (const value_type *data, size_type size) | |
Buffer (const value_type *data, uint64_t size) | |
Create a buffer with size bytes allocated. More... | |
Buffer (const Buffer &)=delete | |
Buffer (Buffer &&rhs) noexcept | |
~Buffer () | |
Assignment | |
Buffer & | operator= (const Buffer &)=delete |
Buffer & | operator= (Buffer &&rhs) noexcept |
Data access | |
const value_type & | operator[] (size_t i) const |
Access the byte at position i. More... | |
value_type & | operator[] (size_t i) |
Access the byte at position i. More... | |
const value_type * | data () const noexcept |
Direct access to the allocated memory or nullptr if no memory is allocated. More... | |
value_type * | data () noexcept |
Direct access to the allocated memory or nullptr if no memory is allocated. More... | |
boost::asio::const_buffer | cbuffer () const noexcept |
Make a boost::asio::buffer from this buffer. More... | |
boost::asio::const_buffer | buffer () const noexcept |
Make a boost::asio::buffer from this buffer. More... | |
boost::asio::mutable_buffer | buffer () noexcept |
Make a boost::asio::buffer from this buffer. More... | |
Iterators | |
const_iterator | cbegin () const noexcept |
const_iterator | begin () const noexcept |
iterator | begin () noexcept |
const_iterator | cend () const noexcept |
const_iterator | end () const noexcept |
iterator | end () noexcept |
Modifiers | |
void | reset (size_type size) |
Reset the size of this buffer. More... | |
void | reset (uint64_t size) |
Reset the size of this buffer. More... | |
void | resize (uint64_t size) |
Resize the buffer, a new block of size size is allocated if the capacity is not enough and the data is copied. More... | |
std::unique_ptr< value_type[]> | pop () noexcept |
Release the contents of this buffer and set its size and capacity to zero. More... | |
void | clear () noexcept |
Clear the contents of this buffer and set its size and capacity to zero. More... | |
copy_from | |
template<typename T > | |
void | copy_from (const T &source) |
Copy source into this buffer. Allocates memory if necessary. More... | |
void | copy_from (const value_type *data, size_type size) |
Copy size bytes of the memory pointed by data into this buffer. More... | |
void | copy_from (size_type offset, const Buffer &rhs) |
Copy source into this buffer leaving at the front an offset of offset bytes uninitialized. More... | |
template<typename T > | |
std::enable_if< boost::asio::is_const_buffer_sequence< T >::value >::type | copy_from (size_type offset, const T &source) |
Copy source into this buffer leaving at the front an offset of offset bytes uninitialized. More... | |
template<typename T > | |
std::enable_if<!boost::asio::is_const_buffer_sequence< T >::value >::type | copy_from (size_type offset, const T &source) |
Copy source into this buffer leaving at the front an offset of offset bytes uninitialized. More... | |
void | copy_from (size_type offset, const value_type *data, size_type size) |
Copy size bytes of the memory pointed by data into this buffer, leaving at the front an offset of offset bytes uninitialized. More... | |
Private Member Functions | |
void | ReuseThisBuffer () |
Private Attributes | |
size_type | _capacity = 0u |
std::unique_ptr< value_type[]> | _data = nullptr |
std::weak_ptr< BufferPool > | _parent_pool |
size_type | _size = 0u |
Friends | |
class | BufferPool |
class | BufferView |
Capacity | |
bool | empty () const noexcept |
size_type | size () const noexcept |
size_type | capacity () const noexcept |
static constexpr size_type | max_size () noexcept |
A piece of raw data.
Note that if more capacity is needed, a new memory block is allocated and the old one is deleted. This means that by default the buffer can only grow. To release the memory use clear
or pop
.
This is a move-only type, meant to be cheap to pass by value. If the buffer is retrieved from a BufferPool, the memory is automatically pushed back to the pool on destruction.
Definition at line 42 of file carla/Buffer.h.
using carla::Buffer::const_iterator = const value_type * |
Definition at line 57 of file carla/Buffer.h.
using carla::Buffer::iterator = value_type * |
Definition at line 55 of file carla/Buffer.h.
using carla::Buffer::size_type = uint32_t |
Definition at line 53 of file carla/Buffer.h.
using carla::Buffer::value_type = unsigned char |
Definition at line 51 of file carla/Buffer.h.
|
default |
|
inlineexplicit |
Create a buffer with size bytes allocated.
Definition at line 71 of file carla/Buffer.h.
|
inlineexplicit |
Create a buffer with size bytes allocated.
Definition at line 77 of file carla/Buffer.h.
References max_size(), size(), and carla::throw_exception().
|
inlineexplicit |
Copy source into this buffer. Allocates the necessary memory.
Definition at line 87 of file carla/Buffer.h.
References copy_from().
|
inlineexplicit |
Definition at line 91 of file carla/Buffer.h.
References copy_from().
|
inlineexplicit |
Create a buffer with size bytes allocated.
Definition at line 96 of file carla/Buffer.h.
References Buffer(), max_size(), size(), and carla::throw_exception().
|
delete |
|
inlinenoexcept |
Definition at line 106 of file carla/Buffer.h.
|
inline |
Definition at line 112 of file carla/Buffer.h.
References _capacity, operator=(), and ReuseThisBuffer().
|
inlinenoexcept |
Definition at line 221 of file carla/Buffer.h.
References cbegin().
Referenced by carla::sensor::RawData::begin(), end(), and carla::operator==().
|
inlinenoexcept |
Definition at line 225 of file carla/Buffer.h.
References _data.
|
inlinenoexcept |
Make a boost::asio::buffer from this buffer.
Definition at line 176 of file carla/Buffer.h.
References cbuffer().
Referenced by carla::multigpu::IncomingMessage::buffer(), carla::streaming::detail::tcp::IncomingMessage::buffer(), and copy_from().
|
inlinenoexcept |
Make a boost::asio::buffer from this buffer.
Definition at line 181 of file carla/Buffer.h.
References data(), and size().
|
inlinenoexcept |
Definition at line 205 of file carla/Buffer.h.
References _capacity.
Referenced by carla::BufferView::capacity().
|
inlinenoexcept |
Definition at line 217 of file carla/Buffer.h.
References _data.
Referenced by carla::BufferView::begin(), begin(), carla::BufferView::cend(), and cend().
|
inlinenoexcept |
Make a boost::asio::buffer from this buffer.
Definition at line 171 of file carla/Buffer.h.
References data(), and size().
Referenced by buffer().
|
inlinenoexcept |
Definition at line 229 of file carla/Buffer.h.
References cbegin(), and size().
Referenced by carla::BufferView::end(), and end().
|
inlinenoexcept |
Clear the contents of this buffer and set its size and capacity to zero.
Deletes allocated memory.
Definition at line 291 of file carla/Buffer.h.
References pop().
|
inline |
Copy source into this buffer. Allocates memory if necessary.
Definition at line 305 of file carla/Buffer.h.
Referenced by Buffer(), copy_from(), resize(), carla::sensor::s11n::RadarSerializer::Serialize(), carla::sensor::s11n::LidarSerializer::Serialize(), carla::sensor::s11n::SemanticLidarSerializer::Serialize(), and TEST().
|
inline |
Copy size bytes of the memory pointed by data into this buffer.
Allocates memory if necessary.
Definition at line 311 of file carla/Buffer.h.
References copy_from().
Copy source into this buffer leaving at the front an offset of offset bytes uninitialized.
Allocates memory if necessary.
Definition at line 317 of file carla/Buffer.h.
References buffer(), and copy_from().
|
inline |
Copy source into this buffer leaving at the front an offset of offset bytes uninitialized.
Allocates memory if necessary.
Definition at line 324 of file carla/Buffer.h.
References buffer(), DEBUG_ASSERT, DEBUG_ONLY, reset(), and size().
|
inline |
Copy source into this buffer leaving at the front an offset of offset bytes uninitialized.
Allocates memory if necessary.
Definition at line 335 of file carla/Buffer.h.
References copy_from().
|
inline |
Copy size bytes of the memory pointed by data into this buffer, leaving at the front an offset of offset bytes uninitialized.
Allocates memory if necessary.
Definition at line 353 of file carla/Buffer.h.
References copy_from(), and ReuseThisBuffer().
|
inlinenoexcept |
Direct access to the allocated memory or nullptr if no memory is allocated.
Definition at line 156 of file carla/Buffer.h.
References _data.
Referenced by util::buffer::as_string(), buffer(), carla::BufferView::cbegin(), carla::BufferView::cbuffer(), cbuffer(), carla::BufferView::data(), carla::sensor::s11n::SensorHeaderSerializer::Deserialize(), FAsyncDataStreamTmpl< T >::GetSensorTimestamp(), FAsyncDataStreamTmpl< T >::GetSensorTransform(), FAsyncDataStreamTmpl< T >::GetSensorType(), carla::BufferView::operator[](), carla::multigpu::SecondaryCommands::process_command(), resize(), FAsyncDataStreamTmpl< T >::SetFrameNumber(), TEST(), util::buffer::to_hex_string(), and carla::MsgPack::UnPack().
|
inlinenoexcept |
Direct access to the allocated memory or nullptr if no memory is allocated.
Definition at line 162 of file carla/Buffer.h.
References _data.
|
inlinenoexcept |
Definition at line 193 of file carla/Buffer.h.
References _size.
|
inlinenoexcept |
Definition at line 233 of file carla/Buffer.h.
References cend().
Referenced by carla::sensor::RawData::end(), and carla::operator==().
|
inlinenoexcept |
Definition at line 237 of file carla/Buffer.h.
References begin(), and size().
|
inlinestaticnoexcept |
Definition at line 201 of file carla/Buffer.h.
Referenced by Buffer(), and reset().
Definition at line 128 of file carla/Buffer.h.
References _capacity, _data, _parent_pool, and _size.
|
inline |
|
inline |
|
inlinenoexcept |
|
inline |
Reset the size of this buffer.
If the capacity is not enough, the current memory is discarded and a new block of size size is allocated.
Definition at line 252 of file carla/Buffer.h.
References _capacity, _data, _size, carla::log_debug(), and size().
Referenced by carla::multigpu::IncomingMessage::buffer(), carla::streaming::detail::tcp::IncomingMessage::buffer(), copy_from(), reset(), resize(), and TEST().
|
inline |
Reset the size of this buffer.
If the capacity is not enough, the current memory is discarded and a new block of size size is allocated.
Definition at line 262 of file carla/Buffer.h.
References max_size(), reset(), and carla::throw_exception().
|
inline |
Resize the buffer, a new block of size size is allocated if the capacity is not enough and the data is copied.
Definition at line 271 of file carla/Buffer.h.
References _capacity, _data, _size, copy_from(), data(), reset(), and size().
|
private |
Definition at line 7 of file carla/Buffer.cpp.
References _parent_pool.
Referenced by copy_from(), and ~Buffer().
|
inlinenoexcept |
Definition at line 197 of file carla/Buffer.h.
References _size.
Referenced by util::buffer::as_string(), Buffer(), buffer(), carla::BufferView::cbuffer(), cbuffer(), carla::BufferView::cend(), cend(), copy_from(), carla::BufferView::empty(), end(), make_special_message(), carla::operator<<(), carla::operator==(), reset(), resize(), carla::BufferView::size(), TEST(), util::buffer::to_hex_string(), and carla::MsgPack::UnPack().
|
friend |
Definition at line 363 of file carla/Buffer.h.
|
friend |
Definition at line 364 of file carla/Buffer.h.
|
private |
Definition at line 370 of file carla/Buffer.h.
Referenced by capacity(), operator=(), pop(), reset(), resize(), and ~Buffer().
|
private |
Definition at line 372 of file carla/Buffer.h.
Referenced by begin(), cbegin(), data(), operator=(), operator[](), pop(), reset(), and resize().
|
private |
Definition at line 366 of file carla/Buffer.h.
Referenced by operator=(), carla::BufferPool::Pop(), and ReuseThisBuffer().
|
private |
Definition at line 368 of file carla/Buffer.h.
Referenced by empty(), operator=(), pop(), reset(), resize(), and size().