Transfer Ease
Loading...
Searching...
No Matches
tease::BytesArray Class Reference

Allow to store an array of bytes. More...

Public Types

using Byte = uint8_t
 
using iterator = typename Container::iterator
 
using const_iterator = typename Container::const_iterator
 
using reverse_iterator = typename Container::reverse_iterator
 
using const_reverse_iterator = typename Container::const_reverse_iterator
 

Public Member Functions

 BytesArray (size_t size)
 
 BytesArray (size_t size, Byte value)
 
 BytesArray (const std::initializer_list< Byte > &args)
 
 BytesArray (const BytesArray &other)
 
 BytesArray (BytesArray &&other) noexcept
 
bool isEmpty () const
 
std::size_t getSize () const
 
std::size_t getMaxSize () const
 
const Byte & at (size_t index) const
 
std::string toString () const
 
bool toFile (const std::string &pathFile) const
 Allow to export bytes array data to a file.
 
void reserve (size_t size)
 Increase capacity of bytes array.
 
void resize (size_t size, Byte value=0)
 
void pushBack (Byte value)
 Append a value to the back of bytes array.
 
void pushBack (std::string_view strView)
 
void pushBack (const Byte *buffer, size_t len)
 
void popBack ()
 
void setFromString (std::string_view strView)
 Allow to set bytes array from a string.
 
bool setFromFile (const std::string &pathFile)
 Allow to set bytes array from file content.
 
Byte * data ()
 
const Byte * dataConst () const
 
void clear ()
 
iterator begin ()
 
const_iterator cbegin () const
 
reverse_iterator rbegin ()
 
const_reverse_iterator crbegin () const
 
iterator end ()
 
const_iterator cend () const
 
reverse_iterator rend ()
 
const_reverse_iterator crend () const
 
Byte & operator[] (size_t index)
 
const Byte & operator[] (size_t index) const
 
BytesArrayoperator= (const BytesArray &other)
 
BytesArrayoperator= (BytesArray &&other) noexcept
 

Friends

TEASE_EXPORT friend bool operator== (const BytesArray &left, const BytesArray &right)
 
TEASE_EXPORT friend bool operator!= (const BytesArray &left, const BytesArray &right)
 

Detailed Description

Allow to store an array of bytes.

Member Function Documentation

◆ pushBack() [1/2]

void tease::BytesArray::pushBack ( Byte value)

Append a value to the back of bytes array.

Parameters
[in]valueValue to add

◆ pushBack() [2/2]

void tease::BytesArray::pushBack ( std::string_view strView)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters
[in]strViewAppend string to bytes array.
See also
setFromString()

◆ reserve()

void tease::BytesArray::reserve ( size_t size)

Increase capacity of bytes array.

Parameters
[in]sizeTotal number of elements that the bytes array can hold without requiring reallocation.
If size is greater than getMaxSize(), new storage is allocated, otherwise the function does nothing (so no shrinking).
See also
resize()
getMaxSize()

◆ setFromFile()

bool tease::BytesArray::setFromFile ( const std::string & pathFile)

Allow to set bytes array from file content.

This method will clear any previous data and load file content data into the bytes array.

Parameters
[in]pathFilePath to file to load.
If file doesn't exist, method will returns false
Warning
Be careful with loaded file, current implementation will allocate same size memory than the loaded file.
Just to prevent any issues, 1Gb limit is currently in place.
Returns
Returns true if succeed.
See also
toFile()
setFromString()

◆ setFromString()

void tease::BytesArray::setFromString ( std::string_view strView)

Allow to set bytes array from a string.

This method will simply clear() any previous data and append string bytes via pushBack() method.

Parameters
[in]strViewString to use to set bytes array
See also
clear(), pushBack()
setFromFile()

◆ toFile()

bool tease::BytesArray::toFile ( const std::string & pathFile) const

Allow to export bytes array data to a file.

Parameters
[in]pathFilePath to file to create.
If file doesn't exists, method will automatically create it (and build needed folders).
If file already exists, it will be truncated before writing to it.
Returns
Returns true if succeed.
See also
setFromFile()
toString()

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