Nazara Engine  0.4
A fast, complete, cross-platform API designed for game development
Nz::ByteArray Class Reference

Core class that represents an array of bytes. More...

Public Types

using allocator_type = Container::allocator_type
 
using const_iterator = Container::const_iterator
 
using const_reference = Container::const_reference
 
using const_pointer = Container::const_pointer
 
using const_reverse_iterator = Container::const_reverse_iterator
 
using difference_type = Container::difference_type
 
using pointer = Container::pointer
 
using iterator = Container::iterator
 
using reference = Container::reference
 
using reverse_iterator = Container::reverse_iterator
 
using size_type = Container::size_type
 
using value_type = Container::value_type
 

Public Member Functions

 ByteArray (size_type n)
 Constructs a ByteArray object with a reserved size. More...
 
 ByteArray (const void *buffer, size_type n)
 Constructs a ByteArray object with a raw memory and a size. More...
 
 ByteArray (size_type n, value_type value)
 Constructs a ByteArray object with n times the same value. More...
 
template<class InputIterator >
 ByteArray (InputIterator first, InputIterator last)
 Constructs a ByteArray object from two iterators. More...
 
 ByteArray (const ByteArray &other)=default
 
 ByteArray (ByteArray &&other)=default
 
iterator Append (const void *buffer, size_type size)
 Appends the content of raw memory. More...
 
iterator Append (const ByteArray &other)
 Appends another array of bytes. More...
 
template<class InputIterator >
void Assign (InputIterator first, InputIterator last)
 Assigns this with the content between two iterators. More...
 
void Assign (size_type n, value_type value)
 Assigns this with n times the same value. More...
 
reference Back ()
 Gets last element. More...
 
const_reference Back () const
 Gets last element. More...
 
void Clear (bool keepBuffer=false)
 Clears the content of the string. More...
 
iterator Erase (const_iterator pos)
 Erases an element from the byte array. More...
 
iterator Erase (const_iterator first, const_iterator last)
 Erases the elements between the two pointers from the byte array. More...
 
reference Front ()
 Gets first element. More...
 
const_reference Front () const
 Gets first element. More...
 
allocator_type GetAllocator () const
 Gets the internal allocator of the byte array. More...
 
pointer GetBuffer ()
 Gets the raw buffer. More...
 
size_type GetCapacity () const noexcept
 Gets the capacity of the byte array. More...
 
const_pointer GetConstBuffer () const
 Gets the raw buffer. More...
 
size_type GetMaxSize () const noexcept
 Gets the maximal size supported by the byte array. More...
 
size_type GetSize () const noexcept
 Gets the size of the byte array. More...
 
ByteArray GetSubArray (const_iterator startPos, const_iterator endPos) const
 Returns a sub byte array of the byte array. More...
 
iterator Insert (const_iterator pos, const void *buffer, size_type n)
 Inserts the content of raw memory at the iterator position. More...
 
iterator Insert (const_iterator pos, const ByteArray &other)
 Inserts the content of another byte array at the iterator position. More...
 
iterator Insert (const_iterator pos, size_type n, value_type byte)
 Inserts n times the same byte at the iterator position. More...
 
template<class InputIterator >
iterator Insert (const_iterator pos, InputIterator first, InputIterator last)
 Inserts the content from two iterators at the iterator position. More...
 
bool IsEmpty () const noexcept
 Checks whether the byte array is empty. More...
 
void PopBack ()
 Erases the last element. More...
 
void PopFront ()
 Erases the first element. More...
 
iterator Prepend (const void *buffer, size_type size)
 Prepends the content of raw memory. More...
 
iterator Prepend (const ByteArray &other)
 Prepends another array of bytes. More...
 
void PushBack (value_type byte)
 Pushes the byte at the end. More...
 
void PushFront (value_type byte)
 Pushes the byte at the beginning. More...
 
void Reserve (size_type bufferSize)
 Reserves enough memory for the buffer size. More...
 
void Resize (size_type newSize)
 Resizes the string. More...
 
void Resize (size_type newSize, value_type byte)
 Resizes the string. More...
 
void ShrinkToFit ()
 Releases the excedent memory.
 
void Swap (ByteArray &other)
 Swaps the content with the other byte array. More...
 
