UaByteArray Class Reference
[UA Base Library Classes]

The UaByteArray handles the access to an array of bytes. UaByteArray can be used to store both raw bytes (including \0s) and traditional 8-bit \0-terminated strings. Using UaByteArray is much more convenient than using const char *. Behind the scenes, it always ensures that the data is followed by a \0 terminator, and uses implicit sharing (copy-on-write) to reduce memory usage and avoid needless copying of data. You don't need to care about resizing or cleaning up the memory. More...

#include <uabytearray.h>

List of all members.


Public Member Functions

 UaByteArray ()
 UaByteArray (const char *pData, int iSize)
 UaByteArray (const UaByteArray &other)
 UaByteArray (const OpcUa_ByteString &other)
 ~UaByteArray ()
UaByteArrayoperator= (const UaByteArray &other)
void resize (int iSize)
int size () const
int capacity () const
const char operator[] (int i) const
const char operator[] (unsigned int i) const
UaByteRef operator[] (int i)
UaByteRef operator[] (unsigned int i)
const char * data () const
 operator const char * () const
 operator const UaUShort * () const
 operator const void * () const
void copyTo (OpcUa_ByteString *) const
UaString toHex (bool bSeparateWithSpace=false) const

Static Public Member Functions

static UaByteArray fromHex (const UaString &src)

Friends

class UaByteRef

Detailed Description

The UaByteArray handles the access to an array of bytes. UaByteArray can be used to store both raw bytes (including \0s) and traditional 8-bit \0-terminated strings. Using UaByteArray is much more convenient than using const char *. Behind the scenes, it always ensures that the data is followed by a \0 terminator, and uses implicit sharing (copy-on-write) to reduce memory usage and avoid needless copying of data. You don't need to care about resizing or cleaning up the memory.

Constructor & Destructor Documentation

UaByteArray::UaByteArray (  ) 

Constructs an empty byte array.

UaByteArray::UaByteArray ( const char *  pData,
int  iSize 
)

Constructs a byte array as copy of pData.

Parameters:
pData data to copy
iSize length of the data in bytes

UaByteArray::UaByteArray ( const UaByteArray other  ) 

Constructs a copy of other. This operation takes constant time, because UaByteArray is implicitly shared. This makes returning a UaByteArray from a function very fast. If a shared instance is modified, it will be copied (copy-on-write), and that takes linear time.

UaByteArray::UaByteArray ( const OpcUa_ByteString &  other  ) 

construction

Parameters:
other the OpcUa_ByteString to assign.

UaByteArray::~UaByteArray (  ) 

Destroys the array.


Member Function Documentation

UaByteArray & UaByteArray::operator= ( const UaByteArray other  ) 

Assigns other to this array and returns a reference to this array.

Parameters:
other the UaByteArray to assign.
Returns:
a reference to this array.

void UaByteArray::resize ( int  iSize  ) 

Resizes the array. If more than one reference exists to this array, this function creates a copy this array with the new size iSize.

Parameters:
iSize the actual size to resize the array.

int UaByteArray::size (  )  const

Returns the size of this array.

Returns:
the size of this array.

int UaByteArray::capacity (  )  const

Returns the capacity of this array. You will rarely ever need this function. You can check how many bytes you can until an automatic resize happens.

Returns:
Descripte capacity of this array.

const char UaByteArray::operator[] ( int  i  )  const

Returns the byte at the given position.

const char UaByteArray::operator[] ( unsigned int  i  )  const

Returns the byte at the given position.

UaByteRef UaByteArray::operator[] ( int  i  )  [inline]

This function is provided for convenience and behaves like the function above.

See also:
operator[](int i)
Returns the byte at index position i as a modifiable reference. If an assignment is made beyond the end of the byte array, the array is extended with resize() before the assignment takes place.

Example:

     UaByteArray ba;
     for (int i = 0; i < 10; ++i)
         ba[i] = 'A' + i;
     // ba == "ABCDEFGHIJ"
  
The return value is of type UaByteRef, a helper class for UaByteArray. When you get an object of type UaByteRef, you can use it as if it were a char &. If you assign to it, the assignment will apply to the character in the UaByteArray from which you got the reference.
See also:
operator[](unsigned int i)
Parameters:
i a variable to compare with.
Returns:
a ByteRef reference.

UaByteRef UaByteArray::operator[] ( unsigned int  i  )  [inline]

This function is provided for convenience and behaves like the function above.

See also:
operator[](int i)
This function is provided for convenience and behaves like the function above.
See also:
operator[](int i)
Parameters:
i a variable to compare with.
Returns:
ByteRef reference.

const char * UaByteArray::data (  )  const

Returns the pointer to the internal array data (as const char*). The pointer stays valid until you modify the array or it's deleted.

UaByteArray::operator const char * (  )  const

Returns the pointer to the internal array data as (const char*). The pointer stays valid until you modify the array or it's deleted.

UaByteArray::operator const UaUShort * (  )  const

Returns the pointer to the internal array data as (const UaUShort*). The pointer stays valid until you modify the array or it's deleted.

UaByteArray::operator const void * (  )  const

Returns the pointer to the internal array data as (const void*). The pointer stays valid until you modify the array or it's deleted.

void UaByteArray::copyTo ( OpcUa_ByteString *  pDst  )  const

Copies the UaByteArray Date into a OpcUa_ByteString.

Parameters:
pDst the destination of this operation.

UaString UaByteArray::toHex ( bool  bSeparateWithSpace = false  )  const

Converts the byte array into a hex string.

Parameters:
bSeparateWithSpace Separates each byte in the hex string with a space. Per default bSeparateWithSpace=false, you can use bSeparateWithSpace = true for better display.
Returns:
a hex string.

UaByteArray UaByteArray::fromHex ( const UaString src  )  [static]

Converts a hexadeciamal string representation of a byte array into a UaByteArray. This string should not contain spaces and the string length must be a mutiple of 2 (2 chars per byte).

Parameters:
src the source of this operation.
Returns:
If an error occurs an empty byte array is returned.


The documentation for this class was generated from the following files:
  • src/uabase/uabasecpp/uabytearray.h
  • src/uabase/uabasecpp/uabytearray.cpp