QKnxByteArray Class

The QKnxByteArray class provides an array of unsigned bytes. 更多...

头: #include <QKnxByteArray>
qmake: QT += knx

公共类型

typedef const_iterator
typedef const_reverse_iterator
typedef iterator
typedef reverse_iterator

公共函数

QKnxByteArray (QKnxByteArray && other )
QKnxByteArray (const QKnxByteArray & other )
QKnxByteArray (std::initializer_list<quint8> args )
QKnxByteArray (const quint8 * data , int size )
QKnxByteArray (const char * data , int size )
QKnxByteArray (int size , quint8 ch )
QKnxByteArray ()
QKnxByteArray & operator= (QKnxByteArray && other )
QKnxByteArray & operator= (const QKnxByteArray & other )
~QKnxByteArray ()
QKnxByteArray & append (const QKnxByteArray & ba )
QKnxByteArray & append (quint8 ch )
QKnxByteArray & append (int count , quint8 ch )
quint8 at (int i ) const
QKnxByteArray::iterator begin ()
QKnxByteArray::const_iterator begin () const
QKnxByteArray::const_iterator cbegin () const
QKnxByteArray::const_iterator cend () const
QKnxByteArray chop (int len ) const
void clear ()
QKnxByteArray::const_iterator constBegin () const
const quint8 * constData () const
QKnxByteArray::const_iterator constEnd () const
bool contains (const QKnxByteArray & ba ) const
bool contains (quint8 ch ) const
QKnxByteArray::const_reverse_iterator crbegin () const
QKnxByteArray::const_reverse_iterator crend () const
quint8 * data ()
const quint8 * data () const
QKnxByteArray::iterator end ()
QKnxByteArray::const_iterator end () const
bool endsWith (const QKnxByteArray & ba ) const
bool endsWith (quint8 ch ) const
QKnxByteArray & fill (quint8 ch , int size = -1)
int indexOf (const QKnxByteArray & ba , int from = 0) const
int indexOf (quint8 ch , int from = 0) const
QKnxByteArray & insert (int i , const QKnxByteArray & ba )
QKnxByteArray & insert (int i , quint8 ch )
QKnxByteArray & insert (int i , int count , quint8 ch )
bool isEmpty () const
bool isNull () const
int lastIndexOf (const QKnxByteArray & ba , int from = -1) const
int lastIndexOf (quint8 ch , int from = -1) const
QKnxByteArray left (int len ) const
QKnxByteArray mid (int pos , int len = -1) const
QKnxByteArray & prepend (const QKnxByteArray & ba )
QKnxByteArray & prepend (quint8 ch )
QKnxByteArray & prepend (int count , quint8 ch )
QKnxByteArray::reverse_iterator rbegin ()
QKnxByteArray::const_reverse_iterator rbegin () const
QKnxByteArray & remove (int pos , int len )
QKnxByteArray::reverse_iterator rend ()
QKnxByteArray::const_reverse_iterator rend () const
QKnxByteArray repeated (int times ) const
QKnxByteArray & replace (int index , int len , const QKnxByteArray & after )
QKnxByteArray & replace (quint8 before , const QKnxByteArray & after )
QKnxByteArray & replace (const QKnxByteArray & before , const QKnxByteArray & after )
QKnxByteArray & replace (quint8 before , quint8 after )
void resize (int size )
QKnxByteArray right (int len ) const
void set (int i , quint8 val )
void setValue (int i , quint8 val )
int size () const
bool startsWith (const QKnxByteArray & ba ) const
bool startsWith (quint8 ch ) const
void swap (QKnxByteArray & other )
const QByteArray & toByteArray () const
QKnxByteArray toHex (quint8 separator = '\0') const
quint8 value (int i , quint8 defaultValue = {}) const
QKnxByteArray & operator+= (const QKnxByteArray & ba )
QKnxByteArray & operator+= (quint8 ch )

静态公共成员