String ToHex () const
 Gives a string representation in base 16. More...
 
String ToString () const
 Gives a string representation. More...
 
iterator begin () noexcept
 Returns an iterator pointing to the beggining of the string. More...
 
const_iterator begin () const noexcept
 Returns an iterator pointing to the beggining of the string. More...
 
bool empty () const noexcept
 Checks whether the byte array is empty. More...
 
iterator end () noexcept
 Returns an iterator pointing to the end of the string. More...
 
const_iterator end () const noexcept
 Returns an iterator pointing to the end of the string. More...
 
reverse_iterator rbegin () noexcept
 Returns a reversed iterator pointing to the beggining of the string. More...
 
const_reverse_iterator rbegin () const noexcept
 Returns a reversed iterator pointing to the beggining of the string. More...
 
reverse_iterator rend () noexcept
 Returns a reversed iterator pointing to the end of the string. More...
 
const_reverse_iterator rend () const noexcept
 
const_iterator cbegin () const noexcept
 Returns a constant iterator pointing to the beggining of the string. More...
 
const_iterator cend () const noexcept
 Returns a constant iterator pointing to the end of the string. More...
 
const_reverse_iterator crbegin () const noexcept
 Returns a constant reversed iterator pointing to the beggining of the string. More...
 
const_reverse_iterator crend () const noexcept
 Returns a constant reversed iterator pointing to the end of the string. More...
 
size_type size () const noexcept
 Gets the size of the byte array. More...
 
reference operator[] (size_type pos)
 Gets the ith byte. More...
 
const_reference operator[] (size_type pos) const
 Gets the ith byte. More...
 
ByteArrayoperator= (const ByteArray &array)=default
 
ByteArrayoperator= (ByteArray &&array)=default
 
ByteArray operator+ (const ByteArray &array) const
 Concatenates the byte array to another. More...
 
ByteArrayoperator+= (const ByteArray &array)
 Concatenates the byte array to this byte array. More...
 
bool operator== (const ByteArray &rhs) const
 Checks whether the first byte array is equal to the second byte array. More...
 
bool operator!= (const ByteArray &rhs) const
 Checks whether the first byte array is equal to the second byte array. More...
 
bool operator< (const ByteArray &rhs) const
 Checks whether the first byte array is less than the second byte array. More...
 
bool operator<= (const ByteArray &rhs) const
 Checks whether the first byte array is less or equal than the second byte array. More...
 
bool operator> (const ByteArray &rhs) const
 Checks whether the first byte array is greater than the second byte array. More...
 
bool operator>= (const ByteArray &rhs) const
 Checks whether the first byte array is greater or equal than the second byte array. More...
 

Friends

NAZARA_CORE_API friend std::ostream & operator<< (std::ostream &out, const Nz::ByteArray &byteArray)
 Output operator. More...
 

Detailed Description

Core class that represents an array of bytes.

Constructor & Destructor Documentation

◆ ByteArray() [1/4]

Nz::ByteArray::ByteArray ( size_type  n)
inlineexplicit

Constructs a ByteArray object with a reserved size.

Parameters
nSpace reserved

◆ ByteArray() [2/4]

Nz::ByteArray::ByteArray ( const void *  buffer,
size_type  n 
)
inline

Constructs a ByteArray object with a raw memory and a size.

Parameters
bufferPointer to raw memory
nSize that can be accessed
Remarks
If preallocated space of buffer is less than the size, the behaviour is undefined

◆ ByteArray() [3/4]

Nz::ByteArray::ByteArray ( size_type  n,
value_type  value 
)
inline

Constructs a ByteArray object with n times the same value.

Parameters
nNumber of repetitions
valueValue to repeat

◆ ByteArray() [4/4]

template<class InputIterator >
Nz::ByteArray::ByteArray ( InputIterator  first,
InputIterator  last 
)

Constructs a ByteArray object from two iterators.

Parameters
firstFirst iterator
lastSecond iterator

Member Function Documentation

◆ Append() [1/2]

ByteArray::iterator Nz::ByteArray::Append ( const void *  buffer,
size_type  n 
)
inline

Appends the content of raw memory.

