summaryrefslogtreecommitdiff
path: root/xfa/src/fgas/src/crt/fx_stream.h
blob: 2273ab1d9b6700ae9bb7fc3fc68c9e2c51c048d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
// Copyright 2014 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com

#ifndef _FX_STREAM_IMP
#define _FX_STREAM_IMP
class CFX_StreamImp;
class CFX_FileStreamImp;
class CFX_BufferStreamImp;
class CFX_FileReadStreamImp;
class CFX_BufferReadStreamImp;
class CFX_FileWriteStreamImp;
class CFX_Stream;
class CFX_TextStream;
class CFX_FileRead;
class CFX_FileWrite;
class CFX_BufferAccImp;
class CFX_StreamImp : public CFX_ThreadLock
{
public:
    virtual void			Release()
    {
        delete this;
    }
    virtual FX_DWORD		GetAccessModes() const
    {
        return m_dwAccess;
    }
    virtual int32_t		GetLength() const = 0;
    virtual int32_t		Seek(FX_STREAMSEEK eSeek, int32_t iOffset) = 0;
    virtual int32_t		GetPosition() = 0;
    virtual FX_BOOL			IsEOF() const = 0;
    virtual int32_t		ReadData(FX_LPBYTE pBuffer, int32_t iBufferSize) = 0;
    virtual int32_t		ReadString(FX_LPWSTR pStr, int32_t iMaxLength, FX_BOOL &bEOS) = 0;
    virtual int32_t		WriteData(FX_LPCBYTE pBuffer, int32_t iBufferSize) = 0;
    virtual int32_t		WriteString(FX_LPCWSTR pStr, int32_t iLength) = 0;
    virtual void			Flush() = 0;
    virtual FX_BOOL			SetLength(int32_t iLength) = 0;
protected:
    CFX_StreamImp();
    virtual ~CFX_StreamImp() {}
    FX_DWORD				m_dwAccess;
};
class CFX_FileStreamImp : public CFX_StreamImp
{
public:
    CFX_FileStreamImp();
    virtual ~CFX_FileStreamImp();
    FX_BOOL			LoadFile(FX_LPCWSTR pszSrcFileName, FX_DWORD dwAccess);
    virtual int32_t		GetLength() const;
    virtual int32_t		Seek(FX_STREAMSEEK eSeek, int32_t iOffset);
    virtual int32_t		GetPosition();
    virtual FX_BOOL			IsEOF() const;
    virtual int32_t		ReadData(FX_LPBYTE pBuffer, int32_t iBufferSize);
    virtual int32_t		ReadString(FX_LPWSTR pStr, int32_t iMaxLength, FX_BOOL &bEOS);
    virtual int32_t		WriteData(FX_LPCBYTE pBuffer, int32_t iBufferSize);
    virtual int32_t		WriteString(FX_LPCWSTR pStr, int32_t iLength);
    virtual void			Flush();
    virtual FX_BOOL			SetLength(int32_t iLength);
protected:
    FXSYS_FILE	*m_hFile;
    int32_t	m_iLength;
};
class CFX_BufferStreamImp : public CFX_StreamImp
{
public:
    CFX_BufferStreamImp();
    virtual ~CFX_BufferStreamImp() {}
    FX_BOOL			LoadBuffer(FX_LPBYTE pData, int32_t iTotalSize, FX_DWORD dwAccess);
    virtual int32_t		GetLength() const;
    virtual int32_t		Seek(FX_STREAMSEEK eSeek, int32_t iOffset);
    virtual int32_t		GetPosition();
    virtual FX_BOOL			IsEOF() const;
    virtual int32_t		ReadData(FX_LPBYTE pBuffer, int32_t iBufferSize);
    virtual int32_t		ReadString(FX_LPWSTR pStr, int32_t iMaxLength, FX_BOOL &bEOS);
    virtual int32_t		WriteData(FX_LPCBYTE pBuffer, int32_t iBufferSize);
    virtual int32_t		WriteString(FX_LPCWSTR pStr, int32_t iLength);
    virtual void			Flush() {}
    virtual FX_BOOL			SetLength(int32_t iLength)
    {
        return FALSE;
    }
protected:
    FX_LPBYTE	m_pData;
    int32_t	m_iTotalSize;
    int32_t	m_iPosition;
    int32_t	m_iLength;
};
class CFX_FileReadStreamImp : public CFX_StreamImp
{
public:
    CFX_FileReadStreamImp();
    virtual ~CFX_FileReadStreamImp() {}
    FX_BOOL			LoadFileRead(IFX_FileRead *pFileRead, FX_DWORD dwAccess);
    virtual int32_t		GetLength() const;
    virtual int32_t		Seek(FX_STREAMSEEK eSeek, int32_t iOffset);
    virtual int32_t		GetPosition()
    {
        return m_iPosition;
    }
    virtual FX_BOOL			IsEOF() const;