QKnxByteArray fromByteArray (const QByteArray & byteArray )
QKnxByteArray fromHex (const QKnxByteArray & hexEncoded )
QKnxByteArray fromHex (const QByteArray & hexEncoded )
uint qHash (const QKnxByteArray & key , uint seed = 0)
bool operator!= (const QKnxByteArray & a1 , const QKnxByteArray & a2 )
const QKnxByteArray operator+ (const QKnxByteArray & a1 , const QKnxByteArray & a2 )
const QKnxByteArray operator+ (const QKnxByteArray & ba , quint8 ch )
const QKnxByteArray operator+ (quint8 ch , const QKnxByteArray & ba )
QDebug operator<< (QDebug debug , const QKnxByteArray & byteArray )
bool operator== (const QKnxByteArray & a1 , const QKnxByteArray & a2 )

详细描述

A KNX byte array can be used to store both raw bytes (including the string \0 and any characters that might come after it) and traditional 8-bit \0 -terminated strings. Using QKnxByteArray is much more convenient than using const quint8 * . Behind the scenes, it always ensures that the data is followed by a null-terminator ( \0 ).

QKnxByteArray makes a deep copy of the data given, so you can modify it later without experiencing side effects.

Another approach is to set the size of the array using resize () and to initialize the data byte per byte. QKnxByteArray uses 0-based indexes, just like C++ arrays. To access the byte at a particular index position, you can use at (), set (), value () 和 setValue ().

To extract several bytes at a time, use left (), right (),或 mid ().

A KNX byte array can embed \0 bytes. The size () function always returns the size of the whole array, including the embedded \0 bytes, but excluding the null-terminator added by QKnxByteArray.

After a call to resize (), newly allocated bytes have undefined values. To set all the bytes to a particular value, call fill ().

要获得实际字符数据指针,调用 data () 或 constData (). These functions return a pointer to the beginning of the data. The pointer is guaranteed to remain valid until a non-const function is called on the byte array.

成员类型文档编制

typedef QKnxByteArray:: const_iterator

此 typedef 提供 STL 样式 const 迭代器为 QKnxByteArray .

typedef QKnxByteArray:: const_reverse_iterator

This typedef provides an STL-style const reverse iterator for QKnxByteArray .

typedef QKnxByteArray:: iterator

This typedef provides an STL-style non-const iterator for QKnxByteArray .

typedef QKnxByteArray:: reverse_iterator

This typedef provides an STL-style non-const reverse iterator for QKnxByteArray .

成员函数文档编制

QKnxByteArray:: QKnxByteArray ( QKnxByteArray && other )

Move-constructs a QKnxByteArray instance, making it point to the same object that other 所指向的。

QKnxByteArray:: QKnxByteArray (const QKnxByteArray & other )

构造副本为 other .

QKnxByteArray:: QKnxByteArray ( std::initializer_list < quint8 > args )

Constructs a byte array from the std::initializer_list 指定通过 args .

QKnxByteArray:: QKnxByteArray (const quint8 * data , int size )

This function overloads QKnxByteArray().

QKnxByteArray:: QKnxByteArray (const char * data , int size )

Constructs a byte array from data containing the number of bytes specified by size starting from the beginning of the data.

data 为 0,构造 null 字节数组。

size 为负, data is assumed to point to a null-terminated string and its length is determined dynamically. The terminating null-character is not considered part of the byte array.

QKnxByteArray makes a deep copy of the string data.

QKnxByteArray:: QKnxByteArray ( int size , quint8 ch )

Constructs a byte array of the size size with every byte set to the character ch .

QKnxByteArray:: QKnxByteArray ()

构造空字节数组。

QKnxByteArray &QKnxByteArray:: operator= ( QKnxByteArray && other )

移动赋值 other 到此 QKnxByteArray 实例。

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

赋值 other to this KNX byte array and returns a reference.

QKnxByteArray:: ~QKnxByteArray ()

销毁字节数组。

QKnxByteArray &QKnxByteArray:: append (const QKnxByteArray & ba )

追加字节数组 ba to the end of this byte array.

QKnxByteArray &QKnxByteArray:: append ( quint8 ch )

此函数重载 append()。

追加字符 ch 到此字节数组。

QKnxByteArray &QKnxByteArray:: append ( int count , quint8 ch )

此函数重载 append()。

Appends the number of copies of the character ch 指定通过 count 到此字节数组,并返回此字节数组的引用。

count is negative or zero, nothing is appended to the byte array.

quint8 QKnxByteArray:: at ( int i ) const

Returns the character at the index position i 在字节数组中。