Parameters
bufferConstant pointer to raw memory
nSize that can be read
Remarks
If preallocated space of buffer is less than the size, the behaviour is undefined
See also
Insert

◆ Append() [2/2]

ByteArray::iterator Nz::ByteArray::Append ( const ByteArray other)
inline

Appends another array of bytes.

Parameters
otherByteArray to add
See also
Insert

◆ Assign() [1/2]

template<class InputIterator >
void Nz::ByteArray::Assign ( InputIterator  first,
InputIterator  last 
)

Assigns this with the content between two iterators.

Parameters
firstFirst iterator
lastSecond iterator

◆ Assign() [2/2]

void Nz::ByteArray::Assign ( size_type  n,
value_type  value 
)
inline

Assigns this with n times the same value.

Parameters
nNumber of repetitions
valueValue to repeat

◆ Back() [1/2]

ByteArray::reference Nz::ByteArray::Back ( )
inline

Gets last element.

Returns
A reference to last element
Remarks
If ByteArray is empty, behaviour is undefined

◆ Back() [2/2]

ByteArray::const_reference Nz::ByteArray::Back ( ) const
inline

Gets last element.

Returns
A constant reference to last element
Remarks
If ByteArray is empty, behaviour is undefined

◆ begin() [1/2]

ByteArray::iterator Nz::ByteArray::begin ( )
inlinenoexcept

Returns an iterator pointing to the beggining of the string.

Returns
Beggining of the string

◆ begin() [2/2]

ByteArray::const_iterator Nz::ByteArray::begin ( ) const
inlinenoexcept

Returns an iterator pointing to the beggining of the string.

Returns
Beggining of the string

◆ cbegin()

ByteArray::const_iterator Nz::ByteArray::cbegin ( ) const
inlinenoexcept

Returns a constant iterator pointing to the beggining of the string.

Returns
Beggining of the string

◆ cend()

ByteArray::const_iterator Nz::ByteArray::cend ( ) const
inlinenoexcept

Returns a constant iterator pointing to the end of the string.

Returns
End of the string

◆ Clear()

void Nz::ByteArray::Clear ( bool  keepBuffer = false)
inline

Clears the content of the string.

Parameters
keepBufferShould the buffer be kept

◆ crbegin()

ByteArray::const_reverse_iterator Nz::ByteArray::crbegin ( ) const
inlinenoexcept

Returns a constant reversed iterator pointing to the beggining of the string.

Returns
Beggining of the string

◆ crend()

ByteArray::const_reverse_iterator Nz::ByteArray::crend ( ) const
inlinenoexcept

Returns a constant reversed iterator pointing to the end of the string.

Returns
End of the string

◆ empty()

bool Nz::ByteArray::empty ( ) const
inlinenoexcept

Checks whether the byte array is empty.

Returns
true if byte array is empty

◆ end() [1/2]

ByteArray::iterator Nz::ByteArray::end ( )
inlinenoexcept

Returns an iterator pointing to the end of the string.

Returns
End of the string

◆ end() [2/2]

ByteArray::const_iterator Nz::ByteArray::end ( ) const
inlinenoexcept

Returns an iterator pointing to the end of the string.

Returns
End of the string

◆ Erase() [1/2]

ByteArray::iterator Nz::ByteArray::Erase ( const_iterator  pos)
inline

Erases an element from the byte array.

Parameters
posIterator to the element

◆ Erase() [2/2]

ByteArray::iterator Nz::ByteArray::Erase ( const_iterator  first,
const_iterator  last 
)
inline

Erases the elements between the two pointers from the byte array.

Parameters
firstFirst iterator
lastSecond iterator

◆ Front() [1/2]

ByteArray::reference Nz::ByteArray::Front ( )
inline

Gets first element.

Returns
A reference to first element
Remarks
If ByteArray is empty, behaviour is undefined

◆ Front() [2/2]

ByteArray::const_reference Nz::ByteArray::Front ( ) const
inline

Gets first element.

Returns
A constant reference to first element
Remarks
If ByteArray is empty, behaviour is undefined

◆ GetAllocator()

ByteArray::allocator_type Nz::ByteArray::GetAllocator ( ) const
inline

Gets the internal allocator of the byte array.

Returns
Allocator

◆ GetBuffer()

