Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

Common/vtkByteSwap.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    $RCSfile: vtkByteSwap.h,v $
00005 
00006   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
00007   All rights reserved.
00008   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00009 
00010      This software is distributed WITHOUT ANY WARRANTY; without even
00011      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00012      PURPOSE.  See the above copyright notice for more information.
00013 
00014 =========================================================================*/
00026 #ifndef __vtkByteSwap_h
00027 #define __vtkByteSwap_h
00028 
00029 #include "vtkObject.h"
00030 
00031 class VTK_COMMON_EXPORT vtkByteSwap : public vtkObject
00032 {
00033 public:
00034   static vtkByteSwap *New();
00035   vtkTypeRevisionMacro(vtkByteSwap,vtkObject);
00036 
00038 
00039   static void Swap2LE(short *s);
00040   static void Swap2LE(unsigned short *s);
00042 
00044 
00045   static void Swap4LE(char *c);
00046   static void Swap4LE(float *p) { vtkByteSwap::Swap4LE((char *)p);};
00047   static void Swap4LE(int *i)   { vtkByteSwap::Swap4LE((char *)i);};
00048   static void Swap4LE(unsigned int *i)   { vtkByteSwap::Swap4LE((char *)i);};
00049   static void Swap4LE(long *i) { vtkByteSwap::Swap4LE((char *)i);};
00050   static void Swap4LE(unsigned long *i) { vtkByteSwap::Swap4LE((char *)i);};
00052 
00054 
00056   static void Swap8LE(char *c);
00057   static void Swap8LE(double *d) { vtkByteSwap::Swap8LE((char *)d);};
00059 
00061 
00063   static void Swap2LERange(char *c,int num);
00064   static void Swap2LERange(short *i,int num) 
00065   { vtkByteSwap::Swap2LERange((char *)i,num);};
00067 
00069 
00071   static void Swap4LERange(char *c,int num);
00072   static void Swap4LERange(unsigned char *c,int num) 
00073   { vtkByteSwap::Swap4LERange((char *)c,num);};
00074   static void Swap4LERange(float *p,int num) 
00075   { vtkByteSwap::Swap4LERange((char *)p,num);};
00076   static void Swap4LERange(int *i,int num) 
00077   { vtkByteSwap::Swap4LERange((char *)i,num);};
00078   static void Swap4LERange(unsigned int *i,int num) 
00079   { vtkByteSwap::Swap4LERange((char *)i,num);};
00080   static void Swap4LERange(long *i,int num) 
00081   { vtkByteSwap::Swap4LERange((char *)i,num);};
00082   static void Swap4LERange(unsigned long *i,int num) 
00083   { vtkByteSwap::Swap4LERange((char *)i,num);};
00085 
00087 
00089   static void Swap8LERange(char *c, int num);
00090   static void Swap8LERange(double *d, int num) 
00091   { vtkByteSwap::Swap8LERange((char *)d, num);};
00093 
00095 
00096   static void Swap2BE(short *s);
00097   static void Swap2BE(unsigned short *s);
00099 
00101 
00103   static void Swap4BE(char *c);
00104   static void Swap4BE(float *p) { vtkByteSwap::Swap4BE((char *)p);};
00105   static void Swap4BE(int *i)   { vtkByteSwap::Swap4BE((char *)i);};
00106   static void Swap4BE(unsigned int *i)  { vtkByteSwap::Swap4BE((char *)i);};
00107   static void Swap4BE(long *i) { vtkByteSwap::Swap4BE((char *)i);};
00108   static void Swap4BE(unsigned long *i) { vtkByteSwap::Swap4BE((char *)i);};
00110 
00112 
00114   static void Swap8BE(char *c);
00115   static void Swap8BE(double *d) { vtkByteSwap::Swap8BE((char *)d);};
00117 
00119 
00121   static void Swap2BERange(char *c,int num);
00122   static void Swap2BERange(short *i,int num) 
00123   { vtkByteSwap::Swap2BERange((char *)i,num);};
00125 
00127 
00129   static void Swap4BERange(char *c,int num);
00130   static void Swap4BERange(float *p,int num) 
00131   { vtkByteSwap::Swap4BERange((char *)p,num); };
00132   static void Swap4BERange(int *i,int num) 
00133   { vtkByteSwap::Swap4BERange((char *)i,num); };
00134   static void Swap4BERange(unsigned int *i,int num) 
00135   { vtkByteSwap::Swap4BERange((char *)i,num); };
00136   static void Swap4BERange(long *i,int num) 
00137   { vtkByteSwap::Swap4BERange((char *)i,num); };
00138   static void Swap4BERange(unsigned long *i,int num) 
00139   { vtkByteSwap::Swap4BERange((char *)i,num); };
00141 
00142 #ifdef VTK_USE_64BIT_IDS
00143   static void Swap4BERange(vtkIdType *i,int num) 
00144   { vtkByteSwap::Swap4BERange((char *)i,num); };
00145 #endif
00146 
00148 
00150   static void Swap8BERange(char *c,int num);
00151   static void Swap8BERange(double *d,int num) 
00152   { vtkByteSwap::Swap8BERange((char *)d,num); };
00154 
00156 
00159   static void SwapWrite2BERange(char *c,int num,FILE *fp);
00160   static void SwapWrite2BERange(short *i,int num, FILE *fp) 
00161   {vtkByteSwap::SwapWrite2BERange((char *)i,num,fp);};
00163 
00165 
00168   static void SwapWrite4BERange(char *c,int num,FILE *fp);
00169   static void SwapWrite4BERange(float *p,int num, FILE *fp) 
00170   { vtkByteSwap::SwapWrite4BERange((char *)p,num,fp);};
00171   static void SwapWrite4BERange(int *i,int num,FILE *fp) 
00172   { vtkByteSwap::SwapWrite4BERange((char *)i,num,fp);};
00173   static void SwapWrite4BERange(unsigned int *i,int num,FILE *fp) 
00174   { vtkByteSwap::SwapWrite4BERange((char *)i,num,fp);};
00175   static void SwapWrite4BERange(unsigned long *i,int num, FILE *fp) 
00176   { vtkByteSwap::SwapWrite4BERange((char *)i,num,fp);};
00177   static void SwapWrite4BERange(long *i,int num, FILE *fp) 
00178   { vtkByteSwap::SwapWrite4BERange((char *)i,num,fp);};
00179 #ifdef VTK_USE_64BIT_IDS
00180   static void SwapWrite4BERange(vtkIdType *i,int num, FILE *fp) 
00181   { vtkByteSwap::SwapWrite4BERange((char *)i,num,fp);};
00183 #endif
00184 
00185 
00188   static void SwapWrite8BERange(char *c,int num,FILE *fp);
00189   static void SwapWrite8BERange(double *d,int num, FILE *fp) 
00190   { vtkByteSwap::SwapWrite8BERange((char *)d,num,fp);};
00192 
00194 
00197   static void SwapWrite2BERange(char *c,int num, ostream *fp);
00198   static void SwapWrite2BERange(short *i,int num, ostream *fp) 
00199   {vtkByteSwap::SwapWrite2BERange((char *)i,num,fp);};
00201 
00203 
00206   static void SwapWrite4BERange(char *c,int num, ostream *fp);
00207   static void SwapWrite4BERange(float *p,int num, ostream *fp) 
00208   { vtkByteSwap::SwapWrite4BERange((char *)p,num,fp);};
00209   static void SwapWrite4BERange(int *i,int num, ostream *fp) 
00210   { vtkByteSwap::SwapWrite4BERange((char *)i,num,fp);};
00211   static void SwapWrite4BERange(unsigned int *i,int num, ostream *fp) 
00212   { vtkByteSwap::SwapWrite4BERange((char *)i,num,fp);};
00213   static void SwapWrite4BERange(unsigned long *i,int num, ostream *fp) 
00214   { vtkByteSwap::SwapWrite4BERange((char *)i,num,fp);};
00215   static void SwapWrite4BERange(long *i,int num, ostream *fp) 
00216   { vtkByteSwap::SwapWrite4BERange((char *)i,num,fp);};
00217 #ifdef VTK_USE_64BIT_IDS
00218   static void SwapWrite4BERange(vtkIdType *i,int num, ostream *fp) 
00219   { vtkByteSwap::SwapWrite4BERange((char *)i,num,fp);};
00221 #endif
00222 
00223 
00226   static void SwapWrite8BERange(char *c,int num, ostream *fp);
00227   static void SwapWrite8BERange(double *d,int num, ostream *fp) 
00228   { vtkByteSwap::SwapWrite8BERange((char *)d,num,fp);};
00230 
00233   static void SwapVoidRange(void *buffer, int numWords, int wordSize);
00234 
00235 
00236 protected:
00237   vtkByteSwap() {};
00238   ~vtkByteSwap() {};
00239 
00240 private:
00242   static void Swap2Bytes(char* &data);
00243 
00244   static void Swap4Bytes(char* &data);
00245  
00246   static void Swap8Bytes(char* &data);
00247 
00248 private:
00249   vtkByteSwap(const vtkByteSwap&);  // Not implemented.
00250   void operator=(const vtkByteSwap&);  // Not implemented.
00251 };
00252 
00253 
00254 inline void 
00255 vtkByteSwap::Swap2Bytes(char* &data)
00256 { 
00257   char one_byte;  
00258   one_byte = data[0]; data[0] = data[1]; data[1] = one_byte;
00259 }
00260 
00261 inline void 
00262 vtkByteSwap::Swap4Bytes(char* &data)
00263 { 
00264   char one_byte; 
00265   one_byte = data[0]; data[0] = data[3]; data[3] = one_byte;
00266   one_byte = data[1]; data[1] = data[2]; data[2] = one_byte; 
00267 }
00268 
00269 inline void 
00270 vtkByteSwap::Swap8Bytes(char* &data)
00271 { 
00272   char one_byte;
00273   one_byte = data[0]; data[0] = data[7]; data[7] = one_byte;
00274   one_byte = data[1]; data[1] = data[6]; data[6] = one_byte;
00275   one_byte = data[2]; data[2] = data[5]; data[5] = one_byte;
00276   one_byte = data[3]; data[3] = data[4]; data[4] = one_byte; 
00277 }
00278 
00279 #endif