LuciadCPillar 2024.0.08
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
luciad::ByteBuffer Class Referencefinal

Represents an implicitly shared buffer of bytes, ie. More...

#include <luciad/containers/ByteBuffer.h>

Public Types

using const_iterator = const std::byte *
 
using iterator = std::byte *
 

Public Member Functions

 ByteBuffer ()
 Creates an empty ByteBuffer. More...
 
 ByteBuffer (ByteBuffer &&) noexcept=default
 Creates a new ByteBuffer that is backed by the same shared data as the given ByteBuffer. More...
 
 ByteBuffer (const ByteBuffer &)=default
 Creates a new ByteBuffer that is backed by the same shared data as the given ByteBuffer. More...
 
template<size_t S>
 ByteBuffer (const std::array< std::byte, S > &values)
 Creates a ByteBuffer with a copy of the given values. More...
 
 ByteBuffer (const std::byte *data, size_t size)
 Creates a ByteBuffer with a copy of the given values. More...
 
template<unsigned Size>
 ByteBuffer (const std::byte(&data)[Size])
 Creates a ByteBuffer from an array. More...
 
 ByteBuffer (size_t size)
 Creates a ByteBuffer with the given size. More...
 
template<typename Deleter >
 ByteBuffer (std::byte *data, size_t length, Deleter deleter)
 Creates a ByteBuffer that wraps the given raw pointer. More...
 
 ByteBuffer (std::initializer_list< std::byte > values)
 Creates a ByteBuffer containing the given values. More...
 
 ~ByteBuffer ()=default
 
std::byte & at (size_t idx)
 Retrieve a byte in the buffer after performing a range check. More...
 
const std::byte & at (size_t idx) const
 Retrieve a byte in the buffer after performing a range check. More...
 
std::byte * data ()
 Returns the underlying byte array. More...
 
const std::byte * data () const
 Returns the underlying byte array. More...
 
bool empty () const
 Checks whether the buffer is empty. More...
 
ByteBufferoperator= (ByteBuffer &&) noexcept=default
 Move: the new ByteBuffer is backed by the same shared data. More...
 
ByteBufferoperator= (const ByteBuffer &)=default
 Shallow copy: the new ByteBuffer is backed by the same shared data. More...
 
std::byte & operator[] (size_t idx)
 
const std::byte & operator[] (size_t idx) const
 Retrieve a byte in the buffer. More...
 
size_t size () const
 Gets the size of the buffer. More...
 
ByteBuffer subrange (size_t offset, size_t length) const
 Creates a sub-buffer on the same shared data. More...
 

Detailed Description

Represents an implicitly shared buffer of bytes, ie.

ByteBuffer copies (i.e. the copy constructor or assignment operator) result in shallow copies.

Note
Primitive type values are translated from sequences of bytes according to the native byte order of the underlying platform (i.e. LITTLE_ENDIAN or BIG_ENDIAN).

Member Typedef Documentation

◆ const_iterator

using luciad::ByteBuffer::const_iterator = const std::byte*

◆ iterator

using luciad::ByteBuffer::iterator = std::byte*

Constructor & Destructor Documentation

◆ ~ByteBuffer()

luciad::ByteBuffer::~ByteBuffer ( )
default

◆ ByteBuffer() [1/9]

luciad::ByteBuffer::ByteBuffer ( )

Creates an empty ByteBuffer.

◆ ByteBuffer() [2/9]

luciad::ByteBuffer::ByteBuffer ( size_t  size)
explicit

Creates a ByteBuffer with the given size.

Parameters
sizethe size of the buffer in bytes.

◆ ByteBuffer() [3/9]

luciad::ByteBuffer::ByteBuffer ( const std::byte *  data,
size_t  size 
)

Creates a ByteBuffer with a copy of the given values.

Parameters
datathe array from which the values will be copied.
sizethe size of the array to copy.

◆ ByteBuffer() [4/9]