ByteArray::pointer Nz::ByteArray::GetBuffer ( )
inline

Gets the raw buffer.

Returns
Raw buffer

◆ GetCapacity()

ByteArray::size_type Nz::ByteArray::GetCapacity ( ) const
inlinenoexcept

Gets the capacity of the byte array.

Returns
Capacity of the byte array

◆ GetConstBuffer()

ByteArray::const_pointer Nz::ByteArray::GetConstBuffer ( ) const
inline

Gets the raw buffer.

Returns
Raw buffer

◆ GetMaxSize()

ByteArray::size_type Nz::ByteArray::GetMaxSize ( ) const
inlinenoexcept

Gets the maximal size supported by the byte array.

Returns
Biggest size handled

◆ GetSize()

ByteArray::size_type Nz::ByteArray::GetSize ( ) const
inlinenoexcept

Gets the size of the byte array.

Returns
Size of the byte array

◆ GetSubArray()

ByteArray Nz::ByteArray::GetSubArray ( const_iterator  startPos,
const_iterator  endPos 
) const
inline

Returns a sub byte array of the byte array.

Returns
Sub byte array
Parameters
startPosFirst iterator
endPosSecond iterator

◆ Insert() [1/4]

ByteArray::iterator Nz::ByteArray::Insert ( const_iterator  pos,
const void *  buffer,
size_type  n 
)
inline

Inserts the content of raw memory at the iterator position.

Parameters
posIterator to the position
bufferConstant pointer to raw memory
nSize that can be read
Remarks
If preallocated space of ptr is less than the size, the behaviour is undefined

◆ Insert() [2/4]

ByteArray::iterator Nz::ByteArray::Insert ( const_iterator  pos,
const ByteArray other 
)
inline

Inserts the content of another byte array at the iterator position.

Parameters
posIterator to the position
otherOther byte array

◆ Insert() [3/4]

ByteArray::iterator Nz::ByteArray::Insert ( const_iterator  pos,
size_type  n,
value_type  byte 
)
inline

Inserts n times the same byte at the iterator position.

Parameters
posIterator to the position
nNumber of repetitions
byteValue to repeat

◆ Insert() [4/4]

template<class InputIterator >
ByteArray::iterator Nz::ByteArray::Insert ( const_iterator  pos,
InputIterator  first,
InputIterator  last 
)

Inserts the content from two iterators at the iterator position.

Parameters
posIterator to the position
firstFirst iterator
lastSecond iterator

◆ IsEmpty()

bool Nz::ByteArray::IsEmpty ( ) const
inlinenoexcept

Checks whether the byte array is empty.

Returns
true if byte array is empty

◆ operator!=()

bool Nz::ByteArray::operator!= ( const ByteArray rhs) const
inline

Checks whether the first byte array is equal to the second byte array.

Returns
false if it is the case
Parameters
rhsByteArray to compare with

◆ operator+()

ByteArray Nz::ByteArray::operator+ ( const ByteArray other) const
inline

Concatenates the byte array to another.

Returns
ByteArray which is the result of the concatenation
Parameters
otherByteArray to add

◆ operator+=()

ByteArray & Nz::ByteArray::operator+= ( const ByteArray other)
inline

Concatenates the byte array to this byte array.

Returns
A reference to this
Parameters
otherByteArray to add

◆ operator<()

bool Nz::ByteArray::operator< ( const ByteArray rhs) const
inline

Checks whether the first byte array is less than the second byte array.

Returns
true if it is the case
Parameters
rhsByteArray to compare with

◆ operator<=()

bool Nz::ByteArray::operator<= ( const ByteArray rhs) const
inline

Checks whether the first byte array is less or equal than the second byte array.

Returns
true if it is the case
Parameters
rhsByteArray to compare with

◆ operator==()

bool Nz::ByteArray::operator== ( const ByteArray rhs) const
inline

Checks whether the first byte array is equal to the second byte array.

Returns
true if it is the case
Parameters
rhsByteArray to compare with

◆ operator>()

bool Nz::ByteArray::operator> ( const ByteArray rhs) const
inline

Checks whether the first byte array is greater than the second byte array.

Returns
true if it is the case
Parameters
rhsByteArray to compare with

