Qt 4.8
Functions
qendian.h File Reference
#include <QtCore/qglobal.h>
#include <stdlib.h>

Go to the source code of this file.

Functions

template<typename T >
void qbswap (const T src, uchar *dest)
 
template<typename T >
qbswap (T source)
 
template<>
qint16 qbswap< qint16 > (qint16 source)
 
template<>
qint32 qbswap< qint32 > (qint32 source)
 
template<>
qint64 qbswap< qint64 > (qint64 source)
 
template<>
quint16 qbswap< quint16 > (quint16 source)
 
template<>
quint32 qbswap< quint32 > (quint32 source)
 
template<>
quint64 qbswap< quint64 > (quint64 source)
 
template<>
quint8 qbswap< quint8 > (quint8 source)
 
void qbswap_helper (const uchar *src, uchar *dest, int size)
 
template<class T >
qFromBigEndian (const uchar *src)
 
template<typename T >
qFromBigEndian (T source)
 
template<>
qint16 qFromBigEndian< qint16 > (const uchar *src)
 
template<>
qint32 qFromBigEndian< qint32 > (const uchar *src)
 
template<>
qint64 qFromBigEndian< qint64 > (const uchar *src)
 
template<>
quint16 qFromBigEndian< quint16 > (const uchar *src)
 
template<>
quint32 qFromBigEndian< quint32 > (const uchar *src)
 
template<>
quint64 qFromBigEndian< quint64 > (const uchar *src)
 
template<typename T >
qFromLittleEndian (const uchar *src)
 
template<typename T >
qFromLittleEndian (T source)
 
template<>
qint16 qFromLittleEndian< qint16 > (const uchar *src)
 
template<>
qint32 qFromLittleEndian< qint32 > (const uchar *src)
 
template<>
qint64 qFromLittleEndian< qint64 > (const uchar *src)
 
template<>
quint16 qFromLittleEndian< quint16 > (const uchar *src)
 
template<>
quint32 qFromLittleEndian< quint32 > (const uchar *src)
 
template<>
quint64 qFromLittleEndian< quint64 > (const uchar *src)
 
template<typename T >
qToBigEndian (T source)
 
template<typename T >
void qToBigEndian (T src, uchar *dest)
 
template<typename T >
qToLittleEndian (T source)
 
template<typename T >
void qToLittleEndian (T src, uchar *dest)
 
template<typename T >
void qToUnaligned (const T src, uchar *dest)
 

Function Documentation

◆ qbswap() [1/2]

template<typename T >
void qbswap ( const T  src,
uchar dest 
)
inline

Definition at line 74 of file qendian.h.

Referenced by QDataStream::operator<<(), operator<<(), QDataStream::operator>>(), operator>>(), and qFromBigEndian< qint16 >().

75 {
76  qbswap_helper(reinterpret_cast<const uchar *>(&src), dest, sizeof(T));
77 }
void qbswap_helper(const uchar *src, uchar *dest, int size)
Definition: qendian.h:63

◆ qbswap() [2/2]

template<typename T >
T qbswap ( source)

◆ qbswap< qint16 >()

template<>
qint16 qbswap< qint16 > ( qint16  source)
inline

Definition at line 330 of file qendian.h.

331 {
332  return qbswap<quint16>(quint16(source));
333 }
unsigned short quint16
Definition: qglobal.h:936
quint16 qbswap< quint16 >(quint16 source)
Definition: qendian.h:311

◆ qbswap< qint32 >()

template<>
qint32 qbswap< qint32 > ( qint32  source)
inline

Definition at line 325 of file qendian.h.

326 {
327  return qbswap<quint32>(quint32(source));
328 }
unsigned int quint32
Definition: qglobal.h:938
quint32 qbswap< quint32 >(quint32 source)
Definition: qendian.h:302

◆ qbswap< qint64 >()

template<>
qint64 qbswap< qint64 > ( qint64  source)
inline

Definition at line 320 of file qendian.h.

321 {
322  return qbswap<quint64>(quint64(source));
323 }
quint64 qbswap< quint64 >(quint64 source)
Definition: qendian.h:289
unsigned __int64 quint64
Definition: qglobal.h:943

◆ qbswap< quint16 >()

template<>
quint16 qbswap< quint16 > ( quint16  source)
inline

Definition at line 311 of file qendian.h.

Referenced by qbswap< qint16 >(), and qFromBigEndian< qint16 >().

312 {
313  return quint16( 0
314  | ((source & 0x00ff) << 8)
315  | ((source & 0xff00) >> 8) );
316 }
unsigned short quint16
Definition: qglobal.h:936

◆ qbswap< quint32 >()

