Swap.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) 2005 Imetric 3D GmbH                                    *
00003  *                                                                         *
00004  *   This file is part of the FreeCAD CAx development system.              *
00005  *                                                                         *
00006  *   This library is free software; you can redistribute it and/or         *
00007  *   modify it under the terms of the GNU Library General Public           *
00008  *   License as published by the Free Software Foundation; either          *
00009  *   version 2 of the License, or (at your option) any later version.      *
00010  *                                                                         *
00011  *   This library  is distributed in the hope that it will be useful,      *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00014  *   GNU Library General Public License for more details.                  *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Library General Public     *
00017  *   License along with this library; see the file COPYING.LIB. If not,    *
00018  *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
00019  *   Suite 330, Boston, MA  02111-1307, USA                                *
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 

Generated on Wed Nov 23 19:00:42 2011 for FreeCAD by  doxygen 1.6.1