00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00055 #ifndef __vtkByteSwap_h
00056 #define __vtkByteSwap_h
00057
00058 #include "vtkObject.h"
00059
00060 class VTK_COMMON_EXPORT vtkByteSwap : public vtkObject
00061 {
00062 public:
00063 static vtkByteSwap *New();
00064 vtkTypeMacro(vtkByteSwap,vtkObject);
00065
00067
00068 static void Swap2LE(short *s);
00069 static void Swap2LE(unsigned short *s);
00071
00073
00074 static void Swap4LE(char *c);
00075 static void Swap4LE(float *p) { vtkByteSwap::Swap4LE((char *)p);};
00076 static void Swap4LE(int *i) { vtkByteSwap::Swap4LE((char *)i);};
00077 static void Swap4LE(unsigned long *i) { vtkByteSwap::Swap4LE((char *)i);};
00078 static void Swap4LE(long *i) { vtkByteSwap::Swap4LE((char *)i);};
00080
00082
00084 static void Swap8LE(char *c);
00085 static void Swap8LE(double *d) { vtkByteSwap::Swap8LE((char *)d);};
00087
00089
00091 static void Swap2LERange(char *c,int num);
00092 static void Swap2LERange(short *i,int num)
00093 { vtkByteSwap::Swap2LERange((char *)i,num);};
00095
00097
00099 static void Swap4LERange(char *c,int num);
00100 static void Swap4LERange(unsigned char *c,int num)
00101 { vtkByteSwap::Swap4LERange((char *)c,num);};
00102 static void Swap4LERange(float *p,int num)
00103 { vtkByteSwap::Swap4LERange((char *)p,num);};
00104 static void Swap4LERange(int *i,int num)
00105 { vtkByteSwap::Swap4LERange((char *)i,num);};
00106 static void Swap4LERange(unsigned long *i,int num)
00107 { vtkByteSwap::Swap4LERange((char *)i,num);};
00109
00111
00113 static void Swap8LERange(char *c, int num);
00114 static void Swap8LERange(double *d, int num)
00115 { vtkByteSwap::Swap8LERange((char *)d, num);};
00117
00119
00120 static void Swap2BE(short *s);
00121 static void Swap2BE(unsigned short *s);
00123
00125
00127 static void Swap4BE(char *c);
00128 static void Swap4BE(float *p) { vtkByteSwap::Swap4BE((char *)p);};
00129 static void Swap4BE(int *i) { vtkByteSwap::Swap4BE((char *)i);};
00130 static void Swap4BE(unsigned long *i) { vtkByteSwap::Swap4BE((char *)i);};
00132
00134
00136 static void Swap8BE(char *c);
00137 static void Swap8BE(double *d) { vtkByteSwap::Swap8BE((char *)d);};
00139
00141
00143 static void Swap2BERange(char *c,int num);
00144 static void Swap2BERange(short *i,int num)
00145 { vtkByteSwap::Swap2BERange((char *)i,num);};
00147
00149
00151 static void Swap4BERange(char *c,int num);
00152 static void Swap4BERange(float *p,int num)
00153 { vtkByteSwap::Swap4BERange((char *)p,num); };
00154 static void Swap4BERange(int *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 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 long *i,int num, ostream *fp)
00226 { vtkByteSwap::SwapWrite4BERange((char *)i,num,fp);};
00227 #ifdef VTK_USE_64BIT_IDS
00228 static void SwapWrite4BERange(vtkIdType *i,int num, ostream *fp)
00229 { vtkByteSwap::SwapWrite4BERange((char *)i,num,fp);};
00231 #endif
00232
00233
00236 static void SwapWrite8BERange(char *c,int num, ostream *fp);
00237 static void SwapWrite8BERange(double *d,int num, ostream *fp)
00238 { vtkByteSwap::SwapWrite8BERange((char *)d,num,fp);};
00240
00243 static void SwapVoidRange(void *buffer, int numWords, int wordSize);
00244
00245
00246 protected:
00247 vtkByteSwap() {};
00248 ~vtkByteSwap() {};
00249
00250 private:
00252 static void Swap2Bytes(char* &data);
00253
00254 static void Swap4Bytes(char* &data);
00255
00256 static void Swap8Bytes(char* &data);
00257
00258 private:
00259 vtkByteSwap(const vtkByteSwap&);
00260 void operator=(const vtkByteSwap&);
00261 };
00262
00263
00264 inline void
00265 vtkByteSwap::Swap2Bytes(char* &data)
00266 {
00267 char one_byte;
00268 one_byte = data[0]; data[0] = data[1]; data[1] = one_byte;
00269 }
00270
00271 inline void
00272 vtkByteSwap::Swap4Bytes(char* &data)
00273 {
00274 char one_byte;
00275 one_byte = data[0]; data[0] = data[3]; data[3] = one_byte;
00276 one_byte = data[1]; data[1] = data[2]; data[2] = one_byte;
00277 }
00278
00279 inline void
00280 vtkByteSwap::Swap8Bytes(char* &data)
00281 {
00282 char one_byte;
00283 one_byte = data[0]; data[0] = data[7]; data[7] = one_byte;
00284 one_byte = data[1]; data[1] = data[6]; data[6] = one_byte;
00285 one_byte = data[2]; data[2] = data[5]; data[5] = one_byte;
00286 one_byte = data[3]; data[3] = data[4]; data[4] = one_byte;
00287 }
00288
00289 #endif