template<size_t S>
luciad::ByteBuffer::ByteBuffer ( const std::array< std::byte, S > &  values)
inlineexplicit

Creates a ByteBuffer with a copy of the given values.

Parameters
valuesthe array from which the values will be copied.

◆ ByteBuffer() [5/9]

luciad::ByteBuffer::ByteBuffer ( std::initializer_list< std::byte >  values)

Creates a ByteBuffer containing the given values.

Parameters
valuesthe initial values contained by this ByteBuffer.

◆ ByteBuffer() [6/9]

template<unsigned Size>
luciad::ByteBuffer::ByteBuffer ( const std::byte(&)  data[Size])
inlineexplicit

Creates a ByteBuffer from an array.

Makes a copy of the original data.

Parameters
dataraw array from which to construct the ByteBuffer.

◆ ByteBuffer() [7/9]

luciad::ByteBuffer::ByteBuffer ( const ByteBuffer )
default

Creates a new ByteBuffer that is backed by the same shared data as the given ByteBuffer.

◆ ByteBuffer() [8/9]

luciad::ByteBuffer::ByteBuffer ( ByteBuffer &&  )
defaultnoexcept

Creates a new ByteBuffer that is backed by the same shared data as the given ByteBuffer.

◆ ByteBuffer() [9/9]

template<typename Deleter >
luciad::ByteBuffer::ByteBuffer ( std::byte *  data,
size_t  length,
Deleter  deleter 
)
inline

Creates a ByteBuffer that wraps the given raw pointer.

Parameters
dataraw pointer to the first byte of the array to use for this ByteBuffer.
lengththe length of the array in T.
deleterthe Deleter that is used to free the raw pointer when the data is no longer used.

Member Function Documentation

◆ at() [1/2]

std::byte & luciad::ByteBuffer::at ( size_t  idx)

Retrieve a byte in the buffer after performing a range check.

Parameters
idxthe index of the byte to retrieve.
Returns
the byte at index idx.

◆ at() [2/2]

const std::byte & luciad::ByteBuffer::at ( size_t  idx) const

Retrieve a byte in the buffer after performing a range check.

Parameters
idxthe index of the byte to retrieve
Returns
the byte at index idx

◆ data() [1/2]

std::byte * luciad::ByteBuffer::data ( )

Returns the underlying byte array.

Returns
the underlying byte array.

◆ data() [2/2]

const std::byte * luciad::ByteBuffer::data ( ) const

Returns the underlying byte array.

Returns
the underlying byte array.

◆ empty()

bool luciad::ByteBuffer::empty ( ) const

Checks whether the buffer is empty.

Returns
a boolean specifying whether the buffer is empty.

◆ operator=() [1/2]

ByteBuffer & luciad::ByteBuffer::operator= ( ByteBuffer &&  )
defaultnoexcept

Move: the new ByteBuffer is backed by the same shared data.

◆ operator=() [2/2]

ByteBuffer & luciad::ByteBuffer::operator= ( const ByteBuffer )
default

Shallow copy: the new ByteBuffer is backed by the same shared data.

◆ operator[]() [1/2]

std::byte & luciad::ByteBuffer::operator[] ( size_t  idx)

◆ operator[]() [2/2]

const std::byte & luciad::ByteBuffer::operator[] ( size_t  idx) const

Retrieve a byte in the buffer.

No range check is performed.

Parameters
idxthe index of the byte to retrieve.
Returns
the byte at index idx.

◆ size()

size_t luciad::ByteBuffer::size ( ) const

Gets the size of the buffer.

Returns
the size of the buffer in bytes.

◆ subrange()

ByteBuffer luciad::ByteBuffer::subrange ( size_t  offset,
size_t  length 
) const

Creates a sub-buffer on the same shared data.

No data is copied.

Parameters
offsetthe index of the first byte in the sub-buffer.
lengththe number of bytes in the sub-buffer.
Returns
a ByteBuffer referencing the data between indices offset and (offset + length).