template<>
quint32 qbswap< quint32 > ( quint32  source)
inline

Definition at line 302 of file qendian.h.

Referenced by QFontEngineWin::getCMap(), QFontEngineWin::getSfntTableData(), QFontEngineDirectWrite::getSfntTableData(), qbswap< qint32 >(), and qFromBigEndian< qint16 >().

303 {
304  return 0
305  | ((source & 0x000000ff) << 24)
306  | ((source & 0x0000ff00) << 8)
307  | ((source & 0x00ff0000) >> 8)
308  | ((source & 0xff000000) >> 24);
309 }

◆ qbswap< quint64 >()

template<>
quint64 qbswap< quint64 > ( quint64  source)
inline

Definition at line 289 of file qendian.h.

Referenced by qbswap< qint64 >(), and qFromBigEndian< qint16 >().

290 {
291  return 0
292  | ((source & Q_UINT64_C(0x00000000000000ff)) << 56)
293  | ((source & Q_UINT64_C(0x000000000000ff00)) << 40)
294  | ((source & Q_UINT64_C(0x0000000000ff0000)) << 24)
295  | ((source & Q_UINT64_C(0x00000000ff000000)) << 8)
296  | ((source & Q_UINT64_C(0x000000ff00000000)) >> 8)
297  | ((source & Q_UINT64_C(0x0000ff0000000000)) >> 24)
298  | ((source & Q_UINT64_C(0x00ff000000000000)) >> 40)
299  | ((source & Q_UINT64_C(0xff00000000000000)) >> 56);
300 }
#define Q_UINT64_C(c)
Definition: qglobal.h:941

◆ qbswap< quint8 >()

template<>
quint8 qbswap< quint8 > ( quint8  source)
inline

Definition at line 366 of file qendian.h.

367 {
368  return source;
369 }

◆ qbswap_helper()

void qbswap_helper ( const uchar src,
uchar dest,
int  size 
)
inline

Definition at line 63 of file qendian.h.

Referenced by qbswap().

64 {
65  for (int i = 0; i < size ; ++i) dest[i] = src[size - 1 - i];
66 }

◆ qFromBigEndian() [1/2]

template<class T >
T qFromBigEndian ( const uchar src)
inline

◆ qFromBigEndian() [2/2]

template<typename T >
T qFromBigEndian ( source)
inline

Definition at line 339 of file qendian.h.

340 { return source; }

◆ qFromBigEndian< qint16 >()

template<>
qint16 qFromBigEndian< qint16 > ( const uchar src)
inline

Definition at line 264 of file qendian.h.

265 { return static_cast<qint16>(qFromBigEndian<quint16>(src)); }
short qint16
Definition: qglobal.h:935
quint16 qFromBigEndian< quint16 >(const uchar *src)
Definition: qendian.h:249

◆ qFromBigEndian< qint32 >()

template<>
qint32 qFromBigEndian< qint32 > ( const uchar src)
inline

Definition at line 261 of file qendian.h.

262 { return static_cast<qint32>(qFromBigEndian<quint32>(src)); }
int qint32
Definition: qglobal.h:937
quint32 qFromBigEndian< quint32 >(const uchar *src)
Definition: qendian.h:239

◆ qFromBigEndian< qint64 >()

template<>
qint64 qFromBigEndian< qint64 > ( const uchar src)
inline

Definition at line 258 of file qendian.h.

259 { return static_cast<qint64>(qFromBigEndian<quint64>(src)); }
__int64 qint64
Definition: qglobal.h:942
quint64 qFromBigEndian< quint64 >(const uchar *src)
Definition: qendian.h:225

◆ qFromBigEndian< quint16 >()

template<>
quint16 qFromBigEndian< quint16 > ( const uchar src)
inline

◆ qFromBigEndian< quint32 >()

template<>
quint32 qFromBigEndian< quint32 > ( const uchar src)
inline

◆ qFromBigEndian< quint64 >()

template<>
quint64 qFromBigEndian< quint64 > ( const uchar src)
inline

Definition at line 225 of file qendian.h.

Referenced by qFromBigEndian< qint64 >().

226 {
227  return 0
228  | src[7]
229  | src[6] * Q_UINT64_C(0x0000000000000100)
230  | src[5] * Q_UINT64_C(0x0000000000010000)
231  | src[4] * Q_UINT64_C(0x0000000001000000)
232  | src[3] * Q_UINT64_C(0x0000000100000000)
233  | src[2] * Q_UINT64_C(0x0000010000000000)
234  | src[1] * Q_UINT64_C(0x0001000000000000)
235  | src[0] * Q_UINT64_C(0x0100000000000000);
236 }
#define Q_UINT64_C(c)
Definition: qglobal.h:941

