00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00040 #ifndef __vtkByteSwap_h
00041 #define __vtkByteSwap_h
00042
00043 #include "vtkObject.h"
00044
00045 class VTK_COMMON_EXPORT vtkByteSwap : public vtkObject
00046 {
00047 public:
00048 static vtkByteSwap *New();
00049 vtkTypeRevisionMacro(vtkByteSwap,vtkObject);
00050
00052
00053 static void Swap2LE(short *s);
00054 static void Swap2LE(unsigned short *s);
00056
00058
00059 static void Swap4LE(char *c);
00060 static void Swap4LE(float *p) { vtkByteSwap::Swap4LE((char *)p);};
00061 static void Swap4LE(int *i) { vtkByteSwap::Swap4LE((char *)i);};
00062 static void Swap4LE(unsigned int *i) { vtkByteSwap::Swap4LE((char *)i);};
00063 static void Swap4LE(long *i) { vtkByteSwap::Swap4LE((char *)i);};
00064 static void Swap4LE(unsigned long *i) { vtkByteSwap::Swap4LE((char *)i);};
00066
00068
00070 static void Swap8LE(char *c);
00071 static void Swap8LE(double *d) { vtkByteSwap::Swap8LE((char *)d);};
00073
00075
00077 static void Swap2LERange(char *c,int num);
00078 static void Swap2LERange(short *i,int num)
00079 { vtkByteSwap::Swap2LERange((char *)i,num);};
00081
00083
00085 static void Swap4LERange(char *c,int num);
00086 static void Swap4LERange(unsigned char *c,int num)
00087 { vtkByteSwap::Swap4LERange((char *)c,num);};
00088 static void Swap4LERange(float *p,int num)
00089 { vtkByteSwap::Swap4LERange((char *)p,num);};
00090 static void Swap4LERange(int *i,int num)
00091 { vtkByteSwap::Swap4LERange((char *)i,num);};
00092 static void Swap4LERange(unsigned int *i,int num)
00093 { vtkByteSwap::Swap4LERange((char *)i,num);};
00094 static void Swap4LERange(long *i,int num)
00095 { vtkByteSwap::Swap4LERange((char *)i,num);};
00096 static void Swap4LERange(unsigned long *i,int num)
00097 { vtkByteSwap::Swap4LERange((char *)i,num);};
00099
00101
00103 static void Swap8LERange(char *c, int num);
00104 static void Swap8LERange(double *d, int num)
00105 { vtkByteSwap::Swap8LERange((char *)d, num);};
00107
00109
00110 static void Swap2BE(short *s);
00111 static void Swap2BE(unsigned short *s);
00113
00115
00117 static void Swap4BE(char *c);
00118 static void Swap4BE(float *p) { vtkByteSwap::Swap4BE((char *)p);};
00119 static void Swap4BE(int *i) { vtkByteSwap::Swap4BE((char *)i);};
00120 static void Swap4BE(unsigned int *i) { vtkByteSwap::Swap4BE((char *)i);};
00121 static void Swap4BE(long *i) { vtkByteSwap::Swap4BE((char *)i);};
00122 static void Swap4BE(unsigned long *i) { vtkByteSwap::Swap4BE((char *)i);};
00124
00126
00128 static void Swap8BE(char *c);
00129 static void Swap8BE(double *d) { vtkByteSwap::Swap8BE((char *)d);};
00131
00133
00135 static void Swap2BERange(char *c,int num);
00136 static void Swap2BERange(short *i,int num)
00137 { vtkByteSwap::Swap2BERange((char *)i,num);};
00139
00141
00143 static void Swap4BERange(char *c,int num);
00144 static void Swap4BERange(float *p,int num)
00145 { vtkByteSwap::Swap4BERange((char *)p,num); };
00146 static void Swap4BERange(int *i,int num)
00147 { vtkByteSwap::Swap4BERange((char *)i,num); };
00148 static void Swap4BERange(unsigned int *i,int num)
00149 { vtkByteSwap::Swap4BERange((char *)i,num); };
00150 static void Swap4BERange(long *i,int num)
00151 { vtkByteSwap::Swap4BERange((char *)i,num); };
00152 static void Swap4BERange(unsigned long *i,int num)
00153 { vtkByteSwap::Swap4BERange((char *)i,num); };
00155
00156 #ifdef VTK_USE_64BIT_IDS
00157 static void Swap4BERange(vtkIdType *i,int num)
00158 { vtkByteSwap::Swap4BERange((char *)i,num); };
00159 #endif
00160
00162
00164 static void Swap8BERange(char *c,int num);
00165 static void Swap8BERange(double *d,int num)
00166 { vtkByteSwap::Swap8BERange((char *)d,num); };
00168
00170
00173 static void SwapWrite2BERange(char *c,int num,FILE *fp);
00174 static void SwapWrite2BERange(short *i,int num, FILE *fp)
00175 {vtkByteSwap::SwapWrite2BERange((char *)i,num,fp);};
00177
00179
00182 static void SwapWrite4BERange(char *c,int num,FILE *fp);
00183 static void SwapWrite4BERange(float *p,int num, FILE *fp)
00184 { vtkByteSwap::SwapWrite4BERange((char *)p,num,fp);};
00185 static void SwapWrite4BERange(int *i,int num,FILE *fp)
00186 { vtkByteSwap::SwapWrite4BERange((char *)i,num,fp);};
00187 static void SwapWrite4BERange(unsigned int *i,int num,FILE *fp)
00188 { vtkByteSwap::SwapWrite4BERange((char *)i,num,fp);};
00189 static void SwapWrite4BERange(unsigned long *i,int num, FILE *fp)
00190 { vtkByteSwap::SwapWrite4BERange((char *)i,num,fp);};
00191 static void SwapWrite4BERange(long *i,int num, FILE *fp)
00192 { vtkByteSwap::SwapWrite4BERange((char *)i,num,fp);};
00193 #ifdef VTK_USE_64BIT_IDS
00194 static void SwapWrite4BERange(vtkIdType *i,int num, FILE *fp)
00195 { vtkByteSwap::SwapWrite4BERange((char *)i,num,fp);};
00197 #endif
00198
00199
00202 static void SwapWrite8BERange(char *c,int num,FILE *fp);
00203 static void SwapWrite8BERange(double *d,int num, FILE *fp)
00204 { vtkByteSwap::SwapWrite8BERange((char *)d,num,fp);};
00206
00208
00211 static void SwapWrite2BERange(char *c,int num, ostream *fp);
00212 static void SwapWrite2BERange(short *i,int num, ostream *fp)
00213 {vtkByteSwap::SwapWrite2BERange((char *)i,num,fp);};
00215
00217
00220 static void SwapWrite4BERange(char *c,int num, ostream *fp);
00221 static void SwapWrite4BERange(float *p,int num, ostream *fp)
00222 { vtkByteSwap::SwapWrite4BERange((char *)p,num,fp);};
00223 static void SwapWrite4BERange(int *i,int num, ostream *fp)
00224 { vtkByteSwap::SwapWrite4BERange((char *)i,num,fp);};
00225 static void SwapWrite4BERange(unsigned int *i,int num, ostream *fp)
00226 { vtkByteSwap::SwapWrite4BERange((char *)i,num,fp);};
00227 static void SwapWrite4BERange(unsigned long *i,int num, ostream *fp)
00228 { vtkByteSwap::SwapWrite4BERange((char *)i,num,fp);};
00229 static void SwapWrite4BERange(long *i,int num, ostream *fp)
00230 { vtkByteSwap::SwapWrite4BERange((char *)i,num,fp);};
00231 #ifdef VTK_USE_64BIT_IDS
00232 static void SwapWrite4BERange(vtkIdType *i,int num, ostream *fp)
00233 { vtkByteSwap::SwapWrite4BERange((char *)i,num,fp);};
00235 #endif
00236
00237
00240 static void SwapWrite8BERange(char *c,int num, ostream *fp);
00241 static void SwapWrite8BERange(double *d,int num, ostream *fp)
00242 { vtkByteSwap::SwapWrite8BERange((char *)d,num,fp);};
00244
00247 static void SwapVoidRange(void *buffer, int numWords, int wordSize);
00248
00249
00250 protected:
00251 vtkByteSwap() {};
00252 ~vtkByteSwap() {};
00253
00254 private:
00256 static void Swap2Bytes(char* &data);
00257
00258 static void Swap4Bytes(char* &data);
00259
00260 static void Swap8Bytes(char* &data);
00261
00262 private:
00263 vtkByteSwap(const vtkByteSwap&);
00264 void operator=(const vtkByteSwap&);
00265 };
00266
00267
00268 inline void
00269 vtkByteSwap::Swap2Bytes(char* &data)
00270 {
00271 char one_byte;
00272 one_byte = data[0]; data[0] = data[1]; data[1] = one_byte;
00273 }
00274
00275 inline void
00276 vtkByteSwap::Swap4Bytes(char* &data)
00277 {
00278 char one_byte;
00279 one_byte = data[0]; data[0] = data[3]; data[3] = one_byte;
00280 one_byte = data[1]; data[1] = data[2]; data[2] = one_byte;
00281 }
00282
00283 inline void
00284 vtkByteSwap::Swap8Bytes(char* &data)
00285 {
00286 char one_byte;
00287 one_byte = data[0]; data[0] = data[7]; data[7] = one_byte;
00288 one_byte = data[1]; data[1] = data[6]; data[6] = one_byte;
00289 one_byte = data[2]; data[2] = data[5]; data[5] = one_byte;
00290 one_byte = data[3]; data[3] = data[4]; data[4] = one_byte;
00291 }
00292
00293 #endif