UA Server SDK C++ Bundle
1.4.0.258
|
This class encapsulates the native OpcUa_String structure and handles memory allocation and cleanup for you. More...
#include <uastring.h>
Public Member Functions | |
UaString () | |
Default constructor. More... | |
UaString (const OpcUa_String *other) | |
Creates a copy of the native OpcUa_String. More... | |
UaString (const OpcUa_String &other) | |
Creates a copy of the native OpcUa_String. More... | |
UaString (const UaString &other) | |
Creates a copy of another UaString. More... | |
UaString (const UaByteString &other) | |
Creates a string initialized with the byte array other. More... | |
UaString (const char *other) | |
Creates a copy of an UTF-8 encoded character string. More... | |
UaString (const UaUShort *other) | |
Creates a copy of an UTF-16 encoded wide character string. More... | |
~UaString () | |
Destroys the string. More... | |
UaString & | operator= (const UaString &other) |
Assigns other to this string and returns a reference to this string. More... | |
UaString & | attach (char *other, int len) |
UaString & | attach (const OpcUa_String *pSrc) |
int | size () const |
Returns the size in bytes that the internal UTF-8 representation needs to hold this string. More... | |
int | length () const |
Returns the number of characters of this string. More... | |
bool | isEmpty () const |
Returns true if the string is empty. More... | |
bool | isNull () const |
Returns true if the string is null. More... | |
const UaChar | at (int i) const |
Returns a read only unicode character. More... | |
int | find (UaChar cFind) const |
Finds the position of an UTF-8 character in the string. More... | |
int | find (UaChar cFind, unsigned int iStart) const |
Finds the position of an UTF-8 character in the string after start index. More... | |
bool | like (const UaString &pattern) const |
Implements the Like-Operator of the UA-Specification. More... | |
bool | operator== (const UaString &other) const |
Returns true if other is equal to this. More... | |
bool | operator!= (const UaString &other) const |
Returns true if other is not equal to this. More... | |
bool | operator< (const UaString &other) const |
This operator is mainly used to sort strings. More... | |
UaString & | operator+= (const UaString &other) |
Appends a string to the internal string. More... | |
UaString | operator+ (const UaString &other) |
Addition operator. More... | |
UaString | arg (const UaString &a, int fieldWidth=0, const UaChar &fillChar=UaChar(' ')) const |
Returns a copy of this string with the lowest numbered place marker replaced by string a, i.e., %1, %2, ..., %99. More... | |
UaString | arg (int a, int fieldWidth=0, int base=10, const UaChar &fillChar=UaChar(' ')) const |
UaString | arg (unsigned int a, int fieldWidth=0, int base=10, const UaChar &fillChar=UaChar(' ')) const |
UaString | arg (double a, int fieldWidth=0, char format= 'g', int precision=-1, const UaChar &fillChar=UaChar(' ')) const |
OpcUa_String * | copy () const |
Creates an independent copy of this string as OpcUa_String. More... | |
void | copyTo (OpcUa_String *pDst) const |
Copies the string contents into an existing OpcUa_String. More... | |
const OpcUa_String * | toOpcUaString () const |
Returns an OpcUa_String to be able to pass this string to low level OPC UA stack functions. More... | |
operator const OpcUa_String * () const | |
This implicitly casts this string to an OpcUa_String to be able to pass it to low level OPC UA stack functions. More... | |
const char * | toUtf8 () const |
Returns the string as a '\0'-terminated array of characters. More... | |
UaByteArray | toUtf16 () const |
Returns a UTF-16 representation of the string as a UaByteArray. More... | |
UaByteArray | toLocal8Bit () const |
void | toVariant (UaVariant &variant) const |
void | toVariant (OpcUa_Variant &variant) const |
void | toVariant (UaVariant &variant, OpcUa_Boolean bDetach) |
void | toVariant (OpcUa_Variant &variant, OpcUa_Boolean bDetach) |
void | toDataValue (UaDataValue &dataValue, OpcUa_Boolean updateTimeStamps) const |
void | toDataValue (OpcUa_DataValue &dataValue, OpcUa_Boolean updateTimeStamps) const |
void | toDataValue (UaDataValue &dataValue, OpcUa_Boolean bDetach, OpcUa_Boolean updateTimeStamps) |
void | toDataValue (OpcUa_DataValue &dataValue, OpcUa_Boolean bDetach, OpcUa_Boolean updateTimeStamps) |
Static Public Member Functions | |
static bool | isLikePatternValid (const UaString &pattern) |
Tests if a given Like-Pattern is valid or not. More... | |
static UaString | number (int n, int base=10) |
Returns a string equivalent of the number n to base base, which is 10 by default and must be between 2 and 36. More... | |
static UaString | number (unsigned int n, int base=10) |
Returns a string equivalent of the number n to base base, which is 10 by default and must be between 2 and 36. More... | |
static OpcUa_String * | clone (const OpcUa_String &source) |
This is a convenience function to clone native OpcUa_String that are used in the OPC UA ANSI Stack. More... | |
static void | cloneTo (const OpcUa_String &source, OpcUa_String ©) |
This is a convenience function and behaves like the function above. More... | |
Friends | |
UABASE_EXPORT UaDataStream & | operator<< (UaDataStream &, const UaString &) |
define UaDataStream operators for UaString. More... | |
UABASE_EXPORT UaDataStream & | operator>> (UaDataStream &, UaString &) |
This class encapsulates the native OpcUa_String structure and handles memory allocation and cleanup for you.
Additionally you can extract native UTF-8 (char*) strings or UTF-16 (ushort*) strings for further processing in other applications.
UaString uses implicit sharing to avoid needless copying and to boost the performance. Only if you modify a shared string it creates a copy for that (copy-on-write). So assigning another UaString or passing it as parameter needs constant time is nearly as fast as assigning a pointer.
UaString::UaString | ( | ) |
Default constructor.
Creates an empty UaString.
UaString::UaString | ( | const OpcUa_String * | other | ) |
Creates a copy of the native OpcUa_String.
other | Source string. |
UaString::UaString | ( | const OpcUa_String & | other | ) |
Creates a copy of the native OpcUa_String.
other | Source string. |
UaString::UaString | ( | const UaString & | other | ) |
UaString::UaString | ( | const UaByteString & | other | ) |
Creates a string initialized with the byte array other.
The given data is interpreted as UTF-8. Stops copying at the first 0 character, otherwise copies the entire byte array. The the array is not 0 terminated a 0 will be appended.
other | the byte array to copy. |
UaString::UaString | ( | const char * | other | ) |
Creates a copy of an UTF-8 encoded character string.
This operation assumes that other is UTF-8 encoded. You may also pass pure ASCII strings with characters below 128. The first 128 characters from US-ASCII (Unicode range U+0000 to U+007F).are a subset of UTF-8.
UaString sample("abc");
Don't use unicode characters in hard coded strings unless you know what you are doing. This will only work if you save your source file UTF-8 encoded.
UaString sample("öäü"); // DANGER!!!
other | the const char. |
UaString::UaString | ( | const UaUShort * | other | ) |
Creates a copy of an UTF-16 encoded wide character string.
This is typically used on Windows with wchar_t* strings.
other | the UaUShort. |
UaString::~UaString | ( | ) |
Destroys the string.
UaString UaString::arg | ( | const UaString & | a, |
int | fieldWidth = 0 , |
||
const UaChar & | fillChar = UaChar(' ') |
||
) | const |
Returns a copy of this string with the lowest numbered place marker replaced by string a, i.e., %1, %2, ..., %99.
a | String to replace the lowest numbered place marker with. |
fieldWidth | specifies the minimum amount of space that argument a shall occupy. If a requires less space than fieldWidth, it is padded to fieldWidth with character fillChar. A positive fieldWidth produces right-aligned text. A negative fieldWidth produces left-aligned text. |
fillChar | If a requires less space than fieldWidth, it is padded to fieldWidth with character fillChar. |
const UaChar UaString::at | ( | int | i | ) | const |
Returns a read only unicode character.
Because UTF-8 is from variable length you cannot simply change a character. Other may need to be moved.
i | the position of the actual char in the string. |
|
static |
This is a convenience function to clone native OpcUa_String that are used in the OPC UA ANSI Stack.
This works without creating an instance of UaString.
source | The source string to clone. |
|
static |
This is a convenience function and behaves like the function above.
The difference is, that is copies the string into an existing OpcUa_String instead of allocating a new structure. This may be used to fill an OpcUa_String that is embedded into another structure.
source | he source string to clone. |
copy | The destination string to copy the string contents to. |
OpcUa_String * UaString::copy | ( | ) | const |
Creates an independent copy of this string as OpcUa_String.
Use this function if you need a copy of this string that is freed from the OPC UA stack. The returned string must be freed with OpcUa_String_Delete.
void UaString::copyTo | ( | OpcUa_String * | pDst | ) | const |
Copies the string contents into an existing OpcUa_String.
Use this function if you need to fill an OpcUa_String that is nested in another OPC UA structure.
Example:
UaString sNodeId("Path/to/Node"); OpcUa_NodeId id; id.IdentifierType = OpcUa_IdentifierType_String; sNodeId.copyTo(&id.Identifier.String);
pDst | the destination of this copy operation. |
int UaString::find | ( | UaChar | cFind | ) | const |
Finds the position of an UTF-8 character in the string.
cFind | the char to find the position of. |
int UaString::find | ( | UaChar | cFind, |
unsigned int | iStart | ||
) | const |
Finds the position of an UTF-8 character in the string after start index.
cFind | the char to find the position of. |
iStart | the start position to find the char. |
bool UaString::isEmpty | ( | ) | const |
Returns true if the string is empty.
This function will return true for a null string.
|
static |
Tests if a given Like-Pattern is valid or not.
pattern | the Like-Pattern to test. |
bool UaString::isNull | ( | ) | const |
Returns true if the string is null.
This function will return false for an empty string.
int UaString::length | ( | ) | const |
Returns the number of characters of this string.
You will need this function for displaying it. With UTF-8 strings the number of characters and the size in bytes may differ
bool UaString::like | ( | const UaString & | pattern | ) | const |
Implements the Like-Operator of the UA-Specification.
Checks if the given pattern matches the string.
pattern | the Like-Pattern to use. |
|
static |
Returns a string equivalent of the number n to base base, which is 10 by default and must be between 2 and 36.
n | a signed int number to convert to a string |
base | the base for interpreting the number |
|
static |
Returns a string equivalent of the number n to base base, which is 10 by default and must be between 2 and 36.
n | a unsigned int number to convert to a string |
base | the base for interpreting the number |
UaString::operator const OpcUa_String * | ( | ) | const |
This implicitly casts this string to an OpcUa_String to be able to pass it to low level OPC UA stack functions.
The result remains valid until the string is modified.
bool UaString::operator!= | ( | const UaString & | other | ) | const |
Returns true if other is not equal to this.
other | the UaString to compare. |
Appends a string to the internal string.
This creates a copy of the string because the internal data needs to changed.
other | the UaString to append. |
bool UaString::operator< | ( | const UaString & | other | ) | const |
This operator is mainly used to sort strings.
That is e.g. necessary to use it as a key in a binary tree.
other | the UaString to append. |
Assigns other to this string and returns a reference to this string.
other | the UaString to assign. |
bool UaString::operator== | ( | const UaString & | other | ) | const |
Returns true if other is equal to this.
other | the UaString to compare. |
int UaString::size | ( | ) | const |
Returns the size in bytes that the internal UTF-8 representation needs to hold this string.
You will only need this function, if you want to allocate a native UTF-8 string that should be big enough to hold this string.
const OpcUa_String * UaString::toOpcUaString | ( | ) | const |
Returns an OpcUa_String to be able to pass this string to low level OPC UA stack functions.
The result remains valid until the string is modified.
UaByteArray UaString::toUtf16 | ( | ) | const |
Returns a UTF-16 representation of the string as a UaByteArray.
This creates a copy of the string because the internal data needs to be converted. UaByteArray takes care of the memory.
Make sure you are always using the function together with a cast to const UaUShort* to make sure you get the right format extracted if you need a wchar_t*.
Example:
wchar_t str[512]; UaString sString("Test String"); // Wrong use swprintf_s(str, 512, L"String:%s", sString.toUtf16()); // str = String: // Right use swprintf_s(str, 512, L"String:%s", (const UaUShort*)sString.toUtf16()); // str = String:Test String
const char * UaString::toUtf8 | ( | ) | const |
Returns the string as a '\0'-terminated array of characters.
The result remains valid until the string is modified
|
friend |
define UaDataStream operators for UaString.