itom
Loading...
Searching...
No Matches
ito::ByteArray Class Reference

This is a Qt-free class for byte arrays (strings) without specific encoding information. More...

#include <byteArray.h>

Classes

struct  Data
 basic data container for class ByteArray that is implicitly shared over multiple instances of ByteArray of the same content More...
 

Public Member Functions

 ByteArray ()
 default constructor. The ByteArray is empty.
 
 ByteArray (const char *str)
 constructor that copies the content of str ('\0'-terminated) to this ByteArray.
 
 ByteArray (const ByteArray &copyConstr)
 copy constructor: the given byte array is implicitly shared between both instances until its content is changed by one of both participating instances.
 
 ByteArray (ByteArray &&other)
 
 ~ByteArray ()
 destructor: the internal data is deleted if no other instance needs it.
 
ByteArrayoperator= (const ByteArray &rhs)
 another ByteArray is assigned to this ByteArray. The old content is deleted and the given byte array is implicitly shared between both instances.
 
ByteArrayoperator= (ByteArray &&rhs)
 
ByteArrayoperator= (const char *str)
 a zero-terminated string is assigned to this ByteArray. The given char* is copied.
 
ByteArrayappend (const char *str)
 
ByteArrayappend (const ByteArray &str)
 
int length () const
 
int size () const
 
bool empty () const
 return true if the ByteArray is empty hence its length is 0
 
const char * data () const
 return the pointer to the internal character array. If it is empty, the returned pointer still points to a '\0' character. It is never NULL.
 
char & operator[] (unsigned int i) const
 access the i-th character of the ByteArray. An assertion is raised, if i is out of range
 
char & operator[] (int i) const
 access the i-th character of the ByteArray. An assertion is raised, if i is out of range
 
bool operator== (const ByteArray &a) const
 return true, if the content of this ByteArray is equal to the given ByteArray a.
 
bool operator!= (const ByteArray &a) const
 return false, if the content of this ByteArray is equal to the given ByteArray a.
 

Private Member Functions

void decAndFree (Data *x)
 

Private Attributes

Datad
 

Static Private Attributes

static char emptyChar = '\0'
 

Detailed Description

This is a Qt-free class for byte arrays (strings) without specific encoding information.

This class uses implicit sharing (copy-on-write) to reduce memory usage and to avoid the needless copying of data. It can be used to store 8-bit '\0' terminated strings and is a easy and safe way to handle const char* types. ByteArray is a lightweight class without any dependency to Qt and is used in many itom libraries e.g. the Qt-free itomCommonLib library.

Member Function Documentation

◆ append() [1/2]

ByteArray & ito::ByteArray::append ( const ByteArray & str)

the content of another ByteArray is appended to this ByteArray. If the ByteArray implictely shared its content with another one, the contents are duplicated before appending the new ByteArray.

◆ append() [2/2]

ByteArray & ito::ByteArray::append ( const char * str)

a zero-terminated string is appended to this ByteArray. If the ByteArray implictely shared its content with another one, the contents are duplicated before appending the new string.

◆ length()

int ito::ByteArray::length ( ) const
inline

return the length of the byte array or 0 if it is empty

See also
size

◆ operator[]() [1/2]

char & ito::ByteArray::operator[] ( int i) const
inline

access the i-th character of the ByteArray. An assertion is raised, if i is out of range

Parameters
iis the index of the requested character [0, length()-1]
Returns
i-th character

◆ operator[]() [2/2]

char & ito::ByteArray::operator[] ( unsigned int i) const
inline

access the i-th character of the ByteArray. An assertion is raised, if i is out of range

Parameters
iis the index of the requested character [0, length()-1]
Returns
i-th character

◆ size()

int ito::ByteArray::size ( ) const
inline

return the length of the byte array or 0 if it is empty

See also
length

Member Data Documentation

◆ d

Data* ito::ByteArray::d
private

pointer to Data container

◆ emptyChar

char ito::ByteArray::emptyChar = '\0'
staticprivate

static character that represents an empty byte array ('\0').


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