    virtual int32_t		ReadData(FX_LPBYTE pBuffer, int32_t iBufferSize);
    virtual int32_t		ReadString(FX_LPWSTR pStr, int32_t iMaxLength, FX_BOOL &bEOS);
    virtual int32_t		WriteData(FX_LPCBYTE pBuffer, int32_t iBufferSize)
    {
        return 0;
    }
    virtual int32_t		WriteString(FX_LPCWSTR pStr, int32_t iLength)
    {
        return 0;
    }
    virtual void			Flush() {}
    virtual FX_BOOL			SetLength(int32_t iLength)
    {
        return FALSE;
    }
protected:
    IFX_FileRead			*m_pFileRead;
    int32_t				m_iPosition;
    int32_t				m_iLength;
};
class CFX_BufferReadStreamImp : public CFX_StreamImp
{
public:
    CFX_BufferReadStreamImp();
    ~CFX_BufferReadStreamImp();
    FX_BOOL			LoadBufferRead(IFX_BufferRead *pBufferRead, int32_t iFileSize, FX_DWORD dwAccess, FX_BOOL bReleaseBufferRead);

    virtual int32_t		GetLength() const;
    virtual int32_t		Seek(FX_STREAMSEEK eSeek, int32_t iOffset);
    virtual int32_t		GetPosition()
    {
        return m_iPosition;
    }
    virtual FX_BOOL			IsEOF() const;

