cgma
CubitFileIOWrapper.hpp
Go to the documentation of this file.
00001 /*******************************************************************************
00002     COPYRIGHT 2002 CATERPILLAR INC.  ALL RIGHTS RESERVED
00003 
00004     This program is the property of Caterpillar Inc., includes Caterpillar's
00005     confidential and trade secret information, and is maintained as an
00006     unpublished copyrighted work.  It is not to be copied or used by others
00007     except under license from Caterpillar.  This program is also protected as an
00008     unpublished work in accordance with the copyright act of 1976.  In the event
00009     of either inadvertent or deliberate publication, Caterpillar Inc. intends to
00010     maintain copyright protection for this work under the relevant copyright
00011     laws pertaining to published works.  The inclusion of a copyright notice
00012     hereon is precautionary only, and does not imply publication or disclosure.
00013 
00014  
00015  Filename      : CubitFileIOWrapper.hpp
00016 
00017  Purpose       : Encapsulates file I/O operations for the Cubit file.
00018            
00019  Special Notes :
00020 
00021  Creator       : Will A. Helden
00022 
00023  Creation Date : 02/15/02
00024 
00025  Owner         : Will A. Helden
00026 
00027 *******************************************************************************/
00028 
00029 #include "CCubitFile.hpp"
00030 #include "CGMUtilConfigure.h"
00031 
00032 #ifndef CubitFileIOWrapper_HPP
00033 #define CubitFileIOWrapper_HPP
00034 
00035 namespace NCubitFile {
00036 
00037 UnsignedInt32 GetLocation(FILE* f);
00038 int SetLocation(FILE* f, UnsignedInt32 offset, int whence);
00039 
00040 class CUBIT_UTIL_EXPORT CIOWrapper {
00041 public:
00042     CIOWrapper(FILE* xpFile,
00043         UnsignedInt32 xeSourceEndian = CCubitFile::mintNativeEndian);
00044     CIOWrapper(UnsignedInt32 swap_endian, 
00045     FILE* xpFile );
00046     CIOWrapper(FILE* xpFile,
00047         UnsignedInt32 xintAbsoluteOffset, UnsignedInt32 xintRelativeOffset);
00048     virtual ~CIOWrapper();
00049     
00050     virtual UnsignedInt32 BeginWriteBlock(UnsignedInt32 xintAbsoluteOffset = 0);
00051     virtual void BeginRewriteBlock(UnsignedInt32 xintAbsoluteOffset,
00052         UnsignedInt32 xintRelativeOffset);
00053     virtual void Write(const UnsignedInt32* xpaintData, UnsignedInt32 xintCount);
00054     virtual void Write(const char* xpachrData, UnsignedInt32 xintCount,
00055         UnsignedInt32 xint32bitPadded = 0);
00056     virtual void Write(const double* xpadblData, UnsignedInt32 xintCount);
00057     virtual void Write(const char* xpachrData);
00058     virtual UnsignedInt32 EndWriteBlock();
00059     
00060     virtual void BeginReadBlock(UnsignedInt32 xintAbsoluteOffset,
00061         UnsignedInt32 xintRelativeOffset = 0);
00062     virtual void Read(UnsignedInt32* xpaintData, UnsignedInt32 xintCount);
00063     virtual void Read(char* xpachrData, UnsignedInt32 xintCount,
00064         UnsignedInt32 xint32bitPadded = 0);
00065     virtual void Read(double* xpadblData, UnsignedInt32 xintCount);
00066     virtual char* Read();
00067     virtual void EndReadBlock();
00068     virtual UnsignedInt32 get_endian() { return mintSwapEndian; }  
00069     
00070     virtual UnsignedInt32 GetLocation();
00071 
00072 private:
00073     FILE* mpFile;
00074     UnsignedInt32 mintSwapEndian;
00075     UnsignedInt32 mintBlockStart;
00076     UnsignedInt32 mintBlockEnd;
00077 };
00078 
00079 template <class T> void SwapEndian(unsigned int xintCount, T* xpT)
00080 {
00081     int lintToByte;
00082     unsigned char* lpCurFromByte;
00083     unsigned char lachrBuffer[sizeof(T)];
00084     
00085     unsigned char* lpCurAtom = (unsigned char*)xpT;
00086     int lintAtom = xintCount;
00087     while(lintAtom) {
00088         lintAtom--;
00089         lintToByte = sizeof(T);
00090         lpCurFromByte = lpCurAtom;
00091         while(lintToByte) {
00092             lintToByte--;
00093             lachrBuffer[lintToByte] = *lpCurFromByte;
00094             lpCurFromByte++;
00095         }
00096         memcpy(lpCurAtom, lachrBuffer, sizeof(T));
00097         lpCurAtom += sizeof(T);
00098     }
00099 }
00100 
00101 /*#define SWAPENDIAN(XINTATOMSIZE, XINTCOUNT, XPTARGET) \
00102     { \
00103         int lintToByte; \
00104         unsigned char* lpCurFromByte; \
00105         unsigned char lachrBuffer[(XINTATOMSIZE)]; \
00106         \
00107         unsigned char* lpCurAtom = (unsigned char*)(XPTARGET); \
00108         int lintAtom = (XINTCOUNT); \
00109         while(lintAtom) { \
00110             lintAtom--; \
00111             lintToByte = (XINTATOMSIZE); \
00112             lpCurFromByte = lpCurAtom; \
00113             while(lintToByte) { \
00114                 lintToByte--; \
00115                 lachrBuffer[lintToByte] = *lpCurFromByte; \
00116                 lpCurFromByte++; \
00117             } \
00118             memcpy(lpCurAtom, lachrBuffer, (XINTATOMSIZE)); \
00119             lpCurAtom += (XINTATOMSIZE); \
00120         } \
00121     }*/
00122 
00123 } // namespace NCubitFile
00124 
00125 #endif
00126 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines