itom 2.2.1
ito::ByteArray Class Reference

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

#include <byteArray.h>

List of all members.

Classes

struct  Data
 basic data container for class ByteArray that is implicitely 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 implicitely shared between both instances until its content is changed by one of both participating instances.
 ~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 implicitely shared between both instances.
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 leightweight class without any dependency to Qt and is used in many itom libraries e.g. the Qt-free itomCommonLib library.


Member Function Documentation

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.

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.

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

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

See also:
size
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
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
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

Data* ito::ByteArray::d [private]

pointer to Data container

char ito::ByteArray::emptyChar = '\0' [static, private]

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


The documentation for this class was generated from the following files:
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Properties Friends