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_ |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 virtual IFX_Stream* Retain(); | 218 virtual IFX_Stream* Retain(); |
219 virtual uint32_t GetAccessModes() const { return m_dwAccess; } | 219 virtual uint32_t GetAccessModes() const { return m_dwAccess; } |
220 virtual int32_t GetLength() const; | 220 virtual int32_t GetLength() const; |
221 virtual int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset); | 221 virtual int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset); |
222 virtual int32_t GetPosition(); | 222 virtual int32_t GetPosition(); |
223 virtual FX_BOOL IsEOF() const; | 223 virtual FX_BOOL IsEOF() const; |
224 virtual int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize); | 224 virtual int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize); |
225 virtual int32_t ReadString(FX_WCHAR* pStr, | 225 virtual int32_t ReadString(FX_WCHAR* pStr, |
226 int32_t iMaxLength, | 226 int32_t iMaxLength, |
227 FX_BOOL& bEOS, | 227 FX_BOOL& bEOS, |
228 int32_t const* pByteSize = NULL); | 228 int32_t const* pByteSize = nullptr); |
229 virtual int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize); | 229 virtual int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize); |
230 virtual int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength); | 230 virtual int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength); |
231 virtual void Flush(); | 231 virtual void Flush(); |
232 virtual FX_BOOL SetLength(int32_t iLength); | 232 virtual FX_BOOL SetLength(int32_t iLength); |
233 virtual int32_t GetBOM(uint8_t bom[4]) const; | 233 virtual int32_t GetBOM(uint8_t bom[4]) const; |
234 virtual uint16_t GetCodePage() const; | 234 virtual uint16_t GetCodePage() const; |
235 virtual uint16_t SetCodePage(uint16_t wCodePage); | 235 virtual uint16_t SetCodePage(uint16_t wCodePage); |
236 virtual IFX_Stream* CreateSharedStream(uint32_t dwAccess, | 236 virtual IFX_Stream* CreateSharedStream(uint32_t dwAccess, |
237 int32_t iOffset, | 237 int32_t iOffset, |
238 int32_t iLength); | 238 int32_t iLength); |
(...skipping 19 matching lines...) Expand all Loading... |
258 virtual uint32_t GetAccessModes() const; | 258 virtual uint32_t GetAccessModes() const; |
259 virtual int32_t GetLength() const; | 259 virtual int32_t GetLength() const; |
260 virtual int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset); | 260 virtual int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset); |
261 virtual int32_t GetPosition(); | 261 virtual int32_t GetPosition(); |
262 virtual FX_BOOL IsEOF() const; | 262 virtual FX_BOOL IsEOF() const; |
263 | 263 |
264 virtual int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize); | 264 virtual int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize); |
265 virtual int32_t ReadString(FX_WCHAR* pStr, | 265 virtual int32_t ReadString(FX_WCHAR* pStr, |
266 int32_t iMaxLength, | 266 int32_t iMaxLength, |
267 FX_BOOL& bEOS, | 267 FX_BOOL& bEOS, |
268 int32_t const* pByteSize = NULL); | 268 int32_t const* pByteSize = nullptr); |
269 virtual int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize); | 269 virtual int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize); |
270 virtual int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength); | 270 virtual int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength); |
271 virtual void Flush(); | 271 virtual void Flush(); |
272 virtual FX_BOOL SetLength(int32_t iLength); | 272 virtual FX_BOOL SetLength(int32_t iLength); |
273 | 273 |
274 virtual int32_t GetBOM(uint8_t bom[4]) const; | 274 virtual int32_t GetBOM(uint8_t bom[4]) const; |
275 virtual uint16_t GetCodePage() const; | 275 virtual uint16_t GetCodePage() const; |
276 virtual uint16_t SetCodePage(uint16_t wCodePage); | 276 virtual uint16_t SetCodePage(uint16_t wCodePage); |
277 | 277 |
278 virtual IFX_Stream* CreateSharedStream(uint32_t dwAccess, | 278 virtual IFX_Stream* CreateSharedStream(uint32_t dwAccess, |
(...skipping 19 matching lines...) Expand all Loading... |
298 virtual void Release() { delete this; } | 298 virtual void Release() { delete this; } |
299 virtual FX_FILESIZE GetSize(); | 299 virtual FX_FILESIZE GetSize(); |
300 virtual FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offset, size_t size); | 300 virtual FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offset, size_t size); |
301 | 301 |
302 protected: | 302 protected: |
303 FX_BOOL m_bReleaseStream; | 303 FX_BOOL m_bReleaseStream; |
304 IFX_Stream* m_pStream; | 304 IFX_Stream* m_pStream; |
305 }; | 305 }; |
306 | 306 |
307 int32_t FileLength(FXSYS_FILE* file) { | 307 int32_t FileLength(FXSYS_FILE* file) { |
308 ASSERT(file != NULL); | 308 ASSERT(file); |
309 #if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN64_ | 309 #if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN64_ |
310 return _filelength(_fileno(file)); | 310 return _filelength(_fileno(file)); |
311 #else | 311 #else |
312 int32_t iPos = FXSYS_ftell(file); | 312 int32_t iPos = FXSYS_ftell(file); |
313 FXSYS_fseek(file, 0, FXSYS_SEEK_END); | 313 FXSYS_fseek(file, 0, FXSYS_SEEK_END); |
314 int32_t iLen = FXSYS_ftell(file); | 314 int32_t iLen = FXSYS_ftell(file); |
315 FXSYS_fseek(file, iPos, FXSYS_SEEK_SET); | 315 FXSYS_fseek(file, iPos, FXSYS_SEEK_SET); |
316 return iLen; | 316 return iLen; |
317 #endif | 317 #endif |
318 } | 318 } |
319 | 319 |
320 FX_BOOL FileSetSize(FXSYS_FILE* file, int32_t size) { | 320 FX_BOOL FileSetSize(FXSYS_FILE* file, int32_t size) { |
321 ASSERT(file != NULL); | 321 ASSERT(file); |
322 #if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN64_ | 322 #if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN64_ |
323 return _chsize(_fileno(file), size) == 0; | 323 return _chsize(_fileno(file), size) == 0; |
324 #elif _FX_OS_ == _FX_WIN32_MOBILE_ | 324 #elif _FX_OS_ == _FX_WIN32_MOBILE_ |
325 HANDLE hFile = _fileno(file); | 325 HANDLE hFile = _fileno(file); |
326 uint32_t dwPos = ::SetFilePointer(hFile, 0, 0, FILE_CURRENT); | 326 uint32_t dwPos = ::SetFilePointer(hFile, 0, 0, FILE_CURRENT); |
327 ::SetFilePointer(hFile, size, 0, FILE_BEGIN); | 327 ::SetFilePointer(hFile, size, 0, FILE_BEGIN); |
328 FX_BOOL bRet = ::SetEndOfFile(hFile); | 328 FX_BOOL bRet = ::SetEndOfFile(hFile); |
329 ::SetFilePointer(hFile, (int32_t)dwPos, 0, FILE_BEGIN); | 329 ::SetFilePointer(hFile, (int32_t)dwPos, 0, FILE_BEGIN); |
330 return bRet; | 330 return bRet; |
331 #else | 331 #else |
332 return FALSE; | 332 return FALSE; |
333 #endif | 333 #endif |
334 } | 334 } |
335 | 335 |
336 } // namespace | 336 } // namespace |
337 | 337 |
338 IFX_Stream* IFX_Stream::CreateStream(IFX_BufferRead* pBufferRead, | 338 IFX_Stream* IFX_Stream::CreateStream(IFX_BufferRead* pBufferRead, |
339 uint32_t dwAccess, | 339 uint32_t dwAccess, |
340 int32_t iFileSize, | 340 int32_t iFileSize, |
341 FX_BOOL bReleaseBufferRead) { | 341 FX_BOOL bReleaseBufferRead) { |
342 CFX_Stream* pSR = new CFX_Stream; | 342 CFX_Stream* pSR = new CFX_Stream; |
343 if (!pSR->LoadBufferRead(pBufferRead, iFileSize, dwAccess, | 343 if (!pSR->LoadBufferRead(pBufferRead, iFileSize, dwAccess, |
344 bReleaseBufferRead)) { | 344 bReleaseBufferRead)) { |
345 pSR->Release(); | 345 pSR->Release(); |
346 return NULL; | 346 return nullptr; |
347 } | 347 } |
348 if (dwAccess & FX_STREAMACCESS_Text) { | 348 if (dwAccess & FX_STREAMACCESS_Text) { |
349 return new CFX_TextStream(pSR, TRUE); | 349 return new CFX_TextStream(pSR, TRUE); |
350 } | 350 } |
351 return pSR; | 351 return pSR; |
352 } | 352 } |
353 IFX_Stream* IFX_Stream::CreateStream(IFX_FileRead* pFileRead, | 353 IFX_Stream* IFX_Stream::CreateStream(IFX_FileRead* pFileRead, |
354 uint32_t dwAccess) { | 354 uint32_t dwAccess) { |
355 CFX_Stream* pSR = new CFX_Stream; | 355 CFX_Stream* pSR = new CFX_Stream; |
356 if (!pSR->LoadFileRead(pFileRead, dwAccess)) { | 356 if (!pSR->LoadFileRead(pFileRead, dwAccess)) { |
357 pSR->Release(); | 357 pSR->Release(); |
358 return NULL; | 358 return nullptr; |
359 } | 359 } |
360 if (dwAccess & FX_STREAMACCESS_Text) { | 360 if (dwAccess & FX_STREAMACCESS_Text) { |
361 return new CFX_TextStream(pSR, TRUE); | 361 return new CFX_TextStream(pSR, TRUE); |
362 } | 362 } |
363 return pSR; | 363 return pSR; |
364 } | 364 } |
365 IFX_Stream* IFX_Stream::CreateStream(IFX_FileWrite* pFileWrite, | 365 IFX_Stream* IFX_Stream::CreateStream(IFX_FileWrite* pFileWrite, |
366 uint32_t dwAccess) { | 366 uint32_t dwAccess) { |
367 CFX_Stream* pSR = new CFX_Stream; | 367 CFX_Stream* pSR = new CFX_Stream; |
368 if (!pSR->LoadFileWrite(pFileWrite, dwAccess)) { | 368 if (!pSR->LoadFileWrite(pFileWrite, dwAccess)) { |
369 pSR->Release(); | 369 pSR->Release(); |
370 return NULL; | 370 return nullptr; |
371 } | 371 } |
372 if (dwAccess & FX_STREAMACCESS_Text) { | 372 if (dwAccess & FX_STREAMACCESS_Text) { |
373 return new CFX_TextStream(pSR, TRUE); | 373 return new CFX_TextStream(pSR, TRUE); |
374 } | 374 } |
375 return pSR; | 375 return pSR; |
376 } | 376 } |
377 IFX_Stream* IFX_Stream::CreateStream(const FX_WCHAR* pszFileName, | 377 IFX_Stream* IFX_Stream::CreateStream(const FX_WCHAR* pszFileName, |
378 uint32_t dwAccess) { | 378 uint32_t dwAccess) { |
379 CFX_Stream* pSR = new CFX_Stream; | 379 CFX_Stream* pSR = new CFX_Stream; |
380 if (!pSR->LoadFile(pszFileName, dwAccess)) { | 380 if (!pSR->LoadFile(pszFileName, dwAccess)) { |
381 pSR->Release(); | 381 pSR->Release(); |
382 return NULL; | 382 return nullptr; |
383 } | 383 } |
384 if (dwAccess & FX_STREAMACCESS_Text) { | 384 if (dwAccess & FX_STREAMACCESS_Text) { |
385 return new CFX_TextStream(pSR, TRUE); | 385 return new CFX_TextStream(pSR, TRUE); |
386 } | 386 } |
387 return pSR; | 387 return pSR; |
388 } | 388 } |
389 IFX_Stream* IFX_Stream::CreateStream(uint8_t* pData, | 389 IFX_Stream* IFX_Stream::CreateStream(uint8_t* pData, |
390 int32_t length, | 390 int32_t length, |
391 uint32_t dwAccess) { | 391 uint32_t dwAccess) { |
392 CFX_Stream* pSR = new CFX_Stream; | 392 CFX_Stream* pSR = new CFX_Stream; |
393 if (!pSR->LoadBuffer(pData, length, dwAccess)) { | 393 if (!pSR->LoadBuffer(pData, length, dwAccess)) { |
394 pSR->Release(); | 394 pSR->Release(); |
395 return NULL; | 395 return nullptr; |
396 } | 396 } |
397 if (dwAccess & FX_STREAMACCESS_Text) { | 397 if (dwAccess & FX_STREAMACCESS_Text) { |
398 return new CFX_TextStream(pSR, TRUE); | 398 return new CFX_TextStream(pSR, TRUE); |
399 } | 399 } |
400 return pSR; | 400 return pSR; |
401 } | 401 } |
402 | 402 |
403 IFX_StreamImp::IFX_StreamImp() : m_dwAccess(0) {} | 403 IFX_StreamImp::IFX_StreamImp() : m_dwAccess(0) {} |
404 | 404 |
405 CFX_FileStreamImp::CFX_FileStreamImp() : m_hFile(nullptr), m_iLength(0) {} | 405 CFX_FileStreamImp::CFX_FileStreamImp() : m_hFile(nullptr), m_iLength(0) {} |
406 | 406 |
407 CFX_FileStreamImp::~CFX_FileStreamImp() { | 407 CFX_FileStreamImp::~CFX_FileStreamImp() { |
408 if (m_hFile) | 408 if (m_hFile) |
409 FXSYS_fclose(m_hFile); | 409 FXSYS_fclose(m_hFile); |
410 } | 410 } |
411 | 411 |
412 FX_BOOL CFX_FileStreamImp::LoadFile(const FX_WCHAR* pszSrcFileName, | 412 FX_BOOL CFX_FileStreamImp::LoadFile(const FX_WCHAR* pszSrcFileName, |
413 uint32_t dwAccess) { | 413 uint32_t dwAccess) { |
414 ASSERT(m_hFile == NULL); | 414 ASSERT(!m_hFile); |
415 ASSERT(pszSrcFileName != NULL && FXSYS_wcslen(pszSrcFileName) > 0); | 415 ASSERT(pszSrcFileName && FXSYS_wcslen(pszSrcFileName) > 0); |
416 #if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN32_MOBILE_ || \ | 416 #if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN32_MOBILE_ || \ |
417 _FX_OS_ == _FX_WIN64_ | 417 _FX_OS_ == _FX_WIN64_ |
418 const FX_WCHAR* wsMode; | 418 const FX_WCHAR* wsMode; |
419 if (dwAccess & FX_STREAMACCESS_Write) { | 419 if (dwAccess & FX_STREAMACCESS_Write) { |
420 if (dwAccess & FX_STREAMACCESS_Append) { | 420 if (dwAccess & FX_STREAMACCESS_Append) { |
421 wsMode = L"a+b"; | 421 wsMode = L"a+b"; |
422 } else if (dwAccess & FX_STREAMACCESS_Truncate) { | 422 } else if (dwAccess & FX_STREAMACCESS_Truncate) { |
423 wsMode = L"w+b"; | 423 wsMode = L"w+b"; |
424 } else { | 424 } else { |
425 wsMode = L"r+b"; | 425 wsMode = L"r+b"; |
(...skipping 26 matching lines...) Expand all Loading... |
452 if (dwAccess & FX_STREAMACCESS_Append) { | 452 if (dwAccess & FX_STREAMACCESS_Append) { |
453 wsMode = "a+b"; | 453 wsMode = "a+b"; |
454 } else if (dwAccess & FX_STREAMACCESS_Truncate) { | 454 } else if (dwAccess & FX_STREAMACCESS_Truncate) { |
455 wsMode = "w+b"; | 455 wsMode = "w+b"; |
456 } else { | 456 } else { |
457 wsMode = "r+b"; | 457 wsMode = "r+b"; |
458 } | 458 } |
459 } | 459 } |
460 CFX_ByteString szFileName = CFX_ByteString::FromUnicode(pszSrcFileName); | 460 CFX_ByteString szFileName = CFX_ByteString::FromUnicode(pszSrcFileName); |
461 m_hFile = FXSYS_fopen(szFileName.c_str(), wsMode); | 461 m_hFile = FXSYS_fopen(szFileName.c_str(), wsMode); |
462 if (m_hFile == NULL) { | 462 if (!m_hFile) { |
463 if (dwAccess & FX_STREAMACCESS_Write) { | 463 if (dwAccess & FX_STREAMACCESS_Write) { |
464 if (dwAccess & FX_STREAMACCESS_Create) { | 464 if (dwAccess & FX_STREAMACCESS_Create) { |
465 m_hFile = FXSYS_fopen(szFileName.c_str(), "w+b"); | 465 m_hFile = FXSYS_fopen(szFileName.c_str(), "w+b"); |
466 } | 466 } |
467 if (m_hFile == NULL) { | 467 if (!m_hFile) { |
468 m_hFile = FXSYS_fopen(szFileName.c_str(), "r+b"); | 468 m_hFile = FXSYS_fopen(szFileName.c_str(), "r+b"); |
469 if (m_hFile == NULL) { | 469 if (!m_hFile) |
470 return FALSE; | 470 return FALSE; |
471 } | 471 |
472 if (dwAccess & FX_STREAMACCESS_Truncate) { | 472 if (dwAccess & FX_STREAMACCESS_Truncate) { |
473 FileSetSize(m_hFile, 0); | 473 FileSetSize(m_hFile, 0); |
474 } | 474 } |
475 } | 475 } |
476 } else { | 476 } else { |
477 return FALSE; | 477 return FALSE; |
478 } | 478 } |
479 } | 479 } |
480 #endif | 480 #endif |
481 SetAccessModes(dwAccess); | 481 SetAccessModes(dwAccess); |
482 if ((dwAccess & (FX_STREAMACCESS_Write | FX_STREAMACCESS_Truncate)) == | 482 if ((dwAccess & (FX_STREAMACCESS_Write | FX_STREAMACCESS_Truncate)) == |
483 (FX_STREAMACCESS_Write | FX_STREAMACCESS_Truncate)) { | 483 (FX_STREAMACCESS_Write | FX_STREAMACCESS_Truncate)) { |
484 m_iLength = 0; | 484 m_iLength = 0; |
485 } else { | 485 } else { |
486 m_iLength = FileLength(m_hFile); | 486 m_iLength = FileLength(m_hFile); |
487 } | 487 } |
488 return TRUE; | 488 return TRUE; |
489 } | 489 } |
490 int32_t CFX_FileStreamImp::GetLength() const { | 490 int32_t CFX_FileStreamImp::GetLength() const { |
491 ASSERT(m_hFile != NULL); | 491 ASSERT(m_hFile); |
492 return m_iLength; | 492 return m_iLength; |
493 } | 493 } |
494 int32_t CFX_FileStreamImp::Seek(FX_STREAMSEEK eSeek, int32_t iOffset) { | 494 int32_t CFX_FileStreamImp::Seek(FX_STREAMSEEK eSeek, int32_t iOffset) { |
495 ASSERT(m_hFile != NULL); | 495 ASSERT(m_hFile); |
496 FXSYS_fseek(m_hFile, iOffset, eSeek); | 496 FXSYS_fseek(m_hFile, iOffset, eSeek); |
497 return FXSYS_ftell(m_hFile); | 497 return FXSYS_ftell(m_hFile); |
498 } | 498 } |
499 int32_t CFX_FileStreamImp::GetPosition() { | 499 int32_t CFX_FileStreamImp::GetPosition() { |
500 ASSERT(m_hFile != NULL); | 500 ASSERT(m_hFile); |
501 return FXSYS_ftell(m_hFile); | 501 return FXSYS_ftell(m_hFile); |
502 } | 502 } |
503 FX_BOOL CFX_FileStreamImp::IsEOF() const { | 503 FX_BOOL CFX_FileStreamImp::IsEOF() const { |
504 ASSERT(m_hFile != NULL); | 504 ASSERT(m_hFile); |
505 return FXSYS_ftell(m_hFile) >= m_iLength; | 505 return FXSYS_ftell(m_hFile) >= m_iLength; |
506 } | 506 } |
507 int32_t CFX_FileStreamImp::ReadData(uint8_t* pBuffer, int32_t iBufferSize) { | 507 int32_t CFX_FileStreamImp::ReadData(uint8_t* pBuffer, int32_t iBufferSize) { |
508 ASSERT(m_hFile != NULL); | 508 ASSERT(m_hFile); |
509 ASSERT(pBuffer != NULL && iBufferSize > 0); | 509 ASSERT(pBuffer && iBufferSize > 0); |
510 return FXSYS_fread(pBuffer, 1, iBufferSize, m_hFile); | 510 return FXSYS_fread(pBuffer, 1, iBufferSize, m_hFile); |
511 } | 511 } |
512 int32_t CFX_FileStreamImp::ReadString(FX_WCHAR* pStr, | 512 int32_t CFX_FileStreamImp::ReadString(FX_WCHAR* pStr, |
513 int32_t iMaxLength, | 513 int32_t iMaxLength, |
514 FX_BOOL& bEOS) { | 514 FX_BOOL& bEOS) { |
515 ASSERT(m_hFile != NULL); | 515 ASSERT(m_hFile); |
516 ASSERT(pStr != NULL && iMaxLength > 0); | 516 ASSERT(pStr && iMaxLength > 0); |
517 if (m_iLength <= 0) { | 517 if (m_iLength <= 0) { |
518 return 0; | 518 return 0; |
519 } | 519 } |
520 int32_t iPosition = FXSYS_ftell(m_hFile); | 520 int32_t iPosition = FXSYS_ftell(m_hFile); |
521 int32_t iLen = std::min((m_iLength - iPosition) / 2, iMaxLength); | 521 int32_t iLen = std::min((m_iLength - iPosition) / 2, iMaxLength); |
522 if (iLen <= 0) { | 522 if (iLen <= 0) { |
523 return 0; | 523 return 0; |
524 } | 524 } |
525 iLen = FXSYS_fread(pStr, 2, iLen, m_hFile); | 525 iLen = FXSYS_fread(pStr, 2, iLen, m_hFile); |
526 int32_t iCount = 0; | 526 int32_t iCount = 0; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
563 ASSERT(m_hFile && (GetAccessModes() & FX_STREAMACCESS_Write) != 0); | 563 ASSERT(m_hFile && (GetAccessModes() & FX_STREAMACCESS_Write) != 0); |
564 FXSYS_fflush(m_hFile); | 564 FXSYS_fflush(m_hFile); |
565 } | 565 } |
566 FX_BOOL CFX_FileStreamImp::SetLength(int32_t iLength) { | 566 FX_BOOL CFX_FileStreamImp::SetLength(int32_t iLength) { |
567 ASSERT(m_hFile && (GetAccessModes() & FX_STREAMACCESS_Write) != 0); | 567 ASSERT(m_hFile && (GetAccessModes() & FX_STREAMACCESS_Write) != 0); |
568 FX_BOOL bRet = FileSetSize(m_hFile, iLength); | 568 FX_BOOL bRet = FileSetSize(m_hFile, iLength); |
569 m_iLength = FileLength(m_hFile); | 569 m_iLength = FileLength(m_hFile); |
570 return bRet; | 570 return bRet; |
571 } | 571 } |
572 CFX_FileReadStreamImp::CFX_FileReadStreamImp() | 572 CFX_FileReadStreamImp::CFX_FileReadStreamImp() |
573 : m_pFileRead(NULL), m_iPosition(0), m_iLength(0) {} | 573 : m_pFileRead(nullptr), m_iPosition(0), m_iLength(0) {} |
574 FX_BOOL CFX_FileReadStreamImp::LoadFileRead(IFX_FileRead* pFileRead, | 574 FX_BOOL CFX_FileReadStreamImp::LoadFileRead(IFX_FileRead* pFileRead, |
575 uint32_t dwAccess) { | 575 uint32_t dwAccess) { |
576 ASSERT(m_pFileRead == NULL && pFileRead != NULL); | 576 ASSERT(!m_pFileRead && pFileRead); |
577 if (dwAccess & FX_STREAMACCESS_Write) { | 577 if (dwAccess & FX_STREAMACCESS_Write) { |
578 return FALSE; | 578 return FALSE; |
579 } | 579 } |
580 m_pFileRead = pFileRead; | 580 m_pFileRead = pFileRead; |
581 m_iLength = m_pFileRead->GetSize(); | 581 m_iLength = m_pFileRead->GetSize(); |
582 return TRUE; | 582 return TRUE; |
583 } | 583 } |
584 int32_t CFX_FileReadStreamImp::GetLength() const { | 584 int32_t CFX_FileReadStreamImp::GetLength() const { |
585 return m_iLength; | 585 return m_iLength; |
586 } | 586 } |
(...skipping 13 matching lines...) Expand all Loading... |
600 m_iPosition = 0; | 600 m_iPosition = 0; |
601 } else if (m_iPosition >= m_iLength) { | 601 } else if (m_iPosition >= m_iLength) { |
602 m_iPosition = m_iLength; | 602 m_iPosition = m_iLength; |
603 } | 603 } |
604 return m_iPosition; | 604 return m_iPosition; |
605 } | 605 } |
606 FX_BOOL CFX_FileReadStreamImp::IsEOF() const { | 606 FX_BOOL CFX_FileReadStreamImp::IsEOF() const { |
607 return m_iPosition >= m_iLength; | 607 return m_iPosition >= m_iLength; |
608 } | 608 } |
609 int32_t CFX_FileReadStreamImp::ReadData(uint8_t* pBuffer, int32_t iBufferSize) { | 609 int32_t CFX_FileReadStreamImp::ReadData(uint8_t* pBuffer, int32_t iBufferSize) { |
610 ASSERT(m_pFileRead != NULL); | 610 ASSERT(m_pFileRead); |
611 ASSERT(pBuffer != NULL && iBufferSize > 0); | 611 ASSERT(pBuffer && iBufferSize > 0); |
612 if (iBufferSize > m_iLength - m_iPosition) { | 612 if (iBufferSize > m_iLength - m_iPosition) { |
613 iBufferSize = m_iLength - m_iPosition; | 613 iBufferSize = m_iLength - m_iPosition; |
614 } | 614 } |
615 if (m_pFileRead->ReadBlock(pBuffer, m_iPosition, iBufferSize)) { | 615 if (m_pFileRead->ReadBlock(pBuffer, m_iPosition, iBufferSize)) { |
616 m_iPosition += iBufferSize; | 616 m_iPosition += iBufferSize; |
617 return iBufferSize; | 617 return iBufferSize; |
618 } | 618 } |
619 return 0; | 619 return 0; |
620 } | 620 } |
621 int32_t CFX_FileReadStreamImp::ReadString(FX_WCHAR* pStr, | 621 int32_t CFX_FileReadStreamImp::ReadString(FX_WCHAR* pStr, |
622 int32_t iMaxLength, | 622 int32_t iMaxLength, |
623 FX_BOOL& bEOS) { | 623 FX_BOOL& bEOS) { |
624 ASSERT(m_pFileRead != NULL); | 624 ASSERT(m_pFileRead); |
625 ASSERT(pStr != NULL && iMaxLength > 0); | 625 ASSERT(pStr && iMaxLength > 0); |
626 iMaxLength = ReadData((uint8_t*)pStr, iMaxLength * 2) / 2; | 626 iMaxLength = ReadData((uint8_t*)pStr, iMaxLength * 2) / 2; |
627 if (iMaxLength <= 0) { | 627 if (iMaxLength <= 0) { |
628 return 0; | 628 return 0; |
629 } | 629 } |
630 int32_t i = 0; | 630 int32_t i = 0; |
631 while (i < iMaxLength && pStr[i] != L'\0') { | 631 while (i < iMaxLength && pStr[i] != L'\0') { |
632 ++i; | 632 ++i; |
633 } | 633 } |
634 bEOS = (m_iPosition >= m_iLength) || pStr[i] == L'\0'; | 634 bEOS = (m_iPosition >= m_iLength) || pStr[i] == L'\0'; |
635 return i; | 635 return i; |
636 } | 636 } |
637 CFX_BufferReadStreamImp::CFX_BufferReadStreamImp() | 637 CFX_BufferReadStreamImp::CFX_BufferReadStreamImp() |
638 : m_pBufferRead(NULL), | 638 : m_pBufferRead(nullptr), |
639 m_bReleaseBufferRead(FALSE), | 639 m_bReleaseBufferRead(FALSE), |
640 m_iPosition(0), | 640 m_iPosition(0), |
641 m_iBufferSize(0) {} | 641 m_iBufferSize(0) {} |
642 CFX_BufferReadStreamImp::~CFX_BufferReadStreamImp() { | 642 CFX_BufferReadStreamImp::~CFX_BufferReadStreamImp() { |
643 if (m_bReleaseBufferRead && m_pBufferRead != NULL) { | 643 if (m_bReleaseBufferRead && m_pBufferRead) { |
644 m_pBufferRead->Release(); | 644 m_pBufferRead->Release(); |
645 } | 645 } |
646 } | 646 } |
647 FX_BOOL CFX_BufferReadStreamImp::LoadBufferRead(IFX_BufferRead* pBufferRead, | 647 FX_BOOL CFX_BufferReadStreamImp::LoadBufferRead(IFX_BufferRead* pBufferRead, |
648 int32_t iFileSize, | 648 int32_t iFileSize, |
649 uint32_t dwAccess, | 649 uint32_t dwAccess, |
650 FX_BOOL bReleaseBufferRead) { | 650 FX_BOOL bReleaseBufferRead) { |
651 ASSERT(m_pBufferRead == NULL && pBufferRead != NULL); | 651 ASSERT(!m_pBufferRead && pBufferRead); |
652 if (dwAccess & FX_STREAMACCESS_Write) { | 652 if (dwAccess & FX_STREAMACCESS_Write) { |
653 return FALSE; | 653 return FALSE; |
654 } | 654 } |
655 m_bReleaseBufferRead = bReleaseBufferRead; | 655 m_bReleaseBufferRead = bReleaseBufferRead; |
656 m_pBufferRead = pBufferRead; | 656 m_pBufferRead = pBufferRead; |
657 m_iBufferSize = iFileSize; | 657 m_iBufferSize = iFileSize; |
658 if (m_iBufferSize >= 0) { | 658 if (m_iBufferSize >= 0) { |
659 return TRUE; | 659 return TRUE; |
660 } | 660 } |
661 if (!m_pBufferRead->ReadNextBlock(TRUE)) { | 661 if (!m_pBufferRead->ReadNextBlock(TRUE)) { |
(...skipping 27 matching lines...) Expand all Loading... |
689 } else if (m_iPosition >= iLength) { | 689 } else if (m_iPosition >= iLength) { |
690 m_iPosition = iLength; | 690 m_iPosition = iLength; |
691 } | 691 } |
692 return m_iPosition; | 692 return m_iPosition; |
693 } | 693 } |
694 FX_BOOL CFX_BufferReadStreamImp::IsEOF() const { | 694 FX_BOOL CFX_BufferReadStreamImp::IsEOF() const { |
695 return m_pBufferRead ? m_pBufferRead->IsEOF() : TRUE; | 695 return m_pBufferRead ? m_pBufferRead->IsEOF() : TRUE; |
696 } | 696 } |
697 int32_t CFX_BufferReadStreamImp::ReadData(uint8_t* pBuffer, | 697 int32_t CFX_BufferReadStreamImp::ReadData(uint8_t* pBuffer, |
698 int32_t iBufferSize) { | 698 int32_t iBufferSize) { |
699 ASSERT(m_pBufferRead != NULL); | 699 ASSERT(m_pBufferRead); |
700 ASSERT(pBuffer != NULL && iBufferSize > 0); | 700 ASSERT(pBuffer && iBufferSize > 0); |
701 int32_t iLength = GetLength(); | 701 int32_t iLength = GetLength(); |
702 if (m_iPosition >= iLength) { | 702 if (m_iPosition >= iLength) { |
703 return 0; | 703 return 0; |
704 } | 704 } |
705 if (iBufferSize > iLength - m_iPosition) { | 705 if (iBufferSize > iLength - m_iPosition) { |
706 iBufferSize = iLength - m_iPosition; | 706 iBufferSize = iLength - m_iPosition; |
707 } | 707 } |
708 uint32_t dwBlockOffset = m_pBufferRead->GetBlockOffset(); | 708 uint32_t dwBlockOffset = m_pBufferRead->GetBlockOffset(); |
709 uint32_t dwBlockSize = m_pBufferRead->GetBlockSize(); | 709 uint32_t dwBlockSize = m_pBufferRead->GetBlockSize(); |
710 if (m_iPosition < (int32_t)dwBlockOffset) { | 710 if (m_iPosition < (int32_t)dwBlockOffset) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
744 FXSYS_memcpy(pBuffer + dwOffsetTmp, pBufferTmp, dwCopySize); | 744 FXSYS_memcpy(pBuffer + dwOffsetTmp, pBufferTmp, dwCopySize); |
745 dwOffsetTmp += dwCopySize; | 745 dwOffsetTmp += dwCopySize; |
746 iBufferSize -= dwCopySize; | 746 iBufferSize -= dwCopySize; |
747 } | 747 } |
748 m_iPosition += dwOffsetTmp; | 748 m_iPosition += dwOffsetTmp; |
749 return dwOffsetTmp; | 749 return dwOffsetTmp; |
750 } | 750 } |
751 int32_t CFX_BufferReadStreamImp::ReadString(FX_WCHAR* pStr, | 751 int32_t CFX_BufferReadStreamImp::ReadString(FX_WCHAR* pStr, |
752 int32_t iMaxLength, | 752 int32_t iMaxLength, |
753 FX_BOOL& bEOS) { | 753 FX_BOOL& bEOS) { |
754 ASSERT(m_pBufferRead != NULL); | 754 ASSERT(m_pBufferRead); |
755 ASSERT(pStr != NULL && iMaxLength > 0); | 755 ASSERT(pStr && iMaxLength > 0); |
756 iMaxLength = ReadData((uint8_t*)pStr, iMaxLength * 2) / 2; | 756 iMaxLength = ReadData((uint8_t*)pStr, iMaxLength * 2) / 2; |
757 if (iMaxLength <= 0) { | 757 if (iMaxLength <= 0) { |
758 return 0; | 758 return 0; |
759 } | 759 } |
760 int32_t i = 0; | 760 int32_t i = 0; |
761 while (i < iMaxLength && pStr[i] != L'\0') { | 761 while (i < iMaxLength && pStr[i] != L'\0') { |
762 ++i; | 762 ++i; |
763 } | 763 } |
764 bEOS = (m_iPosition >= GetLength()) || pStr[i] == L'\0'; | 764 bEOS = (m_iPosition >= GetLength()) || pStr[i] == L'\0'; |
765 return i; | 765 return i; |
766 } | 766 } |
767 CFX_FileWriteStreamImp::CFX_FileWriteStreamImp() | 767 CFX_FileWriteStreamImp::CFX_FileWriteStreamImp() |
768 : m_pFileWrite(NULL), m_iPosition(0) {} | 768 : m_pFileWrite(nullptr), m_iPosition(0) {} |
769 FX_BOOL CFX_FileWriteStreamImp::LoadFileWrite(IFX_FileWrite* pFileWrite, | 769 FX_BOOL CFX_FileWriteStreamImp::LoadFileWrite(IFX_FileWrite* pFileWrite, |
770 uint32_t dwAccess) { | 770 uint32_t dwAccess) { |
771 ASSERT(m_pFileWrite == NULL && pFileWrite != NULL); | 771 ASSERT(!m_pFileWrite && pFileWrite); |
772 if (dwAccess & FX_STREAMACCESS_Read) { | 772 if (dwAccess & FX_STREAMACCESS_Read) { |
773 return FALSE; | 773 return FALSE; |
774 } | 774 } |
775 if (dwAccess & FX_STREAMACCESS_Append) { | 775 if (dwAccess & FX_STREAMACCESS_Append) { |
776 m_iPosition = pFileWrite->GetSize(); | 776 m_iPosition = pFileWrite->GetSize(); |
777 } | 777 } |
778 m_pFileWrite = pFileWrite; | 778 m_pFileWrite = pFileWrite; |
779 return TRUE; | 779 return TRUE; |
780 } | 780 } |
781 int32_t CFX_FileWriteStreamImp::GetLength() const { | 781 int32_t CFX_FileWriteStreamImp::GetLength() const { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
834 uint32_t dwAccess) { | 834 uint32_t dwAccess) { |
835 ASSERT(!m_pData && pData && iTotalSize > 0); | 835 ASSERT(!m_pData && pData && iTotalSize > 0); |
836 SetAccessModes(dwAccess); | 836 SetAccessModes(dwAccess); |
837 m_pData = pData; | 837 m_pData = pData; |
838 m_iTotalSize = iTotalSize; | 838 m_iTotalSize = iTotalSize; |
839 m_iPosition = 0; | 839 m_iPosition = 0; |
840 m_iLength = (dwAccess & FX_STREAMACCESS_Write) != 0 ? 0 : iTotalSize; | 840 m_iLength = (dwAccess & FX_STREAMACCESS_Write) != 0 ? 0 : iTotalSize; |
841 return TRUE; | 841 return TRUE; |
842 } | 842 } |
843 int32_t CFX_BufferStreamImp::GetLength() const { | 843 int32_t CFX_BufferStreamImp::GetLength() const { |
844 ASSERT(m_pData != NULL); | 844 ASSERT(m_pData); |
845 return m_iLength; | 845 return m_iLength; |
846 } | 846 } |
847 int32_t CFX_BufferStreamImp::Seek(FX_STREAMSEEK eSeek, int32_t iOffset) { | 847 int32_t CFX_BufferStreamImp::Seek(FX_STREAMSEEK eSeek, int32_t iOffset) { |
848 ASSERT(m_pData != NULL); | 848 ASSERT(m_pData); |
849 if (eSeek == FX_STREAMSEEK_Begin) { | 849 if (eSeek == FX_STREAMSEEK_Begin) { |
850 m_iPosition = iOffset; | 850 m_iPosition = iOffset; |
851 } else if (eSeek == FX_STREAMSEEK_Current) { | 851 } else if (eSeek == FX_STREAMSEEK_Current) { |
852 m_iPosition += iOffset; | 852 m_iPosition += iOffset; |
853 } else if (eSeek == FX_STREAMSEEK_End) { | 853 } else if (eSeek == FX_STREAMSEEK_End) { |
854 m_iPosition = m_iLength + iOffset; | 854 m_iPosition = m_iLength + iOffset; |
855 } | 855 } |
856 if (m_iPosition > m_iLength) { | 856 if (m_iPosition > m_iLength) { |
857 m_iPosition = m_iLength; | 857 m_iPosition = m_iLength; |
858 } | 858 } |
859 if (m_iPosition < 0) { | 859 if (m_iPosition < 0) { |
860 m_iPosition = 0; | 860 m_iPosition = 0; |
861 } | 861 } |
862 return m_iPosition; | 862 return m_iPosition; |
863 } | 863 } |
864 int32_t CFX_BufferStreamImp::GetPosition() { | 864 int32_t CFX_BufferStreamImp::GetPosition() { |
865 ASSERT(m_pData != NULL); | 865 ASSERT(m_pData); |
866 return m_iPosition; | 866 return m_iPosition; |
867 } | 867 } |
868 FX_BOOL CFX_BufferStreamImp::IsEOF() const { | 868 FX_BOOL CFX_BufferStreamImp::IsEOF() const { |
869 ASSERT(m_pData != NULL); | 869 ASSERT(m_pData); |
870 return m_iPosition >= m_iLength; | 870 return m_iPosition >= m_iLength; |
871 } | 871 } |
872 int32_t CFX_BufferStreamImp::ReadData(uint8_t* pBuffer, int32_t iBufferSize) { | 872 int32_t CFX_BufferStreamImp::ReadData(uint8_t* pBuffer, int32_t iBufferSize) { |
873 ASSERT(m_pData != NULL); | 873 ASSERT(m_pData); |
874 ASSERT(pBuffer != NULL && iBufferSize > 0); | 874 ASSERT(pBuffer && iBufferSize > 0); |
875 int32_t iLen = std::min(m_iLength - m_iPosition, iBufferSize); | 875 int32_t iLen = std::min(m_iLength - m_iPosition, iBufferSize); |
876 if (iLen <= 0) { | 876 if (iLen <= 0) { |
877 return 0; | 877 return 0; |
878 } | 878 } |
879 FXSYS_memcpy(pBuffer, m_pData + m_iPosition, iLen); | 879 FXSYS_memcpy(pBuffer, m_pData + m_iPosition, iLen); |
880 m_iPosition += iLen; | 880 m_iPosition += iLen; |
881 return iLen; | 881 return iLen; |
882 } | 882 } |
883 int32_t CFX_BufferStreamImp::ReadString(FX_WCHAR* pStr, | 883 int32_t CFX_BufferStreamImp::ReadString(FX_WCHAR* pStr, |
884 int32_t iMaxLength, | 884 int32_t iMaxLength, |
885 FX_BOOL& bEOS) { | 885 FX_BOOL& bEOS) { |
886 ASSERT(m_pData != NULL); | 886 ASSERT(m_pData); |
887 ASSERT(pStr != NULL && iMaxLength > 0); | 887 ASSERT(pStr && iMaxLength > 0); |
888 int32_t iLen = std::min((m_iLength - m_iPosition) / 2, iMaxLength); | 888 int32_t iLen = std::min((m_iLength - m_iPosition) / 2, iMaxLength); |
889 if (iLen <= 0) { | 889 if (iLen <= 0) { |
890 return 0; | 890 return 0; |
891 } | 891 } |
892 const FX_WCHAR* pSrc = (const FX_WCHAR*)(FX_CHAR*)(m_pData + m_iPosition); | 892 const FX_WCHAR* pSrc = (const FX_WCHAR*)(FX_CHAR*)(m_pData + m_iPosition); |
893 int32_t iCount = 0; | 893 int32_t iCount = 0; |
894 while (*pSrc && iCount < iLen) { | 894 while (*pSrc && iCount < iLen) { |
895 *pStr++ = *pSrc++; | 895 *pStr++ = *pSrc++; |
896 iCount++; | 896 iCount++; |
897 } | 897 } |
(...skipping 26 matching lines...) Expand all Loading... |
924 } | 924 } |
925 FXSYS_memcpy(m_pData + m_iPosition, pStr, iLen * 2); | 925 FXSYS_memcpy(m_pData + m_iPosition, pStr, iLen * 2); |
926 m_iPosition += iLen * 2; | 926 m_iPosition += iLen * 2; |
927 if (m_iPosition > m_iLength) { | 927 if (m_iPosition > m_iLength) { |
928 m_iLength = m_iPosition; | 928 m_iLength = m_iPosition; |
929 } | 929 } |
930 return iLen; | 930 return iLen; |
931 } | 931 } |
932 IFX_Stream* IFX_Stream::CreateTextStream(IFX_Stream* pBaseStream, | 932 IFX_Stream* IFX_Stream::CreateTextStream(IFX_Stream* pBaseStream, |
933 FX_BOOL bDeleteOnRelease) { | 933 FX_BOOL bDeleteOnRelease) { |
934 ASSERT(pBaseStream != NULL); | 934 ASSERT(pBaseStream); |
935 return new CFX_TextStream(pBaseStream, bDeleteOnRelease); | 935 return new CFX_TextStream(pBaseStream, bDeleteOnRelease); |
936 } | 936 } |
937 CFX_TextStream::CFX_TextStream(IFX_Stream* pStream, FX_BOOL bDelStream) | 937 CFX_TextStream::CFX_TextStream(IFX_Stream* pStream, FX_BOOL bDelStream) |
938 : m_wCodePage(FX_CODEPAGE_DefANSI), | 938 : m_wCodePage(FX_CODEPAGE_DefANSI), |
939 m_wBOMLength(0), | 939 m_wBOMLength(0), |
940 m_dwBOM(0), | 940 m_dwBOM(0), |
941 m_pBuf(NULL), | 941 m_pBuf(nullptr), |
942 m_iBufSize(0), | 942 m_iBufSize(0), |
943 m_bDelStream(bDelStream), | 943 m_bDelStream(bDelStream), |
944 m_pStreamImp(pStream), | 944 m_pStreamImp(pStream), |
945 m_iRefCount(1) { | 945 m_iRefCount(1) { |
946 ASSERT(m_pStreamImp != NULL); | |
947 m_pStreamImp->Retain(); | 946 m_pStreamImp->Retain(); |
948 InitStream(); | 947 InitStream(); |
949 } | 948 } |
950 CFX_TextStream::~CFX_TextStream() { | 949 CFX_TextStream::~CFX_TextStream() { |
951 m_pStreamImp->Release(); | 950 m_pStreamImp->Release(); |
952 if (m_bDelStream) { | 951 if (m_bDelStream) { |
953 m_pStreamImp->Release(); | 952 m_pStreamImp->Release(); |
954 } | 953 } |
955 if (m_pBuf != NULL) { | 954 FX_Free(m_pBuf); |
956 FX_Free(m_pBuf); | |
957 } | |
958 } | 955 } |
959 void CFX_TextStream::InitStream() { | 956 void CFX_TextStream::InitStream() { |
960 int32_t iPosition = m_pStreamImp->GetPosition(); | 957 int32_t iPosition = m_pStreamImp->GetPosition(); |
961 m_pStreamImp->Seek(FX_STREAMSEEK_Begin, 0); | 958 m_pStreamImp->Seek(FX_STREAMSEEK_Begin, 0); |
962 m_pStreamImp->ReadData((uint8_t*)&m_dwBOM, 3); | 959 m_pStreamImp->ReadData((uint8_t*)&m_dwBOM, 3); |
963 #if _FX_ENDIAN_ == _FX_LITTLE_ENDIAN_ | 960 #if _FX_ENDIAN_ == _FX_LITTLE_ENDIAN_ |
964 m_dwBOM &= 0x00FFFFFF; | 961 m_dwBOM &= 0x00FFFFFF; |
965 if (m_dwBOM == 0x00BFBBEF) { | 962 if (m_dwBOM == 0x00BFBBEF) { |
966 m_wBOMLength = 3; | 963 m_wBOMLength = 3; |
967 m_wCodePage = FX_CODEPAGE_UTF8; | 964 m_wCodePage = FX_CODEPAGE_UTF8; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1038 return m_pStreamImp->SetLength(iLength); | 1035 return m_pStreamImp->SetLength(iLength); |
1039 } | 1036 } |
1040 uint16_t CFX_TextStream::GetCodePage() const { | 1037 uint16_t CFX_TextStream::GetCodePage() const { |
1041 return m_wCodePage; | 1038 return m_wCodePage; |
1042 } | 1039 } |
1043 IFX_Stream* CFX_TextStream::CreateSharedStream(uint32_t dwAccess, | 1040 IFX_Stream* CFX_TextStream::CreateSharedStream(uint32_t dwAccess, |
1044 int32_t iOffset, | 1041 int32_t iOffset, |
1045 int32_t iLength) { | 1042 int32_t iLength) { |
1046 IFX_Stream* pSR = | 1043 IFX_Stream* pSR = |
1047 m_pStreamImp->CreateSharedStream(dwAccess, iOffset, iLength); | 1044 m_pStreamImp->CreateSharedStream(dwAccess, iOffset, iLength); |
1048 if (pSR == NULL) { | 1045 if (!pSR) |
1049 return NULL; | 1046 return nullptr; |
1050 } | 1047 |
1051 if (dwAccess & FX_STREAMACCESS_Text) { | 1048 if (dwAccess & FX_STREAMACCESS_Text) { |
1052 return new CFX_TextStream(pSR, TRUE); | 1049 return new CFX_TextStream(pSR, TRUE); |
1053 } | 1050 } |
1054 return pSR; | 1051 return pSR; |
1055 } | 1052 } |
1056 int32_t CFX_TextStream::GetBOM(uint8_t bom[4]) const { | 1053 int32_t CFX_TextStream::GetBOM(uint8_t bom[4]) const { |
1057 if (m_wBOMLength < 1) { | 1054 if (m_wBOMLength < 1) { |
1058 return 0; | 1055 return 0; |
1059 } | 1056 } |
1060 *(uint32_t*)bom = m_dwBOM; | 1057 *(uint32_t*)bom = m_dwBOM; |
1061 return m_wBOMLength; | 1058 return m_wBOMLength; |
1062 } | 1059 } |
1063 uint16_t CFX_TextStream::SetCodePage(uint16_t wCodePage) { | 1060 uint16_t CFX_TextStream::SetCodePage(uint16_t wCodePage) { |
1064 if (m_wBOMLength > 0) { | 1061 if (m_wBOMLength > 0) { |
1065 return m_wCodePage; | 1062 return m_wCodePage; |
1066 } | 1063 } |
1067 uint16_t v = m_wCodePage; | 1064 uint16_t v = m_wCodePage; |
1068 m_wCodePage = wCodePage; | 1065 m_wCodePage = wCodePage; |
1069 return v; | 1066 return v; |
1070 } | 1067 } |
1071 int32_t CFX_TextStream::ReadString(FX_WCHAR* pStr, | 1068 int32_t CFX_TextStream::ReadString(FX_WCHAR* pStr, |
1072 int32_t iMaxLength, | 1069 int32_t iMaxLength, |
1073 FX_BOOL& bEOS, | 1070 FX_BOOL& bEOS, |
1074 int32_t const* pByteSize) { | 1071 int32_t const* pByteSize) { |
1075 ASSERT(pStr != NULL && iMaxLength > 0); | 1072 ASSERT(pStr && iMaxLength > 0); |
1076 if (m_pStreamImp == NULL) { | 1073 if (!m_pStreamImp) |
1077 return -1; | 1074 return -1; |
1078 } | 1075 |
1079 int32_t iLen; | 1076 int32_t iLen; |
1080 if (m_wCodePage == FX_CODEPAGE_UTF16LE || | 1077 if (m_wCodePage == FX_CODEPAGE_UTF16LE || |
1081 m_wCodePage == FX_CODEPAGE_UTF16BE) { | 1078 m_wCodePage == FX_CODEPAGE_UTF16BE) { |
1082 int32_t iBytes = pByteSize == NULL ? iMaxLength * 2 : *pByteSize; | 1079 int32_t iBytes = pByteSize ? *pByteSize : iMaxLength * 2; |
1083 iLen = m_pStreamImp->ReadData((uint8_t*)pStr, iBytes); | 1080 iLen = m_pStreamImp->ReadData((uint8_t*)pStr, iBytes); |
1084 iMaxLength = iLen / 2; | 1081 iMaxLength = iLen / 2; |
1085 if (sizeof(FX_WCHAR) > 2) { | 1082 if (sizeof(FX_WCHAR) > 2) { |
1086 FX_UTF16ToWChar(pStr, iMaxLength); | 1083 FX_UTF16ToWChar(pStr, iMaxLength); |
1087 } | 1084 } |
1088 #if _FX_ENDIAN_ == _FX_BIG_ENDIAN_ | 1085 #if _FX_ENDIAN_ == _FX_BIG_ENDIAN_ |
1089 if (m_wCodePage == FX_CODEPAGE_UTF16LE) { | 1086 if (m_wCodePage == FX_CODEPAGE_UTF16LE) { |
1090 FX_SwapByteOrder(pStr, iMaxLength); | 1087 FX_SwapByteOrder(pStr, iMaxLength); |
1091 } | 1088 } |
1092 #else | 1089 #else |
1093 if (m_wCodePage == FX_CODEPAGE_UTF16BE) { | 1090 if (m_wCodePage == FX_CODEPAGE_UTF16BE) { |
1094 FX_SwapByteOrder(pStr, iMaxLength); | 1091 FX_SwapByteOrder(pStr, iMaxLength); |
1095 } | 1092 } |
1096 #endif | 1093 #endif |
1097 } else { | 1094 } else { |
1098 int32_t pos = m_pStreamImp->GetPosition(); | 1095 int32_t pos = m_pStreamImp->GetPosition(); |
1099 int32_t iBytes = pByteSize == NULL ? iMaxLength : *pByteSize; | 1096 int32_t iBytes = pByteSize ? *pByteSize : iMaxLength; |
1100 iBytes = std::min(iBytes, m_pStreamImp->GetLength() - pos); | 1097 iBytes = std::min(iBytes, m_pStreamImp->GetLength() - pos); |
1101 if (iBytes > 0) { | 1098 if (iBytes > 0) { |
1102 if (m_pBuf == NULL) { | 1099 if (!m_pBuf) { |
1103 m_pBuf = FX_Alloc(uint8_t, iBytes); | 1100 m_pBuf = FX_Alloc(uint8_t, iBytes); |
1104 m_iBufSize = iBytes; | 1101 m_iBufSize = iBytes; |
1105 } else if (iBytes > m_iBufSize) { | 1102 } else if (iBytes > m_iBufSize) { |
1106 m_pBuf = FX_Realloc(uint8_t, m_pBuf, iBytes); | 1103 m_pBuf = FX_Realloc(uint8_t, m_pBuf, iBytes); |
1107 m_iBufSize = iBytes; | 1104 m_iBufSize = iBytes; |
1108 } | 1105 } |
1109 iLen = m_pStreamImp->ReadData(m_pBuf, iBytes); | 1106 iLen = m_pStreamImp->ReadData(m_pBuf, iBytes); |
1110 int32_t iSrc = iLen; | 1107 int32_t iSrc = iLen; |
1111 int32_t iDecode = FX_DecodeString(m_wCodePage, (const FX_CHAR*)m_pBuf, | 1108 int32_t iDecode = FX_DecodeString(m_wCodePage, (const FX_CHAR*)m_pBuf, |
1112 &iSrc, pStr, &iMaxLength, TRUE); | 1109 &iSrc, pStr, &iMaxLength, TRUE); |
1113 m_pStreamImp->Seek(FX_STREAMSEEK_Current, iSrc - iLen); | 1110 m_pStreamImp->Seek(FX_STREAMSEEK_Current, iSrc - iLen); |
1114 if (iDecode < 1) { | 1111 if (iDecode < 1) { |
1115 return -1; | 1112 return -1; |
1116 } | 1113 } |
1117 } else { | 1114 } else { |
1118 iMaxLength = 0; | 1115 iMaxLength = 0; |
1119 } | 1116 } |
1120 } | 1117 } |
1121 bEOS = m_pStreamImp->IsEOF(); | 1118 bEOS = m_pStreamImp->IsEOF(); |
1122 return iMaxLength; | 1119 return iMaxLength; |
1123 } | 1120 } |
1124 int32_t CFX_TextStream::WriteString(const FX_WCHAR* pStr, int32_t iLength) { | 1121 int32_t CFX_TextStream::WriteString(const FX_WCHAR* pStr, int32_t iLength) { |
1125 ASSERT(pStr != NULL && iLength > 0); | 1122 ASSERT(pStr && iLength > 0); |
1126 if ((m_pStreamImp->GetAccessModes() & FX_STREAMACCESS_Write) == 0) { | 1123 if ((m_pStreamImp->GetAccessModes() & FX_STREAMACCESS_Write) == 0) { |
1127 return -1; | 1124 return -1; |
1128 } | 1125 } |
1129 if (m_wCodePage == FX_CODEPAGE_UTF8) { | 1126 if (m_wCodePage == FX_CODEPAGE_UTF8) { |
1130 int32_t len = iLength; | 1127 int32_t len = iLength; |
1131 CFX_UTF8Encoder encoder; | 1128 CFX_UTF8Encoder encoder; |
1132 while (len-- > 0) { | 1129 while (len-- > 0) { |
1133 encoder.Input(*pStr++); | 1130 encoder.Input(*pStr++); |
1134 } | 1131 } |
1135 CFX_ByteStringC bsResult = encoder.GetResult(); | 1132 CFX_ByteStringC bsResult = encoder.GetResult(); |
1136 m_pStreamImp->WriteData((const uint8_t*)bsResult.c_str(), | 1133 m_pStreamImp->WriteData((const uint8_t*)bsResult.c_str(), |
1137 bsResult.GetLength()); | 1134 bsResult.GetLength()); |
1138 } | 1135 } |
1139 return iLength; | 1136 return iLength; |
1140 } | 1137 } |
1141 CFX_Stream::CFX_Stream() | 1138 CFX_Stream::CFX_Stream() |
1142 : m_eStreamType(FX_SREAMTYPE_Unknown), | 1139 : m_eStreamType(FX_SREAMTYPE_Unknown), |
1143 m_pStreamImp(NULL), | 1140 m_pStreamImp(nullptr), |
1144 m_dwAccess(0), | 1141 m_dwAccess(0), |
1145 m_iTotalSize(0), | 1142 m_iTotalSize(0), |
1146 m_iPosition(0), | 1143 m_iPosition(0), |
1147 m_iStart(0), | 1144 m_iStart(0), |
1148 m_iLength(0), | 1145 m_iLength(0), |
1149 m_iRefCount(1) {} | 1146 m_iRefCount(1) {} |
1150 | 1147 |
1151 CFX_Stream::~CFX_Stream() { | 1148 CFX_Stream::~CFX_Stream() { |
1152 if (m_eStreamType != FX_STREAMTYPE_Stream) | 1149 if (m_eStreamType != FX_STREAMTYPE_Stream) |
1153 delete m_pStreamImp; | 1150 delete m_pStreamImp; |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1254 void CFX_Stream::Release() { | 1251 void CFX_Stream::Release() { |
1255 if (--m_iRefCount < 1) { | 1252 if (--m_iRefCount < 1) { |
1256 delete this; | 1253 delete this; |
1257 } | 1254 } |
1258 } | 1255 } |
1259 IFX_Stream* CFX_Stream::Retain() { | 1256 IFX_Stream* CFX_Stream::Retain() { |
1260 m_iRefCount++; | 1257 m_iRefCount++; |
1261 return this; | 1258 return this; |
1262 } | 1259 } |
1263 int32_t CFX_Stream::GetLength() const { | 1260 int32_t CFX_Stream::GetLength() const { |
1264 if (m_pStreamImp == NULL) { | 1261 if (!m_pStreamImp) |
1265 return -1; | 1262 return -1; |
1266 } | 1263 |
1267 if (m_eStreamType == FX_STREAMTYPE_File || | 1264 if (m_eStreamType == FX_STREAMTYPE_File || |
1268 m_eStreamType == FX_STREAMTYPE_Buffer) { | 1265 m_eStreamType == FX_STREAMTYPE_Buffer) { |
1269 return m_pStreamImp->GetLength(); | 1266 return m_pStreamImp->GetLength(); |
1270 } | 1267 } |
1271 return m_iLength; | 1268 return m_iLength; |
1272 } | 1269 } |
1273 int32_t CFX_Stream::Seek(FX_STREAMSEEK eSeek, int32_t iOffset) { | 1270 int32_t CFX_Stream::Seek(FX_STREAMSEEK eSeek, int32_t iOffset) { |
1274 if (m_pStreamImp == NULL) { | 1271 if (!m_pStreamImp) |
1275 return -1; | 1272 return -1; |
1276 } | 1273 |
1277 if (m_eStreamType == FX_STREAMTYPE_File || | 1274 if (m_eStreamType == FX_STREAMTYPE_File || |
1278 m_eStreamType == FX_STREAMTYPE_Buffer) { | 1275 m_eStreamType == FX_STREAMTYPE_Buffer) { |
1279 return m_iPosition = m_pStreamImp->Seek(eSeek, iOffset); | 1276 return m_iPosition = m_pStreamImp->Seek(eSeek, iOffset); |
1280 } | 1277 } |
1281 int32_t iEnd = m_iStart + m_iLength; | 1278 int32_t iEnd = m_iStart + m_iLength; |
1282 int32_t iPosition = m_iStart + iOffset; | 1279 int32_t iPosition = m_iStart + iOffset; |
1283 if (eSeek == FX_STREAMSEEK_Begin) { | 1280 if (eSeek == FX_STREAMSEEK_Begin) { |
1284 m_iPosition = iPosition; | 1281 m_iPosition = iPosition; |
1285 } else if (eSeek == FX_STREAMSEEK_Current) { | 1282 } else if (eSeek == FX_STREAMSEEK_Current) { |
1286 m_iPosition += iOffset; | 1283 m_iPosition += iOffset; |
1287 } else if (eSeek == FX_STREAMSEEK_End) { | 1284 } else if (eSeek == FX_STREAMSEEK_End) { |
1288 m_iPosition = iEnd + iOffset; | 1285 m_iPosition = iEnd + iOffset; |
1289 } | 1286 } |
1290 if (m_iPosition > iEnd) { | 1287 if (m_iPosition > iEnd) { |
1291 m_iPosition = iEnd; | 1288 m_iPosition = iEnd; |
1292 } | 1289 } |
1293 if (m_iPosition < m_iStart) { | 1290 if (m_iPosition < m_iStart) { |
1294 m_iPosition = m_iStart; | 1291 m_iPosition = m_iStart; |
1295 } | 1292 } |
1296 return m_iPosition - m_iStart; | 1293 return m_iPosition - m_iStart; |
1297 } | 1294 } |
1298 int32_t CFX_Stream::GetPosition() { | 1295 int32_t CFX_Stream::GetPosition() { |
1299 if (m_pStreamImp == NULL) { | 1296 if (!m_pStreamImp) |
1300 return -1; | 1297 return -1; |
1301 } | 1298 |
1302 if (m_eStreamType == FX_STREAMTYPE_File || | 1299 if (m_eStreamType == FX_STREAMTYPE_File || |
1303 m_eStreamType == FX_STREAMTYPE_Buffer) { | 1300 m_eStreamType == FX_STREAMTYPE_Buffer) { |
1304 return m_iPosition = m_pStreamImp->GetPosition(); | 1301 return m_iPosition = m_pStreamImp->GetPosition(); |
1305 } | 1302 } |
1306 return m_iPosition - m_iStart; | 1303 return m_iPosition - m_iStart; |
1307 } | 1304 } |
1308 FX_BOOL CFX_Stream::IsEOF() const { | 1305 FX_BOOL CFX_Stream::IsEOF() const { |
1309 if (m_pStreamImp == NULL) { | 1306 if (!m_pStreamImp) |
1310 return TRUE; | 1307 return TRUE; |
1311 } | 1308 |
1312 if (m_eStreamType == FX_STREAMTYPE_File || | 1309 if (m_eStreamType == FX_STREAMTYPE_File || |
1313 m_eStreamType == FX_STREAMTYPE_Buffer) { | 1310 m_eStreamType == FX_STREAMTYPE_Buffer) { |
1314 return m_pStreamImp->IsEOF(); | 1311 return m_pStreamImp->IsEOF(); |
1315 } | 1312 } |
1316 return m_iPosition >= m_iStart + m_iLength; | 1313 return m_iPosition >= m_iStart + m_iLength; |
1317 } | 1314 } |
1318 int32_t CFX_Stream::ReadData(uint8_t* pBuffer, int32_t iBufferSize) { | 1315 int32_t CFX_Stream::ReadData(uint8_t* pBuffer, int32_t iBufferSize) { |
1319 ASSERT(pBuffer != NULL && iBufferSize > 0); | 1316 ASSERT(pBuffer && iBufferSize > 0); |
1320 if (m_pStreamImp == NULL) { | 1317 if (!m_pStreamImp) |
1321 return -1; | 1318 return -1; |
1322 } | 1319 |
1323 int32_t iLen = std::min(m_iStart + m_iLength - m_iPosition, iBufferSize); | 1320 int32_t iLen = std::min(m_iStart + m_iLength - m_iPosition, iBufferSize); |
1324 if (iLen <= 0) { | 1321 if (iLen <= 0) { |
1325 return 0; | 1322 return 0; |
1326 } | 1323 } |
1327 if (m_pStreamImp->GetPosition() != m_iPosition) { | 1324 if (m_pStreamImp->GetPosition() != m_iPosition) { |
1328 m_pStreamImp->Seek(FX_STREAMSEEK_Begin, m_iPosition); | 1325 m_pStreamImp->Seek(FX_STREAMSEEK_Begin, m_iPosition); |
1329 } | 1326 } |
1330 iLen = m_pStreamImp->ReadData(pBuffer, iLen); | 1327 iLen = m_pStreamImp->ReadData(pBuffer, iLen); |
1331 m_iPosition = m_pStreamImp->GetPosition(); | 1328 m_iPosition = m_pStreamImp->GetPosition(); |
1332 return iLen; | 1329 return iLen; |
1333 } | 1330 } |
1334 int32_t CFX_Stream::ReadString(FX_WCHAR* pStr, | 1331 int32_t CFX_Stream::ReadString(FX_WCHAR* pStr, |
1335 int32_t iMaxLength, | 1332 int32_t iMaxLength, |
1336 FX_BOOL& bEOS, | 1333 FX_BOOL& bEOS, |
1337 int32_t const* pByteSize) { | 1334 int32_t const* pByteSize) { |
1338 ASSERT(pStr != NULL && iMaxLength > 0); | 1335 ASSERT(pStr && iMaxLength > 0); |
1339 if (m_pStreamImp == NULL) { | 1336 if (!m_pStreamImp) |
1340 return -1; | 1337 return -1; |
1341 } | 1338 |
1342 int32_t iEnd = m_iStart + m_iLength; | 1339 int32_t iEnd = m_iStart + m_iLength; |
1343 int32_t iLen = iEnd - m_iPosition; | 1340 int32_t iLen = iEnd - m_iPosition; |
1344 if (pByteSize != NULL) { | 1341 if (pByteSize) |
1345 iLen = std::min(iLen, *pByteSize); | 1342 iLen = std::min(iLen, *pByteSize); |
1346 } | 1343 |
1347 iLen = std::min(iEnd / 2, iMaxLength); | 1344 iLen = std::min(iEnd / 2, iMaxLength); |
1348 if (iLen <= 0) { | 1345 if (iLen <= 0) { |
1349 return 0; | 1346 return 0; |
1350 } | 1347 } |
1351 if (m_pStreamImp->GetPosition() != m_iPosition) { | 1348 if (m_pStreamImp->GetPosition() != m_iPosition) { |
1352 m_pStreamImp->Seek(FX_STREAMSEEK_Begin, m_iPosition); | 1349 m_pStreamImp->Seek(FX_STREAMSEEK_Begin, m_iPosition); |
1353 } | 1350 } |
1354 iLen = m_pStreamImp->ReadString(pStr, iLen, bEOS); | 1351 iLen = m_pStreamImp->ReadString(pStr, iLen, bEOS); |
1355 m_iPosition = m_pStreamImp->GetPosition(); | 1352 m_iPosition = m_pStreamImp->GetPosition(); |
1356 if (iLen > 0 && m_iPosition >= iEnd) { | 1353 if (iLen > 0 && m_iPosition >= iEnd) { |
1357 bEOS = TRUE; | 1354 bEOS = TRUE; |
1358 } | 1355 } |
1359 return iLen; | 1356 return iLen; |
1360 } | 1357 } |
1361 | 1358 |
1362 int32_t CFX_Stream::WriteData(const uint8_t* pBuffer, int32_t iBufferSize) { | 1359 int32_t CFX_Stream::WriteData(const uint8_t* pBuffer, int32_t iBufferSize) { |
1363 ASSERT(pBuffer != NULL && iBufferSize > 0); | 1360 ASSERT(pBuffer && iBufferSize > 0); |
1364 if (m_pStreamImp == NULL) { | 1361 if (!m_pStreamImp) |
1365 return -1; | 1362 return -1; |
1366 } | 1363 |
1367 if ((m_dwAccess & FX_STREAMACCESS_Write) == 0) { | 1364 if ((m_dwAccess & FX_STREAMACCESS_Write) == 0) { |
1368 return -1; | 1365 return -1; |
1369 } | 1366 } |
1370 int32_t iLen = iBufferSize; | 1367 int32_t iLen = iBufferSize; |
1371 if (m_eStreamType == FX_STREAMTYPE_Stream) { | 1368 if (m_eStreamType == FX_STREAMTYPE_Stream) { |
1372 iLen = std::min(m_iStart + m_iTotalSize - m_iPosition, iBufferSize); | 1369 iLen = std::min(m_iStart + m_iTotalSize - m_iPosition, iBufferSize); |
1373 if (iLen <= 0) { | 1370 if (iLen <= 0) { |
1374 return 0; | 1371 return 0; |
1375 } | 1372 } |
1376 } | 1373 } |
1377 int32_t iEnd = m_iStart + m_iLength; | 1374 int32_t iEnd = m_iStart + m_iLength; |
1378 if (m_pStreamImp->GetPosition() != m_iPosition) { | 1375 if (m_pStreamImp->GetPosition() != m_iPosition) { |
1379 m_pStreamImp->Seek(FX_STREAMSEEK_Begin, m_iPosition); | 1376 m_pStreamImp->Seek(FX_STREAMSEEK_Begin, m_iPosition); |
1380 } | 1377 } |
1381 iLen = m_pStreamImp->WriteData(pBuffer, iLen); | 1378 iLen = m_pStreamImp->WriteData(pBuffer, iLen); |
1382 m_iPosition = m_pStreamImp->GetPosition(); | 1379 m_iPosition = m_pStreamImp->GetPosition(); |
1383 if (m_iPosition > iEnd) { | 1380 if (m_iPosition > iEnd) { |
1384 m_iLength = m_iPosition - m_iStart; | 1381 m_iLength = m_iPosition - m_iStart; |
1385 } | 1382 } |
1386 return iLen; | 1383 return iLen; |
1387 } | 1384 } |
1388 int32_t CFX_Stream::WriteString(const FX_WCHAR* pStr, int32_t iLength) { | 1385 int32_t CFX_Stream::WriteString(const FX_WCHAR* pStr, int32_t iLength) { |
1389 ASSERT(pStr != NULL && iLength > 0); | 1386 ASSERT(pStr && iLength > 0); |
1390 if (m_pStreamImp == NULL) { | 1387 if (!m_pStreamImp) |
1391 return -1; | 1388 return -1; |
1392 } | 1389 |
1393 if ((m_dwAccess & FX_STREAMACCESS_Write) == 0) { | 1390 if ((m_dwAccess & FX_STREAMACCESS_Write) == 0) { |
1394 return -1; | 1391 return -1; |
1395 } | 1392 } |
1396 int32_t iLen = iLength; | 1393 int32_t iLen = iLength; |
1397 if (m_eStreamType == FX_STREAMTYPE_Stream) { | 1394 if (m_eStreamType == FX_STREAMTYPE_Stream) { |
1398 iLen = std::min((m_iStart + m_iTotalSize - m_iPosition) / 2, iLength); | 1395 iLen = std::min((m_iStart + m_iTotalSize - m_iPosition) / 2, iLength); |
1399 if (iLen <= 0) { | 1396 if (iLen <= 0) { |
1400 return 0; | 1397 return 0; |
1401 } | 1398 } |
1402 } | 1399 } |
1403 int32_t iEnd = m_iStart + m_iLength; | 1400 int32_t iEnd = m_iStart + m_iLength; |
1404 if (m_pStreamImp->GetPosition() != m_iPosition) { | 1401 if (m_pStreamImp->GetPosition() != m_iPosition) { |
1405 m_pStreamImp->Seek(FX_STREAMSEEK_Begin, m_iPosition); | 1402 m_pStreamImp->Seek(FX_STREAMSEEK_Begin, m_iPosition); |
1406 } | 1403 } |
1407 iLen = m_pStreamImp->WriteString(pStr, iLen); | 1404 iLen = m_pStreamImp->WriteString(pStr, iLen); |
1408 m_iPosition = m_pStreamImp->GetPosition(); | 1405 m_iPosition = m_pStreamImp->GetPosition(); |
1409 if (m_iPosition > iEnd) { | 1406 if (m_iPosition > iEnd) { |
1410 m_iLength = m_iPosition - m_iStart; | 1407 m_iLength = m_iPosition - m_iStart; |
1411 } | 1408 } |
1412 return iLen; | 1409 return iLen; |
1413 } | 1410 } |
1414 void CFX_Stream::Flush() { | 1411 void CFX_Stream::Flush() { |
1415 if (m_pStreamImp == NULL) { | 1412 if (!m_pStreamImp) |
1416 return; | 1413 return; |
1417 } | 1414 |
1418 if ((m_dwAccess & FX_STREAMACCESS_Write) == 0) { | 1415 if ((m_dwAccess & FX_STREAMACCESS_Write) == 0) { |
1419 return; | 1416 return; |
1420 } | 1417 } |
1421 m_pStreamImp->Flush(); | 1418 m_pStreamImp->Flush(); |
1422 } | 1419 } |
1423 FX_BOOL CFX_Stream::SetLength(int32_t iLength) { | 1420 FX_BOOL CFX_Stream::SetLength(int32_t iLength) { |
1424 if (m_pStreamImp == NULL) { | 1421 if (!m_pStreamImp) |
1425 return FALSE; | 1422 return FALSE; |
1426 } | 1423 |
1427 if ((m_dwAccess & FX_STREAMACCESS_Write) == 0) { | 1424 if ((m_dwAccess & FX_STREAMACCESS_Write) == 0) { |
1428 return FALSE; | 1425 return FALSE; |
1429 } | 1426 } |
1430 return m_pStreamImp->SetLength(iLength); | 1427 return m_pStreamImp->SetLength(iLength); |
1431 } | 1428 } |
1432 int32_t CFX_Stream::GetBOM(uint8_t bom[4]) const { | 1429 int32_t CFX_Stream::GetBOM(uint8_t bom[4]) const { |
1433 if (m_pStreamImp == NULL) { | 1430 if (!m_pStreamImp) |
1434 return -1; | 1431 return -1; |
1435 } | 1432 |
1436 return 0; | 1433 return 0; |
1437 } | 1434 } |
1438 uint16_t CFX_Stream::GetCodePage() const { | 1435 uint16_t CFX_Stream::GetCodePage() const { |
1439 #if _FX_ENDIAN_ == _FX_LITTLE_ENDIAN_ | 1436 #if _FX_ENDIAN_ == _FX_LITTLE_ENDIAN_ |
1440 return FX_CODEPAGE_UTF16LE; | 1437 return FX_CODEPAGE_UTF16LE; |
1441 #else | 1438 #else |
1442 return FX_CODEPAGE_UTF16BE; | 1439 return FX_CODEPAGE_UTF16BE; |
1443 #endif | 1440 #endif |
1444 } | 1441 } |
1445 uint16_t CFX_Stream::SetCodePage(uint16_t wCodePage) { | 1442 uint16_t CFX_Stream::SetCodePage(uint16_t wCodePage) { |
1446 #if _FX_ENDIAN_ == _FX_LITTLE_ENDIAN_ | 1443 #if _FX_ENDIAN_ == _FX_LITTLE_ENDIAN_ |
1447 return FX_CODEPAGE_UTF16LE; | 1444 return FX_CODEPAGE_UTF16LE; |
1448 #else | 1445 #else |
1449 return FX_CODEPAGE_UTF16BE; | 1446 return FX_CODEPAGE_UTF16BE; |
1450 #endif | 1447 #endif |
1451 } | 1448 } |
1452 IFX_Stream* CFX_Stream::CreateSharedStream(uint32_t dwAccess, | 1449 IFX_Stream* CFX_Stream::CreateSharedStream(uint32_t dwAccess, |
1453 int32_t iOffset, | 1450 int32_t iOffset, |
1454 int32_t iLength) { | 1451 int32_t iLength) { |
1455 ASSERT(iLength > 0); | 1452 ASSERT(iLength > 0); |
1456 if (m_pStreamImp == NULL) { | 1453 if (!m_pStreamImp) |
1457 return NULL; | 1454 return nullptr; |
1458 } | 1455 |
1459 if ((m_dwAccess & FX_STREAMACCESS_Text) != 0 && | 1456 if ((m_dwAccess & FX_STREAMACCESS_Text) != 0 && |
1460 (dwAccess & FX_STREAMACCESS_Text) == 0) { | 1457 (dwAccess & FX_STREAMACCESS_Text) == 0) { |
1461 return NULL; | 1458 return nullptr; |
1462 } | 1459 } |
1463 if ((m_dwAccess & FX_STREAMACCESS_Write) == 0 && | 1460 if ((m_dwAccess & FX_STREAMACCESS_Write) == 0 && |
1464 (dwAccess & FX_STREAMACCESS_Write) != 0) { | 1461 (dwAccess & FX_STREAMACCESS_Write) != 0) { |
1465 return NULL; | 1462 return nullptr; |
1466 } | 1463 } |
1467 int32_t iStart = m_iStart + iOffset; | 1464 int32_t iStart = m_iStart + iOffset; |
1468 int32_t iTotal = m_iStart + m_iLength; | 1465 int32_t iTotal = m_iStart + m_iLength; |
1469 if (iStart < m_iStart || iStart >= iTotal) { | 1466 if (iStart < m_iStart || iStart >= iTotal) { |
1470 return NULL; | 1467 return nullptr; |
1471 } | 1468 } |
1472 int32_t iEnd = iStart + iLength; | 1469 int32_t iEnd = iStart + iLength; |
1473 if (iEnd < iStart || iEnd > iTotal) { | 1470 if (iEnd < iStart || iEnd > iTotal) { |
1474 return NULL; | 1471 return nullptr; |
1475 } | 1472 } |
1476 CFX_Stream* pShared = new CFX_Stream; | 1473 CFX_Stream* pShared = new CFX_Stream; |
1477 pShared->m_eStreamType = FX_STREAMTYPE_Stream; | 1474 pShared->m_eStreamType = FX_STREAMTYPE_Stream; |
1478 pShared->m_pStreamImp = m_pStreamImp; | 1475 pShared->m_pStreamImp = m_pStreamImp; |
1479 pShared->m_dwAccess = dwAccess; | 1476 pShared->m_dwAccess = dwAccess; |
1480 pShared->m_iTotalSize = iLength; | 1477 pShared->m_iTotalSize = iLength; |
1481 pShared->m_iPosition = iStart; | 1478 pShared->m_iPosition = iStart; |
1482 pShared->m_iStart = iStart; | 1479 pShared->m_iStart = iStart; |
1483 pShared->m_iLength = (dwAccess & FX_STREAMACCESS_Write) != 0 ? 0 : iLength; | 1480 pShared->m_iLength = (dwAccess & FX_STREAMACCESS_Write) != 0 ? 0 : iLength; |
1484 if (dwAccess & FX_STREAMACCESS_Text) { | 1481 if (dwAccess & FX_STREAMACCESS_Text) { |
1485 return IFX_Stream::CreateTextStream(pShared, TRUE); | 1482 return IFX_Stream::CreateTextStream(pShared, TRUE); |
1486 } | 1483 } |
1487 return pShared; | 1484 return pShared; |
1488 } | 1485 } |
1489 IFX_FileRead* FX_CreateFileRead(IFX_Stream* pBaseStream, | 1486 IFX_FileRead* FX_CreateFileRead(IFX_Stream* pBaseStream, |
1490 FX_BOOL bReleaseStream) { | 1487 FX_BOOL bReleaseStream) { |
1491 ASSERT(pBaseStream != NULL); | 1488 ASSERT(pBaseStream); |
1492 return new CFGAS_FileRead(pBaseStream, bReleaseStream); | 1489 return new CFGAS_FileRead(pBaseStream, bReleaseStream); |
1493 } | 1490 } |
1494 CFGAS_FileRead::CFGAS_FileRead(IFX_Stream* pStream, FX_BOOL bReleaseStream) | 1491 CFGAS_FileRead::CFGAS_FileRead(IFX_Stream* pStream, FX_BOOL bReleaseStream) |
1495 : m_bReleaseStream(bReleaseStream), m_pStream(pStream) { | 1492 : m_bReleaseStream(bReleaseStream), m_pStream(pStream) { |
1496 ASSERT(m_pStream != NULL); | 1493 ASSERT(m_pStream); |
1497 } | 1494 } |
1498 CFGAS_FileRead::~CFGAS_FileRead() { | 1495 CFGAS_FileRead::~CFGAS_FileRead() { |
1499 if (m_bReleaseStream) { | 1496 if (m_bReleaseStream) { |
1500 m_pStream->Release(); | 1497 m_pStream->Release(); |
1501 } | 1498 } |
1502 } | 1499 } |
1503 FX_FILESIZE CFGAS_FileRead::GetSize() { | 1500 FX_FILESIZE CFGAS_FileRead::GetSize() { |
1504 return (FX_FILESIZE)m_pStream->GetLength(); | 1501 return (FX_FILESIZE)m_pStream->GetLength(); |
1505 } | 1502 } |
1506 FX_BOOL CFGAS_FileRead::ReadBlock(void* buffer, | 1503 FX_BOOL CFGAS_FileRead::ReadBlock(void* buffer, |
1507 FX_FILESIZE offset, | 1504 FX_FILESIZE offset, |
1508 size_t size) { | 1505 size_t size) { |
1509 m_pStream->Seek(FX_STREAMSEEK_Begin, (int32_t)offset); | 1506 m_pStream->Seek(FX_STREAMSEEK_Begin, (int32_t)offset); |
1510 int32_t iLen = m_pStream->ReadData((uint8_t*)buffer, (int32_t)size); | 1507 int32_t iLen = m_pStream->ReadData((uint8_t*)buffer, (int32_t)size); |
1511 return iLen == (int32_t)size; | 1508 return iLen == (int32_t)size; |
1512 } | 1509 } |
OLD | NEW |