OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "xfa/fgas/crt/fgas_stream.h" | 7 #include "xfa/fgas/crt/fgas_stream.h" |
8 | 8 |
9 #if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN32_MOBILE_ || \ | 9 #if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN32_MOBILE_ || \ |
10 _FX_OS_ == _FX_WIN64_ | 10 _FX_OS_ == _FX_WIN64_ |
11 #include <io.h> | 11 #include <io.h> |
12 #endif | 12 #endif |
13 | 13 |
14 #include <algorithm> | 14 #include <algorithm> |
15 #include <memory> | 15 #include <memory> |
16 | 16 |
17 #include "xfa/fgas/crt/fgas_codepage.h" | 17 #include "xfa/fgas/crt/fgas_codepage.h" |
18 | 18 |
19 namespace { | 19 namespace { |
20 | 20 |
21 class IFX_StreamImp { | 21 class IFGAS_StreamImp { |
22 public: | 22 public: |
23 virtual ~IFX_StreamImp() {} | 23 virtual ~IFGAS_StreamImp() {} |
24 | 24 |
25 virtual int32_t GetLength() const = 0; | 25 virtual int32_t GetLength() const = 0; |
26 virtual int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) = 0; | 26 virtual int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) = 0; |
27 virtual int32_t GetPosition() = 0; | 27 virtual int32_t GetPosition() = 0; |
28 virtual bool IsEOF() const = 0; | 28 virtual bool IsEOF() const = 0; |
29 virtual int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) = 0; | 29 virtual int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) = 0; |
30 virtual int32_t ReadString(FX_WCHAR* pStr, | 30 virtual int32_t ReadString(FX_WCHAR* pStr, |
31 int32_t iMaxLength, | 31 int32_t iMaxLength, |
32 bool& bEOS) = 0; | 32 bool& bEOS) = 0; |
33 virtual int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) = 0; | 33 virtual int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) = 0; |
34 virtual int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) = 0; | 34 virtual int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) = 0; |
35 virtual void Flush() = 0; | 35 virtual void Flush() = 0; |
36 virtual bool SetLength(int32_t iLength) = 0; | 36 virtual bool SetLength(int32_t iLength) = 0; |
37 | 37 |
38 protected: | 38 protected: |
39 IFX_StreamImp(); | 39 IFGAS_StreamImp(); |
40 | 40 |
41 uint32_t GetAccessModes() const { return m_dwAccess; } | 41 uint32_t GetAccessModes() const { return m_dwAccess; } |
42 void SetAccessModes(uint32_t modes) { m_dwAccess = modes; } | 42 void SetAccessModes(uint32_t modes) { m_dwAccess = modes; } |
43 | 43 |
44 private: | 44 private: |
45 uint32_t m_dwAccess; | 45 uint32_t m_dwAccess; |
46 }; | 46 }; |
47 | 47 |
48 class CFX_FileStreamImp : public IFX_StreamImp { | 48 class CFGAS_FileStreamImp : public IFGAS_StreamImp { |
49 public: | 49 public: |
50 CFX_FileStreamImp(); | 50 CFGAS_FileStreamImp(); |
51 ~CFX_FileStreamImp() override; | 51 ~CFGAS_FileStreamImp() override; |
52 | 52 |
53 bool LoadFile(const FX_WCHAR* pszSrcFileName, uint32_t dwAccess); | 53 bool LoadFile(const FX_WCHAR* pszSrcFileName, uint32_t dwAccess); |
54 | 54 |
55 // IFX_StreamImp: | 55 // IFGAS_StreamImp: |
56 int32_t GetLength() const override; | 56 int32_t GetLength() const override; |
57 int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) override; | 57 int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) override; |
58 int32_t GetPosition() override; | 58 int32_t GetPosition() override; |
59 bool IsEOF() const override; | 59 bool IsEOF() const override; |
60 int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) override; | 60 int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) override; |
61 int32_t ReadString(FX_WCHAR* pStr, int32_t iMaxLength, bool& bEOS) override; | 61 int32_t ReadString(FX_WCHAR* pStr, int32_t iMaxLength, bool& bEOS) override; |
62 int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) override; | 62 int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) override; |
63 int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) override; | 63 int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) override; |
64 void Flush() override; | 64 void Flush() override; |
65 bool SetLength(int32_t iLength) override; | 65 bool SetLength(int32_t iLength) override; |
66 | 66 |
67 protected: | 67 protected: |
68 FXSYS_FILE* m_hFile; | 68 FXSYS_FILE* m_hFile; |
69 int32_t m_iLength; | 69 int32_t m_iLength; |
70 }; | 70 }; |
71 | 71 |
72 class CFX_BufferStreamImp : public IFX_StreamImp { | 72 class CFGAS_BufferStreamImp : public IFGAS_StreamImp { |
73 public: | 73 public: |
74 CFX_BufferStreamImp(); | 74 CFGAS_BufferStreamImp(); |
75 ~CFX_BufferStreamImp() override {} | 75 ~CFGAS_BufferStreamImp() override {} |
76 | 76 |
77 bool LoadBuffer(uint8_t* pData, int32_t iTotalSize, uint32_t dwAccess); | 77 bool LoadBuffer(uint8_t* pData, int32_t iTotalSize, uint32_t dwAccess); |
78 | 78 |
79 // IFX_StreamImp: | 79 // IFGAS_StreamImp: |
80 int32_t GetLength() const override; | 80 int32_t GetLength() const override; |
81 int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) override; | 81 int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) override; |
82 int32_t GetPosition() override; | 82 int32_t GetPosition() override; |
83 bool IsEOF() const override; | 83 bool IsEOF() const override; |
84 int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) override; | 84 int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) override; |
85 int32_t ReadString(FX_WCHAR* pStr, int32_t iMaxLength, bool& bEOS) override; | 85 int32_t ReadString(FX_WCHAR* pStr, int32_t iMaxLength, bool& bEOS) override; |
86 int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) override; | 86 int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) override; |
87 int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) override; | 87 int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) override; |
88 void Flush() override {} | 88 void Flush() override {} |
89 bool SetLength(int32_t iLength) override { return false; } | 89 bool SetLength(int32_t iLength) override { return false; } |
90 | 90 |
91 protected: | 91 protected: |
92 uint8_t* m_pData; | 92 uint8_t* m_pData; |
93 int32_t m_iTotalSize; | 93 int32_t m_iTotalSize; |
94 int32_t m_iPosition; | 94 int32_t m_iPosition; |
95 int32_t m_iLength; | 95 int32_t m_iLength; |
96 }; | 96 }; |
97 | 97 |
98 class CFX_FileReadStreamImp : public IFX_StreamImp { | 98 class CFGAS_FileReadStreamImp : public IFGAS_StreamImp { |
99 public: | 99 public: |
100 CFX_FileReadStreamImp(); | 100 CFGAS_FileReadStreamImp(); |
101 ~CFX_FileReadStreamImp() override {} | 101 ~CFGAS_FileReadStreamImp() override {} |
102 | 102 |
103 bool LoadFileRead(IFX_SeekableReadStream* pFileRead, uint32_t dwAccess); | 103 bool LoadFileRead(IFX_SeekableReadStream* pFileRead, uint32_t dwAccess); |
104 | 104 |
105 // IFX_StreamImp: | 105 // IFGAS_StreamImp: |
106 int32_t GetLength() const override; | 106 int32_t GetLength() const override; |
107 int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) override; | 107 int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) override; |
108 int32_t GetPosition() override { return m_iPosition; } | 108 int32_t GetPosition() override { return m_iPosition; } |
109 bool IsEOF() const override; | 109 bool IsEOF() const override; |
110 int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) override; | 110 int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) override; |
111 int32_t ReadString(FX_WCHAR* pStr, int32_t iMaxLength, bool& bEOS) override; | 111 int32_t ReadString(FX_WCHAR* pStr, int32_t iMaxLength, bool& bEOS) override; |
112 int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) override { | 112 int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) override { |
113 return 0; | 113 return 0; |
114 } | 114 } |
115 int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) override { | 115 int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) override { |
116 return 0; | 116 return 0; |
117 } | 117 } |
118 void Flush() override {} | 118 void Flush() override {} |
119 bool SetLength(int32_t iLength) override { return false; } | 119 bool SetLength(int32_t iLength) override { return false; } |
120 | 120 |
121 protected: | 121 protected: |
122 IFX_SeekableReadStream* m_pFileRead; | 122 IFX_SeekableReadStream* m_pFileRead; |
123 int32_t m_iPosition; | 123 int32_t m_iPosition; |
124 int32_t m_iLength; | 124 int32_t m_iLength; |
125 }; | 125 }; |
126 | 126 |
127 class CFX_BufferReadStreamImp : public IFX_StreamImp { | 127 class CFGAS_BufferReadStreamImp : public IFGAS_StreamImp { |
128 public: | 128 public: |
129 CFX_BufferReadStreamImp(); | 129 CFGAS_BufferReadStreamImp(); |
130 ~CFX_BufferReadStreamImp() override; | 130 ~CFGAS_BufferReadStreamImp() override; |
131 | 131 |
132 bool LoadBufferRead(IFX_BufferedReadStream* pBufferRead, | 132 bool LoadBufferRead(IFX_BufferedReadStream* pBufferRead, |
133 int32_t iFileSize, | 133 int32_t iFileSize, |
134 uint32_t dwAccess, | 134 uint32_t dwAccess, |
135 bool bReleaseBufferRead); | 135 bool bReleaseBufferRead); |
136 | 136 |
137 // IFX_StreamImp: | 137 // IFGAS_StreamImp: |
138 int32_t GetLength() const override; | 138 int32_t GetLength() const override; |
139 int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) override; | 139 int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) override; |
140 int32_t GetPosition() override { return m_iPosition; } | 140 int32_t GetPosition() override { return m_iPosition; } |
141 bool IsEOF() const override; | 141 bool IsEOF() const override; |
142 int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) override; | 142 int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) override; |
143 int32_t ReadString(FX_WCHAR* pStr, int32_t iMaxLength, bool& bEOS) override; | 143 int32_t ReadString(FX_WCHAR* pStr, int32_t iMaxLength, bool& bEOS) override; |
144 int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) override { | 144 int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) override { |
145 return 0; | 145 return 0; |
146 } | 146 } |
147 int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) override { | 147 int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) override { |
148 return 0; | 148 return 0; |
149 } | 149 } |
150 void Flush() override {} | 150 void Flush() override {} |
151 bool SetLength(int32_t iLength) override { return false; } | 151 bool SetLength(int32_t iLength) override { return false; } |
152 | 152 |
153 private: | 153 private: |
154 IFX_BufferedReadStream* m_pBufferRead; | 154 IFX_BufferedReadStream* m_pBufferRead; |
155 bool m_bReleaseBufferRead; | 155 bool m_bReleaseBufferRead; |
156 int32_t m_iPosition; | 156 int32_t m_iPosition; |
157 int32_t m_iBufferSize; | 157 int32_t m_iBufferSize; |
158 }; | 158 }; |
159 | 159 |
160 class CFX_FileWriteStreamImp : public IFX_StreamImp { | 160 class CFGAS_FileWriteStreamImp : public IFGAS_StreamImp { |
161 public: | 161 public: |
162 CFX_FileWriteStreamImp(); | 162 CFGAS_FileWriteStreamImp(); |
163 ~CFX_FileWriteStreamImp() override {} | 163 ~CFGAS_FileWriteStreamImp() override {} |
164 | 164 |
165 bool LoadFileWrite(IFX_SeekableWriteStream* pFileWrite, uint32_t dwAccess); | 165 bool LoadFileWrite(IFX_SeekableWriteStream* pFileWrite, uint32_t dwAccess); |
166 | 166 |
167 // IFX_StreamImp: | 167 // IFGAS_StreamImp: |
168 int32_t GetLength() const override; | 168 int32_t GetLength() const override; |
169 int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) override; | 169 int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) override; |
170 int32_t GetPosition() override { return m_iPosition; } | 170 int32_t GetPosition() override { return m_iPosition; } |
171 bool IsEOF() const override; | 171 bool IsEOF() const override; |
172 int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) override { return 0; } | 172 int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) override { return 0; } |
173 int32_t ReadString(FX_WCHAR* pStr, int32_t iMaxLength, bool& bEOS) override { | 173 int32_t ReadString(FX_WCHAR* pStr, int32_t iMaxLength, bool& bEOS) override { |
174 return 0; | 174 return 0; |
175 } | 175 } |
176 int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) override; | 176 int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) override; |
177 int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) override; | 177 int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) override; |
178 void Flush() override; | 178 void Flush() override; |
179 bool SetLength(int32_t iLength) override { return false; } | 179 bool SetLength(int32_t iLength) override { return false; } |
180 | 180 |
181 protected: | 181 protected: |
182 IFX_SeekableWriteStream* m_pFileWrite; | 182 IFX_SeekableWriteStream* m_pFileWrite; |
183 int32_t m_iPosition; | 183 int32_t m_iPosition; |
184 }; | 184 }; |
185 | 185 |
186 enum FX_STREAMTYPE { | 186 enum FX_STREAMTYPE { |
187 FX_SREAMTYPE_Unknown = 0, | 187 FX_SREAMTYPE_Unknown = 0, |
188 FX_STREAMTYPE_File, | 188 FX_STREAMTYPE_File, |
189 FX_STREAMTYPE_Buffer, | 189 FX_STREAMTYPE_Buffer, |
190 FX_STREAMTYPE_Stream, | 190 FX_STREAMTYPE_Stream, |
191 FX_STREAMTYPE_BufferRead, | 191 FX_STREAMTYPE_BufferRead, |
192 }; | 192 }; |
193 | 193 |
194 class CFX_Stream : public IFX_Stream { | 194 class CFGAS_Stream : public IFGAS_Stream { |
195 public: | 195 public: |
196 CFX_Stream(); | 196 CFGAS_Stream(); |
197 ~CFX_Stream() override; | 197 ~CFGAS_Stream() override; |
198 | 198 |
199 bool LoadFile(const FX_WCHAR* pszSrcFileName, uint32_t dwAccess); | 199 bool LoadFile(const FX_WCHAR* pszSrcFileName, uint32_t dwAccess); |
200 bool LoadBuffer(uint8_t* pData, int32_t iTotalSize, uint32_t dwAccess); | 200 bool LoadBuffer(uint8_t* pData, int32_t iTotalSize, uint32_t dwAccess); |
201 bool LoadFileRead(IFX_SeekableReadStream* pFileRead, uint32_t dwAccess); | 201 bool LoadFileRead(IFX_SeekableReadStream* pFileRead, uint32_t dwAccess); |
202 bool LoadFileWrite(IFX_SeekableWriteStream* pFileWrite, uint32_t dwAccess); | 202 bool LoadFileWrite(IFX_SeekableWriteStream* pFileWrite, uint32_t dwAccess); |
203 bool LoadBufferRead(IFX_BufferedReadStream* pBufferRead, | 203 bool LoadBufferRead(IFX_BufferedReadStream* pBufferRead, |
204 int32_t iFileSize, | 204 int32_t iFileSize, |
205 uint32_t dwAccess, | 205 uint32_t dwAccess, |
206 bool bReleaseBufferRead); | 206 bool bReleaseBufferRead); |
207 | 207 |
208 // IFX_Stream | 208 // IFGAS_Stream |
209 void Release() override; | 209 void Release() override; |
210 IFX_Stream* Retain() override; | 210 IFGAS_Stream* Retain() override; |
211 uint32_t GetAccessModes() const override; | 211 uint32_t GetAccessModes() const override; |
212 int32_t GetLength() const override; | 212 int32_t GetLength() const override; |
213 int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) override; | 213 int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) override; |
214 int32_t GetPosition() override; | 214 int32_t GetPosition() override; |
215 bool IsEOF() const override; | 215 bool IsEOF() const override; |
216 int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) override; | 216 int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) override; |
217 int32_t ReadString(FX_WCHAR* pStr, int32_t iMaxLength, bool& bEOS) override; | 217 int32_t ReadString(FX_WCHAR* pStr, int32_t iMaxLength, bool& bEOS) override; |
218 int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) override; | 218 int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) override; |
219 int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) override; | 219 int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) override; |
220 void Flush() override; | 220 void Flush() override; |
221 bool SetLength(int32_t iLength) override; | 221 bool SetLength(int32_t iLength) override; |
222 int32_t GetBOM(uint8_t bom[4]) const override; | 222 int32_t GetBOM(uint8_t bom[4]) const override; |
223 uint16_t GetCodePage() const override; | 223 uint16_t GetCodePage() const override; |
224 uint16_t SetCodePage(uint16_t wCodePage) override; | 224 uint16_t SetCodePage(uint16_t wCodePage) override; |
225 IFX_Stream* CreateSharedStream(uint32_t dwAccess, | 225 IFGAS_Stream* CreateSharedStream(uint32_t dwAccess, |
226 int32_t iOffset, | 226 int32_t iOffset, |
227 int32_t iLength) override; | 227 int32_t iLength) override; |
228 | 228 |
229 protected: | 229 protected: |
230 FX_STREAMTYPE m_eStreamType; | 230 FX_STREAMTYPE m_eStreamType; |
231 IFX_StreamImp* m_pStreamImp; | 231 IFGAS_StreamImp* m_pStreamImp; |
232 uint32_t m_dwAccess; | 232 uint32_t m_dwAccess; |
233 int32_t m_iTotalSize; | 233 int32_t m_iTotalSize; |
234 int32_t m_iPosition; | 234 int32_t m_iPosition; |
235 int32_t m_iStart; | 235 int32_t m_iStart; |
236 int32_t m_iLength; | 236 int32_t m_iLength; |
237 int32_t m_iRefCount; | 237 int32_t m_iRefCount; |
238 }; | 238 }; |
239 | 239 |
240 class CFX_TextStream : public IFX_Stream { | 240 class CFGAS_TextStream : public IFGAS_Stream { |
241 public: | 241 public: |
242 CFX_TextStream(IFX_Stream* pStream, bool bDelStream); | 242 CFGAS_TextStream(IFGAS_Stream* pStream, bool bDelStream); |
243 ~CFX_TextStream() override; | 243 ~CFGAS_TextStream() override; |
244 | 244 |
245 // IFX_Stream | 245 // IFGAS_Stream |
246 void Release() override; | 246 void Release() override; |
247 IFX_Stream* Retain() override; | 247 IFGAS_Stream* Retain() override; |
248 uint32_t GetAccessModes() const override; | 248 uint32_t GetAccessModes() const override; |
249 int32_t GetLength() const override; | 249 int32_t GetLength() const override; |
250 int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) override; | 250 int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) override; |
251 int32_t GetPosition() override; | 251 int32_t GetPosition() override; |
252 bool IsEOF() const override; | 252 bool IsEOF() const override; |
253 int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) override; | 253 int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) override; |
254 int32_t ReadString(FX_WCHAR* pStr, int32_t iMaxLength, bool& bEOS) override; | 254 int32_t ReadString(FX_WCHAR* pStr, int32_t iMaxLength, bool& bEOS) override; |
255 int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) override; | 255 int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) override; |
256 int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) override; | 256 int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) override; |
257 void Flush() override; | 257 void Flush() override; |
258 bool SetLength(int32_t iLength) override; | 258 bool SetLength(int32_t iLength) override; |
259 int32_t GetBOM(uint8_t bom[4]) const override; | 259 int32_t GetBOM(uint8_t bom[4]) const override; |
260 uint16_t GetCodePage() const override; | 260 uint16_t GetCodePage() const override; |
261 uint16_t SetCodePage(uint16_t wCodePage) override; | 261 uint16_t SetCodePage(uint16_t wCodePage) override; |
262 IFX_Stream* CreateSharedStream(uint32_t dwAccess, | 262 IFGAS_Stream* CreateSharedStream(uint32_t dwAccess, |
263 int32_t iOffset, | 263 int32_t iOffset, |
264 int32_t iLength) override; | 264 int32_t iLength) override; |
265 | 265 |
266 protected: | 266 protected: |
267 uint16_t m_wCodePage; | 267 uint16_t m_wCodePage; |
268 int32_t m_wBOMLength; | 268 int32_t m_wBOMLength; |
269 uint32_t m_dwBOM; | 269 uint32_t m_dwBOM; |
270 uint8_t* m_pBuf; | 270 uint8_t* m_pBuf; |
271 int32_t m_iBufSize; | 271 int32_t m_iBufSize; |
272 bool m_bDelStream; | 272 bool m_bDelStream; |
273 IFX_Stream* m_pStreamImp; | 273 IFGAS_Stream* m_pStreamImp; |
274 int32_t m_iRefCount; | 274 int32_t m_iRefCount; |
275 void InitStream(); | 275 void InitStream(); |
276 }; | 276 }; |
277 | 277 |
278 class CFGAS_FileRead : public IFX_SeekableReadStream { | 278 class CFGAS_FileRead : public IFX_SeekableReadStream { |
279 public: | 279 public: |
280 CFGAS_FileRead(IFX_Stream* pStream, bool bReleaseStream); | 280 CFGAS_FileRead(IFGAS_Stream* pStream, bool bReleaseStream); |
281 ~CFGAS_FileRead() override; | 281 ~CFGAS_FileRead() override; |
282 | 282 |
283 // IFX_SeekableReadStream | 283 // IFX_SeekableReadStream |
284 void Release() override; | 284 void Release() override; |
285 FX_FILESIZE GetSize() override; | 285 FX_FILESIZE GetSize() override; |
286 bool ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override; | 286 bool ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override; |
287 | 287 |
288 protected: | 288 protected: |
289 bool m_bReleaseStream; | 289 bool m_bReleaseStream; |
290 IFX_Stream* m_pStream; | 290 IFGAS_Stream* m_pStream; |
291 }; | 291 }; |
292 | 292 |
293 int32_t FileLength(FXSYS_FILE* file) { | 293 int32_t FileLength(FXSYS_FILE* file) { |
294 ASSERT(file); | 294 ASSERT(file); |
295 #if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN64_ | 295 #if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN64_ |
296 return _filelength(_fileno(file)); | 296 return _filelength(_fileno(file)); |
297 #else | 297 #else |
298 int32_t iPos = FXSYS_ftell(file); | 298 int32_t iPos = FXSYS_ftell(file); |
299 FXSYS_fseek(file, 0, FXSYS_SEEK_END); | 299 FXSYS_fseek(file, 0, FXSYS_SEEK_END); |
300 int32_t iLen = FXSYS_ftell(file); | 300 int32_t iLen = FXSYS_ftell(file); |
(...skipping 14 matching lines...) Expand all Loading... |
315 ::SetFilePointer(hFile, (int32_t)dwPos, 0, FILE_BEGIN); | 315 ::SetFilePointer(hFile, (int32_t)dwPos, 0, FILE_BEGIN); |
316 return bRet; | 316 return bRet; |
317 #else | 317 #else |
318 return false; | 318 return false; |
319 #endif | 319 #endif |
320 } | 320 } |
321 | 321 |
322 } // namespace | 322 } // namespace |
323 | 323 |
324 // static | 324 // static |
325 IFX_Stream* IFX_Stream::CreateStream(IFX_SeekableReadStream* pFileRead, | 325 IFGAS_Stream* IFGAS_Stream::CreateStream(IFX_SeekableReadStream* pFileRead, |
326 uint32_t dwAccess) { | 326 uint32_t dwAccess) { |
327 CFX_Stream* pSR = new CFX_Stream; | 327 CFGAS_Stream* pSR = new CFGAS_Stream; |
328 if (!pSR->LoadFileRead(pFileRead, dwAccess)) { | 328 if (!pSR->LoadFileRead(pFileRead, dwAccess)) { |
329 pSR->Release(); | 329 pSR->Release(); |
330 return nullptr; | 330 return nullptr; |
331 } | 331 } |
332 if (dwAccess & FX_STREAMACCESS_Text) { | 332 if (dwAccess & FX_STREAMACCESS_Text) |
333 return new CFX_TextStream(pSR, true); | 333 return new CFGAS_TextStream(pSR, true); |
334 } | 334 |
335 return pSR; | 335 return pSR; |
336 } | 336 } |
337 | 337 |
338 // static | 338 // static |
339 IFX_Stream* IFX_Stream::CreateStream(IFX_SeekableWriteStream* pFileWrite, | 339 IFGAS_Stream* IFGAS_Stream::CreateStream(IFX_SeekableWriteStream* pFileWrite, |
340 uint32_t dwAccess) { | 340 uint32_t dwAccess) { |
341 CFX_Stream* pSR = new CFX_Stream; | 341 CFGAS_Stream* pSR = new CFGAS_Stream; |
342 if (!pSR->LoadFileWrite(pFileWrite, dwAccess)) { | 342 if (!pSR->LoadFileWrite(pFileWrite, dwAccess)) { |
343 pSR->Release(); | 343 pSR->Release(); |
344 return nullptr; | 344 return nullptr; |
345 } | 345 } |
346 if (dwAccess & FX_STREAMACCESS_Text) { | 346 if (dwAccess & FX_STREAMACCESS_Text) |
347 return new CFX_TextStream(pSR, true); | 347 return new CFGAS_TextStream(pSR, true); |
348 } | 348 |
349 return pSR; | 349 return pSR; |
350 } | 350 } |
351 | 351 |
352 // static | 352 // static |
353 IFX_Stream* IFX_Stream::CreateStream(uint8_t* pData, | 353 IFGAS_Stream* IFGAS_Stream::CreateStream(uint8_t* pData, |
354 int32_t length, | 354 int32_t length, |
355 uint32_t dwAccess) { | 355 uint32_t dwAccess) { |
356 CFX_Stream* pSR = new CFX_Stream; | 356 CFGAS_Stream* pSR = new CFGAS_Stream; |
357 if (!pSR->LoadBuffer(pData, length, dwAccess)) { | 357 if (!pSR->LoadBuffer(pData, length, dwAccess)) { |
358 pSR->Release(); | 358 pSR->Release(); |
359 return nullptr; | 359 return nullptr; |
360 } | 360 } |
361 if (dwAccess & FX_STREAMACCESS_Text) { | 361 if (dwAccess & FX_STREAMACCESS_Text) |
362 return new CFX_TextStream(pSR, true); | 362 return new CFGAS_TextStream(pSR, true); |
363 } | 363 |
364 return pSR; | 364 return pSR; |
365 } | 365 } |
366 | 366 |
367 IFX_StreamImp::IFX_StreamImp() : m_dwAccess(0) {} | 367 IFGAS_StreamImp::IFGAS_StreamImp() : m_dwAccess(0) {} |
368 | 368 |
369 CFX_FileStreamImp::CFX_FileStreamImp() : m_hFile(nullptr), m_iLength(0) {} | 369 CFGAS_FileStreamImp::CFGAS_FileStreamImp() : m_hFile(nullptr), m_iLength(0) {} |
370 | 370 |
371 CFX_FileStreamImp::~CFX_FileStreamImp() { | 371 CFGAS_FileStreamImp::~CFGAS_FileStreamImp() { |
372 if (m_hFile) | 372 if (m_hFile) |
373 FXSYS_fclose(m_hFile); | 373 FXSYS_fclose(m_hFile); |
374 } | 374 } |
375 | 375 |
376 bool CFX_FileStreamImp::LoadFile(const FX_WCHAR* pszSrcFileName, | 376 bool CFGAS_FileStreamImp::LoadFile(const FX_WCHAR* pszSrcFileName, |
377 uint32_t dwAccess) { | 377 uint32_t dwAccess) { |
378 ASSERT(!m_hFile); | 378 ASSERT(!m_hFile); |
379 ASSERT(pszSrcFileName && FXSYS_wcslen(pszSrcFileName) > 0); | 379 ASSERT(pszSrcFileName && FXSYS_wcslen(pszSrcFileName) > 0); |
380 #if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN32_MOBILE_ || \ | 380 #if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN32_MOBILE_ || \ |
381 _FX_OS_ == _FX_WIN64_ | 381 _FX_OS_ == _FX_WIN64_ |
382 const FX_WCHAR* wsMode; | 382 const FX_WCHAR* wsMode; |
383 if (dwAccess & FX_STREAMACCESS_Write) { | 383 if (dwAccess & FX_STREAMACCESS_Write) { |
384 if (dwAccess & FX_STREAMACCESS_Append) { | 384 if (dwAccess & FX_STREAMACCESS_Append) { |
385 wsMode = L"a+b"; | 385 wsMode = L"a+b"; |
386 } else if (dwAccess & FX_STREAMACCESS_Truncate) { | 386 } else if (dwAccess & FX_STREAMACCESS_Truncate) { |
387 wsMode = L"w+b"; | 387 wsMode = L"w+b"; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 #endif | 444 #endif |
445 SetAccessModes(dwAccess); | 445 SetAccessModes(dwAccess); |
446 if ((dwAccess & (FX_STREAMACCESS_Write | FX_STREAMACCESS_Truncate)) == | 446 if ((dwAccess & (FX_STREAMACCESS_Write | FX_STREAMACCESS_Truncate)) == |
447 (FX_STREAMACCESS_Write | FX_STREAMACCESS_Truncate)) { | 447 (FX_STREAMACCESS_Write | FX_STREAMACCESS_Truncate)) { |
448 m_iLength = 0; | 448 m_iLength = 0; |
449 } else { | 449 } else { |
450 m_iLength = FileLength(m_hFile); | 450 m_iLength = FileLength(m_hFile); |
451 } | 451 } |
452 return true; | 452 return true; |
453 } | 453 } |
454 int32_t CFX_FileStreamImp::GetLength() const { | 454 int32_t CFGAS_FileStreamImp::GetLength() const { |
455 ASSERT(m_hFile); | 455 ASSERT(m_hFile); |
456 return m_iLength; | 456 return m_iLength; |
457 } | 457 } |
458 int32_t CFX_FileStreamImp::Seek(FX_STREAMSEEK eSeek, int32_t iOffset) { | 458 int32_t CFGAS_FileStreamImp::Seek(FX_STREAMSEEK eSeek, int32_t iOffset) { |
459 ASSERT(m_hFile); | 459 ASSERT(m_hFile); |
460 FXSYS_fseek(m_hFile, iOffset, eSeek); | 460 FXSYS_fseek(m_hFile, iOffset, eSeek); |
461 return FXSYS_ftell(m_hFile); | 461 return FXSYS_ftell(m_hFile); |
462 } | 462 } |
463 int32_t CFX_FileStreamImp::GetPosition() { | 463 int32_t CFGAS_FileStreamImp::GetPosition() { |
464 ASSERT(m_hFile); | 464 ASSERT(m_hFile); |
465 return FXSYS_ftell(m_hFile); | 465 return FXSYS_ftell(m_hFile); |
466 } | 466 } |
467 bool CFX_FileStreamImp::IsEOF() const { | 467 bool CFGAS_FileStreamImp::IsEOF() const { |
468 ASSERT(m_hFile); | 468 ASSERT(m_hFile); |
469 return FXSYS_ftell(m_hFile) >= m_iLength; | 469 return FXSYS_ftell(m_hFile) >= m_iLength; |
470 } | 470 } |
471 int32_t CFX_FileStreamImp::ReadData(uint8_t* pBuffer, int32_t iBufferSize) { | 471 int32_t CFGAS_FileStreamImp::ReadData(uint8_t* pBuffer, int32_t iBufferSize) { |
472 ASSERT(m_hFile); | 472 ASSERT(m_hFile); |
473 ASSERT(pBuffer && iBufferSize > 0); | 473 ASSERT(pBuffer && iBufferSize > 0); |
474 return FXSYS_fread(pBuffer, 1, iBufferSize, m_hFile); | 474 return FXSYS_fread(pBuffer, 1, iBufferSize, m_hFile); |
475 } | 475 } |
476 int32_t CFX_FileStreamImp::ReadString(FX_WCHAR* pStr, | 476 int32_t CFGAS_FileStreamImp::ReadString(FX_WCHAR* pStr, |
477 int32_t iMaxLength, | 477 int32_t iMaxLength, |
478 bool& bEOS) { | 478 bool& bEOS) { |
479 ASSERT(m_hFile); | 479 ASSERT(m_hFile); |
480 ASSERT(pStr && iMaxLength > 0); | 480 ASSERT(pStr && iMaxLength > 0); |
481 if (m_iLength <= 0) { | 481 if (m_iLength <= 0) { |
482 return 0; | 482 return 0; |
483 } | 483 } |
484 int32_t iPosition = FXSYS_ftell(m_hFile); | 484 int32_t iPosition = FXSYS_ftell(m_hFile); |
485 int32_t iLen = std::min((m_iLength - iPosition) / 2, iMaxLength); | 485 int32_t iLen = std::min((m_iLength - iPosition) / 2, iMaxLength); |
486 if (iLen <= 0) { | 486 if (iLen <= 0) { |
487 return 0; | 487 return 0; |
488 } | 488 } |
489 iLen = FXSYS_fread(pStr, 2, iLen, m_hFile); | 489 iLen = FXSYS_fread(pStr, 2, iLen, m_hFile); |
490 int32_t iCount = 0; | 490 int32_t iCount = 0; |
491 while (*pStr != L'\0' && iCount < iLen) { | 491 while (*pStr != L'\0' && iCount < iLen) { |
492 pStr++, iCount++; | 492 pStr++, iCount++; |
493 } | 493 } |
494 iPosition += iCount * 2; | 494 iPosition += iCount * 2; |
495 if (FXSYS_ftell(m_hFile) != iPosition) { | 495 if (FXSYS_ftell(m_hFile) != iPosition) { |
496 FXSYS_fseek(m_hFile, iPosition, 0); | 496 FXSYS_fseek(m_hFile, iPosition, 0); |
497 } | 497 } |
498 bEOS = (iPosition >= m_iLength); | 498 bEOS = (iPosition >= m_iLength); |
499 return iCount; | 499 return iCount; |
500 } | 500 } |
501 int32_t CFX_FileStreamImp::WriteData(const uint8_t* pBuffer, | 501 int32_t CFGAS_FileStreamImp::WriteData(const uint8_t* pBuffer, |
502 int32_t iBufferSize) { | 502 int32_t iBufferSize) { |
503 ASSERT(m_hFile && (GetAccessModes() & FX_STREAMACCESS_Write) != 0); | 503 ASSERT(m_hFile && (GetAccessModes() & FX_STREAMACCESS_Write) != 0); |
504 ASSERT(pBuffer && iBufferSize > 0); | 504 ASSERT(pBuffer && iBufferSize > 0); |
505 int32_t iRet = FXSYS_fwrite(pBuffer, 1, iBufferSize, m_hFile); | 505 int32_t iRet = FXSYS_fwrite(pBuffer, 1, iBufferSize, m_hFile); |
506 if (iRet != 0) { | 506 if (iRet != 0) { |
507 int32_t iPos = FXSYS_ftell(m_hFile); | 507 int32_t iPos = FXSYS_ftell(m_hFile); |
508 if (iPos > m_iLength) { | 508 if (iPos > m_iLength) { |
509 m_iLength = iPos; | 509 m_iLength = iPos; |
510 } | 510 } |
511 } | 511 } |
512 return iRet; | 512 return iRet; |
513 } | 513 } |
514 int32_t CFX_FileStreamImp::WriteString(const FX_WCHAR* pStr, int32_t iLength) { | 514 int32_t CFGAS_FileStreamImp::WriteString(const FX_WCHAR* pStr, |
| 515 int32_t iLength) { |
515 ASSERT(m_hFile && (GetAccessModes() & FX_STREAMACCESS_Write) != 0); | 516 ASSERT(m_hFile && (GetAccessModes() & FX_STREAMACCESS_Write) != 0); |
516 ASSERT(pStr && iLength > 0); | 517 ASSERT(pStr && iLength > 0); |
517 int32_t iRet = FXSYS_fwrite(pStr, 2, iLength, m_hFile); | 518 int32_t iRet = FXSYS_fwrite(pStr, 2, iLength, m_hFile); |
518 if (iRet != 0) { | 519 if (iRet != 0) { |
519 int32_t iPos = FXSYS_ftell(m_hFile); | 520 int32_t iPos = FXSYS_ftell(m_hFile); |
520 if (iPos > m_iLength) { | 521 if (iPos > m_iLength) { |
521 m_iLength = iPos; | 522 m_iLength = iPos; |
522 } | 523 } |
523 } | 524 } |
524 return iRet; | 525 return iRet; |
525 } | 526 } |
526 void CFX_FileStreamImp::Flush() { | 527 void CFGAS_FileStreamImp::Flush() { |
527 ASSERT(m_hFile && (GetAccessModes() & FX_STREAMACCESS_Write) != 0); | 528 ASSERT(m_hFile && (GetAccessModes() & FX_STREAMACCESS_Write) != 0); |
528 FXSYS_fflush(m_hFile); | 529 FXSYS_fflush(m_hFile); |
529 } | 530 } |
530 bool CFX_FileStreamImp::SetLength(int32_t iLength) { | 531 bool CFGAS_FileStreamImp::SetLength(int32_t iLength) { |
531 ASSERT(m_hFile && (GetAccessModes() & FX_STREAMACCESS_Write) != 0); | 532 ASSERT(m_hFile && (GetAccessModes() & FX_STREAMACCESS_Write) != 0); |
532 bool bRet = FileSetSize(m_hFile, iLength); | 533 bool bRet = FileSetSize(m_hFile, iLength); |
533 m_iLength = FileLength(m_hFile); | 534 m_iLength = FileLength(m_hFile); |
534 return bRet; | 535 return bRet; |
535 } | 536 } |
536 CFX_FileReadStreamImp::CFX_FileReadStreamImp() | 537 CFGAS_FileReadStreamImp::CFGAS_FileReadStreamImp() |
537 : m_pFileRead(nullptr), m_iPosition(0), m_iLength(0) {} | 538 : m_pFileRead(nullptr), m_iPosition(0), m_iLength(0) {} |
538 bool CFX_FileReadStreamImp::LoadFileRead(IFX_SeekableReadStream* pFileRead, | 539 bool CFGAS_FileReadStreamImp::LoadFileRead(IFX_SeekableReadStream* pFileRead, |
539 uint32_t dwAccess) { | 540 uint32_t dwAccess) { |
540 ASSERT(!m_pFileRead && pFileRead); | 541 ASSERT(!m_pFileRead && pFileRead); |
541 if (dwAccess & FX_STREAMACCESS_Write) { | 542 if (dwAccess & FX_STREAMACCESS_Write) { |
542 return false; | 543 return false; |
543 } | 544 } |
544 m_pFileRead = pFileRead; | 545 m_pFileRead = pFileRead; |
545 m_iLength = m_pFileRead->GetSize(); | 546 m_iLength = m_pFileRead->GetSize(); |
546 return true; | 547 return true; |
547 } | 548 } |
548 int32_t CFX_FileReadStreamImp::GetLength() const { | 549 int32_t CFGAS_FileReadStreamImp::GetLength() const { |
549 return m_iLength; | 550 return m_iLength; |
550 } | 551 } |
551 int32_t CFX_FileReadStreamImp::Seek(FX_STREAMSEEK eSeek, int32_t iOffset) { | 552 int32_t CFGAS_FileReadStreamImp::Seek(FX_STREAMSEEK eSeek, int32_t iOffset) { |
552 switch (eSeek) { | 553 switch (eSeek) { |
553 case FX_STREAMSEEK_Begin: | 554 case FX_STREAMSEEK_Begin: |
554 m_iPosition = iOffset; | 555 m_iPosition = iOffset; |
555 break; | 556 break; |
556 case FX_STREAMSEEK_Current: | 557 case FX_STREAMSEEK_Current: |
557 m_iPosition += iOffset; | 558 m_iPosition += iOffset; |
558 break; | 559 break; |
559 case FX_STREAMSEEK_End: | 560 case FX_STREAMSEEK_End: |
560 m_iPosition = m_iLength + iOffset; | 561 m_iPosition = m_iLength + iOffset; |
561 break; | 562 break; |
562 } | 563 } |
563 if (m_iPosition < 0) { | 564 if (m_iPosition < 0) { |
564 m_iPosition = 0; | 565 m_iPosition = 0; |
565 } else if (m_iPosition >= m_iLength) { | 566 } else if (m_iPosition >= m_iLength) { |
566 m_iPosition = m_iLength; | 567 m_iPosition = m_iLength; |
567 } | 568 } |
568 return m_iPosition; | 569 return m_iPosition; |
569 } | 570 } |
570 bool CFX_FileReadStreamImp::IsEOF() const { | 571 bool CFGAS_FileReadStreamImp::IsEOF() const { |
571 return m_iPosition >= m_iLength; | 572 return m_iPosition >= m_iLength; |
572 } | 573 } |
573 int32_t CFX_FileReadStreamImp::ReadData(uint8_t* pBuffer, int32_t iBufferSize) { | 574 int32_t CFGAS_FileReadStreamImp::ReadData(uint8_t* pBuffer, |
| 575 int32_t iBufferSize) { |
574 ASSERT(m_pFileRead); | 576 ASSERT(m_pFileRead); |
575 ASSERT(pBuffer && iBufferSize > 0); | 577 ASSERT(pBuffer && iBufferSize > 0); |
576 if (iBufferSize > m_iLength - m_iPosition) { | 578 if (iBufferSize > m_iLength - m_iPosition) { |
577 iBufferSize = m_iLength - m_iPosition; | 579 iBufferSize = m_iLength - m_iPosition; |
578 } | 580 } |
579 if (m_pFileRead->ReadBlock(pBuffer, m_iPosition, iBufferSize)) { | 581 if (m_pFileRead->ReadBlock(pBuffer, m_iPosition, iBufferSize)) { |
580 m_iPosition += iBufferSize; | 582 m_iPosition += iBufferSize; |
581 return iBufferSize; | 583 return iBufferSize; |
582 } | 584 } |
583 return 0; | 585 return 0; |
584 } | 586 } |
585 int32_t CFX_FileReadStreamImp::ReadString(FX_WCHAR* pStr, | 587 int32_t CFGAS_FileReadStreamImp::ReadString(FX_WCHAR* pStr, |
586 int32_t iMaxLength, | 588 int32_t iMaxLength, |
587 bool& bEOS) { | 589 bool& bEOS) { |
588 ASSERT(m_pFileRead); | 590 ASSERT(m_pFileRead); |
589 ASSERT(pStr && iMaxLength > 0); | 591 ASSERT(pStr && iMaxLength > 0); |
590 iMaxLength = ReadData((uint8_t*)pStr, iMaxLength * 2) / 2; | 592 iMaxLength = ReadData((uint8_t*)pStr, iMaxLength * 2) / 2; |
591 if (iMaxLength <= 0) { | 593 if (iMaxLength <= 0) { |
592 return 0; | 594 return 0; |
593 } | 595 } |
594 int32_t i = 0; | 596 int32_t i = 0; |
595 while (i < iMaxLength && pStr[i] != L'\0') { | 597 while (i < iMaxLength && pStr[i] != L'\0') { |
596 ++i; | 598 ++i; |
597 } | 599 } |
598 bEOS = (m_iPosition >= m_iLength) || pStr[i] == L'\0'; | 600 bEOS = (m_iPosition >= m_iLength) || pStr[i] == L'\0'; |
599 return i; | 601 return i; |
600 } | 602 } |
601 CFX_BufferReadStreamImp::CFX_BufferReadStreamImp() | 603 CFGAS_BufferReadStreamImp::CFGAS_BufferReadStreamImp() |
602 : m_pBufferRead(nullptr), | 604 : m_pBufferRead(nullptr), |
603 m_bReleaseBufferRead(false), | 605 m_bReleaseBufferRead(false), |
604 m_iPosition(0), | 606 m_iPosition(0), |
605 m_iBufferSize(0) {} | 607 m_iBufferSize(0) {} |
606 CFX_BufferReadStreamImp::~CFX_BufferReadStreamImp() { | 608 CFGAS_BufferReadStreamImp::~CFGAS_BufferReadStreamImp() { |
607 if (m_bReleaseBufferRead && m_pBufferRead) { | 609 if (m_bReleaseBufferRead && m_pBufferRead) { |
608 m_pBufferRead->Release(); | 610 m_pBufferRead->Release(); |
609 } | 611 } |
610 } | 612 } |
611 bool CFX_BufferReadStreamImp::LoadBufferRead( | 613 bool CFGAS_BufferReadStreamImp::LoadBufferRead( |
612 IFX_BufferedReadStream* pBufferRead, | 614 IFX_BufferedReadStream* pBufferRead, |
613 int32_t iFileSize, | 615 int32_t iFileSize, |
614 uint32_t dwAccess, | 616 uint32_t dwAccess, |
615 bool bReleaseBufferRead) { | 617 bool bReleaseBufferRead) { |
616 ASSERT(!m_pBufferRead && pBufferRead); | 618 ASSERT(!m_pBufferRead && pBufferRead); |
617 if (dwAccess & FX_STREAMACCESS_Write) { | 619 if (dwAccess & FX_STREAMACCESS_Write) { |
618 return false; | 620 return false; |
619 } | 621 } |
620 m_bReleaseBufferRead = bReleaseBufferRead; | 622 m_bReleaseBufferRead = bReleaseBufferRead; |
621 m_pBufferRead = pBufferRead; | 623 m_pBufferRead = pBufferRead; |
622 m_iBufferSize = iFileSize; | 624 m_iBufferSize = iFileSize; |
623 if (m_iBufferSize >= 0) { | 625 if (m_iBufferSize >= 0) { |
624 return true; | 626 return true; |
625 } | 627 } |
626 if (!m_pBufferRead->ReadNextBlock(true)) { | 628 if (!m_pBufferRead->ReadNextBlock(true)) { |
627 return false; | 629 return false; |
628 } | 630 } |
629 m_iBufferSize = m_pBufferRead->GetBlockSize(); | 631 m_iBufferSize = m_pBufferRead->GetBlockSize(); |
630 while (!m_pBufferRead->IsEOF()) { | 632 while (!m_pBufferRead->IsEOF()) { |
631 m_pBufferRead->ReadNextBlock(false); | 633 m_pBufferRead->ReadNextBlock(false); |
632 m_iBufferSize += m_pBufferRead->GetBlockSize(); | 634 m_iBufferSize += m_pBufferRead->GetBlockSize(); |
633 } | 635 } |
634 return true; | 636 return true; |
635 } | 637 } |
636 int32_t CFX_BufferReadStreamImp::GetLength() const { | 638 int32_t CFGAS_BufferReadStreamImp::GetLength() const { |
637 return m_iBufferSize; | 639 return m_iBufferSize; |
638 } | 640 } |
639 int32_t CFX_BufferReadStreamImp::Seek(FX_STREAMSEEK eSeek, int32_t iOffset) { | 641 int32_t CFGAS_BufferReadStreamImp::Seek(FX_STREAMSEEK eSeek, int32_t iOffset) { |
640 int32_t iLength = GetLength(); | 642 int32_t iLength = GetLength(); |
641 switch (eSeek) { | 643 switch (eSeek) { |
642 case FX_STREAMSEEK_Begin: | 644 case FX_STREAMSEEK_Begin: |
643 m_iPosition = iOffset; | 645 m_iPosition = iOffset; |
644 break; | 646 break; |
645 case FX_STREAMSEEK_Current: | 647 case FX_STREAMSEEK_Current: |
646 m_iPosition += iOffset; | 648 m_iPosition += iOffset; |
647 break; | 649 break; |
648 case FX_STREAMSEEK_End: | 650 case FX_STREAMSEEK_End: |
649 m_iPosition = iLength + iOffset; | 651 m_iPosition = iLength + iOffset; |
650 break; | 652 break; |
651 } | 653 } |
652 if (m_iPosition < 0) { | 654 if (m_iPosition < 0) { |
653 m_iPosition = 0; | 655 m_iPosition = 0; |
654 } else if (m_iPosition >= iLength) { | 656 } else if (m_iPosition >= iLength) { |
655 m_iPosition = iLength; | 657 m_iPosition = iLength; |
656 } | 658 } |
657 return m_iPosition; | 659 return m_iPosition; |
658 } | 660 } |
659 bool CFX_BufferReadStreamImp::IsEOF() const { | 661 bool CFGAS_BufferReadStreamImp::IsEOF() const { |
660 return m_pBufferRead ? m_pBufferRead->IsEOF() : true; | 662 return m_pBufferRead ? m_pBufferRead->IsEOF() : true; |
661 } | 663 } |
662 int32_t CFX_BufferReadStreamImp::ReadData(uint8_t* pBuffer, | 664 int32_t CFGAS_BufferReadStreamImp::ReadData(uint8_t* pBuffer, |
663 int32_t iBufferSize) { | 665 int32_t iBufferSize) { |
664 ASSERT(m_pBufferRead); | 666 ASSERT(m_pBufferRead); |
665 ASSERT(pBuffer && iBufferSize > 0); | 667 ASSERT(pBuffer && iBufferSize > 0); |
666 int32_t iLength = GetLength(); | 668 int32_t iLength = GetLength(); |
667 if (m_iPosition >= iLength) { | 669 if (m_iPosition >= iLength) { |
668 return 0; | 670 return 0; |
669 } | 671 } |
670 if (iBufferSize > iLength - m_iPosition) { | 672 if (iBufferSize > iLength - m_iPosition) { |
671 iBufferSize = iLength - m_iPosition; | 673 iBufferSize = iLength - m_iPosition; |
672 } | 674 } |
673 uint32_t dwBlockOffset = m_pBufferRead->GetBlockOffset(); | 675 uint32_t dwBlockOffset = m_pBufferRead->GetBlockOffset(); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
706 dwBlockSize = m_pBufferRead->GetBlockSize(); | 708 dwBlockSize = m_pBufferRead->GetBlockSize(); |
707 pBufferTmp = m_pBufferRead->GetBlockBuffer(); | 709 pBufferTmp = m_pBufferRead->GetBlockBuffer(); |
708 dwCopySize = std::min((uint32_t)iBufferSize, dwBlockSize); | 710 dwCopySize = std::min((uint32_t)iBufferSize, dwBlockSize); |
709 FXSYS_memcpy(pBuffer + dwOffsetTmp, pBufferTmp, dwCopySize); | 711 FXSYS_memcpy(pBuffer + dwOffsetTmp, pBufferTmp, dwCopySize); |
710 dwOffsetTmp += dwCopySize; | 712 dwOffsetTmp += dwCopySize; |
711 iBufferSize -= dwCopySize; | 713 iBufferSize -= dwCopySize; |
712 } | 714 } |
713 m_iPosition += dwOffsetTmp; | 715 m_iPosition += dwOffsetTmp; |
714 return dwOffsetTmp; | 716 return dwOffsetTmp; |
715 } | 717 } |
716 int32_t CFX_BufferReadStreamImp::ReadString(FX_WCHAR* pStr, | 718 int32_t CFGAS_BufferReadStreamImp::ReadString(FX_WCHAR* pStr, |
717 int32_t iMaxLength, | 719 int32_t iMaxLength, |
718 bool& bEOS) { | 720 bool& bEOS) { |
719 ASSERT(m_pBufferRead); | 721 ASSERT(m_pBufferRead); |
720 ASSERT(pStr && iMaxLength > 0); | 722 ASSERT(pStr && iMaxLength > 0); |
721 iMaxLength = ReadData((uint8_t*)pStr, iMaxLength * 2) / 2; | 723 iMaxLength = ReadData((uint8_t*)pStr, iMaxLength * 2) / 2; |
722 if (iMaxLength <= 0) { | 724 if (iMaxLength <= 0) { |
723 return 0; | 725 return 0; |
724 } | 726 } |
725 int32_t i = 0; | 727 int32_t i = 0; |
726 while (i < iMaxLength && pStr[i] != L'\0') { | 728 while (i < iMaxLength && pStr[i] != L'\0') { |
727 ++i; | 729 ++i; |
728 } | 730 } |
729 bEOS = (m_iPosition >= GetLength()) || pStr[i] == L'\0'; | 731 bEOS = (m_iPosition >= GetLength()) || pStr[i] == L'\0'; |
730 return i; | 732 return i; |
731 } | 733 } |
732 CFX_FileWriteStreamImp::CFX_FileWriteStreamImp() | 734 CFGAS_FileWriteStreamImp::CFGAS_FileWriteStreamImp() |
733 : m_pFileWrite(nullptr), m_iPosition(0) {} | 735 : m_pFileWrite(nullptr), m_iPosition(0) {} |
734 bool CFX_FileWriteStreamImp::LoadFileWrite(IFX_SeekableWriteStream* pFileWrite, | 736 bool CFGAS_FileWriteStreamImp::LoadFileWrite( |
735 uint32_t dwAccess) { | 737 IFX_SeekableWriteStream* pFileWrite, |
| 738 uint32_t dwAccess) { |
736 ASSERT(!m_pFileWrite && pFileWrite); | 739 ASSERT(!m_pFileWrite && pFileWrite); |
737 if (dwAccess & FX_STREAMACCESS_Read) { | 740 if (dwAccess & FX_STREAMACCESS_Read) { |
738 return false; | 741 return false; |
739 } | 742 } |
740 if (dwAccess & FX_STREAMACCESS_Append) { | 743 if (dwAccess & FX_STREAMACCESS_Append) { |
741 m_iPosition = pFileWrite->GetSize(); | 744 m_iPosition = pFileWrite->GetSize(); |
742 } | 745 } |
743 m_pFileWrite = pFileWrite; | 746 m_pFileWrite = pFileWrite; |
744 return true; | 747 return true; |
745 } | 748 } |
746 int32_t CFX_FileWriteStreamImp::GetLength() const { | 749 int32_t CFGAS_FileWriteStreamImp::GetLength() const { |
747 if (!m_pFileWrite) { | 750 if (!m_pFileWrite) { |
748 return 0; | 751 return 0; |
749 } | 752 } |
750 return (int32_t)m_pFileWrite->GetSize(); | 753 return (int32_t)m_pFileWrite->GetSize(); |
751 } | 754 } |
752 int32_t CFX_FileWriteStreamImp::Seek(FX_STREAMSEEK eSeek, int32_t iOffset) { | 755 int32_t CFGAS_FileWriteStreamImp::Seek(FX_STREAMSEEK eSeek, int32_t iOffset) { |
753 int32_t iLength = GetLength(); | 756 int32_t iLength = GetLength(); |
754 switch (eSeek) { | 757 switch (eSeek) { |
755 case FX_STREAMSEEK_Begin: | 758 case FX_STREAMSEEK_Begin: |
756 m_iPosition = iOffset; | 759 m_iPosition = iOffset; |
757 break; | 760 break; |
758 case FX_STREAMSEEK_Current: | 761 case FX_STREAMSEEK_Current: |
759 m_iPosition += iOffset; | 762 m_iPosition += iOffset; |
760 break; | 763 break; |
761 case FX_STREAMSEEK_End: | 764 case FX_STREAMSEEK_End: |
762 m_iPosition = iLength + iOffset; | 765 m_iPosition = iLength + iOffset; |
763 break; | 766 break; |
764 } | 767 } |
765 if (m_iPosition < 0) { | 768 if (m_iPosition < 0) { |
766 m_iPosition = 0; | 769 m_iPosition = 0; |
767 } else if (m_iPosition >= iLength) { | 770 } else if (m_iPosition >= iLength) { |
768 m_iPosition = iLength; | 771 m_iPosition = iLength; |
769 } | 772 } |
770 return m_iPosition; | 773 return m_iPosition; |
771 } | 774 } |
772 bool CFX_FileWriteStreamImp::IsEOF() const { | 775 bool CFGAS_FileWriteStreamImp::IsEOF() const { |
773 return m_iPosition >= GetLength(); | 776 return m_iPosition >= GetLength(); |
774 } | 777 } |
775 int32_t CFX_FileWriteStreamImp::WriteData(const uint8_t* pBuffer, | 778 int32_t CFGAS_FileWriteStreamImp::WriteData(const uint8_t* pBuffer, |
776 int32_t iBufferSize) { | 779 int32_t iBufferSize) { |
777 if (!m_pFileWrite) { | 780 if (!m_pFileWrite) { |
778 return 0; | 781 return 0; |
779 } | 782 } |
780 if (m_pFileWrite->WriteBlock(pBuffer, m_iPosition, iBufferSize)) { | 783 if (m_pFileWrite->WriteBlock(pBuffer, m_iPosition, iBufferSize)) { |
781 m_iPosition += iBufferSize; | 784 m_iPosition += iBufferSize; |
782 } | 785 } |
783 return iBufferSize; | 786 return iBufferSize; |
784 } | 787 } |
785 int32_t CFX_FileWriteStreamImp::WriteString(const FX_WCHAR* pStr, | 788 int32_t CFGAS_FileWriteStreamImp::WriteString(const FX_WCHAR* pStr, |
786 int32_t iLength) { | 789 int32_t iLength) { |
787 return WriteData((const uint8_t*)pStr, iLength * sizeof(FX_WCHAR)); | 790 return WriteData((const uint8_t*)pStr, iLength * sizeof(FX_WCHAR)); |
788 } | 791 } |
789 void CFX_FileWriteStreamImp::Flush() { | 792 void CFGAS_FileWriteStreamImp::Flush() { |
790 if (m_pFileWrite) { | 793 if (m_pFileWrite) { |
791 m_pFileWrite->Flush(); | 794 m_pFileWrite->Flush(); |
792 } | 795 } |
793 } | 796 } |
794 CFX_BufferStreamImp::CFX_BufferStreamImp() | 797 CFGAS_BufferStreamImp::CFGAS_BufferStreamImp() |
795 : m_pData(nullptr), m_iTotalSize(0), m_iPosition(0), m_iLength(0) {} | 798 : m_pData(nullptr), m_iTotalSize(0), m_iPosition(0), m_iLength(0) {} |
796 | 799 |
797 bool CFX_BufferStreamImp::LoadBuffer(uint8_t* pData, | 800 bool CFGAS_BufferStreamImp::LoadBuffer(uint8_t* pData, |
798 int32_t iTotalSize, | 801 int32_t iTotalSize, |
799 uint32_t dwAccess) { | 802 uint32_t dwAccess) { |
800 ASSERT(!m_pData && pData && iTotalSize > 0); | 803 ASSERT(!m_pData && pData && iTotalSize > 0); |
801 SetAccessModes(dwAccess); | 804 SetAccessModes(dwAccess); |
802 m_pData = pData; | 805 m_pData = pData; |
803 m_iTotalSize = iTotalSize; | 806 m_iTotalSize = iTotalSize; |
804 m_iPosition = 0; | 807 m_iPosition = 0; |
805 m_iLength = (dwAccess & FX_STREAMACCESS_Write) != 0 ? 0 : iTotalSize; | 808 m_iLength = (dwAccess & FX_STREAMACCESS_Write) != 0 ? 0 : iTotalSize; |
806 return true; | 809 return true; |
807 } | 810 } |
808 int32_t CFX_BufferStreamImp::GetLength() const { | 811 int32_t CFGAS_BufferStreamImp::GetLength() const { |
809 ASSERT(m_pData); | 812 ASSERT(m_pData); |
810 return m_iLength; | 813 return m_iLength; |
811 } | 814 } |
812 int32_t CFX_BufferStreamImp::Seek(FX_STREAMSEEK eSeek, int32_t iOffset) { | 815 int32_t CFGAS_BufferStreamImp::Seek(FX_STREAMSEEK eSeek, int32_t iOffset) { |
813 ASSERT(m_pData); | 816 ASSERT(m_pData); |
814 if (eSeek == FX_STREAMSEEK_Begin) { | 817 if (eSeek == FX_STREAMSEEK_Begin) { |
815 m_iPosition = iOffset; | 818 m_iPosition = iOffset; |
816 } else if (eSeek == FX_STREAMSEEK_Current) { | 819 } else if (eSeek == FX_STREAMSEEK_Current) { |
817 m_iPosition += iOffset; | 820 m_iPosition += iOffset; |
818 } else if (eSeek == FX_STREAMSEEK_End) { | 821 } else if (eSeek == FX_STREAMSEEK_End) { |
819 m_iPosition = m_iLength + iOffset; | 822 m_iPosition = m_iLength + iOffset; |
820 } | 823 } |
821 if (m_iPosition > m_iLength) { | 824 if (m_iPosition > m_iLength) { |
822 m_iPosition = m_iLength; | 825 m_iPosition = m_iLength; |
823 } | 826 } |
824 if (m_iPosition < 0) { | 827 if (m_iPosition < 0) { |
825 m_iPosition = 0; | 828 m_iPosition = 0; |
826 } | 829 } |
827 return m_iPosition; | 830 return m_iPosition; |
828 } | 831 } |
829 int32_t CFX_BufferStreamImp::GetPosition() { | 832 int32_t CFGAS_BufferStreamImp::GetPosition() { |
830 ASSERT(m_pData); | 833 ASSERT(m_pData); |
831 return m_iPosition; | 834 return m_iPosition; |
832 } | 835 } |
833 bool CFX_BufferStreamImp::IsEOF() const { | 836 bool CFGAS_BufferStreamImp::IsEOF() const { |
834 ASSERT(m_pData); | 837 ASSERT(m_pData); |
835 return m_iPosition >= m_iLength; | 838 return m_iPosition >= m_iLength; |
836 } | 839 } |
837 int32_t CFX_BufferStreamImp::ReadData(uint8_t* pBuffer, int32_t iBufferSize) { | 840 int32_t CFGAS_BufferStreamImp::ReadData(uint8_t* pBuffer, int32_t iBufferSize) { |
838 ASSERT(m_pData); | 841 ASSERT(m_pData); |
839 ASSERT(pBuffer && iBufferSize > 0); | 842 ASSERT(pBuffer && iBufferSize > 0); |
840 int32_t iLen = std::min(m_iLength - m_iPosition, iBufferSize); | 843 int32_t iLen = std::min(m_iLength - m_iPosition, iBufferSize); |
841 if (iLen <= 0) { | 844 if (iLen <= 0) { |
842 return 0; | 845 return 0; |
843 } | 846 } |
844 FXSYS_memcpy(pBuffer, m_pData + m_iPosition, iLen); | 847 FXSYS_memcpy(pBuffer, m_pData + m_iPosition, iLen); |
845 m_iPosition += iLen; | 848 m_iPosition += iLen; |
846 return iLen; | 849 return iLen; |
847 } | 850 } |
848 int32_t CFX_BufferStreamImp::ReadString(FX_WCHAR* pStr, | 851 int32_t CFGAS_BufferStreamImp::ReadString(FX_WCHAR* pStr, |
849 int32_t iMaxLength, | 852 int32_t iMaxLength, |
850 bool& bEOS) { | 853 bool& bEOS) { |
851 ASSERT(m_pData); | 854 ASSERT(m_pData); |
852 ASSERT(pStr && iMaxLength > 0); | 855 ASSERT(pStr && iMaxLength > 0); |
853 int32_t iLen = std::min((m_iLength - m_iPosition) / 2, iMaxLength); | 856 int32_t iLen = std::min((m_iLength - m_iPosition) / 2, iMaxLength); |
854 if (iLen <= 0) { | 857 if (iLen <= 0) { |
855 return 0; | 858 return 0; |
856 } | 859 } |
857 const FX_WCHAR* pSrc = (const FX_WCHAR*)(FX_CHAR*)(m_pData + m_iPosition); | 860 const FX_WCHAR* pSrc = (const FX_WCHAR*)(FX_CHAR*)(m_pData + m_iPosition); |
858 int32_t iCount = 0; | 861 int32_t iCount = 0; |
859 while (*pSrc && iCount < iLen) { | 862 while (*pSrc && iCount < iLen) { |
860 *pStr++ = *pSrc++; | 863 *pStr++ = *pSrc++; |
861 iCount++; | 864 iCount++; |
862 } | 865 } |
863 m_iPosition += iCount * 2; | 866 m_iPosition += iCount * 2; |
864 bEOS = (*pSrc == L'\0') || (m_iPosition >= m_iLength); | 867 bEOS = (*pSrc == L'\0') || (m_iPosition >= m_iLength); |
865 return iCount; | 868 return iCount; |
866 } | 869 } |
867 int32_t CFX_BufferStreamImp::WriteData(const uint8_t* pBuffer, | 870 int32_t CFGAS_BufferStreamImp::WriteData(const uint8_t* pBuffer, |
868 int32_t iBufferSize) { | 871 int32_t iBufferSize) { |
869 ASSERT(m_pData && (GetAccessModes() & FX_STREAMACCESS_Write) != 0); | 872 ASSERT(m_pData && (GetAccessModes() & FX_STREAMACCESS_Write) != 0); |
870 ASSERT(pBuffer && iBufferSize > 0); | 873 ASSERT(pBuffer && iBufferSize > 0); |
871 int32_t iLen = std::min(m_iTotalSize - m_iPosition, iBufferSize); | 874 int32_t iLen = std::min(m_iTotalSize - m_iPosition, iBufferSize); |
872 if (iLen <= 0) { | 875 if (iLen <= 0) { |
873 return 0; | 876 return 0; |
874 } | 877 } |
875 FXSYS_memcpy(m_pData + m_iPosition, pBuffer, iLen); | 878 FXSYS_memcpy(m_pData + m_iPosition, pBuffer, iLen); |
876 m_iPosition += iLen; | 879 m_iPosition += iLen; |
877 if (m_iPosition > m_iLength) { | 880 if (m_iPosition > m_iLength) { |
878 m_iLength = m_iPosition; | 881 m_iLength = m_iPosition; |
879 } | 882 } |
880 return iLen; | 883 return iLen; |
881 } | 884 } |
882 int32_t CFX_BufferStreamImp::WriteString(const FX_WCHAR* pStr, | 885 int32_t CFGAS_BufferStreamImp::WriteString(const FX_WCHAR* pStr, |
883 int32_t iLength) { | 886 int32_t iLength) { |
884 ASSERT(m_pData && (GetAccessModes() & FX_STREAMACCESS_Write) != 0); | 887 ASSERT(m_pData && (GetAccessModes() & FX_STREAMACCESS_Write) != 0); |
885 ASSERT(pStr && iLength > 0); | 888 ASSERT(pStr && iLength > 0); |
886 int32_t iLen = std::min((m_iTotalSize - m_iPosition) / 2, iLength); | 889 int32_t iLen = std::min((m_iTotalSize - m_iPosition) / 2, iLength); |
887 if (iLen <= 0) { | 890 if (iLen <= 0) { |
888 return 0; | 891 return 0; |
889 } | 892 } |
890 FXSYS_memcpy(m_pData + m_iPosition, pStr, iLen * 2); | 893 FXSYS_memcpy(m_pData + m_iPosition, pStr, iLen * 2); |
891 m_iPosition += iLen * 2; | 894 m_iPosition += iLen * 2; |
892 if (m_iPosition > m_iLength) { | 895 if (m_iPosition > m_iLength) { |
893 m_iLength = m_iPosition; | 896 m_iLength = m_iPosition; |
894 } | 897 } |
895 return iLen; | 898 return iLen; |
896 } | 899 } |
897 | 900 |
898 // static | 901 // static |
899 IFX_Stream* IFX_Stream::CreateTextStream(IFX_Stream* pBaseStream, | 902 IFGAS_Stream* IFGAS_Stream::CreateTextStream(IFGAS_Stream* pBaseStream, |
900 bool bDeleteOnRelease) { | 903 bool bDeleteOnRelease) { |
901 ASSERT(pBaseStream); | 904 ASSERT(pBaseStream); |
902 return new CFX_TextStream(pBaseStream, bDeleteOnRelease); | 905 return new CFGAS_TextStream(pBaseStream, bDeleteOnRelease); |
903 } | 906 } |
904 | 907 |
905 CFX_TextStream::CFX_TextStream(IFX_Stream* pStream, bool bDelStream) | 908 CFGAS_TextStream::CFGAS_TextStream(IFGAS_Stream* pStream, bool bDelStream) |
906 : m_wCodePage(FX_CODEPAGE_DefANSI), | 909 : m_wCodePage(FX_CODEPAGE_DefANSI), |
907 m_wBOMLength(0), | 910 m_wBOMLength(0), |
908 m_dwBOM(0), | 911 m_dwBOM(0), |
909 m_pBuf(nullptr), | 912 m_pBuf(nullptr), |
910 m_iBufSize(0), | 913 m_iBufSize(0), |
911 m_bDelStream(bDelStream), | 914 m_bDelStream(bDelStream), |
912 m_pStreamImp(pStream), | 915 m_pStreamImp(pStream), |
913 m_iRefCount(1) { | 916 m_iRefCount(1) { |
914 ASSERT(m_pStreamImp); | 917 ASSERT(m_pStreamImp); |
915 m_pStreamImp->Retain(); | 918 m_pStreamImp->Retain(); |
916 InitStream(); | 919 InitStream(); |
917 } | 920 } |
918 CFX_TextStream::~CFX_TextStream() { | 921 |
| 922 CFGAS_TextStream::~CFGAS_TextStream() { |
919 m_pStreamImp->Release(); | 923 m_pStreamImp->Release(); |
920 if (m_bDelStream) { | 924 if (m_bDelStream) |
921 m_pStreamImp->Release(); | 925 m_pStreamImp->Release(); |
922 } | 926 if (m_pBuf) |
923 if (m_pBuf) { | |
924 FX_Free(m_pBuf); | 927 FX_Free(m_pBuf); |
925 } | |
926 } | 928 } |
927 void CFX_TextStream::InitStream() { | 929 |
| 930 void CFGAS_TextStream::InitStream() { |
928 int32_t iPosition = m_pStreamImp->GetPosition(); | 931 int32_t iPosition = m_pStreamImp->GetPosition(); |
929 m_pStreamImp->Seek(FX_STREAMSEEK_Begin, 0); | 932 m_pStreamImp->Seek(FX_STREAMSEEK_Begin, 0); |
930 m_pStreamImp->ReadData((uint8_t*)&m_dwBOM, 3); | 933 m_pStreamImp->ReadData((uint8_t*)&m_dwBOM, 3); |
931 #if _FX_ENDIAN_ == _FX_LITTLE_ENDIAN_ | 934 #if _FX_ENDIAN_ == _FX_LITTLE_ENDIAN_ |
932 m_dwBOM &= 0x00FFFFFF; | 935 m_dwBOM &= 0x00FFFFFF; |
933 if (m_dwBOM == 0x00BFBBEF) { | 936 if (m_dwBOM == 0x00BFBBEF) { |
934 m_wBOMLength = 3; | 937 m_wBOMLength = 3; |
935 m_wCodePage = FX_CODEPAGE_UTF8; | 938 m_wCodePage = FX_CODEPAGE_UTF8; |
936 } else { | 939 } else { |
937 m_dwBOM &= 0x0000FFFF; | 940 m_dwBOM &= 0x0000FFFF; |
(...skipping 24 matching lines...) Expand all Loading... |
962 m_wCodePage = FX_CODEPAGE_UTF16LE; | 965 m_wCodePage = FX_CODEPAGE_UTF16LE; |
963 } else { | 966 } else { |
964 m_wBOMLength = 0; | 967 m_wBOMLength = 0; |
965 m_dwBOM = 0; | 968 m_dwBOM = 0; |
966 m_wCodePage = FXSYS_GetACP(); | 969 m_wCodePage = FXSYS_GetACP(); |
967 } | 970 } |
968 } | 971 } |
969 #endif | 972 #endif |
970 m_pStreamImp->Seek(FX_STREAMSEEK_Begin, std::max(m_wBOMLength, iPosition)); | 973 m_pStreamImp->Seek(FX_STREAMSEEK_Begin, std::max(m_wBOMLength, iPosition)); |
971 } | 974 } |
972 void CFX_TextStream::Release() { | 975 |
973 if (--m_iRefCount < 1) { | 976 void CFGAS_TextStream::Release() { |
| 977 if (--m_iRefCount < 1) |
974 delete this; | 978 delete this; |
975 } | |
976 } | 979 } |
977 IFX_Stream* CFX_TextStream::Retain() { | 980 |
| 981 IFGAS_Stream* CFGAS_TextStream::Retain() { |
978 m_iRefCount++; | 982 m_iRefCount++; |
979 return this; | 983 return this; |
980 } | 984 } |
981 uint32_t CFX_TextStream::GetAccessModes() const { | 985 |
| 986 uint32_t CFGAS_TextStream::GetAccessModes() const { |
982 return m_pStreamImp->GetAccessModes() | FX_STREAMACCESS_Text; | 987 return m_pStreamImp->GetAccessModes() | FX_STREAMACCESS_Text; |
983 } | 988 } |
984 int32_t CFX_TextStream::GetLength() const { | 989 |
| 990 int32_t CFGAS_TextStream::GetLength() const { |
985 return m_pStreamImp->GetLength(); | 991 return m_pStreamImp->GetLength(); |
986 } | 992 } |
987 int32_t CFX_TextStream::Seek(FX_STREAMSEEK eSeek, int32_t iOffset) { | 993 |
| 994 int32_t CFGAS_TextStream::Seek(FX_STREAMSEEK eSeek, int32_t iOffset) { |
988 return m_pStreamImp->Seek(eSeek, iOffset); | 995 return m_pStreamImp->Seek(eSeek, iOffset); |
989 } | 996 } |
990 int32_t CFX_TextStream::GetPosition() { | 997 |
| 998 int32_t CFGAS_TextStream::GetPosition() { |
991 return m_pStreamImp->GetPosition(); | 999 return m_pStreamImp->GetPosition(); |
992 } | 1000 } |
993 bool CFX_TextStream::IsEOF() const { | 1001 |
| 1002 bool CFGAS_TextStream::IsEOF() const { |
994 return m_pStreamImp->IsEOF(); | 1003 return m_pStreamImp->IsEOF(); |
995 } | 1004 } |
996 int32_t CFX_TextStream::ReadData(uint8_t* pBuffer, int32_t iBufferSize) { | 1005 |
| 1006 int32_t CFGAS_TextStream::ReadData(uint8_t* pBuffer, int32_t iBufferSize) { |
997 return m_pStreamImp->ReadData(pBuffer, iBufferSize); | 1007 return m_pStreamImp->ReadData(pBuffer, iBufferSize); |
998 } | 1008 } |
999 int32_t CFX_TextStream::WriteData(const uint8_t* pBuffer, int32_t iBufferSize) { | 1009 |
| 1010 int32_t CFGAS_TextStream::WriteData(const uint8_t* pBuffer, |
| 1011 int32_t iBufferSize) { |
1000 return m_pStreamImp->WriteData(pBuffer, iBufferSize); | 1012 return m_pStreamImp->WriteData(pBuffer, iBufferSize); |
1001 } | 1013 } |
1002 void CFX_TextStream::Flush() { | 1014 |
| 1015 void CFGAS_TextStream::Flush() { |
1003 m_pStreamImp->Flush(); | 1016 m_pStreamImp->Flush(); |
1004 } | 1017 } |
1005 bool CFX_TextStream::SetLength(int32_t iLength) { | 1018 |
| 1019 bool CFGAS_TextStream::SetLength(int32_t iLength) { |
1006 return m_pStreamImp->SetLength(iLength); | 1020 return m_pStreamImp->SetLength(iLength); |
1007 } | 1021 } |
1008 uint16_t CFX_TextStream::GetCodePage() const { | 1022 |
| 1023 uint16_t CFGAS_TextStream::GetCodePage() const { |
1009 return m_wCodePage; | 1024 return m_wCodePage; |
1010 } | 1025 } |
1011 IFX_Stream* CFX_TextStream::CreateSharedStream(uint32_t dwAccess, | 1026 |
1012 int32_t iOffset, | 1027 IFGAS_Stream* CFGAS_TextStream::CreateSharedStream(uint32_t dwAccess, |
1013 int32_t iLength) { | 1028 int32_t iOffset, |
1014 IFX_Stream* pSR = | 1029 int32_t iLength) { |
| 1030 IFGAS_Stream* pSR = |
1015 m_pStreamImp->CreateSharedStream(dwAccess, iOffset, iLength); | 1031 m_pStreamImp->CreateSharedStream(dwAccess, iOffset, iLength); |
1016 if (!pSR) { | 1032 if (!pSR) |
1017 return nullptr; | 1033 return nullptr; |
1018 } | 1034 |
1019 if (dwAccess & FX_STREAMACCESS_Text) { | 1035 if (dwAccess & FX_STREAMACCESS_Text) |
1020 return new CFX_TextStream(pSR, true); | 1036 return new CFGAS_TextStream(pSR, true); |
1021 } | 1037 |
1022 return pSR; | 1038 return pSR; |
1023 } | 1039 } |
1024 int32_t CFX_TextStream::GetBOM(uint8_t bom[4]) const { | 1040 |
1025 if (m_wBOMLength < 1) { | 1041 int32_t CFGAS_TextStream::GetBOM(uint8_t bom[4]) const { |
| 1042 if (m_wBOMLength < 1) |
1026 return 0; | 1043 return 0; |
1027 } | 1044 |
1028 *(uint32_t*)bom = m_dwBOM; | 1045 *(uint32_t*)bom = m_dwBOM; |
1029 return m_wBOMLength; | 1046 return m_wBOMLength; |
1030 } | 1047 } |
1031 uint16_t CFX_TextStream::SetCodePage(uint16_t wCodePage) { | 1048 |
1032 if (m_wBOMLength > 0) { | 1049 uint16_t CFGAS_TextStream::SetCodePage(uint16_t wCodePage) { |
| 1050 if (m_wBOMLength > 0) |
1033 return m_wCodePage; | 1051 return m_wCodePage; |
1034 } | 1052 |
1035 uint16_t v = m_wCodePage; | 1053 uint16_t v = m_wCodePage; |
1036 m_wCodePage = wCodePage; | 1054 m_wCodePage = wCodePage; |
1037 return v; | 1055 return v; |
1038 } | 1056 } |
1039 int32_t CFX_TextStream::ReadString(FX_WCHAR* pStr, | 1057 |
1040 int32_t iMaxLength, | 1058 int32_t CFGAS_TextStream::ReadString(FX_WCHAR* pStr, |
1041 bool& bEOS) { | 1059 int32_t iMaxLength, |
| 1060 bool& bEOS) { |
1042 ASSERT(pStr && iMaxLength > 0); | 1061 ASSERT(pStr && iMaxLength > 0); |
1043 if (!m_pStreamImp) { | 1062 if (!m_pStreamImp) { |
1044 return -1; | 1063 return -1; |
1045 } | 1064 } |
1046 int32_t iLen; | 1065 int32_t iLen; |
1047 if (m_wCodePage == FX_CODEPAGE_UTF16LE || | 1066 if (m_wCodePage == FX_CODEPAGE_UTF16LE || |
1048 m_wCodePage == FX_CODEPAGE_UTF16BE) { | 1067 m_wCodePage == FX_CODEPAGE_UTF16BE) { |
1049 int32_t iBytes = iMaxLength * 2; | 1068 int32_t iBytes = iMaxLength * 2; |
1050 iLen = m_pStreamImp->ReadData((uint8_t*)pStr, iBytes); | 1069 iLen = m_pStreamImp->ReadData((uint8_t*)pStr, iBytes); |
1051 iMaxLength = iLen / 2; | 1070 iMaxLength = iLen / 2; |
(...skipping 29 matching lines...) Expand all Loading... |
1081 if (iDecode < 1) { | 1100 if (iDecode < 1) { |
1082 return -1; | 1101 return -1; |
1083 } | 1102 } |
1084 } else { | 1103 } else { |
1085 iMaxLength = 0; | 1104 iMaxLength = 0; |
1086 } | 1105 } |
1087 } | 1106 } |
1088 bEOS = m_pStreamImp->IsEOF(); | 1107 bEOS = m_pStreamImp->IsEOF(); |
1089 return iMaxLength; | 1108 return iMaxLength; |
1090 } | 1109 } |
1091 int32_t CFX_TextStream::WriteString(const FX_WCHAR* pStr, int32_t iLength) { | 1110 |
| 1111 int32_t CFGAS_TextStream::WriteString(const FX_WCHAR* pStr, int32_t iLength) { |
1092 ASSERT(pStr && iLength > 0); | 1112 ASSERT(pStr && iLength > 0); |
1093 if ((m_pStreamImp->GetAccessModes() & FX_STREAMACCESS_Write) == 0) { | 1113 if ((m_pStreamImp->GetAccessModes() & FX_STREAMACCESS_Write) == 0) |
1094 return -1; | 1114 return -1; |
1095 } | 1115 |
1096 if (m_wCodePage == FX_CODEPAGE_UTF8) { | 1116 if (m_wCodePage == FX_CODEPAGE_UTF8) { |
1097 int32_t len = iLength; | 1117 int32_t len = iLength; |
1098 CFX_UTF8Encoder encoder; | 1118 CFX_UTF8Encoder encoder; |
1099 while (len-- > 0) { | 1119 while (len-- > 0) { |
1100 encoder.Input(*pStr++); | 1120 encoder.Input(*pStr++); |
1101 } | 1121 } |
1102 CFX_ByteStringC bsResult = encoder.GetResult(); | 1122 CFX_ByteStringC bsResult = encoder.GetResult(); |
1103 m_pStreamImp->WriteData((const uint8_t*)bsResult.c_str(), | 1123 m_pStreamImp->WriteData((const uint8_t*)bsResult.c_str(), |
1104 bsResult.GetLength()); | 1124 bsResult.GetLength()); |
1105 } | 1125 } |
1106 return iLength; | 1126 return iLength; |
1107 } | 1127 } |
1108 CFX_Stream::CFX_Stream() | 1128 |
| 1129 CFGAS_Stream::CFGAS_Stream() |
1109 : m_eStreamType(FX_SREAMTYPE_Unknown), | 1130 : m_eStreamType(FX_SREAMTYPE_Unknown), |
1110 m_pStreamImp(nullptr), | 1131 m_pStreamImp(nullptr), |
1111 m_dwAccess(0), | 1132 m_dwAccess(0), |
1112 m_iTotalSize(0), | 1133 m_iTotalSize(0), |
1113 m_iPosition(0), | 1134 m_iPosition(0), |
1114 m_iStart(0), | 1135 m_iStart(0), |
1115 m_iLength(0), | 1136 m_iLength(0), |
1116 m_iRefCount(1) {} | 1137 m_iRefCount(1) {} |
1117 | 1138 |
1118 CFX_Stream::~CFX_Stream() { | 1139 CFGAS_Stream::~CFGAS_Stream() { |
1119 if (m_eStreamType != FX_STREAMTYPE_Stream) | 1140 if (m_eStreamType != FX_STREAMTYPE_Stream) |
1120 delete m_pStreamImp; | 1141 delete m_pStreamImp; |
1121 } | 1142 } |
1122 | 1143 |
1123 bool CFX_Stream::LoadFile(const FX_WCHAR* pszSrcFileName, uint32_t dwAccess) { | 1144 bool CFGAS_Stream::LoadFile(const FX_WCHAR* pszSrcFileName, uint32_t dwAccess) { |
1124 if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp) | 1145 if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp) |
1125 return false; | 1146 return false; |
1126 | 1147 |
1127 if (!pszSrcFileName || FXSYS_wcslen(pszSrcFileName) < 1) | 1148 if (!pszSrcFileName || FXSYS_wcslen(pszSrcFileName) < 1) |
1128 return false; | 1149 return false; |
1129 | 1150 |
1130 std::unique_ptr<CFX_FileStreamImp> pImp(new CFX_FileStreamImp()); | 1151 std::unique_ptr<CFGAS_FileStreamImp> pImp(new CFGAS_FileStreamImp()); |
1131 if (!pImp->LoadFile(pszSrcFileName, dwAccess)) | 1152 if (!pImp->LoadFile(pszSrcFileName, dwAccess)) |
1132 return false; | 1153 return false; |
1133 | 1154 |
1134 m_pStreamImp = pImp.release(); | 1155 m_pStreamImp = pImp.release(); |
1135 m_eStreamType = FX_STREAMTYPE_File; | 1156 m_eStreamType = FX_STREAMTYPE_File; |
1136 m_dwAccess = dwAccess; | 1157 m_dwAccess = dwAccess; |
1137 m_iLength = m_pStreamImp->GetLength(); | 1158 m_iLength = m_pStreamImp->GetLength(); |
1138 return true; | 1159 return true; |
1139 } | 1160 } |
1140 | 1161 |
1141 bool CFX_Stream::LoadFileRead(IFX_SeekableReadStream* pFileRead, | 1162 bool CFGAS_Stream::LoadFileRead(IFX_SeekableReadStream* pFileRead, |
1142 uint32_t dwAccess) { | 1163 uint32_t dwAccess) { |
1143 if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp) | 1164 if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp) |
1144 return false; | 1165 return false; |
1145 | 1166 |
1146 if (!pFileRead) | 1167 if (!pFileRead) |
1147 return false; | 1168 return false; |
1148 | 1169 |
1149 std::unique_ptr<CFX_FileReadStreamImp> pImp(new CFX_FileReadStreamImp()); | 1170 std::unique_ptr<CFGAS_FileReadStreamImp> pImp(new CFGAS_FileReadStreamImp()); |
1150 if (!pImp->LoadFileRead(pFileRead, dwAccess)) | 1171 if (!pImp->LoadFileRead(pFileRead, dwAccess)) |
1151 return false; | 1172 return false; |
1152 | 1173 |
1153 m_pStreamImp = pImp.release(); | 1174 m_pStreamImp = pImp.release(); |
1154 m_eStreamType = FX_STREAMTYPE_File; | 1175 m_eStreamType = FX_STREAMTYPE_File; |
1155 m_dwAccess = dwAccess; | 1176 m_dwAccess = dwAccess; |
1156 m_iLength = m_pStreamImp->GetLength(); | 1177 m_iLength = m_pStreamImp->GetLength(); |
1157 return true; | 1178 return true; |
1158 } | 1179 } |
1159 | 1180 |
1160 bool CFX_Stream::LoadFileWrite(IFX_SeekableWriteStream* pFileWrite, | 1181 bool CFGAS_Stream::LoadFileWrite(IFX_SeekableWriteStream* pFileWrite, |
1161 uint32_t dwAccess) { | 1182 uint32_t dwAccess) { |
1162 if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp) | 1183 if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp) |
1163 return false; | 1184 return false; |
1164 | 1185 |
1165 if (!pFileWrite) | 1186 if (!pFileWrite) |
1166 return false; | 1187 return false; |
1167 | 1188 |
1168 std::unique_ptr<CFX_FileWriteStreamImp> pImp(new CFX_FileWriteStreamImp()); | 1189 std::unique_ptr<CFGAS_FileWriteStreamImp> pImp( |
| 1190 new CFGAS_FileWriteStreamImp()); |
1169 if (!pImp->LoadFileWrite(pFileWrite, dwAccess)) | 1191 if (!pImp->LoadFileWrite(pFileWrite, dwAccess)) |
1170 return false; | 1192 return false; |
1171 | 1193 |
1172 m_pStreamImp = pImp.release(); | 1194 m_pStreamImp = pImp.release(); |
1173 m_eStreamType = FX_STREAMTYPE_File; | 1195 m_eStreamType = FX_STREAMTYPE_File; |
1174 m_dwAccess = dwAccess; | 1196 m_dwAccess = dwAccess; |
1175 m_iLength = m_pStreamImp->GetLength(); | 1197 m_iLength = m_pStreamImp->GetLength(); |
1176 return true; | 1198 return true; |
1177 } | 1199 } |
1178 | 1200 |
1179 bool CFX_Stream::LoadBuffer(uint8_t* pData, | 1201 bool CFGAS_Stream::LoadBuffer(uint8_t* pData, |
1180 int32_t iTotalSize, | 1202 int32_t iTotalSize, |
1181 uint32_t dwAccess) { | 1203 uint32_t dwAccess) { |
1182 if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp) | 1204 if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp) |
1183 return false; | 1205 return false; |
1184 | 1206 |
1185 if (!pData || iTotalSize < 1) | 1207 if (!pData || iTotalSize < 1) |
1186 return false; | 1208 return false; |
1187 | 1209 |
1188 std::unique_ptr<CFX_BufferStreamImp> pImp(new CFX_BufferStreamImp()); | 1210 std::unique_ptr<CFGAS_BufferStreamImp> pImp(new CFGAS_BufferStreamImp()); |
1189 if (!pImp->LoadBuffer(pData, iTotalSize, dwAccess)) | 1211 if (!pImp->LoadBuffer(pData, iTotalSize, dwAccess)) |
1190 return false; | 1212 return false; |
1191 | 1213 |
1192 m_pStreamImp = pImp.release(); | 1214 m_pStreamImp = pImp.release(); |
1193 m_eStreamType = FX_STREAMTYPE_Buffer; | 1215 m_eStreamType = FX_STREAMTYPE_Buffer; |
1194 m_dwAccess = dwAccess; | 1216 m_dwAccess = dwAccess; |
1195 m_iLength = m_pStreamImp->GetLength(); | 1217 m_iLength = m_pStreamImp->GetLength(); |
1196 return true; | 1218 return true; |
1197 } | 1219 } |
1198 | 1220 |
1199 bool CFX_Stream::LoadBufferRead(IFX_BufferedReadStream* pBufferRead, | 1221 bool CFGAS_Stream::LoadBufferRead(IFX_BufferedReadStream* pBufferRead, |
1200 int32_t iFileSize, | 1222 int32_t iFileSize, |
1201 uint32_t dwAccess, | 1223 uint32_t dwAccess, |
1202 bool bReleaseBufferRead) { | 1224 bool bReleaseBufferRead) { |
1203 if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp) | 1225 if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp) |
1204 return false; | 1226 return false; |
1205 | 1227 |
1206 if (!pBufferRead) | 1228 if (!pBufferRead) |
1207 return false; | 1229 return false; |
1208 | 1230 |
1209 std::unique_ptr<CFX_BufferReadStreamImp> pImp(new CFX_BufferReadStreamImp); | 1231 std::unique_ptr<CFGAS_BufferReadStreamImp> pImp( |
| 1232 new CFGAS_BufferReadStreamImp); |
1210 if (!pImp->LoadBufferRead(pBufferRead, iFileSize, dwAccess, | 1233 if (!pImp->LoadBufferRead(pBufferRead, iFileSize, dwAccess, |
1211 bReleaseBufferRead)) | 1234 bReleaseBufferRead)) |
1212 return false; | 1235 return false; |
1213 | 1236 |
1214 m_pStreamImp = pImp.release(); | 1237 m_pStreamImp = pImp.release(); |
1215 m_eStreamType = FX_STREAMTYPE_BufferRead; | 1238 m_eStreamType = FX_STREAMTYPE_BufferRead; |
1216 m_dwAccess = dwAccess; | 1239 m_dwAccess = dwAccess; |
1217 m_iLength = m_pStreamImp->GetLength(); | 1240 m_iLength = m_pStreamImp->GetLength(); |
1218 return true; | 1241 return true; |
1219 } | 1242 } |
1220 | 1243 |
1221 void CFX_Stream::Release() { | 1244 void CFGAS_Stream::Release() { |
1222 if (--m_iRefCount < 1) { | 1245 if (--m_iRefCount < 1) { |
1223 delete this; | 1246 delete this; |
1224 } | 1247 } |
1225 } | 1248 } |
1226 IFX_Stream* CFX_Stream::Retain() { | 1249 IFGAS_Stream* CFGAS_Stream::Retain() { |
1227 m_iRefCount++; | 1250 m_iRefCount++; |
1228 return this; | 1251 return this; |
1229 } | 1252 } |
1230 | 1253 |
1231 uint32_t CFX_Stream::GetAccessModes() const { | 1254 uint32_t CFGAS_Stream::GetAccessModes() const { |
1232 return m_dwAccess; | 1255 return m_dwAccess; |
1233 } | 1256 } |
1234 | 1257 |
1235 int32_t CFX_Stream::GetLength() const { | 1258 int32_t CFGAS_Stream::GetLength() const { |
1236 if (!m_pStreamImp) { | 1259 if (!m_pStreamImp) { |
1237 return -1; | 1260 return -1; |
1238 } | 1261 } |
1239 if (m_eStreamType == FX_STREAMTYPE_File || | 1262 if (m_eStreamType == FX_STREAMTYPE_File || |
1240 m_eStreamType == FX_STREAMTYPE_Buffer) { | 1263 m_eStreamType == FX_STREAMTYPE_Buffer) { |
1241 return m_pStreamImp->GetLength(); | 1264 return m_pStreamImp->GetLength(); |
1242 } | 1265 } |
1243 return m_iLength; | 1266 return m_iLength; |
1244 } | 1267 } |
1245 int32_t CFX_Stream::Seek(FX_STREAMSEEK eSeek, int32_t iOffset) { | 1268 int32_t CFGAS_Stream::Seek(FX_STREAMSEEK eSeek, int32_t iOffset) { |
1246 if (!m_pStreamImp) { | 1269 if (!m_pStreamImp) { |
1247 return -1; | 1270 return -1; |
1248 } | 1271 } |
1249 if (m_eStreamType == FX_STREAMTYPE_File || | 1272 if (m_eStreamType == FX_STREAMTYPE_File || |
1250 m_eStreamType == FX_STREAMTYPE_Buffer) { | 1273 m_eStreamType == FX_STREAMTYPE_Buffer) { |
1251 return m_iPosition = m_pStreamImp->Seek(eSeek, iOffset); | 1274 return m_iPosition = m_pStreamImp->Seek(eSeek, iOffset); |
1252 } | 1275 } |
1253 int32_t iEnd = m_iStart + m_iLength; | 1276 int32_t iEnd = m_iStart + m_iLength; |
1254 int32_t iPosition = m_iStart + iOffset; | 1277 int32_t iPosition = m_iStart + iOffset; |
1255 if (eSeek == FX_STREAMSEEK_Begin) { | 1278 if (eSeek == FX_STREAMSEEK_Begin) { |
1256 m_iPosition = iPosition; | 1279 m_iPosition = iPosition; |
1257 } else if (eSeek == FX_STREAMSEEK_Current) { | 1280 } else if (eSeek == FX_STREAMSEEK_Current) { |
1258 m_iPosition += iOffset; | 1281 m_iPosition += iOffset; |
1259 } else if (eSeek == FX_STREAMSEEK_End) { | 1282 } else if (eSeek == FX_STREAMSEEK_End) { |
1260 m_iPosition = iEnd + iOffset; | 1283 m_iPosition = iEnd + iOffset; |
1261 } | 1284 } |
1262 if (m_iPosition > iEnd) { | 1285 if (m_iPosition > iEnd) { |
1263 m_iPosition = iEnd; | 1286 m_iPosition = iEnd; |
1264 } | 1287 } |
1265 if (m_iPosition < m_iStart) { | 1288 if (m_iPosition < m_iStart) { |
1266 m_iPosition = m_iStart; | 1289 m_iPosition = m_iStart; |
1267 } | 1290 } |
1268 return m_iPosition - m_iStart; | 1291 return m_iPosition - m_iStart; |
1269 } | 1292 } |
1270 int32_t CFX_Stream::GetPosition() { | 1293 int32_t CFGAS_Stream::GetPosition() { |
1271 if (!m_pStreamImp) { | 1294 if (!m_pStreamImp) { |
1272 return -1; | 1295 return -1; |
1273 } | 1296 } |
1274 if (m_eStreamType == FX_STREAMTYPE_File || | 1297 if (m_eStreamType == FX_STREAMTYPE_File || |
1275 m_eStreamType == FX_STREAMTYPE_Buffer) { | 1298 m_eStreamType == FX_STREAMTYPE_Buffer) { |
1276 return m_iPosition = m_pStreamImp->GetPosition(); | 1299 return m_iPosition = m_pStreamImp->GetPosition(); |
1277 } | 1300 } |
1278 return m_iPosition - m_iStart; | 1301 return m_iPosition - m_iStart; |
1279 } | 1302 } |
1280 bool CFX_Stream::IsEOF() const { | 1303 bool CFGAS_Stream::IsEOF() const { |
1281 if (!m_pStreamImp) { | 1304 if (!m_pStreamImp) { |
1282 return true; | 1305 return true; |
1283 } | 1306 } |
1284 if (m_eStreamType == FX_STREAMTYPE_File || | 1307 if (m_eStreamType == FX_STREAMTYPE_File || |
1285 m_eStreamType == FX_STREAMTYPE_Buffer) { | 1308 m_eStreamType == FX_STREAMTYPE_Buffer) { |
1286 return m_pStreamImp->IsEOF(); | 1309 return m_pStreamImp->IsEOF(); |
1287 } | 1310 } |
1288 return m_iPosition >= m_iStart + m_iLength; | 1311 return m_iPosition >= m_iStart + m_iLength; |
1289 } | 1312 } |
1290 int32_t CFX_Stream::ReadData(uint8_t* pBuffer, int32_t iBufferSize) { | 1313 int32_t CFGAS_Stream::ReadData(uint8_t* pBuffer, int32_t iBufferSize) { |
1291 ASSERT(pBuffer && iBufferSize > 0); | 1314 ASSERT(pBuffer && iBufferSize > 0); |
1292 if (!m_pStreamImp) { | 1315 if (!m_pStreamImp) { |
1293 return -1; | 1316 return -1; |
1294 } | 1317 } |
1295 int32_t iLen = std::min(m_iStart + m_iLength - m_iPosition, iBufferSize); | 1318 int32_t iLen = std::min(m_iStart + m_iLength - m_iPosition, iBufferSize); |
1296 if (iLen <= 0) { | 1319 if (iLen <= 0) { |
1297 return 0; | 1320 return 0; |
1298 } | 1321 } |
1299 if (m_pStreamImp->GetPosition() != m_iPosition) { | 1322 if (m_pStreamImp->GetPosition() != m_iPosition) { |
1300 m_pStreamImp->Seek(FX_STREAMSEEK_Begin, m_iPosition); | 1323 m_pStreamImp->Seek(FX_STREAMSEEK_Begin, m_iPosition); |
1301 } | 1324 } |
1302 iLen = m_pStreamImp->ReadData(pBuffer, iLen); | 1325 iLen = m_pStreamImp->ReadData(pBuffer, iLen); |
1303 m_iPosition = m_pStreamImp->GetPosition(); | 1326 m_iPosition = m_pStreamImp->GetPosition(); |
1304 return iLen; | 1327 return iLen; |
1305 } | 1328 } |
1306 int32_t CFX_Stream::ReadString(FX_WCHAR* pStr, int32_t iMaxLength, bool& bEOS) { | 1329 int32_t CFGAS_Stream::ReadString(FX_WCHAR* pStr, |
| 1330 int32_t iMaxLength, |
| 1331 bool& bEOS) { |
1307 ASSERT(pStr && iMaxLength > 0); | 1332 ASSERT(pStr && iMaxLength > 0); |
1308 if (!m_pStreamImp) { | 1333 if (!m_pStreamImp) { |
1309 return -1; | 1334 return -1; |
1310 } | 1335 } |
1311 int32_t iEnd = m_iStart + m_iLength; | 1336 int32_t iEnd = m_iStart + m_iLength; |
1312 int32_t iLen = iEnd - m_iPosition; | 1337 int32_t iLen = iEnd - m_iPosition; |
1313 iLen = std::min(iEnd / 2, iMaxLength); | 1338 iLen = std::min(iEnd / 2, iMaxLength); |
1314 if (iLen <= 0) { | 1339 if (iLen <= 0) { |
1315 return 0; | 1340 return 0; |
1316 } | 1341 } |
1317 if (m_pStreamImp->GetPosition() != m_iPosition) { | 1342 if (m_pStreamImp->GetPosition() != m_iPosition) { |
1318 m_pStreamImp->Seek(FX_STREAMSEEK_Begin, m_iPosition); | 1343 m_pStreamImp->Seek(FX_STREAMSEEK_Begin, m_iPosition); |
1319 } | 1344 } |
1320 iLen = m_pStreamImp->ReadString(pStr, iLen, bEOS); | 1345 iLen = m_pStreamImp->ReadString(pStr, iLen, bEOS); |
1321 m_iPosition = m_pStreamImp->GetPosition(); | 1346 m_iPosition = m_pStreamImp->GetPosition(); |
1322 if (iLen > 0 && m_iPosition >= iEnd) { | 1347 if (iLen > 0 && m_iPosition >= iEnd) { |
1323 bEOS = true; | 1348 bEOS = true; |
1324 } | 1349 } |
1325 return iLen; | 1350 return iLen; |
1326 } | 1351 } |
1327 | 1352 |
1328 int32_t CFX_Stream::WriteData(const uint8_t* pBuffer, int32_t iBufferSize) { | 1353 int32_t CFGAS_Stream::WriteData(const uint8_t* pBuffer, int32_t iBufferSize) { |
1329 ASSERT(pBuffer && iBufferSize > 0); | 1354 ASSERT(pBuffer && iBufferSize > 0); |
1330 if (!m_pStreamImp) { | 1355 if (!m_pStreamImp) { |
1331 return -1; | 1356 return -1; |
1332 } | 1357 } |
1333 if ((m_dwAccess & FX_STREAMACCESS_Write) == 0) { | 1358 if ((m_dwAccess & FX_STREAMACCESS_Write) == 0) { |
1334 return -1; | 1359 return -1; |
1335 } | 1360 } |
1336 int32_t iLen = iBufferSize; | 1361 int32_t iLen = iBufferSize; |
1337 if (m_eStreamType == FX_STREAMTYPE_Stream) { | 1362 if (m_eStreamType == FX_STREAMTYPE_Stream) { |
1338 iLen = std::min(m_iStart + m_iTotalSize - m_iPosition, iBufferSize); | 1363 iLen = std::min(m_iStart + m_iTotalSize - m_iPosition, iBufferSize); |
1339 if (iLen <= 0) { | 1364 if (iLen <= 0) { |
1340 return 0; | 1365 return 0; |
1341 } | 1366 } |
1342 } | 1367 } |
1343 int32_t iEnd = m_iStart + m_iLength; | 1368 int32_t iEnd = m_iStart + m_iLength; |
1344 if (m_pStreamImp->GetPosition() != m_iPosition) { | 1369 if (m_pStreamImp->GetPosition() != m_iPosition) { |
1345 m_pStreamImp->Seek(FX_STREAMSEEK_Begin, m_iPosition); | 1370 m_pStreamImp->Seek(FX_STREAMSEEK_Begin, m_iPosition); |
1346 } | 1371 } |
1347 iLen = m_pStreamImp->WriteData(pBuffer, iLen); | 1372 iLen = m_pStreamImp->WriteData(pBuffer, iLen); |
1348 m_iPosition = m_pStreamImp->GetPosition(); | 1373 m_iPosition = m_pStreamImp->GetPosition(); |
1349 if (m_iPosition > iEnd) { | 1374 if (m_iPosition > iEnd) { |
1350 m_iLength = m_iPosition - m_iStart; | 1375 m_iLength = m_iPosition - m_iStart; |
1351 } | 1376 } |
1352 return iLen; | 1377 return iLen; |
1353 } | 1378 } |
1354 int32_t CFX_Stream::WriteString(const FX_WCHAR* pStr, int32_t iLength) { | 1379 int32_t CFGAS_Stream::WriteString(const FX_WCHAR* pStr, int32_t iLength) { |
1355 ASSERT(pStr && iLength > 0); | 1380 ASSERT(pStr && iLength > 0); |
1356 if (!m_pStreamImp) { | 1381 if (!m_pStreamImp) { |
1357 return -1; | 1382 return -1; |
1358 } | 1383 } |
1359 if ((m_dwAccess & FX_STREAMACCESS_Write) == 0) { | 1384 if ((m_dwAccess & FX_STREAMACCESS_Write) == 0) { |
1360 return -1; | 1385 return -1; |
1361 } | 1386 } |
1362 int32_t iLen = iLength; | 1387 int32_t iLen = iLength; |
1363 if (m_eStreamType == FX_STREAMTYPE_Stream) { | 1388 if (m_eStreamType == FX_STREAMTYPE_Stream) { |
1364 iLen = std::min((m_iStart + m_iTotalSize - m_iPosition) / 2, iLength); | 1389 iLen = std::min((m_iStart + m_iTotalSize - m_iPosition) / 2, iLength); |
1365 if (iLen <= 0) { | 1390 if (iLen <= 0) { |
1366 return 0; | 1391 return 0; |
1367 } | 1392 } |
1368 } | 1393 } |
1369 int32_t iEnd = m_iStart + m_iLength; | 1394 int32_t iEnd = m_iStart + m_iLength; |
1370 if (m_pStreamImp->GetPosition() != m_iPosition) { | 1395 if (m_pStreamImp->GetPosition() != m_iPosition) { |
1371 m_pStreamImp->Seek(FX_STREAMSEEK_Begin, m_iPosition); | 1396 m_pStreamImp->Seek(FX_STREAMSEEK_Begin, m_iPosition); |
1372 } | 1397 } |
1373 iLen = m_pStreamImp->WriteString(pStr, iLen); | 1398 iLen = m_pStreamImp->WriteString(pStr, iLen); |
1374 m_iPosition = m_pStreamImp->GetPosition(); | 1399 m_iPosition = m_pStreamImp->GetPosition(); |
1375 if (m_iPosition > iEnd) { | 1400 if (m_iPosition > iEnd) { |
1376 m_iLength = m_iPosition - m_iStart; | 1401 m_iLength = m_iPosition - m_iStart; |
1377 } | 1402 } |
1378 return iLen; | 1403 return iLen; |
1379 } | 1404 } |
1380 void CFX_Stream::Flush() { | 1405 void CFGAS_Stream::Flush() { |
1381 if (!m_pStreamImp) { | 1406 if (!m_pStreamImp) { |
1382 return; | 1407 return; |
1383 } | 1408 } |
1384 if ((m_dwAccess & FX_STREAMACCESS_Write) == 0) { | 1409 if ((m_dwAccess & FX_STREAMACCESS_Write) == 0) { |
1385 return; | 1410 return; |
1386 } | 1411 } |
1387 m_pStreamImp->Flush(); | 1412 m_pStreamImp->Flush(); |
1388 } | 1413 } |
1389 bool CFX_Stream::SetLength(int32_t iLength) { | 1414 bool CFGAS_Stream::SetLength(int32_t iLength) { |
1390 if (!m_pStreamImp) { | 1415 if (!m_pStreamImp) { |
1391 return false; | 1416 return false; |
1392 } | 1417 } |
1393 if ((m_dwAccess & FX_STREAMACCESS_Write) == 0) { | 1418 if ((m_dwAccess & FX_STREAMACCESS_Write) == 0) { |
1394 return false; | 1419 return false; |
1395 } | 1420 } |
1396 return m_pStreamImp->SetLength(iLength); | 1421 return m_pStreamImp->SetLength(iLength); |
1397 } | 1422 } |
1398 int32_t CFX_Stream::GetBOM(uint8_t bom[4]) const { | 1423 int32_t CFGAS_Stream::GetBOM(uint8_t bom[4]) const { |
1399 if (!m_pStreamImp) { | 1424 if (!m_pStreamImp) { |
1400 return -1; | 1425 return -1; |
1401 } | 1426 } |
1402 return 0; | 1427 return 0; |
1403 } | 1428 } |
1404 uint16_t CFX_Stream::GetCodePage() const { | 1429 uint16_t CFGAS_Stream::GetCodePage() const { |
1405 #if _FX_ENDIAN_ == _FX_LITTLE_ENDIAN_ | 1430 #if _FX_ENDIAN_ == _FX_LITTLE_ENDIAN_ |
1406 return FX_CODEPAGE_UTF16LE; | 1431 return FX_CODEPAGE_UTF16LE; |
1407 #else | 1432 #else |
1408 return FX_CODEPAGE_UTF16BE; | 1433 return FX_CODEPAGE_UTF16BE; |
1409 #endif | 1434 #endif |
1410 } | 1435 } |
1411 uint16_t CFX_Stream::SetCodePage(uint16_t wCodePage) { | 1436 uint16_t CFGAS_Stream::SetCodePage(uint16_t wCodePage) { |
1412 #if _FX_ENDIAN_ == _FX_LITTLE_ENDIAN_ | 1437 #if _FX_ENDIAN_ == _FX_LITTLE_ENDIAN_ |
1413 return FX_CODEPAGE_UTF16LE; | 1438 return FX_CODEPAGE_UTF16LE; |
1414 #else | 1439 #else |
1415 return FX_CODEPAGE_UTF16BE; | 1440 return FX_CODEPAGE_UTF16BE; |
1416 #endif | 1441 #endif |
1417 } | 1442 } |
1418 IFX_Stream* CFX_Stream::CreateSharedStream(uint32_t dwAccess, | 1443 IFGAS_Stream* CFGAS_Stream::CreateSharedStream(uint32_t dwAccess, |
1419 int32_t iOffset, | 1444 int32_t iOffset, |
1420 int32_t iLength) { | 1445 int32_t iLength) { |
1421 ASSERT(iLength > 0); | 1446 ASSERT(iLength > 0); |
1422 if (!m_pStreamImp) { | 1447 if (!m_pStreamImp) |
1423 return nullptr; | 1448 return nullptr; |
1424 } | 1449 |
1425 if ((m_dwAccess & FX_STREAMACCESS_Text) != 0 && | 1450 if ((m_dwAccess & FX_STREAMACCESS_Text) != 0 && |
1426 (dwAccess & FX_STREAMACCESS_Text) == 0) { | 1451 (dwAccess & FX_STREAMACCESS_Text) == 0) { |
1427 return nullptr; | 1452 return nullptr; |
1428 } | 1453 } |
1429 if ((m_dwAccess & FX_STREAMACCESS_Write) == 0 && | 1454 if ((m_dwAccess & FX_STREAMACCESS_Write) == 0 && |
1430 (dwAccess & FX_STREAMACCESS_Write) != 0) { | 1455 (dwAccess & FX_STREAMACCESS_Write) != 0) { |
1431 return nullptr; | 1456 return nullptr; |
1432 } | 1457 } |
1433 int32_t iStart = m_iStart + iOffset; | 1458 int32_t iStart = m_iStart + iOffset; |
1434 int32_t iTotal = m_iStart + m_iLength; | 1459 int32_t iTotal = m_iStart + m_iLength; |
1435 if (iStart < m_iStart || iStart >= iTotal) { | 1460 if (iStart < m_iStart || iStart >= iTotal) |
1436 return nullptr; | 1461 return nullptr; |
1437 } | 1462 |
1438 int32_t iEnd = iStart + iLength; | 1463 int32_t iEnd = iStart + iLength; |
1439 if (iEnd < iStart || iEnd > iTotal) { | 1464 if (iEnd < iStart || iEnd > iTotal) |
1440 return nullptr; | 1465 return nullptr; |
1441 } | 1466 |
1442 CFX_Stream* pShared = new CFX_Stream; | 1467 CFGAS_Stream* pShared = new CFGAS_Stream; |
1443 pShared->m_eStreamType = FX_STREAMTYPE_Stream; | 1468 pShared->m_eStreamType = FX_STREAMTYPE_Stream; |
1444 pShared->m_pStreamImp = m_pStreamImp; | 1469 pShared->m_pStreamImp = m_pStreamImp; |
1445 pShared->m_dwAccess = dwAccess; | 1470 pShared->m_dwAccess = dwAccess; |
1446 pShared->m_iTotalSize = iLength; | 1471 pShared->m_iTotalSize = iLength; |
1447 pShared->m_iPosition = iStart; | 1472 pShared->m_iPosition = iStart; |
1448 pShared->m_iStart = iStart; | 1473 pShared->m_iStart = iStart; |
1449 pShared->m_iLength = (dwAccess & FX_STREAMACCESS_Write) != 0 ? 0 : iLength; | 1474 pShared->m_iLength = (dwAccess & FX_STREAMACCESS_Write) != 0 ? 0 : iLength; |
1450 if (dwAccess & FX_STREAMACCESS_Text) { | 1475 if (dwAccess & FX_STREAMACCESS_Text) |
1451 return IFX_Stream::CreateTextStream(pShared, true); | 1476 return IFGAS_Stream::CreateTextStream(pShared, true); |
1452 } | 1477 |
1453 return pShared; | 1478 return pShared; |
1454 } | 1479 } |
1455 | 1480 |
1456 IFX_SeekableReadStream* IFX_Stream::MakeSeekableReadStream() { | 1481 IFX_SeekableReadStream* IFGAS_Stream::MakeSeekableReadStream() { |
1457 return new CFGAS_FileRead(this, false); | 1482 return new CFGAS_FileRead(this, false); |
1458 } | 1483 } |
1459 | 1484 |
1460 CFGAS_FileRead::CFGAS_FileRead(IFX_Stream* pStream, bool bReleaseStream) | 1485 CFGAS_FileRead::CFGAS_FileRead(IFGAS_Stream* pStream, bool bReleaseStream) |
1461 : m_bReleaseStream(bReleaseStream), m_pStream(pStream) { | 1486 : m_bReleaseStream(bReleaseStream), m_pStream(pStream) { |
1462 ASSERT(m_pStream); | 1487 ASSERT(m_pStream); |
1463 } | 1488 } |
1464 CFGAS_FileRead::~CFGAS_FileRead() { | 1489 CFGAS_FileRead::~CFGAS_FileRead() { |
1465 if (m_bReleaseStream) { | 1490 if (m_bReleaseStream) { |
1466 m_pStream->Release(); | 1491 m_pStream->Release(); |
1467 } | 1492 } |
1468 } | 1493 } |
1469 FX_FILESIZE CFGAS_FileRead::GetSize() { | 1494 FX_FILESIZE CFGAS_FileRead::GetSize() { |
1470 return (FX_FILESIZE)m_pStream->GetLength(); | 1495 return (FX_FILESIZE)m_pStream->GetLength(); |
1471 } | 1496 } |
1472 | 1497 |
1473 bool CFGAS_FileRead::ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) { | 1498 bool CFGAS_FileRead::ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) { |
1474 m_pStream->Seek(FX_STREAMSEEK_Begin, (int32_t)offset); | 1499 m_pStream->Seek(FX_STREAMSEEK_Begin, (int32_t)offset); |
1475 int32_t iLen = m_pStream->ReadData((uint8_t*)buffer, (int32_t)size); | 1500 int32_t iLen = m_pStream->ReadData((uint8_t*)buffer, (int32_t)size); |
1476 return iLen == (int32_t)size; | 1501 return iLen == (int32_t)size; |
1477 } | 1502 } |
1478 | 1503 |
1479 void CFGAS_FileRead::Release() { | 1504 void CFGAS_FileRead::Release() { |
1480 delete this; | 1505 delete this; |
1481 } | 1506 } |
OLD | NEW |