Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound 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   Language:  C++
00006 
00007   Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen 
00008   All rights reserved.
00009   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00010 
00011      This software is distributed WITHOUT ANY WARRANTY; without even 
00012      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00013      PURPOSE.  See the above copyright notice for more information.
00014 
00015 =========================================================================*/
00044 #ifndef __vtkByteSwap_h
00045 #define __vtkByteSwap_h
00046 
00047 #include "vtkObject.h"
00048 
00049 class VTK_COMMON_EXPORT vtkByteSwap : public vtkObject
00050 {
00051 public:
00052   static vtkByteSwap *New();
00053   vtkTypeRevisionMacro(vtkByteSwap,vtkObject);
00054 
00056 
00057   static void Swap2LE(short *s);
00058   static void Swap2LE(unsigned short *s);
00060 
00062 
00063   static void Swap4LE(char *c);
00064   static void Swap4LE(float *p) { vtkByteSwap::Swap4LE((char *)p);};
00065   static void Swap4LE(int *i)   { vtkByteSwap::Swap4LE((char *)i);};
00066   static void Swap4LE(unsigned int *i)   { vtkByteSwap::Swap4LE((char *)i);};
00067   static void Swap4LE(long *i) { vtkByteSwap::Swap4LE((char *)i);};
00068   static void Swap4LE(unsigned long *i) { vtkByteSwap::Swap4LE((char *)i);};
00070 
00072 
00074   static void Swap8LE(char *c);
00075   static void Swap8LE(double *d) { vtkByteSwap::Swap8LE((char *)d);};
00077 
00079 
00081   static void Swap2LERange(char *c,int num);
00082   static void Swap2LERange(short *i,int num) 
00083   { vtkByteSwap::Swap2LERange((char *)i,num);};
00085 
00087 
00089   static void Swap4LERange(char *c,int num);
00090   static void Swap4LERange(unsigned char *c,int num) 
00091   { vtkByteSwap::Swap4LERange((char *)c,num);};
00092   static void Swap4LERange(float *p,int num) 
00093   { vtkByteSwap::Swap4LERange((char *)p,num);};
00094   static void Swap4LERange(int *i,int num) 
00095   { vtkByteSwap::Swap4LERange((char *)i,num);};
00096   static void Swap4LERange(unsigned int *i,int num) 
00097   { vtkByteSwap::Swap4LERange((char *)i,num);};
00098   static void Swap4LERange(long *i,int num) 
00099   { vtkByteSwap::Swap4LERange((char *)i,num);};
00100   static void Swap4LERange(unsigned long *i,int num) 
00101   { vtkByteSwap::Swap4LERange((char *)i,num);};
00103 
00105 
00107   static void Swap8LERange(char *c, int num);
00108   static void Swap8LERange(double *d, int num) 
00109   { vtkByteSwap::Swap8LERange((char *)d, num);};
00111 
00113 
00114   static void Swap2BE(short *s);
00115   static void Swap2BE(unsigned short *s);
00117 
00119 
00121   static void Swap4BE(char *c);
00122   static void Swap4BE(float *p) { vtkByteSwap::Swap4BE((char *)p);};
00123   static void Swap4BE(int *i)   { vtkByteSwap::Swap4BE((char *)i);};
00124   static void Swap4BE(unsigned int *i)  { vtkByteSwap::Swap4BE((char *)i);};
00125   static void Swap4BE(long *i) { vtkByteSwap::Swap4BE((char *)i);};
00126   static void Swap4BE(unsigned long *i) { vtkByteSwap::Swap4BE((char *)i);};
00128 
00130 
00132   static void Swap8BE(char *c);
00133   static void Swap8BE(double *d) { vtkByteSwap::Swap8BE((char *)d);};
00135 
00137 
00139   static void Swap2BERange(char *c,int num);
00140   static void Swap2BERange(short *i,int num) 
00141   { vtkByteSwap::Swap2BERange((char *)i,num);};
00143 
00145 
00147   static void Swap4BERange(char *c,int num);
00148   static void Swap4BERange(float *p,int num) 
00149   { vtkByteSwap::Swap4BERange((char *)p,num); };
00150   static void Swap4BERange(int *i,int num) 
00151   { vtkByteSwap::Swap4BERange((char *)i,num); };
00152   static void Swap4BERange(unsigned int *i,int num) 
00153   { vtkByteSwap::Swap4BERange((char *)i,num); };
00154   static void Swap4BERange(long *i,int num) 
00155   { vtkByteSwap::Swap4BERange((char *)i,num); };
00156   static void Swap4BERange(unsigned long *i,int num) 
00157   { vtkByteSwap::Swap4BERange((char *)i,num); };
00159 
00160 #ifdef VTK_USE_64BIT_IDS
00161   static void Swap4BERange(vtkIdType *i,int num) 
00162   { vtkByteSwap::Swap4BERange((char *)i,num); };
00163 #endif
00164 
00166 
00168   static void Swap8BERange(char *c,int num);
00169   static void Swap8BERange(double *d,int num) 
00170   { vtkByteSwap::Swap8BERange((char *)d,num); };
00172 
00174 
00177   static void SwapWrite2BERange(char *c,int num,FILE *fp);
00178   static void SwapWrite2BERange(short *i,int num, FILE *fp) 
00179   {vtkByteSwap::SwapWrite2BERange((char *)i,num,fp);};
00181 
00183 
00186   static void SwapWrite4BERange(char *c,int num,FILE *fp);
00187   static void SwapWrite4BERange(float *p,int num, FILE *fp) 
00188   { vtkByteSwap::SwapWrite4BERange((char *)p,num,fp);};
00189   static void SwapWrite4BERange(int *i,int num,FILE *fp) 
00190   { vtkByteSwap::SwapWrite4BERange((char *)i,num,fp);};
00191   static void SwapWrite4BERange(unsigned int *i,int num,FILE *fp) 
00192   { vtkByteSwap::SwapWrite4BERange((char *)i,num,fp);};
00193   static void SwapWrite4BERange(unsigned long *i,int num, FILE *fp) 
00194   { vtkByteSwap::SwapWrite4BERange((char *)i,num,fp);};
00195   static void SwapWrite4BERange(long *i,int num, FILE *fp) 
00196   { vtkByteSwap::SwapWrite4BERange((char *)i,num,fp);};
00197 #ifdef VTK_USE_64BIT_IDS
00198   static void SwapWrite4BERange(vtkIdType *i,int num, FILE *fp) 
00199   { vtkByteSwap::SwapWrite4BERange((char *)i,num,fp);};
00201 #endif
00202 
00203 
00206   static void SwapWrite8BERange(char *c,int num,FILE *fp);
00207   static void SwapWrite8BERange(double *d,int num, FILE *fp) 
00208   { vtkByteSwap::SwapWrite8BERange((char *)d,num,fp);};
00210 
00212 
00215   static void SwapWrite2BERange(char *c,int num, ostream *fp);
00216   static void SwapWrite2BERange(short *i,int num, ostream *fp) 
00217   {vtkByteSwap::SwapWrite2BERange((char *)i,num,fp);};
00219 
00221 
00224   static void SwapWrite4BERange(char *c,int num, ostream *fp);
00225   static void SwapWrite4BERange(float *p,int num, ostream *fp) 
00226   { vtkByteSwap::SwapWrite4BERange((char *)p,num,fp);};
00227   static void SwapWrite4BERange(int *i,int num, ostream *fp) 
00228   { vtkByteSwap::SwapWrite4BERange((char *)i,num,fp);};
00229   static void SwapWrite4BERange(unsigned int *i,int num, ostream *fp) 
00230   { vtkByteSwap::SwapWrite4BERange((char *)i,num,fp);};
00231   static void SwapWrite4BERange(unsigned long *i,int num, ostream *fp) 
00232   { vtkByteSwap::SwapWrite4BERange((char *)i,num,fp);};
00233   static void SwapWrite4BERange(long *i,int num, ostream *fp) 
00234   { vtkByteSwap::SwapWrite4BERange((char *)i,num,fp);};
00235 #ifdef VTK_USE_64BIT_IDS
00236   static void SwapWrite4BERange(vtkIdType *i,int num, ostream *fp) 
00237   { vtkByteSwap::SwapWrite4BERange((char *)i,num,fp);};
00239 #endif
00240 
00241 
00244   static void SwapWrite8BERange(char *c,int num, ostream *fp);
00245   static void SwapWrite8BERange(double *d,int num, ostream *fp) 
00246   { vtkByteSwap::SwapWrite8BERange((char *)d,num,fp);};
00248 
00251   static void SwapVoidRange(void *buffer, int numWords, int wordSize);
00252 
00253 
00254 protected:
00255   vtkByteSwap() {};
00256   ~vtkByteSwap() {};
00257 
00258 private:
00260   static void Swap2Bytes(char* &data);
00261 
00262   static void Swap4Bytes(char* &data);
00263  
00264   static void Swap8Bytes(char* &data);
00265 
00266 private:
00267   vtkByteSwap(const vtkByteSwap&);  // Not implemented.
00268   void operator=(const vtkByteSwap&);  // Not implemented.
00269 };
00270 
00271 
00272 inline void 
00273 vtkByteSwap::Swap2Bytes(char* &data)
00274 { 
00275   char one_byte;  
00276   one_byte = data[0]; data[0] = data[1]; data[1] = one_byte;
00277 }
00278 
00279 inline void 
00280 vtkByteSwap::Swap4Bytes(char* &data)
00281 { 
00282   char one_byte; 
00283   one_byte = data[0]; data[0] = data[3]; data[3] = one_byte;
00284   one_byte = data[1]; data[1] = data[2]; data[2] = one_byte; 
00285 }
00286 
00287 inline void 
00288 vtkByteSwap::Swap8Bytes(char* &data)
00289 { 
00290   char one_byte;
00291   one_byte = data[0]; data[0] = data[7]; data[7] = one_byte;
00292   one_byte = data[1]; data[1] = data[6]; data[6] = one_byte;
00293   one_byte = data[2]; data[2] = data[5]; data[5] = one_byte;
00294   one_byte = data[3]; data[3] = data[4]; data[4] = one_byte; 
00295 }
00296 
00297 #endif