Jameo Core Library
Loading...
Searching...
No Matches
Public Member Functions | Friends | List of all members
jm::ByteArray Class Reference

Represents a byte array and provide convenient methods for accessing the data. The Byte array is always \0 terminated. More...

Inheritance diagram for jm::ByteArray:
jm::Object

Public Member Functions

 ByteArray ()
 Default Constructor.
 
 ByteArray (const int8 *buffer, size_t size=npos)
 Create a byte array. If size is < 0, a 0 terminated string is assumed. We make a copy of buffer. If buffer is NULL a NULL array is created.
 
 ByteArray (const uint8 *buffer, size_t size=npos)
 
 ByteArray (size_t size, uint8 ch)
 Creates a byte array of size and fills every byte with ch.
 
 ByteArray (const ByteArray &other)
 
 ByteArray (std::initializer_list< uint8 > list)
 
 ~ByteArray () override
 
int8 * data ()
 Returns the pointer to the data. With the pointer it is possible to modify the data. The data is always \0-terminated. The number of bytes can be assumed as Size()+1, including the \0-terminator.
 
const char * constData () const
 Returns a const pointer to the data.
 
size_t size () const
 Returns the size of the array.
 
bool isNull () const
 Returns true, if the array is NULL.
 
bool isEmpty () const
 Returns true, if the size of the array is 0.
 
void sort ()
 Sort the bytes in the array in ascending order.
 
void fill (uint8 ch)
 Set every byte in the array to ch.
 
void resize (size_t newSize)
 Resize the byte array. If the new size is bigger, it will increase the array. If the size is smaller, the bytes beyond the new size are excluded, but the array will have the same size.
 
void reserve (size_t size)
 Reserve space for a given number of bytes. The size of the array is not changed.
 
uint8 get (size_t index) const
 
void set (size_t index, uint8 item)
 
void replace (size_t tgtOffset, size_t srcOffset, const ByteArray &buffer, size_t length)
 Replaces the content of this array with the content of the other array.
 
void replace (uint8 oldValue, uint8 newValue)
 Replaces every byte of oldValue by the newValue.
 
uint8 operator[] (size_t index) const
 
uint8 & operator[] (size_t index)
 
ByteArrayoperator= (const ByteArray &another)
 
- Public Member Functions inherited from jm::Object
 Object () noexcept
 Constructor.
 
virtual ~Object () noexcept
 Destructor.
 
void release () noexcept
 Decreases the reference counter and releases the object immediately when the reference counter becomes 0.
 
Objectretain () noexcept
 Increases the reference counter of this object by 1.
 
Objectautorelease () noexcept
 Same function as release(), but releases the object with a delay if the reference counter is 0. AutoreleasePool::drain() must be called in the to release the object.
 
int32 referenceCount () const noexcept
 Returns the value of the reference counter.
 
virtual bool equals (const Object *other) const
 Comparison of objects.
 
virtual String displayName () const
 Returns the display name of the object intended to present to a user.
 
virtual void printDiffInfo (DiffOperation operation, Object *other) const
 Output method for outputting the diff results for the diff algorithm.
 
void setHighBit (bool status) noexcept
 
bool highBit () const noexcept
 

Friends

bool operator== (const ByteArray &a1, const ByteArray &a2)
 

Detailed Description

Represents a byte array and provide convenient methods for accessing the data. The Byte array is always \0 terminated.

Constructor & Destructor Documentation

◆ ByteArray() [1/6]

jm::ByteArray::ByteArray ( )

Default Constructor.

◆ ByteArray() [2/6]

jm::ByteArray::ByteArray ( const int8 *  buffer,
size_t  size = npos 
)
explicit

Create a byte array. If size is < 0, a 0 terminated string is assumed. We make a copy of buffer. If buffer is NULL a NULL array is created.

◆ ByteArray() [3/6]

jm::ByteArray::ByteArray ( const uint8 *  buffer,
size_t  size = npos 
)
explicit

◆ ByteArray() [4/6]

jm::ByteArray::ByteArray ( size_t  size,
uint8  ch 
)

Creates a byte array of size and fills every byte with ch.

◆ ByteArray() [5/6]

jm::ByteArray::ByteArray ( const ByteArray other)

◆ ByteArray() [6/6]

jm::ByteArray::ByteArray ( std::initializer_list< uint8 >  list)

◆ ~ByteArray()

jm::ByteArray::~ByteArray ( )
override

Member Function Documentation

◆ constData()

const char * jm::ByteArray::constData ( ) const

Returns a const pointer to the data.

Note
We use char (instead of int8 here, because char can be signe or unsigned, depending on operating system.)

◆ data()

int8 * jm::ByteArray::data ( )

Returns the pointer to the data. With the pointer it is possible to modify the data. The data is always \0-terminated. The number of bytes can be assumed as Size()+1, including the \0-terminator.

◆ fill()

void jm::ByteArray::fill ( uint8  ch)

Set every byte in the array to ch.

◆ get()

uint8 jm::ByteArray::get ( size_t  index) const

◆ isEmpty()

bool jm::ByteArray::isEmpty ( ) const

Returns true, if the size of the array is 0.

◆ isNull()

bool jm::ByteArray::isNull ( ) const

Returns true, if the array is NULL.

◆ operator=()

ByteArray & jm::ByteArray::operator= ( const ByteArray another)

◆ operator[]() [1/2]

uint8 & jm::ByteArray::operator[] ( size_t  index)

◆ operator[]() [2/2]

uint8 jm::ByteArray::operator[] ( size_t  index) const

◆ replace() [1/2]

void jm::ByteArray::replace ( size_t  tgtOffset,
size_t  srcOffset,
const ByteArray buffer,
size_t  length 
)

Replaces the content of this array with the content of the other array.

◆ replace() [2/2]

void jm::ByteArray::replace ( uint8  oldValue,
uint8  newValue 
)

Replaces every byte of oldValue by the newValue.

◆ reserve()

void jm::ByteArray::reserve ( size_t  size)

Reserve space for a given number of bytes. The size of the array is not changed.

Parameters
sizeThe number of elements to reserve space for.

◆ resize()

void jm::ByteArray::resize ( size_t  newSize)

Resize the byte array. If the new size is bigger, it will increase the array. If the size is smaller, the bytes beyond the new size are excluded, but the array will have the same size.

Parameters
newSizeThe new size of the array.

◆ set()

void jm::ByteArray::set ( size_t  index,
uint8  item 
)

◆ size()

size_t jm::ByteArray::size ( ) const

Returns the size of the array.

◆ sort()

void jm::ByteArray::sort ( )

Sort the bytes in the array in ascending order.

Friends And Related Symbol Documentation

◆ operator==

bool operator== ( const ByteArray a1,
const ByteArray a2 
)
friend