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