◆ operator>=()

bool Nz::ByteArray::operator>= ( const ByteArray rhs) const
inline

Checks whether the first byte array is greater or equal than the second byte array.

Returns
true if it is the case
Parameters
rhsByteArray to compare with

◆ operator[]() [1/2]

ByteArray::reference Nz::ByteArray::operator[] ( size_type  pos)
inline

Gets the ith byte.

Returns
A reference to the byte at the ith position
Remarks
Produces a NazaraAssert if pos is greather than the size

◆ operator[]() [2/2]

ByteArray::const_reference Nz::ByteArray::operator[] ( size_type  pos) const
inline

Gets the ith byte.

Returns
A constant reference to the byte at the ith position
Remarks
Produces a NazaraAssert if pos is greather than the size

◆ PopBack()

void Nz::ByteArray::PopBack ( )
inline

Erases the last element.

Remarks
If byte array is empty, the behaviour is undefined

◆ PopFront()

void Nz::ByteArray::PopFront ( )
inline

Erases the first element.

Remarks
If byte array is empty, the behaviour is undefined

◆ Prepend() [1/2]

ByteArray::iterator Nz::ByteArray::Prepend ( const void *  buffer,
size_type  n 
)
inline

Prepends the content of raw memory.

Parameters
bufferConstant pointer to raw memory
nSize that can be read
Remarks
If preallocated space of buffer is less than the size, the behaviour is undefined
See also
Insert

◆ Prepend() [2/2]

ByteArray::iterator Nz::ByteArray::Prepend ( const ByteArray other)
inline

Prepends another array of bytes.

Parameters
otherByteArray to add
See also
Insert

◆ PushBack()

void Nz::ByteArray::PushBack ( value_type  byte)
inline

Pushes the byte at the end.

Parameters
byteByte to add

◆ PushFront()

void Nz::ByteArray::PushFront ( value_type  byte)
inline

Pushes the byte at the beginning.

Parameters
byteByte to add

◆ rbegin() [1/2]

ByteArray::reverse_iterator Nz::ByteArray::rbegin ( )
inlinenoexcept

Returns a reversed iterator pointing to the beggining of the string.

Returns
Beggining of the string

◆ rbegin() [2/2]

ByteArray::const_reverse_iterator Nz::ByteArray::rbegin ( ) const
inlinenoexcept

Returns a reversed iterator pointing to the beggining of the string.

Returns
Beggining of the string

◆ rend()

ByteArray::reverse_iterator Nz::ByteArray::rend ( )
inlinenoexcept

Returns a reversed iterator pointing to the end of the string.

Returns
End of the string

◆ Reserve()

void Nz::ByteArray::Reserve ( size_type  bufferSize)
inline

Reserves enough memory for the buffer size.

Parameters
bufferSizeSize of the buffer to allocate
Remarks
If bufferSize is smaller than the old one, nothing is done

◆ Resize() [1/2]

void Nz::ByteArray::Resize ( size_type  newSize)
inline

Resizes the string.

Returns
A reference to this
Parameters
newSizeTarget size

◆ Resize() [2/2]

void Nz::ByteArray::Resize ( size_type  newSize,
value_type  byte 
)
inline

Resizes the string.

Returns
A reference to this
Parameters
newSizeTarget size
byteByte to add if newSize is greather than actual size

◆ size()

ByteArray::size_type Nz::ByteArray::size ( ) const
inlinenoexcept

Gets the size of the byte array.

Returns
Size of the byte array

◆ Swap()

void Nz::ByteArray::Swap ( ByteArray other)
inline

Swaps the content with the other byte array.

Parameters
otherOther byte array to swap with

◆ ToHex()

String Nz::ByteArray::ToHex ( ) const

Gives a string representation in base 16.

Returns
String in base 16

◆ ToString()

String Nz::ByteArray::ToString ( ) const
inline

Gives a string representation.

Returns
String where each byte is converted to char

Friends And Related Function Documentation

◆ operator<<

NAZARA_CORE_API friend std::ostream& operator<< ( std::ostream &  out,
const Nz::ByteArray byteArray 
)
friend

Output operator.

Returns
The stream
Parameters
outThe stream
byteArrayThe ByteArray to output

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