Swap.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "PreCompiled.h"
00025
00026 #include "Swap.h"
00027
00028 unsigned short Base::SwapOrder (void)
00029 {
00030 unsigned short usDummy = 1;
00031 return *((char*) &usDummy) == 1 ? LOW_ENDIAN : HIGH_ENDIAN;
00032 }
00033
00034 void Base::SwapVar (char&)
00035 {
00036 }
00037
00038 void Base::SwapVar (unsigned char&)
00039 {
00040 }
00041
00042 void Base::SwapVar (short& s)
00043 {
00044 short sTmp = s;
00045 int i;
00046
00047 for (i = 0; i < (int)sizeof (short); i++)
00048 *(((char*) &sTmp) + i) = *(((char*) &s) + sizeof (short) - i - 1);
00049 s = sTmp;
00050 }
00051
00052 void Base::SwapVar (unsigned short& s)
00053 {
00054 short sTmp = s;
00055 int i;
00056
00057 for (i = 0; i < (int)sizeof (short); i++)
00058 *(((char*) &sTmp) + i) = *(((char*) &s) + sizeof (short) - i - 1);
00059 s = sTmp;
00060 }
00061
00062 void Base::SwapVar (long& l)
00063 {
00064 long lTmp = l;
00065 int i;
00066
00067 for (i = 0; i < (int)sizeof (long); i++)
00068 *(((char*) &lTmp) + i) = *(((char*) &l) + sizeof (long) - i - 1);
00069 l = lTmp;
00070 }
00071
00072 void Base::SwapVar (unsigned long& l)
00073 {
00074 long lTmp = l;
00075 int i;
00076
00077 for (i = 0; i < (int)sizeof (long); i++)
00078 *(((char*) &lTmp) + i) = *(((char*) &l) + sizeof (long) - i - 1);
00079 l = lTmp;
00080 }
00081
00082 void Base::SwapVar (float& f)
00083 {
00084 float fTmp = f;
00085 int i;
00086
00087 for (i = 0; i < (int)sizeof (float); i++)
00088 *(((char*) &fTmp) + i) = *(((char*) &f) + sizeof (float) - i - 1);
00089 f = fTmp;
00090 }
00091
00092 void Base::SwapVar (double& d)
00093 {
00094 double dTmp = d;
00095 int i;
00096
00097 for (i = 0; i < (int)sizeof (double); i++)
00098 *(((char*) &dTmp) + i) = *(((char*) &d) + sizeof (double) - i - 1);
00099 d = dTmp;
00100 }
00101
00102