i must be a valid index position in the byte array (that is, between 0 and the value returned by size ()).

QKnxByteArray::iterator QKnxByteArray:: begin ()

返回 STL 样式迭代器 pointing to the first character in the byte array.

QKnxByteArray::const_iterator QKnxByteArray:: begin () const

此函数重载 begin()。

QKnxByteArray::const_iterator QKnxByteArray:: cbegin () const

返回常量 STL 样式迭代器 pointing to the first character in the byte array.

QKnxByteArray::const_iterator QKnxByteArray:: cend () const

返回常量 STL 样式迭代器 pointing to the imaginary character after the last character in the list.

QKnxByteArray QKnxByteArray:: chop ( int len ) const

Returns a byte array that contains the number of leftmost bytes in this byte array calculated by subtracting the amount of bytes specified by len from the amount of bytes of returned by size ().

注意: 行为未定义若 len 为负。

void QKnxByteArray:: clear ()

Clears the contents of the byte array and makes it null.

QKnxByteArray::const_iterator QKnxByteArray:: constBegin () const

返回常量 STL 样式迭代器 pointing to the first character in the byte array.

const quint8 *QKnxByteArray:: constData () const

Returns a pointer to the data stored in the byte array. The pointer can be used to access the bytes that compose the array. The data is null-terminated.

The pointer remains valid until the byte array is reallocated or destroyed.

QKnxByteArray::const_iterator QKnxByteArray:: constEnd () const

返回常量 STL 样式迭代器 pointing to the imaginary character after the last character in the list.

bool QKnxByteArray:: contains (const QKnxByteArray & ba ) const

返回 true if the byte array contains an occurrence of the byte array ba ;否则返回 false .

bool QKnxByteArray:: contains ( quint8 ch ) const

此函数重载 contains()。

返回 true if the byte array contains the character ch ;否则返回 false .

QKnxByteArray::const_reverse_iterator QKnxByteArray:: crbegin () const

返回常量 STL-style reverse iterator pointing to the first character in the byte array, in reverse order.

QKnxByteArray::const_reverse_iterator QKnxByteArray:: crend () const

返回常量 STL-style reverse iterator pointing to one past the last character in the byte array, in reverse order.

quint8 *QKnxByteArray:: data ()

Returns a pointer to the data stored in the byte array. The pointer can be used to access and modify the bytes that compose the array. The data is null-terminated, which means that the number of bytes in the returned character string is the value returned by size () plus 1 for the null-terminator.

The pointer remains valid until the byte array is reallocated or destroyed.

const quint8 *QKnxByteArray:: data () const

此函数重载 data()。

QKnxByteArray::iterator QKnxByteArray:: end ()

返回 STL 样式迭代器 pointing to the imaginary character after the last character in the byte array.

QKnxByteArray::const_iterator QKnxByteArray:: end () const

此函数重载 end()。

bool QKnxByteArray:: endsWith (const QKnxByteArray & ba ) const

返回 true if this byte array ends with the byte array ba ;否则返回 false .

bool QKnxByteArray:: endsWith ( quint8 ch ) const

此函数重载 endsWith()。

返回 true if this byte array ends with the character ch ;否则返回 false .

QKnxByteArray &QKnxByteArray:: fill ( quint8 ch , int size = -1)

Sets every byte in the byte array to the character ch and returns a reference to this byte array. If size is different from -1, the byte array is resized to size 事先。

[static] QKnxByteArray QKnxByteArray:: fromByteArray (const QByteArray & byteArray )

Returns a byte array constructed from byteArray .

[static] QKnxByteArray QKnxByteArray:: fromHex (const QKnxByteArray & hexEncoded )

Returns a decoded copy of the hex encoded array hexEncoded . Input is not checked for validity; invalid characters in the input are skipped, enabling the decoding process to continue with subsequent characters.

[static] QKnxByteArray QKnxByteArray:: fromHex (const QByteArray & hexEncoded )

This function overloads fromHex().

int QKnxByteArray:: indexOf (const QKnxByteArray & ba , int from = 0) const

Returns the index position of the first occurrence of the byte array ba in this byte array, searching forward from the index position from . Returns -1 if ba could not be found.

int QKnxByteArray:: indexOf ( quint8 ch , int from = 0) const

