| 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 #ifndef CORE_FXCRT_FX_STREAM_H_ | 7 #ifndef CORE_FXCRT_FX_STREAM_H_ |
| 8 #define CORE_FXCRT_FX_STREAM_H_ | 8 #define CORE_FXCRT_FX_STREAM_H_ |
| 9 | 9 |
| 10 #include "core/fxcrt/cfx_retain_ptr.h" |
| 10 #include "core/fxcrt/fx_string.h" | 11 #include "core/fxcrt/fx_string.h" |
| 11 #include "core/fxcrt/fx_system.h" | 12 #include "core/fxcrt/fx_system.h" |
| 12 | 13 |
| 13 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 14 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
| 14 #include <direct.h> | 15 #include <direct.h> |
| 15 | 16 |
| 16 class CFindFileDataA; | 17 class CFindFileDataA; |
| 17 typedef CFindFileDataA FX_FileHandle; | 18 typedef CFindFileDataA FX_FileHandle; |
| 18 #define FX_FILESIZE int32_t | 19 #define FX_FILESIZE int32_t |
| 19 | 20 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 41 bool FX_GetNextFile(FX_FileHandle* handle, | 42 bool FX_GetNextFile(FX_FileHandle* handle, |
| 42 CFX_ByteString* filename, | 43 CFX_ByteString* filename, |
| 43 bool* bFolder); | 44 bool* bFolder); |
| 44 void FX_CloseFolder(FX_FileHandle* handle); | 45 void FX_CloseFolder(FX_FileHandle* handle); |
| 45 FX_WCHAR FX_GetFolderSeparator(); | 46 FX_WCHAR FX_GetFolderSeparator(); |
| 46 | 47 |
| 47 #define FX_FILEMODE_Write 0 | 48 #define FX_FILEMODE_Write 0 |
| 48 #define FX_FILEMODE_ReadOnly 1 | 49 #define FX_FILEMODE_ReadOnly 1 |
| 49 #define FX_FILEMODE_Truncate 2 | 50 #define FX_FILEMODE_Truncate 2 |
| 50 | 51 |
| 51 class IFX_WriteStream { | 52 class IFX_WriteStream : virtual public CFX_Retainable { |
| 52 public: | 53 public: |
| 53 virtual ~IFX_WriteStream() {} | |
| 54 virtual void Release() = 0; | |
| 55 virtual bool WriteBlock(const void* pData, size_t size) = 0; | 54 virtual bool WriteBlock(const void* pData, size_t size) = 0; |
| 56 }; | 55 }; |
| 57 | 56 |
| 58 class IFX_ReadStream { | 57 class IFX_ReadStream : virtual public CFX_Retainable { |
| 59 public: | 58 public: |
| 60 virtual ~IFX_ReadStream() {} | |
| 61 | |
| 62 virtual void Release() = 0; | |
| 63 virtual bool IsEOF() = 0; | 59 virtual bool IsEOF() = 0; |
| 64 virtual FX_FILESIZE GetPosition() = 0; | 60 virtual FX_FILESIZE GetPosition() = 0; |
| 65 virtual size_t ReadBlock(void* buffer, size_t size) = 0; | 61 virtual size_t ReadBlock(void* buffer, size_t size) = 0; |
| 66 }; | 62 }; |
| 67 | 63 |
| 68 class IFX_SeekableWriteStream : public IFX_WriteStream { | 64 class IFX_SeekableWriteStream : public IFX_WriteStream { |
| 69 public: | 65 public: |
| 70 // IFX_WriteStream: | 66 // IFX_WriteStream: |
| 71 bool WriteBlock(const void* pData, size_t size) override; | 67 bool WriteBlock(const void* pData, size_t size) override; |
| 68 |
| 72 virtual FX_FILESIZE GetSize() = 0; | 69 virtual FX_FILESIZE GetSize() = 0; |
| 73 virtual bool Flush() = 0; | 70 virtual bool Flush() = 0; |
| 74 virtual bool WriteBlock(const void* pData, | 71 virtual bool WriteBlock(const void* pData, |
| 75 FX_FILESIZE offset, | 72 FX_FILESIZE offset, |
| 76 size_t size) = 0; | 73 size_t size) = 0; |
| 77 }; | 74 }; |
| 78 | 75 |
| 79 class IFX_SeekableReadStream : public IFX_ReadStream { | 76 class IFX_SeekableReadStream : public IFX_ReadStream { |
| 80 public: | 77 public: |
| 81 static IFX_SeekableReadStream* CreateFromFilename(const FX_CHAR* filename); | 78 static CFX_RetainPtr<IFX_SeekableReadStream> CreateFromFilename( |
| 79 const FX_CHAR* filename); |
| 82 | 80 |
| 83 // IFX_ReadStream: | 81 // IFX_ReadStream: |
| 84 void Release() override = 0; | |
| 85 bool IsEOF() override; | 82 bool IsEOF() override; |
| 86 FX_FILESIZE GetPosition() override; | 83 FX_FILESIZE GetPosition() override; |
| 87 size_t ReadBlock(void* buffer, size_t size) override; | 84 size_t ReadBlock(void* buffer, size_t size) override; |
| 88 | 85 |
| 89 virtual bool ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) = 0; | 86 virtual bool ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) = 0; |
| 90 virtual FX_FILESIZE GetSize() = 0; | 87 virtual FX_FILESIZE GetSize() = 0; |
| 91 }; | 88 }; |
| 92 | 89 |
| 93 class IFX_SeekableStream : public IFX_SeekableReadStream, | 90 class IFX_SeekableStream : public IFX_SeekableReadStream, |
| 94 public IFX_SeekableWriteStream { | 91 public IFX_SeekableWriteStream { |
| 95 public: | 92 public: |
| 96 static IFX_SeekableStream* CreateFromFilename(const FX_CHAR* filename, | 93 static CFX_RetainPtr<IFX_SeekableStream> CreateFromFilename( |
| 97 uint32_t dwModes); | 94 const FX_CHAR* filename, |
| 98 static IFX_SeekableStream* CreateFromFilename(const FX_WCHAR* filename, | 95 uint32_t dwModes); |
| 99 uint32_t dwModes); | |
| 100 | 96 |
| 101 virtual IFX_SeekableStream* Retain() = 0; | 97 static CFX_RetainPtr<IFX_SeekableStream> CreateFromFilename( |
| 98 const FX_WCHAR* filename, |
| 99 uint32_t dwModes); |
| 102 | 100 |
| 103 // IFX_SeekableReadStream: | 101 // IFX_SeekableReadStream: |
| 104 void Release() override = 0; | |
| 105 bool IsEOF() override = 0; | 102 bool IsEOF() override = 0; |
| 106 FX_FILESIZE GetPosition() override = 0; | 103 FX_FILESIZE GetPosition() override = 0; |
| 107 size_t ReadBlock(void* buffer, size_t size) override = 0; | 104 size_t ReadBlock(void* buffer, size_t size) override = 0; |
| 108 bool ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override = 0; | 105 bool ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override = 0; |
| 109 FX_FILESIZE GetSize() override = 0; | 106 FX_FILESIZE GetSize() override = 0; |
| 110 | 107 |
| 111 // IFX_SeekableWriteStream: | 108 // IFX_SeekableWriteStream: |
| 112 bool WriteBlock(const void* buffer, | 109 bool WriteBlock(const void* buffer, |
| 113 FX_FILESIZE offset, | 110 FX_FILESIZE offset, |
| 114 size_t size) override = 0; | 111 size_t size) override = 0; |
| 115 bool WriteBlock(const void* buffer, size_t size) override; | 112 bool WriteBlock(const void* buffer, size_t size) override; |
| 116 bool Flush() override = 0; | 113 bool Flush() override = 0; |
| 117 }; | 114 }; |
| 118 | 115 |
| 119 class IFX_MemoryStream : public IFX_SeekableStream { | 116 class IFX_MemoryStream : public IFX_SeekableStream { |
| 120 public: | 117 public: |
| 121 static IFX_MemoryStream* Create(uint8_t* pBuffer, | 118 static CFX_RetainPtr<IFX_MemoryStream> Create(uint8_t* pBuffer, |
| 122 size_t nSize, | 119 size_t nSize, |
| 123 bool bTakeOver = false); | 120 bool bTakeOver = false); |
| 124 static IFX_MemoryStream* Create(bool bConsecutive = false); | 121 static CFX_RetainPtr<IFX_MemoryStream> Create(bool bConsecutive = false); |
| 125 | 122 |
| 126 virtual bool IsConsecutive() const = 0; | 123 virtual bool IsConsecutive() const = 0; |
| 127 virtual void EstimateSize(size_t nInitSize, size_t nGrowSize) = 0; | 124 virtual void EstimateSize(size_t nInitSize, size_t nGrowSize) = 0; |
| 128 virtual uint8_t* GetBuffer() const = 0; | 125 virtual uint8_t* GetBuffer() const = 0; |
| 129 virtual void AttachBuffer(uint8_t* pBuffer, | 126 virtual void AttachBuffer(uint8_t* pBuffer, |
| 130 size_t nSize, | 127 size_t nSize, |
| 131 bool bTakeOver = false) = 0; | 128 bool bTakeOver = false) = 0; |
| 132 virtual void DetachBuffer() = 0; | 129 virtual void DetachBuffer() = 0; |
| 133 }; | 130 }; |
| 134 | 131 |
| 135 class IFX_BufferedReadStream : public IFX_ReadStream { | 132 class IFX_BufferedReadStream : public IFX_ReadStream { |
| 136 public: | 133 public: |
| 137 // IFX_ReadStream: | 134 // IFX_ReadStream: |
| 138 void Release() override = 0; | |
| 139 bool IsEOF() override = 0; | 135 bool IsEOF() override = 0; |
| 140 FX_FILESIZE GetPosition() override = 0; | 136 FX_FILESIZE GetPosition() override = 0; |
| 141 size_t ReadBlock(void* buffer, size_t size) override = 0; | 137 size_t ReadBlock(void* buffer, size_t size) override = 0; |
| 142 | 138 |
| 143 virtual bool ReadNextBlock(bool bRestart = false) = 0; | 139 virtual bool ReadNextBlock(bool bRestart = false) = 0; |
| 144 virtual const uint8_t* GetBlockBuffer() = 0; | 140 virtual const uint8_t* GetBlockBuffer() = 0; |
| 145 virtual size_t GetBlockSize() = 0; | 141 virtual size_t GetBlockSize() = 0; |
| 146 virtual FX_FILESIZE GetBlockOffset() = 0; | 142 virtual FX_FILESIZE GetBlockOffset() = 0; |
| 147 }; | 143 }; |
| 148 | 144 |
| 149 #ifdef PDF_ENABLE_XFA | 145 #ifdef PDF_ENABLE_XFA |
| 150 class IFX_FileAccess { | 146 class IFX_FileAccess { |
| 151 public: | 147 public: |
| 152 static IFX_FileAccess* CreateDefault(const CFX_WideStringC& wsPath); | 148 static IFX_FileAccess* CreateDefault(const CFX_WideStringC& wsPath); |
| 153 | 149 |
| 154 virtual ~IFX_FileAccess() {} | 150 virtual ~IFX_FileAccess() {} |
| 155 virtual void Release() = 0; | 151 virtual void Release() = 0; |
| 156 virtual IFX_FileAccess* Retain() = 0; | 152 virtual IFX_FileAccess* Retain() = 0; |
| 157 virtual void GetPath(CFX_WideString& wsPath) = 0; | 153 virtual void GetPath(CFX_WideString& wsPath) = 0; |
| 158 virtual IFX_SeekableStream* CreateFileStream(uint32_t dwModes) = 0; | 154 virtual CFX_RetainPtr<IFX_SeekableStream> CreateFileStream( |
| 155 uint32_t dwModes) = 0; |
| 159 }; | 156 }; |
| 160 #endif // PDF_ENABLE_XFA | 157 #endif // PDF_ENABLE_XFA |
| 161 | 158 |
| 162 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 159 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
| 163 class CFindFileData { | 160 class CFindFileData { |
| 164 public: | 161 public: |
| 165 virtual ~CFindFileData() {} | 162 virtual ~CFindFileData() {} |
| 166 HANDLE m_Handle; | 163 HANDLE m_Handle; |
| 167 bool m_bEnd; | 164 bool m_bEnd; |
| 168 }; | 165 }; |
| 169 | 166 |
| 170 class CFindFileDataA : public CFindFileData { | 167 class CFindFileDataA : public CFindFileData { |
| 171 public: | 168 public: |
| 172 ~CFindFileDataA() override {} | 169 ~CFindFileDataA() override {} |
| 173 WIN32_FIND_DATAA m_FindData; | 170 WIN32_FIND_DATAA m_FindData; |
| 174 }; | 171 }; |
| 175 | 172 |
| 176 class CFindFileDataW : public CFindFileData { | 173 class CFindFileDataW : public CFindFileData { |
| 177 public: | 174 public: |
| 178 ~CFindFileDataW() override {} | 175 ~CFindFileDataW() override {} |
| 179 WIN32_FIND_DATAW m_FindData; | 176 WIN32_FIND_DATAW m_FindData; |
| 180 }; | 177 }; |
| 181 #endif | 178 #endif |
| 182 | 179 |
| 183 #endif // CORE_FXCRT_FX_STREAM_H_ | 180 #endif // CORE_FXCRT_FX_STREAM_H_ |
| OLD | NEW |