    virtual int32_t		ReadData(FX_LPBYTE pBuffer, int32_t iBufferSize);
    virtual int32_t		ReadString(FX_LPWSTR pStr, int32_t iMaxLength, FX_BOOL &bEOS);
    virtual int32_t		WriteData(FX_LPCBYTE pBuffer, int32_t iBufferSize)
    {
        return 0;
    }
    virtual int32_t		WriteString(FX_LPCWSTR pStr, int32_t iLength)
    {
        return 0;
    }
    virtual void			Flush() {}
    virtual FX_BOOL			SetLength(int32_t iLength)
    {
        return FALSE;
    }
private:
    IFX_BufferRead			*m_pBufferRead;
    FX_BOOL					m_bReleaseBufferRead;
    int32_t				m_iPosition;
    int32_t				m_iBufferSize;
};
class CFX_FileWriteStreamImp : public CFX_StreamImp
{
public:
    CFX_FileWriteStreamImp();
    virtual ~CFX_FileWriteStreamImp() {}
    FX_BOOL			LoadFileWrite(IFX_FileWrite *pFileWrite, FX_DWORD dwAccess);
    virtual int32_t		GetLength() const;
    virtual int32_t		Seek(FX_STREAMSEEK eSeek, int32_t iOffset);
    virtual int32_t		GetPosition()
    {
        return m_iPosition;
    }
    virtual FX_BOOL			IsEOF() const;
    virtual int32_t		ReadData(FX_LPBYTE pBuffer, int32_t iBufferSize)
    {
        return 0;
    }
    virtual int32_t		ReadString(FX_LPWSTR pStr, int32_t iMaxLength, FX_BOOL &bEOS)
    {
        return 0;
    }
    virtual int32_t		WriteData(FX_LPCBYTE pBuffer, int32_t iBufferSize);
    virtual int32_t		WriteString(FX_LPCWSTR pStr, int32_t iLength);
    virtual void			Flush();
    virtual FX_BOOL			SetLength(int32_t iLength)
    {
        return FALSE;
    }
protected:
    IFX_FileWrite			*m_pFileWrite;
    int32_t				m_iPosition;
};
enum FX_STREAMTYPE {
    FX_SREAMTYPE_Unknown	=  0,
    FX_STREAMTYPE_File			,
    FX_STREAMTYPE_Buffer		,
    FX_STREAMTYPE_Stream		,
    FX_STREAMTYPE_BufferRead	,
};
class CFX_Stream : public IFX_Stream, public CFX_ThreadLock
{
public:
    CFX_Stream();
    ~CFX_Stream();
    FX_BOOL			LoadFile(FX_LPCWSTR pszSrcFileName, FX_DWORD dwAccess);
    FX_BOOL			LoadBuffer(FX_LPBYTE pData, int32_t iTotalSize, FX_DWORD dwAccess);
    FX_BOOL			LoadFileRead(IFX_FileRead *pFileRead, FX_DWORD dwAccess);
    FX_BOOL			LoadFileWrite(IFX_FileWrite *pFileWrite, FX_DWORD dwAccess);
    FX_BOOL			LoadBufferRead(IFX_BufferRead *pBufferRead, int32_t iFileSize, FX_DWORD dwAccess, FX_BOOL bReleaseBufferRead);
    virtual void			Release();
    virtual IFX_Stream*		Retain();
    virtual FX_DWORD		GetAccessModes() const
    {
        return m_dwAccess;
    }
    virtual int32_t		GetLength() const;
    virtual int32_t		Seek(FX_STREAMSEEK eSeek, int32_t iOffset);
    virtual int32_t		GetPosition();
    virtual FX_BOOL			IsEOF() const;
    virtual int32_t		ReadData(FX_LPBYTE pBuffer, int32_t iBufferSize);
    virtual int32_t		ReadString(FX_LPWSTR pStr, int32_t iMaxLength, FX_BOOL &bEOS, int32_t const *pByteSize = NULL);
    virtual int32_t		WriteData(FX_LPCBYTE pBuffer, int32_t iBufferSize);
    virtual int32_t		WriteString(FX_LPCWSTR pStr, int32_t iLength);
    virtual void			Flush();
    virtual FX_BOOL			SetLength(int32_t iLength);
    virtual int32_t		GetBOM(uint8_t bom[4]) const;
    virtual FX_WORD			GetCodePage() const;
    virtual FX_WORD			SetCodePage(FX_WORD wCodePage);
    virtual void			Lock()
    {
        CFX_ThreadLock::Lock();
    }
    virtual void			Unlock()
    {
        CFX_ThreadLock::Unlock();
    }
    virtual IFX_Stream*		CreateSharedStream(FX_DWORD dwAccess, int32_t iOffset, int32_t iLength);
protected:
    FX_STREAMTYPE			m_eStreamType;
    CFX_StreamImp			*m_pStreamImp;
    FX_DWORD				m_dwAccess;
    int32_t				m_iTotalSize;
    int32_t				m_iPosition;
    int32_t				m_iStart;
    int32_t				m_iLength;
    int32_t				m_iRefCount;
};
class CFX_TextStream : public IFX_Stream, public CFX_ThreadLock
{
public:
    CFX_TextStream(IFX_Stream *pStream, FX_BOOL bDelStream);
    ~CFX_TextStream();
    virtual void				Release();
    virtual IFX_Stream*			Retain();

    virtual FX_DWORD			GetAccessModes() const;
    virtual int32_t			GetLength() const;
    virtual int32_t			Seek(FX_STREAMSEEK eSeek, int32_t iOffset);
    virtual int32_t			GetPosition();
    virtual FX_BOOL				IsEOF() const;

    virtual int32_t			ReadData(FX_LPBYTE pBuffer, int32_t iBufferSize);
    virtual int32_t			ReadString(FX_LPWSTR pStr, int32_t iMaxLength, FX_BOOL &bEOS, int32_t const *pByteSize = NULL);
    virtual int32_t			WriteData(FX_LPCBYTE pBuffer, int32_t iBufferSize);
    virtual int32_t			WriteString(FX_LPCWSTR pStr, int32_t iLength);
    virtual void				Flush();
    virtual FX_BOOL				SetLength(int32_t iLength);

    virtual int32_t			GetBOM(uint8_t bom[4]) const;
    virtual FX_WORD				GetCodePage() const;
    virtual FX_WORD				SetCodePage(FX_WORD wCodePage);

    virtual void				Lock()
    {
        CFX_ThreadLock::Lock();
    }
    virtual void				Unlock()
    {
        CFX_ThreadLock::Unlock();
    }

