UA Server SDK C++ Bundle
1.4.1.271
|
The UaByteArray handles the access to an array of bytes. More...
#include <uabytearray.h>
Public Member Functions | |
UaByteArray () | |
Constructs an empty byte array. More... | |
UaByteArray (const char *pData, int iSize) | |
Constructs a byte array as copy of pData. More... | |
UaByteArray (const UaByteArray &other) | |
Constructs a copy of other. More... | |
UaByteArray (const OpcUa_ByteString &other) | |
construction More... | |
UaByteArray (const UaByteString &other) | |
Constructs a byte array from a given byte string. More... | |
~UaByteArray () | |
Destroys the array. More... | |
UaByteArray & | operator= (const UaByteArray &other) |
Assigns other to this array and returns a reference to this array. More... | |
void | resize (int iSize) |
Resizes the array. More... | |
int | size () const |
Returns the size of this array. More... | |
int | capacity () const |
Returns the capacity of this array. More... | |
char | operator[] (int i) const |
Returns the byte at the given position. More... | |
char | operator[] (unsigned int i) const |
Returns the byte at the given position. More... | |
UaByteRef | operator[] (int i) |
This function is provided for convenience and behaves like the function above. More... | |
UaByteRef | operator[] (unsigned int i) |
This function is provided for convenience and behaves like the function above. More... | |
const char * | data () const |
Returns the pointer to the internal array data (as const char*). More... | |
operator const char * () const | |
Returns the pointer to the internal array data as (const char*). More... | |
operator const UaUShort * () const | |
Returns the pointer to the internal array data as (const UaUShort*). More... | |
operator const void * () const | |
Returns the pointer to the internal array data as (const void*). More... | |
void | copyTo (OpcUa_ByteString *) const |
Copies the UaByteArray Date into a OpcUa_ByteString. More... | |
UaString | toHex (bool bSeparateWithSpace=false) const |
Converts the byte array into a hex string. More... | |
Static Public Member Functions | |
static UaByteArray | fromHex (const UaString &src) |
Converts a hexadecimal string representation of a byte array into a UaByteArray. More... | |
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.
UaByteArray::UaByteArray | ( | ) |
Constructs an empty byte array.
UaByteArray::UaByteArray | ( | const char * | pData, |
int | iSize | ||
) |
Constructs a byte array as copy of pData.
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
other | the OpcUa_ByteString to assign. |
UaByteArray::UaByteArray | ( | const UaByteString & | other | ) |
Constructs a byte array from a given byte string.
other | the byte string to copy |
UaByteArray::~UaByteArray | ( | ) |
Destroys the 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.
void UaByteArray::copyTo | ( | OpcUa_ByteString * | pDst | ) | const |
Copies the UaByteArray Date into a OpcUa_ByteString.
pDst | the destination of this operation. |
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.
|
static |
Converts a hexadecimal string representation of a byte array into a UaByteArray.
This string should not contain spaces and the string length must be a multiple of 2 (2 chars per byte).
src | the source of this operation. |
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.
UaByteArray & UaByteArray::operator= | ( | const UaByteArray & | other | ) |
Assigns other to this array and returns a reference to this array.
other | the UaByteArray to assign. |
char UaByteArray::operator[] | ( | int | i | ) | const |
Returns the byte at the given position.
char UaByteArray::operator[] | ( | unsigned int | i | ) | const |
Returns the byte at the given position.
|
inline |
This function is provided for convenience and behaves like the function above.
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.
i | a variable to compare with. |
|
inline |
This function is provided for convenience and behaves like the function above.
i | a variable to compare with. |
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.
iSize | the actual size to resize the array. If <= 0, the ByteArray gets cleared and the size and the capacity are set to 0. |
int UaByteArray::size | ( | ) | const |
Returns the size of this array.
UaString UaByteArray::toHex | ( | bool | bSeparateWithSpace = false | ) | const |
Converts the byte array into a hex string.
bSeparateWithSpace | Separates each byte in the hex string with a space. Per default bSeparateWithSpace=false, you can use bSeparateWithSpace = true for better display. |