Branch data Line data Source code
1 : : /*******************************************************************************
2 : : COPYRIGHT 2002 CATERPILLAR INC. ALL RIGHTS RESERVED
3 : :
4 : : This program is the property of Caterpillar Inc., includes Caterpillar's
5 : : confidential and trade secret information, and is maintained as an
6 : : unpublished copyrighted work. It is not to be copied or used by others
7 : : except under license from Caterpillar. This program is also protected as an
8 : : unpublished work in accordance with the copyright act of 1976. In the event
9 : : of either inadvertent or deliberate publication, Caterpillar Inc. intends to
10 : : maintain copyright protection for this work under the relevant copyright
11 : : laws pertaining to published works. The inclusion of a copyright notice
12 : : hereon is precautionary only, and does not imply publication or disclosure.
13 : :
14 : :
15 : : Filename : CubitFileIOWrapper.hpp
16 : :
17 : : Purpose : Encapsulates file I/O operations for the Cubit file.
18 : :
19 : : Special Notes :
20 : :
21 : : Creator : Will A. Helden
22 : :
23 : : Creation Date : 02/15/02
24 : :
25 : : Owner : Will A. Helden
26 : :
27 : : *******************************************************************************/
28 : :
29 : : #include "CCubitFile.hpp"
30 : : #include "CGMUtilConfigure.h"
31 : :
32 : : #ifndef CubitFileIOWrapper_HPP
33 : : #define CubitFileIOWrapper_HPP
34 : :
35 : : namespace NCubitFile {
36 : :
37 : : UnsignedInt32 GetLocation(FILE* f);
38 : : int SetLocation(FILE* f, UnsignedInt32 offset, int whence);
39 : :
40 : : class CUBIT_UTIL_EXPORT CIOWrapper {
41 : : public:
42 : : CIOWrapper(FILE* xpFile,
43 : : UnsignedInt32 xeSourceEndian = CCubitFile::mintNativeEndian);
44 : : CIOWrapper(UnsignedInt32 swap_endian,
45 : : FILE* xpFile );
46 : : CIOWrapper(FILE* xpFile,
47 : : UnsignedInt32 xintAbsoluteOffset, UnsignedInt32 xintRelativeOffset);
48 : : virtual ~CIOWrapper();
49 : :
50 : : virtual UnsignedInt32 BeginWriteBlock(UnsignedInt32 xintAbsoluteOffset = 0);
51 : : virtual void BeginRewriteBlock(UnsignedInt32 xintAbsoluteOffset,
52 : : UnsignedInt32 xintRelativeOffset);
53 : : virtual void Write(const UnsignedInt32* xpaintData, UnsignedInt32 xintCount);
54 : : virtual void Write(const char* xpachrData, UnsignedInt32 xintCount,
55 : : UnsignedInt32 xint32bitPadded = 0);
56 : : virtual void Write(const double* xpadblData, UnsignedInt32 xintCount);
57 : : virtual void Write(const char* xpachrData);
58 : : virtual UnsignedInt32 EndWriteBlock();
59 : :
60 : : virtual void BeginReadBlock(UnsignedInt32 xintAbsoluteOffset,
61 : : UnsignedInt32 xintRelativeOffset = 0);
62 : : virtual void Read(UnsignedInt32* xpaintData, UnsignedInt32 xintCount);
63 : : virtual void Read(char* xpachrData, UnsignedInt32 xintCount,
64 : : UnsignedInt32 xint32bitPadded = 0);
65 : : virtual void Read(double* xpadblData, UnsignedInt32 xintCount);
66 : : virtual char* Read();
67 : : virtual void EndReadBlock();
68 : 44 : virtual UnsignedInt32 get_endian() { return mintSwapEndian; }
69 : :
70 : : virtual UnsignedInt32 GetLocation();
71 : :
72 : : private:
73 : : FILE* mpFile;
74 : : UnsignedInt32 mintSwapEndian;
75 : : UnsignedInt32 mintBlockStart;
76 : : UnsignedInt32 mintBlockEnd;
77 : : };
78 : :
79 : 0 : template <class T> void SwapEndian(unsigned int xintCount, T* xpT)
80 : : {
81 : : int lintToByte;
82 : : unsigned char* lpCurFromByte;
83 : : unsigned char lachrBuffer[sizeof(T)];
84 : :
85 : 0 : unsigned char* lpCurAtom = (unsigned char*)xpT;
86 : 0 : int lintAtom = xintCount;
87 [ # # ][ # # ]: 0 : while(lintAtom) {
88 : 0 : lintAtom--;
89 : 0 : lintToByte = sizeof(T);
90 : 0 : lpCurFromByte = lpCurAtom;
91 [ # # ][ # # ]: 0 : while(lintToByte) {
92 : 0 : lintToByte--;
93 : 0 : lachrBuffer[lintToByte] = *lpCurFromByte;
94 : 0 : lpCurFromByte++;
95 : : }
96 : 0 : memcpy(lpCurAtom, lachrBuffer, sizeof(T));
97 : 0 : lpCurAtom += sizeof(T);
98 : : }
99 : 0 : }
100 : :
101 : : /*#define SWAPENDIAN(XINTATOMSIZE, XINTCOUNT, XPTARGET) \
102 : : { \
103 : : int lintToByte; \
104 : : unsigned char* lpCurFromByte; \
105 : : unsigned char lachrBuffer[(XINTATOMSIZE)]; \
106 : : \
107 : : unsigned char* lpCurAtom = (unsigned char*)(XPTARGET); \
108 : : int lintAtom = (XINTCOUNT); \
109 : : while(lintAtom) { \
110 : : lintAtom--; \
111 : : lintToByte = (XINTATOMSIZE); \
112 : : lpCurFromByte = lpCurAtom; \
113 : : while(lintToByte) { \
114 : : lintToByte--; \
115 : : lachrBuffer[lintToByte] = *lpCurFromByte; \
116 : : lpCurFromByte++; \
117 : : } \
118 : : memcpy(lpCurAtom, lachrBuffer, (XINTATOMSIZE)); \
119 : : lpCurAtom += (XINTATOMSIZE); \
120 : : } \
121 : : }*/
122 : :
123 : : } // namespace NCubitFile
124 : :
125 : : #endif
126 : :
|