◆ qFromLittleEndian() [1/2]

template<typename T >
T qFromLittleEndian ( const uchar src)
inline

◆ qFromLittleEndian() [2/2]

template<typename T >
T qFromLittleEndian ( source)
inline

Definition at line 343 of file qendian.h.

344 { return qbswap<T>(source); }

◆ qFromLittleEndian< qint16 >()

template<>
qint16 qFromLittleEndian< qint16 > ( const uchar src)
inline

Definition at line 171 of file qendian.h.

172 { return static_cast<qint16>(qFromLittleEndian<quint16>(src)); }
quint16 qFromLittleEndian< quint16 >(const uchar *src)
Definition: qendian.h:157
short qint16
Definition: qglobal.h:935

◆ qFromLittleEndian< qint32 >()

template<>
qint32 qFromLittleEndian< qint32 > ( const uchar src)
inline

Definition at line 168 of file qendian.h.

169 { return static_cast<qint32>(qFromLittleEndian<quint32>(src)); }
int qint32
Definition: qglobal.h:937
quint32 qFromLittleEndian< quint32 >(const uchar *src)
Definition: qendian.h:148

◆ qFromLittleEndian< qint64 >()

template<>
qint64 qFromLittleEndian< qint64 > ( const uchar src)
inline

Definition at line 165 of file qendian.h.

166 { return static_cast<qint64>(qFromLittleEndian<quint64>(src)); }
quint64 qFromLittleEndian< quint64 >(const uchar *src)
Definition: qendian.h:135
__int64 qint64
Definition: qglobal.h:942

◆ qFromLittleEndian< quint16 >()

template<>
quint16 qFromLittleEndian< quint16 > ( const uchar src)
inline

Definition at line 157 of file qendian.h.

Referenced by QUuid::operator>>(), qFromLittleEndian< qint16 >(), readBMPInfoHeader(), readIconDir(), and readIconDirEntry().

158 {
159  return quint16(0
160  | src[0]
161  | src[1] * 0x0100);
162 }
unsigned short quint16
Definition: qglobal.h:936

◆ qFromLittleEndian< quint32 >()

template<>
quint32 qFromLittleEndian< quint32 > ( const uchar src)
inline

Definition at line 148 of file qendian.h.

Referenced by QUtf32::convertToUnicode(), QZipPrivate::fillFileInfo(), QUuid::operator>>(), qFromLittleEndian< qint32 >(), readBMPInfoHeader(), and readIconDirEntry().

149 {
150  return 0
151  | src[0]
152  | src[1] * quint32(0x00000100)
153  | src[2] * quint32(0x00010000)
154  | src[3] * quint32(0x01000000);
155 }
unsigned int quint32
Definition: qglobal.h:938

◆ qFromLittleEndian< quint64 >()

template<>
quint64 qFromLittleEndian< quint64 > ( const uchar src)
inline

Definition at line 135 of file qendian.h.

Referenced by qFromLittleEndian< qint64 >().

136 {
137  return 0
138  | src[0]
139  | src[1] * Q_UINT64_C(0x0000000000000100)
140  | src[2] * Q_UINT64_C(0x0000000000010000)
141  | src[3] * Q_UINT64_C(0x0000000001000000)
142  | src[4] * Q_UINT64_C(0x0000000100000000)
143  | src[5] * Q_UINT64_C(0x0000010000000000)
144  | src[6] * Q_UINT64_C(0x0001000000000000)
145  | src[7] * Q_UINT64_C(0x0100000000000000);
146 }
#define Q_UINT64_C(c)
Definition: qglobal.h:941

◆ qToBigEndian() [1/2]

template<typename T >
T qToBigEndian ( source)
inline

◆ qToBigEndian() [2/2]

template<typename T >
void qToBigEndian ( src,
uchar dest 
)
inline

Definition at line 345 of file qendian.h.

346 { qToUnaligned<T>(src, dest); }

◆ qToLittleEndian() [1/2]

template<typename T >
T qToLittleEndian ( source)
inline

◆ qToLittleEndian() [2/2]

template<typename T >
void qToLittleEndian ( src,
uchar dest 
)
inline

Definition at line 347 of file qendian.h.

348 { qbswap<T>(src, dest); }

◆ qToUnaligned()

template<typename T >
void qToUnaligned ( const T  src,
uchar dest 
)
inline

Definition at line 81 of file qendian.h.

82 {
83  qMemCopy(dest, &src, sizeof(T));
84 }
void * qMemCopy(void *dest, const void *src, size_t n)
Definition: qglobal.cpp:2508