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 
00008 Copyright (c) 1993-2001 Ken Martin, Will Schroeder, Bill Lorensen 
00009 
00010 All rights reserved.
00011 
00012 Redistribution and use in source and binary forms, with or without
00013 modification, are permitted provided that the following conditions are met:
00014 
00015  * Redistributions of source code must retain the above copyright notice,
00016    this list of conditions and the following disclaimer.
00017 
00018  * Redistributions in binary form must reproduce the above copyright notice,
00019    this list of conditions and the following disclaimer in the documentation
00020    and/or other materials provided with the distribution.
00021 
00022  * Neither name of Ken Martin, Will Schroeder, or Bill Lorensen nor the names
00023    of any contributors may be used to endorse or promote products derived
00024    from this software without specific prior written permission.
00025 
00026  * Modified source versions must be plainly marked as such, and must not be
00027    misrepresented as being the original software.
00028 
00029 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
00030 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00031 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00032 ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
00033 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00034 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00035 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00036 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00037 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00038 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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&);  // Not implemented.
00260   void operator=(const vtkByteSwap&);  // Not implemented.
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

Generated on Thu Mar 28 14:19:14 2002 for VTK by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001