    virtual IFX_Stream*			CreateSharedStream(FX_DWORD dwAccess, int32_t iOffset, int32_t iLength);
protected:
    FX_WORD		m_wCodePage;
    FX_WORD		m_wBOMLength;
    FX_DWORD	m_dwBOM;
    FX_LPBYTE	m_pBuf;
    int32_t	m_iBufSize;
    FX_BOOL		m_bDelStream;
    IFX_Stream	*m_pStreamImp;
    int32_t	m_iRefCount;
    void		InitStream();
};
#ifdef FX_FILESIZE
class CFGAS_FileRead : public IFX_FileRead
{
public:
    CFGAS_FileRead(IFX_Stream *pStream, FX_BOOL bReleaseStream);
    virtual ~CFGAS_FileRead();
    virtual void			Release()
    {
        delete this;
    }
    virtual FX_FILESIZE		GetSize();
    virtual FX_BOOL			ReadBlock(void* buffer, FX_FILESIZE offset, size_t size);
protected:
    FX_BOOL					m_bReleaseStream;
    IFX_Stream				*m_pStream;
};
#else
class CFGAS_FileRead : public IFX_FileRead
{
public:
    CFGAS_FileRead(IFX_Stream *pStream, FX_BOOL bReleaseStream);
    virtual ~CFGAS_FileRead();

    virtual void			Release()
    {
        delete this;
    }
    virtual FX_DWORD		GetSize();
    virtual FX_BOOL			ReadBlock(void* buffer, FX_DWORD offset, FX_DWORD size);

protected:
    FX_BOOL					m_bReleaseStream;
    IFX_Stream				*m_pStream;
};
#endif
#ifdef FX_FILESIZE
class CFX_BufferAccImp : public IFX_FileRead
{
public:
    CFX_BufferAccImp(IFX_BufferRead *pBufferRead, FX_FILESIZE iFileSize, FX_BOOL bReleaseStream);
    virtual ~CFX_BufferAccImp();
    virtual void			Release()
    {
        delete this;
    }
    virtual FX_FILESIZE		GetSize();
    virtual FX_BOOL			ReadBlock(void* buffer, FX_FILESIZE offset, size_t size);
protected:
    IFX_BufferRead			*m_pBufferRead;
    FX_BOOL					m_bReleaseStream;
    FX_FILESIZE				m_iBufSize;
};
#else
class CFX_BufferAccImp : public IFX_FileRead
{
public:
    CFX_BufferAccImp(IFX_BufferRead *pBufferRead, int32_t iFileSize, FX_BOOL bReleaseStream);
    virtual ~CFX_BufferAccImp();

    virtual void			Release()
    {
        delete this;
    }
    virtual FX_DWORD		GetSize();
    virtual FX_BOOL			ReadBlock(void* buffer, FX_DWORD offset, FX_DWORD size);

protected:
    IFX_BufferRead			*m_pBufferRead;
    FX_BOOL					m_bReleaseStream;
    int32_t				m_iBufSize;
};
#endif
#ifdef FX_FILESIZE
class CFGAS_FileWrite : public IFX_FileWrite
{
public:
    CFGAS_FileWrite(IFX_Stream *pStream, FX_BOOL bReleaseStream);
    virtual ~CFGAS_FileWrite();
    virtual void			Release()
    {
        delete this;
    }
    virtual FX_FILESIZE		GetSize();
    virtual FX_BOOL			Flush();
    virtual	FX_BOOL			WriteBlock(const void* pData, size_t size);
    virtual	FX_BOOL			WriteBlock(const void* pData, FX_FILESIZE offset, size_t size);
protected:
    IFX_Stream				*m_pStream;
    FX_BOOL					m_bReleaseStream;
};
#else
class CFGAS_FileWrite : public IFX_FileWrite
{
public:
    CFGAS_FileWrite(IFX_Stream *pStream, FX_BOOL bReleaseStream);
    virtual ~CFGAS_FileWrite();

    virtual void			Release()
    {
        delete this;
    }
    virtual FX_DWORD		GetSize();
    virtual FX_DWORD		Flush();
    virtual	FX_BOOL			WriteBlock(const void* pData, FX_DWORD size);
    virtual	FX_BOOL			WriteBlock(const void* pData, FX_DWORD offset, FX_DWORD size);

protected:
    IFX_Stream				*m_pStream;
    FX_BOOL					m_bReleaseStream;
};
#endif
#endif