Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: xfa/fgas/crt/fgas_stream.cpp

Issue 2535723010: Rename IFX_Stream to IFGAS_Stream. (Closed)
Patch Set: Also fix CFX_TextStream Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « xfa/fgas/crt/fgas_stream.h ('k') | xfa/fgas/font/cfgas_gefont.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 IFX_StreamImp {
npm 2016/12/02 16:23:22 You probably want to rename all the classes in thi
Tom Sepez 2016/12/02 18:02:08 Good suggestion.
22 public: 22 public:
23 virtual ~IFX_StreamImp() {} 23 virtual ~IFX_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,
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 IFX_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
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) {
npm 2016/12/02 16:23:22 Nit: {}
Tom Sepez 2016/12/02 18:02:08 Done.
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) {
npm 2016/12/02 16:23:22 Nitto
Tom Sepez 2016/12/02 18:02:07 Done.
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) {
npm 2016/12/02 16:23:22 Nitto
Tom Sepez 2016/12/02 18:02:08 Done.
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 IFX_StreamImp::IFX_StreamImp() : m_dwAccess(0) {}
368 368
369 CFX_FileStreamImp::CFX_FileStreamImp() : m_hFile(nullptr), m_iLength(0) {} 369 CFX_FileStreamImp::CFX_FileStreamImp() : m_hFile(nullptr), m_iLength(0) {}
370 370
371 CFX_FileStreamImp::~CFX_FileStreamImp() { 371 CFX_FileStreamImp::~CFX_FileStreamImp() {
372 if (m_hFile) 372 if (m_hFile)
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after
889 } 889 }
890 FXSYS_memcpy(m_pData + m_iPosition, pStr, iLen * 2); 890 FXSYS_memcpy(m_pData + m_iPosition, pStr, iLen * 2);
891 m_iPosition += iLen * 2; 891 m_iPosition += iLen * 2;
892 if (m_iPosition > m_iLength) { 892 if (m_iPosition > m_iLength) {
893 m_iLength = m_iPosition; 893 m_iLength = m_iPosition;
894 } 894 }
895 return iLen; 895 return iLen;
896 } 896 }
897 897
898 // static 898 // static
899 IFX_Stream* IFX_Stream::CreateTextStream(IFX_Stream* pBaseStream, 899 IFGAS_Stream* IFGAS_Stream::CreateTextStream(IFGAS_Stream* pBaseStream,
900 bool bDeleteOnRelease) { 900 bool bDeleteOnRelease) {
901 ASSERT(pBaseStream); 901 ASSERT(pBaseStream);
902 return new CFX_TextStream(pBaseStream, bDeleteOnRelease); 902 return new CFGAS_TextStream(pBaseStream, bDeleteOnRelease);
903 } 903 }
904 904
905 CFX_TextStream::CFX_TextStream(IFX_Stream* pStream, bool bDelStream) 905 CFGAS_TextStream::CFGAS_TextStream(IFGAS_Stream* pStream, bool bDelStream)
906 : m_wCodePage(FX_CODEPAGE_DefANSI), 906 : m_wCodePage(FX_CODEPAGE_DefANSI),
907 m_wBOMLength(0), 907 m_wBOMLength(0),
908 m_dwBOM(0), 908 m_dwBOM(0),
909 m_pBuf(nullptr), 909 m_pBuf(nullptr),
910 m_iBufSize(0), 910 m_iBufSize(0),
911 m_bDelStream(bDelStream), 911 m_bDelStream(bDelStream),
912 m_pStreamImp(pStream), 912 m_pStreamImp(pStream),
913 m_iRefCount(1) { 913 m_iRefCount(1) {
914 ASSERT(m_pStreamImp); 914 ASSERT(m_pStreamImp);
915 m_pStreamImp->Retain(); 915 m_pStreamImp->Retain();
916 InitStream(); 916 InitStream();
917 } 917 }
npm 2016/12/02 16:23:22 Nits: space needed between methods
Tom Sepez 2016/12/02 18:02:08 Done.
918 CFX_TextStream::~CFX_TextStream() { 918 CFGAS_TextStream::~CFGAS_TextStream() {
919 m_pStreamImp->Release(); 919 m_pStreamImp->Release();
920 if (m_bDelStream) { 920 if (m_bDelStream) {
921 m_pStreamImp->Release(); 921 m_pStreamImp->Release();
922 } 922 }
923 if (m_pBuf) { 923 if (m_pBuf) {
924 FX_Free(m_pBuf); 924 FX_Free(m_pBuf);
925 } 925 }
926 } 926 }
927 void CFX_TextStream::InitStream() { 927 void CFGAS_TextStream::InitStream() {
928 int32_t iPosition = m_pStreamImp->GetPosition(); 928 int32_t iPosition = m_pStreamImp->GetPosition();
929 m_pStreamImp->Seek(FX_STREAMSEEK_Begin, 0); 929 m_pStreamImp->Seek(FX_STREAMSEEK_Begin, 0);
930 m_pStreamImp->ReadData((uint8_t*)&m_dwBOM, 3); 930 m_pStreamImp->ReadData((uint8_t*)&m_dwBOM, 3);
931 #if _FX_ENDIAN_ == _FX_LITTLE_ENDIAN_ 931 #if _FX_ENDIAN_ == _FX_LITTLE_ENDIAN_
932 m_dwBOM &= 0x00FFFFFF; 932 m_dwBOM &= 0x00FFFFFF;
933 if (m_dwBOM == 0x00BFBBEF) { 933 if (m_dwBOM == 0x00BFBBEF) {
934 m_wBOMLength = 3; 934 m_wBOMLength = 3;
935 m_wCodePage = FX_CODEPAGE_UTF8; 935 m_wCodePage = FX_CODEPAGE_UTF8;
936 } else { 936 } else {
937 m_dwBOM &= 0x0000FFFF; 937 m_dwBOM &= 0x0000FFFF;
(...skipping 24 matching lines...) Expand all
962 m_wCodePage = FX_CODEPAGE_UTF16LE; 962 m_wCodePage = FX_CODEPAGE_UTF16LE;
963 } else { 963 } else {
964 m_wBOMLength = 0; 964 m_wBOMLength = 0;
965 m_dwBOM = 0; 965 m_dwBOM = 0;
966 m_wCodePage = FXSYS_GetACP(); 966 m_wCodePage = FXSYS_GetACP();
967 } 967 }
968 } 968 }
969 #endif 969 #endif
970 m_pStreamImp->Seek(FX_STREAMSEEK_Begin, std::max(m_wBOMLength, iPosition)); 970 m_pStreamImp->Seek(FX_STREAMSEEK_Begin, std::max(m_wBOMLength, iPosition));
971 } 971 }
972 void CFX_TextStream::Release() { 972 void CFGAS_TextStream::Release() {
973 if (--m_iRefCount < 1) { 973 if (--m_iRefCount < 1) {
974 delete this; 974 delete this;
975 } 975 }
976 } 976 }
977 IFX_Stream* CFX_TextStream::Retain() { 977 IFGAS_Stream* CFGAS_TextStream::Retain() {
978 m_iRefCount++; 978 m_iRefCount++;
979 return this; 979 return this;
980 } 980 }
981 uint32_t CFX_TextStream::GetAccessModes() const { 981 uint32_t CFGAS_TextStream::GetAccessModes() const {
982 return m_pStreamImp->GetAccessModes() | FX_STREAMACCESS_Text; 982 return m_pStreamImp->GetAccessModes() | FX_STREAMACCESS_Text;
983 } 983 }
984 int32_t CFX_TextStream::GetLength() const { 984 int32_t CFGAS_TextStream::GetLength() const {
985 return m_pStreamImp->GetLength(); 985 return m_pStreamImp->GetLength();
986 } 986 }
987 int32_t CFX_TextStream::Seek(FX_STREAMSEEK eSeek, int32_t iOffset) { 987 int32_t CFGAS_TextStream::Seek(FX_STREAMSEEK eSeek, int32_t iOffset) {
988 return m_pStreamImp->Seek(eSeek, iOffset); 988 return m_pStreamImp->Seek(eSeek, iOffset);
989 } 989 }
990 int32_t CFX_TextStream::GetPosition() { 990 int32_t CFGAS_TextStream::GetPosition() {
991 return m_pStreamImp->GetPosition(); 991 return m_pStreamImp->GetPosition();
992 } 992 }
993 bool CFX_TextStream::IsEOF() const { 993 bool CFGAS_TextStream::IsEOF() const {
994 return m_pStreamImp->IsEOF(); 994 return m_pStreamImp->IsEOF();
995 } 995 }
996 int32_t CFX_TextStream::ReadData(uint8_t* pBuffer, int32_t iBufferSize) { 996 int32_t CFGAS_TextStream::ReadData(uint8_t* pBuffer, int32_t iBufferSize) {
997 return m_pStreamImp->ReadData(pBuffer, iBufferSize); 997 return m_pStreamImp->ReadData(pBuffer, iBufferSize);
998 } 998 }
999 int32_t CFX_TextStream::WriteData(const uint8_t* pBuffer, int32_t iBufferSize) { 999 int32_t CFGAS_TextStream::WriteData(const uint8_t* pBuffer,
1000 int32_t iBufferSize) {
1000 return m_pStreamImp->WriteData(pBuffer, iBufferSize); 1001 return m_pStreamImp->WriteData(pBuffer, iBufferSize);
1001 } 1002 }
1002 void CFX_TextStream::Flush() { 1003 void CFGAS_TextStream::Flush() {
1003 m_pStreamImp->Flush(); 1004 m_pStreamImp->Flush();
1004 } 1005 }
1005 bool CFX_TextStream::SetLength(int32_t iLength) { 1006 bool CFGAS_TextStream::SetLength(int32_t iLength) {
1006 return m_pStreamImp->SetLength(iLength); 1007 return m_pStreamImp->SetLength(iLength);
1007 } 1008 }
1008 uint16_t CFX_TextStream::GetCodePage() const { 1009 uint16_t CFGAS_TextStream::GetCodePage() const {
1009 return m_wCodePage; 1010 return m_wCodePage;
1010 } 1011 }
1011 IFX_Stream* CFX_TextStream::CreateSharedStream(uint32_t dwAccess, 1012 IFGAS_Stream* CFGAS_TextStream::CreateSharedStream(uint32_t dwAccess,
1012 int32_t iOffset, 1013 int32_t iOffset,
1013 int32_t iLength) { 1014 int32_t iLength) {
1014 IFX_Stream* pSR = 1015 IFGAS_Stream* pSR =
1015 m_pStreamImp->CreateSharedStream(dwAccess, iOffset, iLength); 1016 m_pStreamImp->CreateSharedStream(dwAccess, iOffset, iLength);
1016 if (!pSR) { 1017 if (!pSR) {
1017 return nullptr; 1018 return nullptr;
1018 } 1019 }
1019 if (dwAccess & FX_STREAMACCESS_Text) { 1020 if (dwAccess & FX_STREAMACCESS_Text) {
npm 2016/12/02 16:23:22 {}
Tom Sepez 2016/12/02 18:02:08 Done.
1020 return new CFX_TextStream(pSR, true); 1021 return new CFGAS_TextStream(pSR, true);
1021 } 1022 }
1022 return pSR; 1023 return pSR;
1023 } 1024 }
1024 int32_t CFX_TextStream::GetBOM(uint8_t bom[4]) const { 1025 int32_t CFGAS_TextStream::GetBOM(uint8_t bom[4]) const {
1025 if (m_wBOMLength < 1) { 1026 if (m_wBOMLength < 1) {
1026 return 0; 1027 return 0;
1027 } 1028 }
1028 *(uint32_t*)bom = m_dwBOM; 1029 *(uint32_t*)bom = m_dwBOM;
1029 return m_wBOMLength; 1030 return m_wBOMLength;
1030 } 1031 }
1031 uint16_t CFX_TextStream::SetCodePage(uint16_t wCodePage) { 1032 uint16_t CFGAS_TextStream::SetCodePage(uint16_t wCodePage) {
1032 if (m_wBOMLength > 0) { 1033 if (m_wBOMLength > 0) {
1033 return m_wCodePage; 1034 return m_wCodePage;
1034 } 1035 }
1035 uint16_t v = m_wCodePage; 1036 uint16_t v = m_wCodePage;
1036 m_wCodePage = wCodePage; 1037 m_wCodePage = wCodePage;
1037 return v; 1038 return v;
1038 } 1039 }
1039 int32_t CFX_TextStream::ReadString(FX_WCHAR* pStr, 1040 int32_t CFGAS_TextStream::ReadString(FX_WCHAR* pStr,
1040 int32_t iMaxLength, 1041 int32_t iMaxLength,
1041 bool& bEOS) { 1042 bool& bEOS) {
1042 ASSERT(pStr && iMaxLength > 0); 1043 ASSERT(pStr && iMaxLength > 0);
1043 if (!m_pStreamImp) { 1044 if (!m_pStreamImp) {
1044 return -1; 1045 return -1;
1045 } 1046 }
1046 int32_t iLen; 1047 int32_t iLen;
1047 if (m_wCodePage == FX_CODEPAGE_UTF16LE || 1048 if (m_wCodePage == FX_CODEPAGE_UTF16LE ||
1048 m_wCodePage == FX_CODEPAGE_UTF16BE) { 1049 m_wCodePage == FX_CODEPAGE_UTF16BE) {
1049 int32_t iBytes = iMaxLength * 2; 1050 int32_t iBytes = iMaxLength * 2;
1050 iLen = m_pStreamImp->ReadData((uint8_t*)pStr, iBytes); 1051 iLen = m_pStreamImp->ReadData((uint8_t*)pStr, iBytes);
1051 iMaxLength = iLen / 2; 1052 iMaxLength = iLen / 2;
(...skipping 29 matching lines...) Expand all
1081 if (iDecode < 1) { 1082 if (iDecode < 1) {
1082 return -1; 1083 return -1;
1083 } 1084 }
1084 } else { 1085 } else {
1085 iMaxLength = 0; 1086 iMaxLength = 0;
1086 } 1087 }
1087 } 1088 }
1088 bEOS = m_pStreamImp->IsEOF(); 1089 bEOS = m_pStreamImp->IsEOF();
1089 return iMaxLength; 1090 return iMaxLength;
1090 } 1091 }
1091 int32_t CFX_TextStream::WriteString(const FX_WCHAR* pStr, int32_t iLength) { 1092 int32_t CFGAS_TextStream::WriteString(const FX_WCHAR* pStr, int32_t iLength) {
1092 ASSERT(pStr && iLength > 0); 1093 ASSERT(pStr && iLength > 0);
1093 if ((m_pStreamImp->GetAccessModes() & FX_STREAMACCESS_Write) == 0) { 1094 if ((m_pStreamImp->GetAccessModes() & FX_STREAMACCESS_Write) == 0) {
1094 return -1; 1095 return -1;
1095 } 1096 }
1096 if (m_wCodePage == FX_CODEPAGE_UTF8) { 1097 if (m_wCodePage == FX_CODEPAGE_UTF8) {
1097 int32_t len = iLength; 1098 int32_t len = iLength;
1098 CFX_UTF8Encoder encoder; 1099 CFX_UTF8Encoder encoder;
1099 while (len-- > 0) { 1100 while (len-- > 0) {
1100 encoder.Input(*pStr++); 1101 encoder.Input(*pStr++);
1101 } 1102 }
1102 CFX_ByteStringC bsResult = encoder.GetResult(); 1103 CFX_ByteStringC bsResult = encoder.GetResult();
1103 m_pStreamImp->WriteData((const uint8_t*)bsResult.c_str(), 1104 m_pStreamImp->WriteData((const uint8_t*)bsResult.c_str(),
1104 bsResult.GetLength()); 1105 bsResult.GetLength());
1105 } 1106 }
1106 return iLength; 1107 return iLength;
1107 } 1108 }
1108 CFX_Stream::CFX_Stream() 1109 CFGAS_Stream::CFGAS_Stream()
1109 : m_eStreamType(FX_SREAMTYPE_Unknown), 1110 : m_eStreamType(FX_SREAMTYPE_Unknown),
1110 m_pStreamImp(nullptr), 1111 m_pStreamImp(nullptr),
1111 m_dwAccess(0), 1112 m_dwAccess(0),
1112 m_iTotalSize(0), 1113 m_iTotalSize(0),
1113 m_iPosition(0), 1114 m_iPosition(0),
1114 m_iStart(0), 1115 m_iStart(0),
1115 m_iLength(0), 1116 m_iLength(0),
1116 m_iRefCount(1) {} 1117 m_iRefCount(1) {}
1117 1118
1118 CFX_Stream::~CFX_Stream() { 1119 CFGAS_Stream::~CFGAS_Stream() {
1119 if (m_eStreamType != FX_STREAMTYPE_Stream) 1120 if (m_eStreamType != FX_STREAMTYPE_Stream)
1120 delete m_pStreamImp; 1121 delete m_pStreamImp;
1121 } 1122 }
1122 1123
1123 bool CFX_Stream::LoadFile(const FX_WCHAR* pszSrcFileName, uint32_t dwAccess) { 1124 bool CFGAS_Stream::LoadFile(const FX_WCHAR* pszSrcFileName, uint32_t dwAccess) {
1124 if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp) 1125 if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp)
1125 return false; 1126 return false;
1126 1127
1127 if (!pszSrcFileName || FXSYS_wcslen(pszSrcFileName) < 1) 1128 if (!pszSrcFileName || FXSYS_wcslen(pszSrcFileName) < 1)
1128 return false; 1129 return false;
1129 1130
1130 std::unique_ptr<CFX_FileStreamImp> pImp(new CFX_FileStreamImp()); 1131 std::unique_ptr<CFX_FileStreamImp> pImp(new CFX_FileStreamImp());
1131 if (!pImp->LoadFile(pszSrcFileName, dwAccess)) 1132 if (!pImp->LoadFile(pszSrcFileName, dwAccess))
1132 return false; 1133 return false;
1133 1134
1134 m_pStreamImp = pImp.release(); 1135 m_pStreamImp = pImp.release();
1135 m_eStreamType = FX_STREAMTYPE_File; 1136 m_eStreamType = FX_STREAMTYPE_File;
1136 m_dwAccess = dwAccess; 1137 m_dwAccess = dwAccess;
1137 m_iLength = m_pStreamImp->GetLength(); 1138 m_iLength = m_pStreamImp->GetLength();
1138 return true; 1139 return true;
1139 } 1140 }
1140 1141
1141 bool CFX_Stream::LoadFileRead(IFX_SeekableReadStream* pFileRead, 1142 bool CFGAS_Stream::LoadFileRead(IFX_SeekableReadStream* pFileRead,
1142 uint32_t dwAccess) { 1143 uint32_t dwAccess) {
1143 if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp) 1144 if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp)
1144 return false; 1145 return false;
1145 1146
1146 if (!pFileRead) 1147 if (!pFileRead)
1147 return false; 1148 return false;
1148 1149
1149 std::unique_ptr<CFX_FileReadStreamImp> pImp(new CFX_FileReadStreamImp()); 1150 std::unique_ptr<CFX_FileReadStreamImp> pImp(new CFX_FileReadStreamImp());
1150 if (!pImp->LoadFileRead(pFileRead, dwAccess)) 1151 if (!pImp->LoadFileRead(pFileRead, dwAccess))
1151 return false; 1152 return false;
1152 1153
1153 m_pStreamImp = pImp.release(); 1154 m_pStreamImp = pImp.release();
1154 m_eStreamType = FX_STREAMTYPE_File; 1155 m_eStreamType = FX_STREAMTYPE_File;
1155 m_dwAccess = dwAccess; 1156 m_dwAccess = dwAccess;
1156 m_iLength = m_pStreamImp->GetLength(); 1157 m_iLength = m_pStreamImp->GetLength();
1157 return true; 1158 return true;
1158 } 1159 }
1159 1160
1160 bool CFX_Stream::LoadFileWrite(IFX_SeekableWriteStream* pFileWrite, 1161 bool CFGAS_Stream::LoadFileWrite(IFX_SeekableWriteStream* pFileWrite,
1161 uint32_t dwAccess) { 1162 uint32_t dwAccess) {
1162 if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp) 1163 if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp)
1163 return false; 1164 return false;
1164 1165
1165 if (!pFileWrite) 1166 if (!pFileWrite)
1166 return false; 1167 return false;
1167 1168
1168 std::unique_ptr<CFX_FileWriteStreamImp> pImp(new CFX_FileWriteStreamImp()); 1169 std::unique_ptr<CFX_FileWriteStreamImp> pImp(new CFX_FileWriteStreamImp());
1169 if (!pImp->LoadFileWrite(pFileWrite, dwAccess)) 1170 if (!pImp->LoadFileWrite(pFileWrite, dwAccess))
1170 return false; 1171 return false;
1171 1172
1172 m_pStreamImp = pImp.release(); 1173 m_pStreamImp = pImp.release();
1173 m_eStreamType = FX_STREAMTYPE_File; 1174 m_eStreamType = FX_STREAMTYPE_File;
1174 m_dwAccess = dwAccess; 1175 m_dwAccess = dwAccess;
1175 m_iLength = m_pStreamImp->GetLength(); 1176 m_iLength = m_pStreamImp->GetLength();
1176 return true; 1177 return true;
1177 } 1178 }
1178 1179
1179 bool CFX_Stream::LoadBuffer(uint8_t* pData, 1180 bool CFGAS_Stream::LoadBuffer(uint8_t* pData,
1180 int32_t iTotalSize, 1181 int32_t iTotalSize,
1181 uint32_t dwAccess) { 1182 uint32_t dwAccess) {
1182 if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp) 1183 if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp)
1183 return false; 1184 return false;
1184 1185
1185 if (!pData || iTotalSize < 1) 1186 if (!pData || iTotalSize < 1)
1186 return false; 1187 return false;
1187 1188
1188 std::unique_ptr<CFX_BufferStreamImp> pImp(new CFX_BufferStreamImp()); 1189 std::unique_ptr<CFX_BufferStreamImp> pImp(new CFX_BufferStreamImp());
1189 if (!pImp->LoadBuffer(pData, iTotalSize, dwAccess)) 1190 if (!pImp->LoadBuffer(pData, iTotalSize, dwAccess))
1190 return false; 1191 return false;
1191 1192
1192 m_pStreamImp = pImp.release(); 1193 m_pStreamImp = pImp.release();
1193 m_eStreamType = FX_STREAMTYPE_Buffer; 1194 m_eStreamType = FX_STREAMTYPE_Buffer;
1194 m_dwAccess = dwAccess; 1195 m_dwAccess = dwAccess;
1195 m_iLength = m_pStreamImp->GetLength(); 1196 m_iLength = m_pStreamImp->GetLength();
1196 return true; 1197 return true;
1197 } 1198 }
1198 1199
1199 bool CFX_Stream::LoadBufferRead(IFX_BufferedReadStream* pBufferRead, 1200 bool CFGAS_Stream::LoadBufferRead(IFX_BufferedReadStream* pBufferRead,
1200 int32_t iFileSize, 1201 int32_t iFileSize,
1201 uint32_t dwAccess, 1202 uint32_t dwAccess,
1202 bool bReleaseBufferRead) { 1203 bool bReleaseBufferRead) {
1203 if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp) 1204 if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp)
1204 return false; 1205 return false;
1205 1206
1206 if (!pBufferRead) 1207 if (!pBufferRead)
1207 return false; 1208 return false;
1208 1209
1209 std::unique_ptr<CFX_BufferReadStreamImp> pImp(new CFX_BufferReadStreamImp); 1210 std::unique_ptr<CFX_BufferReadStreamImp> pImp(new CFX_BufferReadStreamImp);
1210 if (!pImp->LoadBufferRead(pBufferRead, iFileSize, dwAccess, 1211 if (!pImp->LoadBufferRead(pBufferRead, iFileSize, dwAccess,
1211 bReleaseBufferRead)) 1212 bReleaseBufferRead))
1212 return false; 1213 return false;
1213 1214
1214 m_pStreamImp = pImp.release(); 1215 m_pStreamImp = pImp.release();
1215 m_eStreamType = FX_STREAMTYPE_BufferRead; 1216 m_eStreamType = FX_STREAMTYPE_BufferRead;
1216 m_dwAccess = dwAccess; 1217 m_dwAccess = dwAccess;
1217 m_iLength = m_pStreamImp->GetLength(); 1218 m_iLength = m_pStreamImp->GetLength();
1218 return true; 1219 return true;
1219 } 1220 }
1220 1221
1221 void CFX_Stream::Release() { 1222 void CFGAS_Stream::Release() {
1222 if (--m_iRefCount < 1) { 1223 if (--m_iRefCount < 1) {
1223 delete this; 1224 delete this;
1224 } 1225 }
1225 } 1226 }
1226 IFX_Stream* CFX_Stream::Retain() { 1227 IFGAS_Stream* CFGAS_Stream::Retain() {
1227 m_iRefCount++; 1228 m_iRefCount++;
1228 return this; 1229 return this;
1229 } 1230 }
1230 1231
1231 uint32_t CFX_Stream::GetAccessModes() const { 1232 uint32_t CFGAS_Stream::GetAccessModes() const {
1232 return m_dwAccess; 1233 return m_dwAccess;
1233 } 1234 }
1234 1235
1235 int32_t CFX_Stream::GetLength() const { 1236 int32_t CFGAS_Stream::GetLength() const {
1236 if (!m_pStreamImp) { 1237 if (!m_pStreamImp) {
1237 return -1; 1238 return -1;
1238 } 1239 }
1239 if (m_eStreamType == FX_STREAMTYPE_File || 1240 if (m_eStreamType == FX_STREAMTYPE_File ||
1240 m_eStreamType == FX_STREAMTYPE_Buffer) { 1241 m_eStreamType == FX_STREAMTYPE_Buffer) {
1241 return m_pStreamImp->GetLength(); 1242 return m_pStreamImp->GetLength();
1242 } 1243 }
1243 return m_iLength; 1244 return m_iLength;
1244 } 1245 }
1245 int32_t CFX_Stream::Seek(FX_STREAMSEEK eSeek, int32_t iOffset) { 1246 int32_t CFGAS_Stream::Seek(FX_STREAMSEEK eSeek, int32_t iOffset) {
1246 if (!m_pStreamImp) { 1247 if (!m_pStreamImp) {
1247 return -1; 1248 return -1;
1248 } 1249 }
1249 if (m_eStreamType == FX_STREAMTYPE_File || 1250 if (m_eStreamType == FX_STREAMTYPE_File ||
1250 m_eStreamType == FX_STREAMTYPE_Buffer) { 1251 m_eStreamType == FX_STREAMTYPE_Buffer) {
1251 return m_iPosition = m_pStreamImp->Seek(eSeek, iOffset); 1252 return m_iPosition = m_pStreamImp->Seek(eSeek, iOffset);
1252 } 1253 }
1253 int32_t iEnd = m_iStart + m_iLength; 1254 int32_t iEnd = m_iStart + m_iLength;
1254 int32_t iPosition = m_iStart + iOffset; 1255 int32_t iPosition = m_iStart + iOffset;
1255 if (eSeek == FX_STREAMSEEK_Begin) { 1256 if (eSeek == FX_STREAMSEEK_Begin) {
1256 m_iPosition = iPosition; 1257 m_iPosition = iPosition;
1257 } else if (eSeek == FX_STREAMSEEK_Current) { 1258 } else if (eSeek == FX_STREAMSEEK_Current) {
1258 m_iPosition += iOffset; 1259 m_iPosition += iOffset;
1259 } else if (eSeek == FX_STREAMSEEK_End) { 1260 } else if (eSeek == FX_STREAMSEEK_End) {
1260 m_iPosition = iEnd + iOffset; 1261 m_iPosition = iEnd + iOffset;
1261 } 1262 }
1262 if (m_iPosition > iEnd) { 1263 if (m_iPosition > iEnd) {
1263 m_iPosition = iEnd; 1264 m_iPosition = iEnd;
1264 } 1265 }
1265 if (m_iPosition < m_iStart) { 1266 if (m_iPosition < m_iStart) {
1266 m_iPosition = m_iStart; 1267 m_iPosition = m_iStart;
1267 } 1268 }
1268 return m_iPosition - m_iStart; 1269 return m_iPosition - m_iStart;
1269 } 1270 }
1270 int32_t CFX_Stream::GetPosition() { 1271 int32_t CFGAS_Stream::GetPosition() {
1271 if (!m_pStreamImp) { 1272 if (!m_pStreamImp) {
1272 return -1; 1273 return -1;
1273 } 1274 }
1274 if (m_eStreamType == FX_STREAMTYPE_File || 1275 if (m_eStreamType == FX_STREAMTYPE_File ||
1275 m_eStreamType == FX_STREAMTYPE_Buffer) { 1276 m_eStreamType == FX_STREAMTYPE_Buffer) {
1276 return m_iPosition = m_pStreamImp->GetPosition(); 1277 return m_iPosition = m_pStreamImp->GetPosition();
1277 } 1278 }
1278 return m_iPosition - m_iStart; 1279 return m_iPosition - m_iStart;
1279 } 1280 }
1280 bool CFX_Stream::IsEOF() const { 1281 bool CFGAS_Stream::IsEOF() const {
1281 if (!m_pStreamImp) { 1282 if (!m_pStreamImp) {
1282 return true; 1283 return true;
1283 } 1284 }
1284 if (m_eStreamType == FX_STREAMTYPE_File || 1285 if (m_eStreamType == FX_STREAMTYPE_File ||
1285 m_eStreamType == FX_STREAMTYPE_Buffer) { 1286 m_eStreamType == FX_STREAMTYPE_Buffer) {
1286 return m_pStreamImp->IsEOF(); 1287 return m_pStreamImp->IsEOF();
1287 } 1288 }
1288 return m_iPosition >= m_iStart + m_iLength; 1289 return m_iPosition >= m_iStart + m_iLength;
1289 } 1290 }
1290 int32_t CFX_Stream::ReadData(uint8_t* pBuffer, int32_t iBufferSize) { 1291 int32_t CFGAS_Stream::ReadData(uint8_t* pBuffer, int32_t iBufferSize) {
1291 ASSERT(pBuffer && iBufferSize > 0); 1292 ASSERT(pBuffer && iBufferSize > 0);
1292 if (!m_pStreamImp) { 1293 if (!m_pStreamImp) {
1293 return -1; 1294 return -1;
1294 } 1295 }
1295 int32_t iLen = std::min(m_iStart + m_iLength - m_iPosition, iBufferSize); 1296 int32_t iLen = std::min(m_iStart + m_iLength - m_iPosition, iBufferSize);
1296 if (iLen <= 0) { 1297 if (iLen <= 0) {
1297 return 0; 1298 return 0;
1298 } 1299 }
1299 if (m_pStreamImp->GetPosition() != m_iPosition) { 1300 if (m_pStreamImp->GetPosition() != m_iPosition) {
1300 m_pStreamImp->Seek(FX_STREAMSEEK_Begin, m_iPosition); 1301 m_pStreamImp->Seek(FX_STREAMSEEK_Begin, m_iPosition);
1301 } 1302 }
1302 iLen = m_pStreamImp->ReadData(pBuffer, iLen); 1303 iLen = m_pStreamImp->ReadData(pBuffer, iLen);
1303 m_iPosition = m_pStreamImp->GetPosition(); 1304 m_iPosition = m_pStreamImp->GetPosition();
1304 return iLen; 1305 return iLen;
1305 } 1306 }
1306 int32_t CFX_Stream::ReadString(FX_WCHAR* pStr, int32_t iMaxLength, bool& bEOS) { 1307 int32_t CFGAS_Stream::ReadString(FX_WCHAR* pStr,
1308 int32_t iMaxLength,
1309 bool& bEOS) {
1307 ASSERT(pStr && iMaxLength > 0); 1310 ASSERT(pStr && iMaxLength > 0);
1308 if (!m_pStreamImp) { 1311 if (!m_pStreamImp) {
1309 return -1; 1312 return -1;
1310 } 1313 }
1311 int32_t iEnd = m_iStart + m_iLength; 1314 int32_t iEnd = m_iStart + m_iLength;
1312 int32_t iLen = iEnd - m_iPosition; 1315 int32_t iLen = iEnd - m_iPosition;
1313 iLen = std::min(iEnd / 2, iMaxLength); 1316 iLen = std::min(iEnd / 2, iMaxLength);
1314 if (iLen <= 0) { 1317 if (iLen <= 0) {
1315 return 0; 1318 return 0;
1316 } 1319 }
1317 if (m_pStreamImp->GetPosition() != m_iPosition) { 1320 if (m_pStreamImp->GetPosition() != m_iPosition) {
1318 m_pStreamImp->Seek(FX_STREAMSEEK_Begin, m_iPosition); 1321 m_pStreamImp->Seek(FX_STREAMSEEK_Begin, m_iPosition);
1319 } 1322 }
1320 iLen = m_pStreamImp->ReadString(pStr, iLen, bEOS); 1323 iLen = m_pStreamImp->ReadString(pStr, iLen, bEOS);
1321 m_iPosition = m_pStreamImp->GetPosition(); 1324 m_iPosition = m_pStreamImp->GetPosition();
1322 if (iLen > 0 && m_iPosition >= iEnd) { 1325 if (iLen > 0 && m_iPosition >= iEnd) {
1323 bEOS = true; 1326 bEOS = true;
1324 } 1327 }
1325 return iLen; 1328 return iLen;
1326 } 1329 }
1327 1330
1328 int32_t CFX_Stream::WriteData(const uint8_t* pBuffer, int32_t iBufferSize) { 1331 int32_t CFGAS_Stream::WriteData(const uint8_t* pBuffer, int32_t iBufferSize) {
1329 ASSERT(pBuffer && iBufferSize > 0); 1332 ASSERT(pBuffer && iBufferSize > 0);
1330 if (!m_pStreamImp) { 1333 if (!m_pStreamImp) {
1331 return -1; 1334 return -1;
1332 } 1335 }
1333 if ((m_dwAccess & FX_STREAMACCESS_Write) == 0) { 1336 if ((m_dwAccess & FX_STREAMACCESS_Write) == 0) {
1334 return -1; 1337 return -1;
1335 } 1338 }
1336 int32_t iLen = iBufferSize; 1339 int32_t iLen = iBufferSize;
1337 if (m_eStreamType == FX_STREAMTYPE_Stream) { 1340 if (m_eStreamType == FX_STREAMTYPE_Stream) {
1338 iLen = std::min(m_iStart + m_iTotalSize - m_iPosition, iBufferSize); 1341 iLen = std::min(m_iStart + m_iTotalSize - m_iPosition, iBufferSize);
1339 if (iLen <= 0) { 1342 if (iLen <= 0) {
1340 return 0; 1343 return 0;
1341 } 1344 }
1342 } 1345 }
1343 int32_t iEnd = m_iStart + m_iLength; 1346 int32_t iEnd = m_iStart + m_iLength;
1344 if (m_pStreamImp->GetPosition() != m_iPosition) { 1347 if (m_pStreamImp->GetPosition() != m_iPosition) {
1345 m_pStreamImp->Seek(FX_STREAMSEEK_Begin, m_iPosition); 1348 m_pStreamImp->Seek(FX_STREAMSEEK_Begin, m_iPosition);
1346 } 1349 }
1347 iLen = m_pStreamImp->WriteData(pBuffer, iLen); 1350 iLen = m_pStreamImp->WriteData(pBuffer, iLen);
1348 m_iPosition = m_pStreamImp->GetPosition(); 1351 m_iPosition = m_pStreamImp->GetPosition();
1349 if (m_iPosition > iEnd) { 1352 if (m_iPosition > iEnd) {
1350 m_iLength = m_iPosition - m_iStart; 1353 m_iLength = m_iPosition - m_iStart;
1351 } 1354 }
1352 return iLen; 1355 return iLen;
1353 } 1356 }
1354 int32_t CFX_Stream::WriteString(const FX_WCHAR* pStr, int32_t iLength) { 1357 int32_t CFGAS_Stream::WriteString(const FX_WCHAR* pStr, int32_t iLength) {
1355 ASSERT(pStr && iLength > 0); 1358 ASSERT(pStr && iLength > 0);
1356 if (!m_pStreamImp) { 1359 if (!m_pStreamImp) {
1357 return -1; 1360 return -1;
1358 } 1361 }
1359 if ((m_dwAccess & FX_STREAMACCESS_Write) == 0) { 1362 if ((m_dwAccess & FX_STREAMACCESS_Write) == 0) {
1360 return -1; 1363 return -1;
1361 } 1364 }
1362 int32_t iLen = iLength; 1365 int32_t iLen = iLength;
1363 if (m_eStreamType == FX_STREAMTYPE_Stream) { 1366 if (m_eStreamType == FX_STREAMTYPE_Stream) {
1364 iLen = std::min((m_iStart + m_iTotalSize - m_iPosition) / 2, iLength); 1367 iLen = std::min((m_iStart + m_iTotalSize - m_iPosition) / 2, iLength);
1365 if (iLen <= 0) { 1368 if (iLen <= 0) {
1366 return 0; 1369 return 0;
1367 } 1370 }
1368 } 1371 }
1369 int32_t iEnd = m_iStart + m_iLength; 1372 int32_t iEnd = m_iStart + m_iLength;
1370 if (m_pStreamImp->GetPosition() != m_iPosition) { 1373 if (m_pStreamImp->GetPosition() != m_iPosition) {
1371 m_pStreamImp->Seek(FX_STREAMSEEK_Begin, m_iPosition); 1374 m_pStreamImp->Seek(FX_STREAMSEEK_Begin, m_iPosition);
1372 } 1375 }
1373 iLen = m_pStreamImp->WriteString(pStr, iLen); 1376 iLen = m_pStreamImp->WriteString(pStr, iLen);
1374 m_iPosition = m_pStreamImp->GetPosition(); 1377 m_iPosition = m_pStreamImp->GetPosition();
1375 if (m_iPosition > iEnd) { 1378 if (m_iPosition > iEnd) {
1376 m_iLength = m_iPosition - m_iStart; 1379 m_iLength = m_iPosition - m_iStart;
1377 } 1380 }
1378 return iLen; 1381 return iLen;
1379 } 1382 }
1380 void CFX_Stream::Flush() { 1383 void CFGAS_Stream::Flush() {
1381 if (!m_pStreamImp) { 1384 if (!m_pStreamImp) {
1382 return; 1385 return;
1383 } 1386 }
1384 if ((m_dwAccess & FX_STREAMACCESS_Write) == 0) { 1387 if ((m_dwAccess & FX_STREAMACCESS_Write) == 0) {
1385 return; 1388 return;
1386 } 1389 }
1387 m_pStreamImp->Flush(); 1390 m_pStreamImp->Flush();
1388 } 1391 }
1389 bool CFX_Stream::SetLength(int32_t iLength) { 1392 bool CFGAS_Stream::SetLength(int32_t iLength) {
1390 if (!m_pStreamImp) { 1393 if (!m_pStreamImp) {
1391 return false; 1394 return false;
1392 } 1395 }
1393 if ((m_dwAccess & FX_STREAMACCESS_Write) == 0) { 1396 if ((m_dwAccess & FX_STREAMACCESS_Write) == 0) {
1394 return false; 1397 return false;
1395 } 1398 }
1396 return m_pStreamImp->SetLength(iLength); 1399 return m_pStreamImp->SetLength(iLength);
1397 } 1400 }
1398 int32_t CFX_Stream::GetBOM(uint8_t bom[4]) const { 1401 int32_t CFGAS_Stream::GetBOM(uint8_t bom[4]) const {
1399 if (!m_pStreamImp) { 1402 if (!m_pStreamImp) {
1400 return -1; 1403 return -1;
1401 } 1404 }
1402 return 0; 1405 return 0;
1403 } 1406 }
1404 uint16_t CFX_Stream::GetCodePage() const { 1407 uint16_t CFGAS_Stream::GetCodePage() const {
1405 #if _FX_ENDIAN_ == _FX_LITTLE_ENDIAN_ 1408 #if _FX_ENDIAN_ == _FX_LITTLE_ENDIAN_
1406 return FX_CODEPAGE_UTF16LE; 1409 return FX_CODEPAGE_UTF16LE;
1407 #else 1410 #else
1408 return FX_CODEPAGE_UTF16BE; 1411 return FX_CODEPAGE_UTF16BE;
1409 #endif 1412 #endif
1410 } 1413 }
1411 uint16_t CFX_Stream::SetCodePage(uint16_t wCodePage) { 1414 uint16_t CFGAS_Stream::SetCodePage(uint16_t wCodePage) {
1412 #if _FX_ENDIAN_ == _FX_LITTLE_ENDIAN_ 1415 #if _FX_ENDIAN_ == _FX_LITTLE_ENDIAN_
1413 return FX_CODEPAGE_UTF16LE; 1416 return FX_CODEPAGE_UTF16LE;
1414 #else 1417 #else
1415 return FX_CODEPAGE_UTF16BE; 1418 return FX_CODEPAGE_UTF16BE;
1416 #endif 1419 #endif
1417 } 1420 }
1418 IFX_Stream* CFX_Stream::CreateSharedStream(uint32_t dwAccess, 1421 IFGAS_Stream* CFGAS_Stream::CreateSharedStream(uint32_t dwAccess,
1419 int32_t iOffset, 1422 int32_t iOffset,
1420 int32_t iLength) { 1423 int32_t iLength) {
1421 ASSERT(iLength > 0); 1424 ASSERT(iLength > 0);
1422 if (!m_pStreamImp) { 1425 if (!m_pStreamImp) {
1423 return nullptr; 1426 return nullptr;
1424 } 1427 }
1425 if ((m_dwAccess & FX_STREAMACCESS_Text) != 0 && 1428 if ((m_dwAccess & FX_STREAMACCESS_Text) != 0 &&
1426 (dwAccess & FX_STREAMACCESS_Text) == 0) { 1429 (dwAccess & FX_STREAMACCESS_Text) == 0) {
1427 return nullptr; 1430 return nullptr;
1428 } 1431 }
1429 if ((m_dwAccess & FX_STREAMACCESS_Write) == 0 && 1432 if ((m_dwAccess & FX_STREAMACCESS_Write) == 0 &&
1430 (dwAccess & FX_STREAMACCESS_Write) != 0) { 1433 (dwAccess & FX_STREAMACCESS_Write) != 0) {
1431 return nullptr; 1434 return nullptr;
1432 } 1435 }
1433 int32_t iStart = m_iStart + iOffset; 1436 int32_t iStart = m_iStart + iOffset;
1434 int32_t iTotal = m_iStart + m_iLength; 1437 int32_t iTotal = m_iStart + m_iLength;
1435 if (iStart < m_iStart || iStart >= iTotal) { 1438 if (iStart < m_iStart || iStart >= iTotal) {
1436 return nullptr; 1439 return nullptr;
1437 } 1440 }
1438 int32_t iEnd = iStart + iLength; 1441 int32_t iEnd = iStart + iLength;
1439 if (iEnd < iStart || iEnd > iTotal) { 1442 if (iEnd < iStart || iEnd > iTotal) {
1440 return nullptr; 1443 return nullptr;
1441 } 1444 }
1442 CFX_Stream* pShared = new CFX_Stream; 1445 CFGAS_Stream* pShared = new CFGAS_Stream;
1443 pShared->m_eStreamType = FX_STREAMTYPE_Stream; 1446 pShared->m_eStreamType = FX_STREAMTYPE_Stream;
1444 pShared->m_pStreamImp = m_pStreamImp; 1447 pShared->m_pStreamImp = m_pStreamImp;
1445 pShared->m_dwAccess = dwAccess; 1448 pShared->m_dwAccess = dwAccess;
1446 pShared->m_iTotalSize = iLength; 1449 pShared->m_iTotalSize = iLength;
1447 pShared->m_iPosition = iStart; 1450 pShared->m_iPosition = iStart;
1448 pShared->m_iStart = iStart; 1451 pShared->m_iStart = iStart;
1449 pShared->m_iLength = (dwAccess & FX_STREAMACCESS_Write) != 0 ? 0 : iLength; 1452 pShared->m_iLength = (dwAccess & FX_STREAMACCESS_Write) != 0 ? 0 : iLength;
1450 if (dwAccess & FX_STREAMACCESS_Text) { 1453 if (dwAccess & FX_STREAMACCESS_Text) {
1451 return IFX_Stream::CreateTextStream(pShared, true); 1454 return IFGAS_Stream::CreateTextStream(pShared, true);
npm 2016/12/02 16:23:22 {}
Tom Sepez 2016/12/02 18:02:08 Done.
1452 } 1455 }
1453 return pShared; 1456 return pShared;
1454 } 1457 }
1455 1458
1456 IFX_SeekableReadStream* IFX_Stream::MakeSeekableReadStream() { 1459 IFX_SeekableReadStream* IFGAS_Stream::MakeSeekableReadStream() {
1457 return new CFGAS_FileRead(this, false); 1460 return new CFGAS_FileRead(this, false);
1458 } 1461 }
1459 1462
1460 CFGAS_FileRead::CFGAS_FileRead(IFX_Stream* pStream, bool bReleaseStream) 1463 CFGAS_FileRead::CFGAS_FileRead(IFGAS_Stream* pStream, bool bReleaseStream)
1461 : m_bReleaseStream(bReleaseStream), m_pStream(pStream) { 1464 : m_bReleaseStream(bReleaseStream), m_pStream(pStream) {
1462 ASSERT(m_pStream); 1465 ASSERT(m_pStream);
1463 } 1466 }
1464 CFGAS_FileRead::~CFGAS_FileRead() { 1467 CFGAS_FileRead::~CFGAS_FileRead() {
1465 if (m_bReleaseStream) { 1468 if (m_bReleaseStream) {
1466 m_pStream->Release(); 1469 m_pStream->Release();
1467 } 1470 }
1468 } 1471 }
1469 FX_FILESIZE CFGAS_FileRead::GetSize() { 1472 FX_FILESIZE CFGAS_FileRead::GetSize() {
1470 return (FX_FILESIZE)m_pStream->GetLength(); 1473 return (FX_FILESIZE)m_pStream->GetLength();
1471 } 1474 }
1472 1475
1473 bool CFGAS_FileRead::ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) { 1476 bool CFGAS_FileRead::ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) {
1474 m_pStream->Seek(FX_STREAMSEEK_Begin, (int32_t)offset); 1477 m_pStream->Seek(FX_STREAMSEEK_Begin, (int32_t)offset);
1475 int32_t iLen = m_pStream->ReadData((uint8_t*)buffer, (int32_t)size); 1478 int32_t iLen = m_pStream->ReadData((uint8_t*)buffer, (int32_t)size);
1476 return iLen == (int32_t)size; 1479 return iLen == (int32_t)size;
1477 } 1480 }
1478 1481
1479 void CFGAS_FileRead::Release() { 1482 void CFGAS_FileRead::Release() {
1480 delete this; 1483 delete this;
1481 } 1484 }
OLDNEW
« no previous file with comments | « xfa/fgas/crt/fgas_stream.h ('k') | xfa/fgas/font/cfgas_gefont.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698