此函数重载 indexOf()。

Returns the index position of the first occurrence of the character ch in the byte array, searching forward from the index position from . Returns -1 if ch could not be found.

QKnxByteArray &QKnxByteArray:: insert ( int i , const QKnxByteArray & ba )

Inserts the byte array ba at the index position i and returns a reference to this byte array.

QKnxByteArray &QKnxByteArray:: insert ( int i , quint8 ch )

This function overloads insert().

Inserts the character ch at the index position i in the byte array. If i is greater than the number of bytes returned by size (), the array is first extended using resize ().

QKnxByteArray &QKnxByteArray:: insert ( int i , int count , quint8 ch )

This function overloads insert().

Inserts the number of copies of the character ch 指定通过 count at the index position i 在字节数组中。

i is greater than the value returned by size (), the array is first extended using resize ().

bool QKnxByteArray:: isEmpty () const

返回 true if the byte array has the size 0; otherwise returns false .

bool QKnxByteArray:: isNull () const

返回 true if this byte array is null; otherwise returns false .

int QKnxByteArray:: lastIndexOf (const QKnxByteArray & ba , int from = -1) const

Returns the index position of the last occurrence of the byte array ba in this byte array, searching backward from the index position from 。若 from is -1 (the default), the search starts at the last byte. Returns -1 if ba could not be found.

int QKnxByteArray:: lastIndexOf ( quint8 ch , int from = -1) const

This function overloads lastIndexOf().

Returns the index position of the last occurrence of the character ch in the byte array, searching backward from the index position from 。若 from is -1 (the default), the search starts at the last byte (that is, the value returned by size () minus 1). Returns -1 if ch cannot be found.

QKnxByteArray QKnxByteArray:: left ( int len ) const

Returns a byte array that contains the number of leftmost bytes in the byte array specified by len .

返回整个字节数组若 len is greater than the value returned by size ().

QKnxByteArray QKnxByteArray:: mid ( int pos , int len = -1) const

Returns a byte array containing the number of bytes in the byte array specified by len , starting at the position pos .

len 为 -1 (默认),或 pos added to len is equal to or larger than the value returned by size (), returns a byte array containing all bytes starting from the position pos to the end of the byte array.

QKnxByteArray &QKnxByteArray:: prepend (const QKnxByteArray & ba )

前置字节数组 ba 到此字节数组,并返回此字节数组的引用。

QKnxByteArray &QKnxByteArray:: prepend ( quint8 ch )

This function overloads prepend().

前置字符 ch 到此字节数组。

QKnxByteArray &QKnxByteArray:: prepend ( int count , quint8 ch )

This function overloads prepend().

Prepends the number of copies of the character ch 指定通过 count 到此字节数组。

QKnxByteArray::reverse_iterator QKnxByteArray:: rbegin ()

返回 STL-style reverse iterator pointing to the first character in the byte array, in reverse order.

QKnxByteArray::const_reverse_iterator QKnxByteArray:: rbegin () const

This function overloads rbegin().

QKnxByteArray &QKnxByteArray:: remove ( int pos , int len )

Removes the number of bytes specified by len from the array, starting at the index position pos , and returns a reference to the array.

pos is out of range, nothing happens. If pos is valid, but pos added to len is larger than the size of the array, the array is truncated at the position pos .

QKnxByteArray::reverse_iterator QKnxByteArray:: rend ()

返回 STL-style reverse iterator pointing to one past the last character in the byte array, in reverse order.

QKnxByteArray::const_reverse_iterator QKnxByteArray:: rend () const

This function overloads rend().

QKnxByteArray QKnxByteArray:: repeated ( int times ) const

Returns a copy of this byte array repeated the specified number of times .

times is less than 1, an empty byte array is returned.

QKnxByteArray &QKnxByteArray:: replace ( int index , int len , const QKnxByteArray & after )

Replaces the number of bytes specified by len beginning at the index position index with the byte array after , and returns a reference to this byte array.

QKnxByteArray &QKnxByteArray:: replace ( quint8 before , const QKnxByteArray & after )

此函数重载 replace()。

Replaces every occurrence of the character before with the byte array after .

QKnxByteArray &QKnxByteArray:: replace (const QKnxByteArray & before , const QKnxByteArray & after )

