13 #include <boost/asio/buffer.hpp> 18 #include <type_traits> 20 #ifdef LIBCARLA_INCLUDED_FROM_UE4 22 #include "Containers/Array.h" 24 #endif // LIBCARLA_INCLUDED_FROM_UE4 171 boost::asio::const_buffer
cbuffer() const noexcept {
176 boost::asio::const_buffer
buffer() const noexcept {
181 boost::asio::mutable_buffer
buffer() noexcept {
202 return (std::numeric_limits<size_type>::max)();
254 log_debug(
"allocating buffer of", size,
"bytes");
255 _data = std::make_unique<value_type[]>(
size);
266 reset(static_cast<size_type>(size));
273 std::unique_ptr<value_type[]>
data = std::move(
_data);
274 uint64_t old_size =
size;
283 std::unique_ptr<value_type[]>
pop() noexcept {
286 return std::move(
_data);
304 template <
typename T>
322 template <
typename T>
323 typename std::enable_if<boost::asio::is_const_buffer_sequence<T>::value>::type
325 reset(boost::asio::buffer_size(source) + offset);
328 boost::asio::buffer_copy(
buffer() + offset, source);
333 template <
typename T>
334 typename std::enable_if<!boost::asio::is_const_buffer_sequence<T>::value>::type
336 copy_from(offset, boost::asio::buffer(source));
339 #ifdef LIBCARLA_INCLUDED_FROM_UE4 341 template <
typename T>
345 reinterpret_cast<const value_type *>(source.GetData()),
346 sizeof(T) * source.Num());
348 #endif // LIBCARLA_INCLUDED_FROM_UE4 354 copy_from(offset, boost::asio::buffer(data, size));
372 std::unique_ptr<value_type[]>
_data =
nullptr;
const value_type * const_iterator
const value_type * data() const noexcept
Direct access to the allocated memory or nullptr if no memory is allocated.
Buffer(Buffer &&rhs) noexcept
void clear() noexcept
Clear the contents of this buffer and set its size and capacity to zero.
value_type & operator[](size_t i)
Access the byte at position i.
void throw_exception(const std::exception &e)
Buffer(const value_type *data, uint64_t size)
Create a buffer with size bytes allocated.
Creating a constant view from an existing buffer.
This file contains definitions of common data structures used in traffic manager. ...
boost::asio::mutable_buffer buffer() noexcept
Make a boost::asio::buffer from this buffer.
Buffer(uint64_t size)
Create a buffer with size bytes allocated.
bool empty() const noexcept
value_type * data() noexcept
Direct access to the allocated memory or nullptr if no memory is allocated.
std::unique_ptr< value_type[]> pop() noexcept
Release the contents of this buffer and set its size and capacity to zero.
static void log_debug(Args &&...)
Buffer(const value_type *data, size_type size)
#define DEBUG_ASSERT(predicate)
void reset(size_type size)
Reset the size of this buffer.
iterator begin() noexcept
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.
const_iterator cend() const noexcept
boost::asio::const_buffer buffer() const noexcept
Make a boost::asio::buffer from this buffer.
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 i...
const_iterator end() const noexcept
Buffer & operator=(const Buffer &)=delete
std::weak_ptr< BufferPool > _parent_pool
size_type capacity() const noexcept
const_iterator begin() const noexcept
const_iterator cbegin() const noexcept
void reset(uint64_t size)
Reset the size of this buffer.
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 off...
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.
Buffer()=default
Create an empty buffer.
const value_type & operator[](size_t i) const
Access the byte at position i.
void copy_from(const value_type *data, size_type size)
Copy size bytes of the memory pointed by data into this buffer.
static constexpr size_type max_size() noexcept
size_type size() const noexcept
boost::asio::const_buffer cbuffer() const noexcept
Make a boost::asio::buffer from this buffer.
void copy_from(const T &source)
Copy source into this buffer. Allocates memory if necessary.
void copy_from(size_type offset, const Buffer &rhs)
Copy source into this buffer leaving at the front an offset of offset bytes uninitialized.
std::unique_ptr< value_type[]> _data
Buffer(const T &source)
Copy source into this buffer. Allocates the necessary memory.
Buffer(size_type size)
Create a buffer with size bytes allocated.
Buffer & operator=(Buffer &&rhs) noexcept