Chromium Code Reviews| 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 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <memory> | |
| 10 | 11 |
| 11 #include "xfa/fgas/crt/fgas_codepage.h" | 12 #include "xfa/fgas/crt/fgas_codepage.h" |
| 12 #include "xfa/fgas/crt/fgas_system.h" | 13 #include "xfa/fgas/crt/fgas_system.h" |
| 13 | 14 |
| 14 namespace { | 15 namespace { |
| 15 | 16 |
| 16 class CFX_StreamImp { | 17 class IFX_StreamImp { |
| 17 public: | 18 public: |
| 18 virtual void Release() { delete this; } | 19 virtual ~IFX_StreamImp() {} |
| 20 | |
| 19 virtual uint32_t GetAccessModes() const { return m_dwAccess; } | 21 virtual uint32_t GetAccessModes() const { return m_dwAccess; } |
|
Lei Zhang
2016/05/18 23:02:30
This doesn't need to be virtual?
Tom Sepez
2016/05/18 23:29:56
Done.
| |
| 20 virtual int32_t GetLength() const = 0; | 22 virtual int32_t GetLength() const = 0; |
| 21 virtual int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) = 0; | 23 virtual int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) = 0; |
| 22 virtual int32_t GetPosition() = 0; | 24 virtual int32_t GetPosition() = 0; |
| 23 virtual FX_BOOL IsEOF() const = 0; | 25 virtual FX_BOOL IsEOF() const = 0; |
| 24 virtual int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) = 0; | 26 virtual int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) = 0; |
| 25 virtual int32_t ReadString(FX_WCHAR* pStr, | 27 virtual int32_t ReadString(FX_WCHAR* pStr, |
| 26 int32_t iMaxLength, | 28 int32_t iMaxLength, |
| 27 FX_BOOL& bEOS) = 0; | 29 FX_BOOL& bEOS) = 0; |
| 28 virtual int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) = 0; | 30 virtual int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) = 0; |
| 29 virtual int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) = 0; | 31 virtual int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) = 0; |
| 30 virtual void Flush() = 0; | 32 virtual void Flush() = 0; |
| 31 virtual FX_BOOL SetLength(int32_t iLength) = 0; | 33 virtual FX_BOOL SetLength(int32_t iLength) = 0; |
| 32 | 34 |
| 33 protected: | 35 protected: |
| 34 CFX_StreamImp(); | 36 IFX_StreamImp(); |
| 35 virtual ~CFX_StreamImp() {} | 37 |
| 36 uint32_t m_dwAccess; | 38 uint32_t m_dwAccess; |
|
Lei Zhang
2016/05/18 23:02:30
Should be private with GetAccessModes() and a sett
Tom Sepez
2016/05/18 23:29:56
Done. PTAL.
| |
| 37 }; | 39 }; |
| 38 | 40 |
| 39 class CFX_FileStreamImp : public CFX_StreamImp { | 41 class CFX_FileStreamImp : public IFX_StreamImp { |
| 40 public: | 42 public: |
| 41 CFX_FileStreamImp(); | 43 CFX_FileStreamImp(); |
| 42 virtual ~CFX_FileStreamImp(); | 44 ~CFX_FileStreamImp() override; |
| 45 | |
| 43 FX_BOOL LoadFile(const FX_WCHAR* pszSrcFileName, uint32_t dwAccess); | 46 FX_BOOL LoadFile(const FX_WCHAR* pszSrcFileName, uint32_t dwAccess); |
| 44 virtual int32_t GetLength() const; | 47 |
| 45 virtual int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset); | 48 // IFX_StreamImp: |
| 46 virtual int32_t GetPosition(); | 49 int32_t GetLength() const override; |
| 47 virtual FX_BOOL IsEOF() const; | 50 int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) override; |
| 48 virtual int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize); | 51 int32_t GetPosition() override; |
| 49 virtual int32_t ReadString(FX_WCHAR* pStr, int32_t iMaxLength, FX_BOOL& bEOS); | 52 FX_BOOL IsEOF() const override; |
| 50 virtual int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize); | 53 int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) override; |
| 51 virtual int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength); | 54 int32_t ReadString(FX_WCHAR* pStr, |
| 52 virtual void Flush(); | 55 int32_t iMaxLength, |
| 53 virtual FX_BOOL SetLength(int32_t iLength); | 56 FX_BOOL& bEOS) override; |
| 57 int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) override; | |
| 58 int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) override; | |
| 59 void Flush() override; | |
| 60 FX_BOOL SetLength(int32_t iLength) override; | |
| 54 | 61 |
| 55 protected: | 62 protected: |
| 56 FXSYS_FILE* m_hFile; | 63 FXSYS_FILE* m_hFile; |
| 57 int32_t m_iLength; | 64 int32_t m_iLength; |
| 58 }; | 65 }; |
| 59 | 66 |
| 60 class CFX_BufferStreamImp : public CFX_StreamImp { | 67 class CFX_BufferStreamImp : public IFX_StreamImp { |
| 61 public: | 68 public: |
| 62 CFX_BufferStreamImp(); | 69 CFX_BufferStreamImp(); |
| 63 virtual ~CFX_BufferStreamImp() {} | 70 ~CFX_BufferStreamImp() override {} |
| 71 | |
| 64 FX_BOOL LoadBuffer(uint8_t* pData, int32_t iTotalSize, uint32_t dwAccess); | 72 FX_BOOL LoadBuffer(uint8_t* pData, int32_t iTotalSize, uint32_t dwAccess); |
| 65 virtual int32_t GetLength() const; | 73 |
| 66 virtual int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset); | 74 // IFX_StreamImp: |
| 67 virtual int32_t GetPosition(); | 75 int32_t GetLength() const override; |
| 68 virtual FX_BOOL IsEOF() const; | 76 int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) override; |
| 69 virtual int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize); | 77 int32_t GetPosition() override; |
| 70 virtual int32_t ReadString(FX_WCHAR* pStr, int32_t iMaxLength, FX_BOOL& bEOS); | 78 FX_BOOL IsEOF() const override; |
| 71 virtual int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize); | 79 int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) override; |
| 72 virtual int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength); | 80 int32_t ReadString(FX_WCHAR* pStr, |
| 73 virtual void Flush() {} | 81 int32_t iMaxLength, |
| 74 virtual FX_BOOL SetLength(int32_t iLength) { return FALSE; } | 82 FX_BOOL& bEOS) override; |
| 83 int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) override; | |
| 84 int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) override; | |
| 85 void Flush() override {} | |
| 86 FX_BOOL SetLength(int32_t iLength) override { return FALSE; } | |
| 75 | 87 |
| 76 protected: | 88 protected: |
| 77 uint8_t* m_pData; | 89 uint8_t* m_pData; |
| 78 int32_t m_iTotalSize; | 90 int32_t m_iTotalSize; |
| 79 int32_t m_iPosition; | 91 int32_t m_iPosition; |
| 80 int32_t m_iLength; | 92 int32_t m_iLength; |
| 81 }; | 93 }; |
| 82 | 94 |
| 83 class CFX_FileReadStreamImp : public CFX_StreamImp { | 95 class CFX_FileReadStreamImp : public IFX_StreamImp { |
| 84 public: | 96 public: |
| 85 CFX_FileReadStreamImp(); | 97 CFX_FileReadStreamImp(); |
| 86 virtual ~CFX_FileReadStreamImp() {} | 98 ~CFX_FileReadStreamImp() override {} |
| 99 | |
| 87 FX_BOOL LoadFileRead(IFX_FileRead* pFileRead, uint32_t dwAccess); | 100 FX_BOOL LoadFileRead(IFX_FileRead* pFileRead, uint32_t dwAccess); |
| 88 virtual int32_t GetLength() const; | |
| 89 virtual int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset); | |
| 90 virtual int32_t GetPosition() { return m_iPosition; } | |
| 91 virtual FX_BOOL IsEOF() const; | |
| 92 | 101 |
| 93 virtual int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize); | 102 // IFX_StreamImp: |
| 94 virtual int32_t ReadString(FX_WCHAR* pStr, int32_t iMaxLength, FX_BOOL& bEOS); | 103 int32_t GetLength() const override; |
| 95 virtual int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) { | 104 int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) override; |
| 105 int32_t GetPosition() override { return m_iPosition; } | |
| 106 FX_BOOL IsEOF() const override; | |
| 107 | |
| 108 int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) override; | |
| 109 int32_t ReadString(FX_WCHAR* pStr, | |
| 110 int32_t iMaxLength, | |
| 111 FX_BOOL& bEOS) override; | |
| 112 int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) override { | |
| 96 return 0; | 113 return 0; |
| 97 } | 114 } |
| 98 virtual int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) { | 115 int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) override { |
| 99 return 0; | 116 return 0; |
| 100 } | 117 } |
| 101 virtual void Flush() {} | 118 void Flush() override {} |
| 102 virtual FX_BOOL SetLength(int32_t iLength) { return FALSE; } | 119 FX_BOOL SetLength(int32_t iLength) override { return FALSE; } |
| 103 | 120 |
| 104 protected: | 121 protected: |
| 105 IFX_FileRead* m_pFileRead; | 122 IFX_FileRead* m_pFileRead; |
| 106 int32_t m_iPosition; | 123 int32_t m_iPosition; |
| 107 int32_t m_iLength; | 124 int32_t m_iLength; |
| 108 }; | 125 }; |
| 109 | 126 |
| 110 class CFX_BufferReadStreamImp : public CFX_StreamImp { | 127 class CFX_BufferReadStreamImp : public IFX_StreamImp { |
| 111 public: | 128 public: |
| 112 CFX_BufferReadStreamImp(); | 129 CFX_BufferReadStreamImp(); |
| 113 ~CFX_BufferReadStreamImp(); | 130 ~CFX_BufferReadStreamImp() override; |
| 131 | |
| 114 FX_BOOL LoadBufferRead(IFX_BufferRead* pBufferRead, | 132 FX_BOOL LoadBufferRead(IFX_BufferRead* pBufferRead, |
| 115 int32_t iFileSize, | 133 int32_t iFileSize, |
| 116 uint32_t dwAccess, | 134 uint32_t dwAccess, |
| 117 FX_BOOL bReleaseBufferRead); | 135 FX_BOOL bReleaseBufferRead); |
| 118 | 136 |
| 119 virtual int32_t GetLength() const; | 137 // IFX_StreamImp: |
| 120 virtual int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset); | 138 int32_t GetLength() const override; |
| 121 virtual int32_t GetPosition() { return m_iPosition; } | 139 int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) override; |
| 122 virtual FX_BOOL IsEOF() const; | 140 int32_t GetPosition() override { return m_iPosition; } |
| 123 | 141 FX_BOOL IsEOF() const override; |
| 124 virtual int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize); | 142 int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) override; |
| 125 virtual int32_t ReadString(FX_WCHAR* pStr, int32_t iMaxLength, FX_BOOL& bEOS); | 143 int32_t ReadString(FX_WCHAR* pStr, |
| 126 virtual int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) { | 144 int32_t iMaxLength, |
| 145 FX_BOOL& bEOS) override; | |
| 146 int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) override { | |
| 127 return 0; | 147 return 0; |
| 128 } | 148 } |
| 129 virtual int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) { | 149 int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) override { |
| 130 return 0; | 150 return 0; |
| 131 } | 151 } |
| 132 virtual void Flush() {} | 152 void Flush() override {} |
| 133 virtual FX_BOOL SetLength(int32_t iLength) { return FALSE; } | 153 FX_BOOL SetLength(int32_t iLength) override { return FALSE; } |
| 134 | 154 |
| 135 private: | 155 private: |
| 136 IFX_BufferRead* m_pBufferRead; | 156 IFX_BufferRead* m_pBufferRead; |
| 137 FX_BOOL m_bReleaseBufferRead; | 157 FX_BOOL m_bReleaseBufferRead; |
| 138 int32_t m_iPosition; | 158 int32_t m_iPosition; |
| 139 int32_t m_iBufferSize; | 159 int32_t m_iBufferSize; |
| 140 }; | 160 }; |
| 141 | 161 |
| 142 class CFX_FileWriteStreamImp : public CFX_StreamImp { | 162 class CFX_FileWriteStreamImp : public IFX_StreamImp { |
| 143 public: | 163 public: |
| 144 CFX_FileWriteStreamImp(); | 164 CFX_FileWriteStreamImp(); |
| 145 virtual ~CFX_FileWriteStreamImp() {} | 165 ~CFX_FileWriteStreamImp() override {} |
| 166 | |
| 146 FX_BOOL LoadFileWrite(IFX_FileWrite* pFileWrite, uint32_t dwAccess); | 167 FX_BOOL LoadFileWrite(IFX_FileWrite* pFileWrite, uint32_t dwAccess); |
| 147 virtual int32_t GetLength() const; | 168 |
| 148 virtual int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset); | 169 // IFX_StreamImp: |
| 149 virtual int32_t GetPosition() { return m_iPosition; } | 170 int32_t GetLength() const override; |
| 150 virtual FX_BOOL IsEOF() const; | 171 int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) override; |
| 151 virtual int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) { return 0; } | 172 int32_t GetPosition() override { return m_iPosition; } |
| 152 virtual int32_t ReadString(FX_WCHAR* pStr, | 173 FX_BOOL IsEOF() const override; |
| 153 int32_t iMaxLength, | 174 int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) override { return 0; } |
| 154 FX_BOOL& bEOS) { | 175 int32_t ReadString(FX_WCHAR* pStr, |
| 176 int32_t iMaxLength, | |
| 177 FX_BOOL& bEOS) override { | |
| 155 return 0; | 178 return 0; |
| 156 } | 179 } |
| 157 virtual int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize); | 180 int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) override; |
| 158 virtual int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength); | 181 int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) override; |
| 159 virtual void Flush(); | 182 void Flush() override; |
| 160 virtual FX_BOOL SetLength(int32_t iLength) { return FALSE; } | 183 FX_BOOL SetLength(int32_t iLength) override { return FALSE; } |
| 161 | 184 |
| 162 protected: | 185 protected: |
| 163 IFX_FileWrite* m_pFileWrite; | 186 IFX_FileWrite* m_pFileWrite; |
| 164 int32_t m_iPosition; | 187 int32_t m_iPosition; |
| 165 }; | 188 }; |
| 166 | 189 |
| 167 enum FX_STREAMTYPE { | 190 enum FX_STREAMTYPE { |
| 168 FX_SREAMTYPE_Unknown = 0, | 191 FX_SREAMTYPE_Unknown = 0, |
| 169 FX_STREAMTYPE_File, | 192 FX_STREAMTYPE_File, |
| 170 FX_STREAMTYPE_Buffer, | 193 FX_STREAMTYPE_Buffer, |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 202 virtual FX_BOOL SetLength(int32_t iLength); | 225 virtual FX_BOOL SetLength(int32_t iLength); |
| 203 virtual int32_t GetBOM(uint8_t bom[4]) const; | 226 virtual int32_t GetBOM(uint8_t bom[4]) const; |
| 204 virtual uint16_t GetCodePage() const; | 227 virtual uint16_t GetCodePage() const; |
| 205 virtual uint16_t SetCodePage(uint16_t wCodePage); | 228 virtual uint16_t SetCodePage(uint16_t wCodePage); |
| 206 virtual IFX_Stream* CreateSharedStream(uint32_t dwAccess, | 229 virtual IFX_Stream* CreateSharedStream(uint32_t dwAccess, |
| 207 int32_t iOffset, | 230 int32_t iOffset, |
| 208 int32_t iLength); | 231 int32_t iLength); |
| 209 | 232 |
| 210 protected: | 233 protected: |
| 211 FX_STREAMTYPE m_eStreamType; | 234 FX_STREAMTYPE m_eStreamType; |
| 212 CFX_StreamImp* m_pStreamImp; | 235 IFX_StreamImp* m_pStreamImp; |
| 213 uint32_t m_dwAccess; | 236 uint32_t m_dwAccess; |
| 214 int32_t m_iTotalSize; | 237 int32_t m_iTotalSize; |
| 215 int32_t m_iPosition; | 238 int32_t m_iPosition; |
| 216 int32_t m_iStart; | 239 int32_t m_iStart; |
| 217 int32_t m_iLength; | 240 int32_t m_iLength; |
| 218 int32_t m_iRefCount; | 241 int32_t m_iRefCount; |
| 219 }; | 242 }; |
| 220 | 243 |
| 221 class CFX_TextStream : public IFX_Stream { | 244 class CFX_TextStream : public IFX_Stream { |
| 222 public: | 245 public: |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 367 if (!pSR->LoadBuffer(pData, length, dwAccess)) { | 390 if (!pSR->LoadBuffer(pData, length, dwAccess)) { |
| 368 pSR->Release(); | 391 pSR->Release(); |
| 369 return NULL; | 392 return NULL; |
| 370 } | 393 } |
| 371 if (dwAccess & FX_STREAMACCESS_Text) { | 394 if (dwAccess & FX_STREAMACCESS_Text) { |
| 372 return new CFX_TextStream(pSR, TRUE); | 395 return new CFX_TextStream(pSR, TRUE); |
| 373 } | 396 } |
| 374 return pSR; | 397 return pSR; |
| 375 } | 398 } |
| 376 | 399 |
| 377 CFX_StreamImp::CFX_StreamImp() : m_dwAccess(0) {} | 400 IFX_StreamImp::IFX_StreamImp() : m_dwAccess(0) {} |
| 378 CFX_FileStreamImp::CFX_FileStreamImp() | 401 CFX_FileStreamImp::CFX_FileStreamImp() |
| 379 : CFX_StreamImp(), m_hFile(NULL), m_iLength(0) {} | 402 : IFX_StreamImp(), m_hFile(NULL), m_iLength(0) {} |
| 380 CFX_FileStreamImp::~CFX_FileStreamImp() { | 403 CFX_FileStreamImp::~CFX_FileStreamImp() { |
| 381 if (m_hFile != NULL) { | 404 if (m_hFile != NULL) { |
| 382 FXSYS_fclose(m_hFile); | 405 FXSYS_fclose(m_hFile); |
| 383 } | 406 } |
| 384 } | 407 } |
| 385 FX_BOOL CFX_FileStreamImp::LoadFile(const FX_WCHAR* pszSrcFileName, | 408 FX_BOOL CFX_FileStreamImp::LoadFile(const FX_WCHAR* pszSrcFileName, |
| 386 uint32_t dwAccess) { | 409 uint32_t dwAccess) { |
| 387 ASSERT(m_hFile == NULL); | 410 ASSERT(m_hFile == NULL); |
| 388 ASSERT(pszSrcFileName != NULL && FXSYS_wcslen(pszSrcFileName) > 0); | 411 ASSERT(pszSrcFileName != NULL && FXSYS_wcslen(pszSrcFileName) > 0); |
| 389 #if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN32_MOBILE_ || \ | 412 #if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN32_MOBILE_ || \ |
| (...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 793 int32_t CFX_FileWriteStreamImp::WriteString(const FX_WCHAR* pStr, | 816 int32_t CFX_FileWriteStreamImp::WriteString(const FX_WCHAR* pStr, |
| 794 int32_t iLength) { | 817 int32_t iLength) { |
| 795 return WriteData((const uint8_t*)pStr, iLength * sizeof(FX_WCHAR)); | 818 return WriteData((const uint8_t*)pStr, iLength * sizeof(FX_WCHAR)); |
| 796 } | 819 } |
| 797 void CFX_FileWriteStreamImp::Flush() { | 820 void CFX_FileWriteStreamImp::Flush() { |
| 798 if (m_pFileWrite) { | 821 if (m_pFileWrite) { |
| 799 m_pFileWrite->Flush(); | 822 m_pFileWrite->Flush(); |
| 800 } | 823 } |
| 801 } | 824 } |
| 802 CFX_BufferStreamImp::CFX_BufferStreamImp() | 825 CFX_BufferStreamImp::CFX_BufferStreamImp() |
| 803 : CFX_StreamImp(), | 826 : m_pData(nullptr), m_iTotalSize(0), m_iPosition(0), m_iLength(0) {} |
| 804 m_pData(NULL), | 827 |
| 805 m_iTotalSize(0), | |
| 806 m_iPosition(0), | |
| 807 m_iLength(0) {} | |
| 808 FX_BOOL CFX_BufferStreamImp::LoadBuffer(uint8_t* pData, | 828 FX_BOOL CFX_BufferStreamImp::LoadBuffer(uint8_t* pData, |
| 809 int32_t iTotalSize, | 829 int32_t iTotalSize, |
| 810 uint32_t dwAccess) { | 830 uint32_t dwAccess) { |
| 811 ASSERT(m_pData == NULL); | 831 ASSERT(m_pData == NULL); |
| 812 ASSERT(pData != NULL && iTotalSize > 0); | 832 ASSERT(pData != NULL && iTotalSize > 0); |
| 813 m_dwAccess = dwAccess; | 833 m_dwAccess = dwAccess; |
| 814 m_pData = pData; | 834 m_pData = pData; |
| 815 m_iTotalSize = iTotalSize; | 835 m_iTotalSize = iTotalSize; |
| 816 m_iPosition = 0; | 836 m_iPosition = 0; |
| 817 m_iLength = (dwAccess & FX_STREAMACCESS_Write) != 0 ? 0 : iTotalSize; | 837 m_iLength = (dwAccess & FX_STREAMACCESS_Write) != 0 ? 0 : iTotalSize; |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1117 } | 1137 } |
| 1118 CFX_Stream::CFX_Stream() | 1138 CFX_Stream::CFX_Stream() |
| 1119 : m_eStreamType(FX_SREAMTYPE_Unknown), | 1139 : m_eStreamType(FX_SREAMTYPE_Unknown), |
| 1120 m_pStreamImp(NULL), | 1140 m_pStreamImp(NULL), |
| 1121 m_dwAccess(0), | 1141 m_dwAccess(0), |
| 1122 m_iTotalSize(0), | 1142 m_iTotalSize(0), |
| 1123 m_iPosition(0), | 1143 m_iPosition(0), |
| 1124 m_iStart(0), | 1144 m_iStart(0), |
| 1125 m_iLength(0), | 1145 m_iLength(0), |
| 1126 m_iRefCount(1) {} | 1146 m_iRefCount(1) {} |
| 1147 | |
| 1127 CFX_Stream::~CFX_Stream() { | 1148 CFX_Stream::~CFX_Stream() { |
| 1128 if (m_eStreamType != FX_STREAMTYPE_Stream && m_pStreamImp != NULL) { | 1149 if (m_eStreamType != FX_STREAMTYPE_Stream) |
| 1129 m_pStreamImp->Release(); | 1150 delete m_pStreamImp; |
| 1130 } | |
| 1131 } | 1151 } |
| 1152 | |
| 1132 FX_BOOL CFX_Stream::LoadFile(const FX_WCHAR* pszSrcFileName, | 1153 FX_BOOL CFX_Stream::LoadFile(const FX_WCHAR* pszSrcFileName, |
| 1133 uint32_t dwAccess) { | 1154 uint32_t dwAccess) { |
| 1134 if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp != NULL) { | 1155 if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp) |
| 1135 return FALSE; | 1156 return FALSE; |
| 1136 } | 1157 |
| 1137 if (pszSrcFileName == NULL || FXSYS_wcslen(pszSrcFileName) < 1) { | 1158 if (!pszSrcFileName || FXSYS_wcslen(pszSrcFileName) < 1) |
| 1138 return FALSE; | 1159 return FALSE; |
| 1139 } | 1160 |
| 1140 m_pStreamImp = new CFX_FileStreamImp(); | 1161 std::unique_ptr<CFX_FileStreamImp> pImp(new CFX_FileStreamImp()); |
| 1141 FX_BOOL bRet = | 1162 if (!pImp->LoadFile(pszSrcFileName, dwAccess)) |
| 1142 ((CFX_FileStreamImp*)m_pStreamImp)->LoadFile(pszSrcFileName, dwAccess); | 1163 return FALSE; |
| 1143 if (!bRet) { | 1164 |
| 1144 m_pStreamImp->Release(); | 1165 m_pStreamImp = pImp.release(); |
| 1145 m_pStreamImp = NULL; | 1166 m_eStreamType = FX_STREAMTYPE_File; |
| 1146 } else { | 1167 m_dwAccess = dwAccess; |
| 1147 m_eStreamType = FX_STREAMTYPE_File; | 1168 m_iLength = m_pStreamImp->GetLength(); |
| 1148 m_dwAccess = dwAccess; | 1169 return TRUE; |
| 1149 m_iLength = m_pStreamImp->GetLength(); | |
| 1150 } | |
| 1151 return bRet; | |
| 1152 } | 1170 } |
| 1171 | |
| 1153 FX_BOOL CFX_Stream::LoadFileRead(IFX_FileRead* pFileRead, uint32_t dwAccess) { | 1172 FX_BOOL CFX_Stream::LoadFileRead(IFX_FileRead* pFileRead, uint32_t dwAccess) { |
| 1154 if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp != NULL) { | 1173 if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp) |
| 1155 return FALSE; | 1174 return FALSE; |
| 1156 } | 1175 |
| 1157 if (pFileRead == NULL) { | 1176 if (!pFileRead) |
| 1158 return FALSE; | 1177 return FALSE; |
| 1159 } | 1178 |
| 1160 m_pStreamImp = new CFX_FileReadStreamImp(); | 1179 std::unique_ptr<CFX_FileReadStreamImp> pImp(new CFX_FileReadStreamImp()); |
| 1161 FX_BOOL bRet = | 1180 if (!pImp->LoadFileRead(pFileRead, dwAccess)) |
| 1162 ((CFX_FileReadStreamImp*)m_pStreamImp)->LoadFileRead(pFileRead, dwAccess); | 1181 return FALSE; |
| 1163 if (!bRet) { | 1182 |
| 1164 m_pStreamImp->Release(); | 1183 m_pStreamImp = pImp.release(); |
| 1165 m_pStreamImp = NULL; | 1184 m_eStreamType = FX_STREAMTYPE_File; |
| 1166 } else { | 1185 m_dwAccess = dwAccess; |
| 1167 m_eStreamType = FX_STREAMTYPE_File; | 1186 m_iLength = m_pStreamImp->GetLength(); |
| 1168 m_dwAccess = dwAccess; | 1187 return TRUE; |
| 1169 m_iLength = m_pStreamImp->GetLength(); | |
| 1170 } | |
| 1171 return bRet; | |
| 1172 } | 1188 } |
| 1189 | |
| 1173 FX_BOOL CFX_Stream::LoadFileWrite(IFX_FileWrite* pFileWrite, | 1190 FX_BOOL CFX_Stream::LoadFileWrite(IFX_FileWrite* pFileWrite, |
| 1174 uint32_t dwAccess) { | 1191 uint32_t dwAccess) { |
| 1175 if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp != NULL) { | 1192 if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp) |
| 1176 return FALSE; | 1193 return FALSE; |
| 1177 } | 1194 |
| 1178 if (pFileWrite == NULL) { | 1195 if (!pFileWrite) |
| 1179 return FALSE; | 1196 return FALSE; |
| 1180 } | 1197 |
| 1181 m_pStreamImp = new CFX_FileWriteStreamImp(); | 1198 std::unique_ptr<CFX_FileWriteStreamImp> pImp(new CFX_FileWriteStreamImp()); |
| 1182 FX_BOOL bRet = ((CFX_FileWriteStreamImp*)m_pStreamImp) | 1199 if (!pImp->LoadFileWrite(pFileWrite, dwAccess)) |
| 1183 ->LoadFileWrite(pFileWrite, dwAccess); | 1200 return FALSE; |
| 1184 if (!bRet) { | 1201 |
| 1185 m_pStreamImp->Release(); | 1202 m_pStreamImp = pImp.release(); |
| 1186 m_pStreamImp = NULL; | 1203 m_eStreamType = FX_STREAMTYPE_File; |
| 1187 } else { | 1204 m_dwAccess = dwAccess; |
| 1188 m_eStreamType = FX_STREAMTYPE_File; | 1205 m_iLength = m_pStreamImp->GetLength(); |
| 1189 m_dwAccess = dwAccess; | 1206 return TRUE; |
| 1190 m_iLength = m_pStreamImp->GetLength(); | |
| 1191 } | |
| 1192 return bRet; | |
| 1193 } | 1207 } |
| 1208 | |
| 1194 FX_BOOL CFX_Stream::LoadBuffer(uint8_t* pData, | 1209 FX_BOOL CFX_Stream::LoadBuffer(uint8_t* pData, |
| 1195 int32_t iTotalSize, | 1210 int32_t iTotalSize, |
| 1196 uint32_t dwAccess) { | 1211 uint32_t dwAccess) { |
| 1197 if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp != NULL) { | 1212 if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp) |
| 1198 return FALSE; | 1213 return FALSE; |
| 1199 } | 1214 |
| 1200 if (pData == NULL || iTotalSize < 1) { | 1215 if (!pData || iTotalSize < 1) |
| 1201 return FALSE; | 1216 return FALSE; |
| 1202 } | 1217 |
| 1203 m_pStreamImp = new CFX_BufferStreamImp(); | 1218 std::unique_ptr<CFX_BufferStreamImp> pImp(new CFX_BufferStreamImp()); |
| 1204 FX_BOOL bRet = ((CFX_BufferStreamImp*)m_pStreamImp) | 1219 if (!pImp->LoadBuffer(pData, iTotalSize, dwAccess)) |
| 1205 ->LoadBuffer(pData, iTotalSize, dwAccess); | 1220 return FALSE; |
| 1206 if (!bRet) { | 1221 |
| 1207 m_pStreamImp->Release(); | 1222 m_pStreamImp = pImp.release(); |
| 1208 m_pStreamImp = NULL; | 1223 m_eStreamType = FX_STREAMTYPE_Buffer; |
| 1209 } else { | 1224 m_dwAccess = dwAccess; |
| 1210 m_eStreamType = FX_STREAMTYPE_Buffer; | 1225 m_iLength = m_pStreamImp->GetLength(); |
| 1211 m_dwAccess = dwAccess; | 1226 return TRUE; |
| 1212 m_iLength = m_pStreamImp->GetLength(); | |
| 1213 } | |
| 1214 return bRet; | |
| 1215 } | 1227 } |
| 1228 | |
| 1216 FX_BOOL CFX_Stream::LoadBufferRead(IFX_BufferRead* pBufferRead, | 1229 FX_BOOL CFX_Stream::LoadBufferRead(IFX_BufferRead* pBufferRead, |
| 1217 int32_t iFileSize, | 1230 int32_t iFileSize, |
| 1218 uint32_t dwAccess, | 1231 uint32_t dwAccess, |
| 1219 FX_BOOL bReleaseBufferRead) { | 1232 FX_BOOL bReleaseBufferRead) { |
| 1220 if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp != NULL) { | 1233 if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp) |
| 1221 return FALSE; | 1234 return FALSE; |
| 1222 } | 1235 |
| 1223 if (!pBufferRead) { | 1236 if (!pBufferRead) |
| 1224 return FALSE; | 1237 return FALSE; |
| 1225 } | 1238 |
| 1226 m_pStreamImp = new CFX_BufferReadStreamImp; | 1239 std::unique_ptr<CFX_BufferReadStreamImp> pImp(new CFX_BufferReadStreamImp); |
| 1227 FX_BOOL bRet = ((CFX_BufferReadStreamImp*)m_pStreamImp) | 1240 if (!pImp->LoadBufferRead(pBufferRead, iFileSize, dwAccess, |
| 1228 ->LoadBufferRead(pBufferRead, iFileSize, dwAccess, | 1241 bReleaseBufferRead)) |
| 1229 bReleaseBufferRead); | 1242 return FALSE; |
| 1230 if (!bRet) { | 1243 |
| 1231 m_pStreamImp->Release(); | 1244 m_pStreamImp = pImp.release(); |
| 1232 m_pStreamImp = NULL; | 1245 m_eStreamType = FX_STREAMTYPE_BufferRead; |
| 1233 } else { | 1246 m_dwAccess = dwAccess; |
| 1234 m_eStreamType = FX_STREAMTYPE_BufferRead; | 1247 m_iLength = m_pStreamImp->GetLength(); |
| 1235 m_dwAccess = dwAccess; | 1248 return TRUE; |
| 1236 m_iLength = m_pStreamImp->GetLength(); | |
| 1237 } | |
| 1238 return bRet; | |
| 1239 } | 1249 } |
| 1250 | |
| 1240 void CFX_Stream::Release() { | 1251 void CFX_Stream::Release() { |
| 1241 if (--m_iRefCount < 1) { | 1252 if (--m_iRefCount < 1) { |
| 1242 delete this; | 1253 delete this; |
| 1243 } | 1254 } |
| 1244 } | 1255 } |
| 1245 IFX_Stream* CFX_Stream::Retain() { | 1256 IFX_Stream* CFX_Stream::Retain() { |
| 1246 m_iRefCount++; | 1257 m_iRefCount++; |
| 1247 return this; | 1258 return this; |
| 1248 } | 1259 } |
| 1249 int32_t CFX_Stream::GetLength() const { | 1260 int32_t CFX_Stream::GetLength() const { |
| (...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1617 return m_pStream->WriteData((const uint8_t*)pData, (int32_t)size) == | 1628 return m_pStream->WriteData((const uint8_t*)pData, (int32_t)size) == |
| 1618 (int32_t)size; | 1629 (int32_t)size; |
| 1619 } | 1630 } |
| 1620 FX_BOOL CFGAS_FileWrite::WriteBlock(const void* pData, | 1631 FX_BOOL CFGAS_FileWrite::WriteBlock(const void* pData, |
| 1621 FX_FILESIZE offset, | 1632 FX_FILESIZE offset, |
| 1622 size_t size) { | 1633 size_t size) { |
| 1623 m_pStream->Seek(FX_STREAMSEEK_Begin, offset); | 1634 m_pStream->Seek(FX_STREAMSEEK_Begin, offset); |
| 1624 int32_t iLen = m_pStream->WriteData((uint8_t*)pData, (int32_t)size); | 1635 int32_t iLen = m_pStream->WriteData((uint8_t*)pData, (int32_t)size); |
| 1625 return iLen == (int32_t)size; | 1636 return iLen == (int32_t)size; |
| 1626 } | 1637 } |
| OLD | NEW |