此函数重载 replace()。

Replaces every occurrence of the byte array before with the byte array after .

QKnxByteArray &QKnxByteArray:: replace ( quint8 before , quint8 after )

此函数重载 replace()。

Replaces every occurrence of the character before with the character after .

void QKnxByteArray:: resize ( int size )

Sets the size of the byte array to the number of bytes specified by size .

size is greater than the current size, the byte array is extended to size bytes by adding default-constructed values to the end of the array.

size is less than the current size, bytes are removed from the end of the array.

Returns a byte array that contains the number of rightmost bytes in the byte array specified by len .

返回整个字节数组若 len is greater than the value returned by size ().

void QKnxByteArray:: set ( int i , quint8 val )

Sets the character at the index position i in the byte array to val .

i must be a valid index position in the byte array (that is, between 0 and the value returned by size ()).

void QKnxByteArray:: setValue ( int i , quint8 val )

Sets the value at the index position i in the byte array to val .

If the index i is out of bounds, the function does nothing. If you are certain that i is within bounds, you can use set () instead, which is slightly faster.

另请参阅 value ().

int QKnxByteArray:: size () const

Returns the number of bytes in this byte array. The last byte in the byte array is at the position returned by this function minus 1.

bool QKnxByteArray:: startsWith (const QKnxByteArray & ba ) const

返回 true if this byte array starts with the byte array ba ;否则返回 false .

bool QKnxByteArray:: startsWith ( quint8 ch ) const

This function overloads startsWith().

返回 true if this byte array starts with the character ch ;否则返回 false .

void QKnxByteArray:: swap ( QKnxByteArray & other )

Swaps the byte array other with this byte array. This operation is very fast and never fails.

const QByteArray &QKnxByteArray:: toByteArray () const

Returns a copy of this byte array as QByteArray .

QKnxByteArray QKnxByteArray:: toHex ( quint8 separator = '\0') const

Returns a hex encoded copy of the byte array. The hex encoding uses the numbers 0-9 and the letters a-f.

separator 不是 \0 , the separator character is inserted between the hex bytes.

范例:

auto macAddress = QKnxByteArray::fromHex("123456abcdef");
macAddress.toHex(':'); // returns "12:34:56:ab:cd:ef"
macAddress.toHex(0);   // returns "123456abcdef"
					

quint8 QKnxByteArray:: value ( int i , quint8 defaultValue = {}) const

Returns the value at the index position i 在字节数组中。

If the index i is out of bounds, the function returns defaultValue , which may be a 默认构造值 . If you are certain that i is within bounds, you can use at () instead, which is slightly faster.

另请参阅 setValue ().

QKnxByteArray &QKnxByteArray:: operator+= (const QKnxByteArray & ba )

追加字节数组 ba onto the end of this byte array and returns a reference to this byte array.

QKnxByteArray &QKnxByteArray:: operator+= ( quint8 ch )

This function overloads operator+=().

追加字符 ch onto the end of this byte array and returns a reference to this byte array.

相关非成员

uint qHash (const QKnxByteArray & key , uint seed = 0)

返回哈希值为 key ,使用 seed 做计算种子。

bool operator!= (const QKnxByteArray & a1 , const QKnxByteArray & a2 )

返回 true if the byte array a1 is not equal to the byte array a2 ;否则返回 false .

const QKnxByteArray operator+ (const QKnxByteArray & a1 , const QKnxByteArray & a2 )

Returns a byte array that is the result of concatenating the byte array a1 和字节数组 a2 .

const QKnxByteArray operator+ (const QKnxByteArray & ba , quint8 ch )

This function overloads operator+().

Returns a byte array that is the result of concatenating the byte array ba 和字符 ch .

const QKnxByteArray operator+ ( quint8 ch , const QKnxByteArray & ba )

This function overloads operator+().

Returns a byte array that is the result of concatenating the character ch 和字节数组 ba .

QDebug operator<< ( QDebug debug , const QKnxByteArray & byteArray )

Writes the byte array byteArray debug stream.

bool operator== (const QKnxByteArray & a1 , const QKnxByteArray & a2 )

返回 true if the byte array a1 is equal to the byte array a2 ;否则返回 false .