Mobile API Reference  MicroStrategy 2019
EndianConversion.h
Go to the documentation of this file.
1 //==============================================================================================
2 // FILENAME : EndianConversion.h
3 // AUTHOR : Yuan Ding
4 // CREATION : 07/16/2002
5 // Copyright (C) MicroStrategy Incorporated 1999
6 // All Rights Reserved
7 //==============================================================================================
8 #ifndef MBase_EndianConversion_h
9 #define MBase_EndianConversion_h
10 
12 #include "Base/Base/System.h"
13 
14 namespace MBase
15 {
16 
26  template<class T> inline T ConvertEndian(T iData)
27  {
28  if (IsBigEndian())
29  {
30  unsigned long lnDataSize = sizeof(T);
31  unsigned char* lpByte = (unsigned char*)(&iData);
32  unsigned char lpTemp = 0;
33  for (unsigned Int32 idxByte = 0; idxByte < lnDataSize/2; idxByte++)
34  {
35  lpTemp = *(lpByte+idxByte);
36  *(lpByte+idxByte) = *(lpByte+lnDataSize-idxByte-1);
37  *(lpByte+lnDataSize-idxByte-1) = lpTemp;
38  }
39  }
40 
41  return iData;
42  }
43 
44 #ifdef GUID_DEFINED
45 
46  inline void EndianConvertGUID(::GUID &irGUID)
47  {
48  if (IsBigEndian())
49  {
50  irGUID.Data1 = ConvertEndian<unsigned Int32>(irGUID.Data1);
51  irGUID.Data2 = ConvertEndian<unsigned short>(irGUID.Data2);
52  irGUID.Data3 = ConvertEndian<unsigned short>(irGUID.Data3);
53  }
54  }
55 
56 #endif // GUID_DEFINED
57 }
58 
59 #endif // MBase_EndianConversion_h
unsigned short Data2
Definition: Base/Base/GUID.h:35
bool IsBigEndian()
Definition: System.h:150
T ConvertEndian(T iData)
Definition: EndianConversion.h:26
#define Int32
Definition: BasicTypes.h:20
unsigned int Data1
Definition: Base/Base/GUID.h:34
Definition: Allocator.h:47
unsigned short Data3
Definition: Base/Base/GUID.h:36
Definition: Base/Base/GUID.h:32