summaryrefslogtreecommitdiff
path: root/core/include/fxcrt/fx_stream.h
blob: ff8344dd68131c04a34e8c7b99e320321d70bee8 (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
// 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_H_
#define _FX_STREAM_H_
#ifndef _FX_MEMORY_H_
#include "fx_memory.h"
#endif
void* FX_OpenFolder(FX_LPCSTR path);
void* FX_OpenFolder(FX_LPCWSTR path);
FX_BOOL FX_GetNextFile(void* handle, CFX_ByteString& filename, FX_BOOL& bFolder);
FX_BOOL FX_GetNextFile(void* handle, CFX_WideString& filename, FX_BOOL& bFolder);
void FX_CloseFolder(void* handle);
FX_WCHAR FX_GetFolderSeparator();
FX_DEFINEHANDLE(FX_HFILE)
#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
#define FX_FILESIZE			FX_INT32
#else
#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>
#ifndef O_BINARY
#define O_BINARY 		0
#endif
#ifndef O_LARGEFILE
#define O_LARGEFILE		0
#endif
#define FX_FILESIZE			off_t
#endif
#define FX_GETBYTEOFFSET32(a)	0
#define FX_GETBYTEOFFSET40(a)	0
#define FX_GETBYTEOFFSET48(a)	0
#define FX_GETBYTEOFFSET56(a)	0
#define FX_GETBYTEOFFSET24(a)  ((FX_BYTE)(a>>24))
#define FX_GETBYTEOFFSET16(a)  ((FX_BYTE)(a>>16))
#define FX_GETBYTEOFFSET8(a)   ((FX_BYTE)(a>>8))
#define FX_GETBYTEOFFSET0(a)   ((FX_BYTE)(a))
#define FX_FILEMODE_Write		0
#define FX_FILEMODE_ReadOnly	1
#define FX_FILEMODE_Truncate	2
FX_HFILE	FX_File_Open(FX_BSTR fileName, FX_DWORD dwMode);
FX_HFILE	FX_File_Open(FX_WSTR fileName, FX_DWORD dwMode);
void		FX_File_Close(FX_HFILE hFile);
FX_FILESIZE	FX_File_GetSize(FX_HFILE hFile);
FX_FILESIZE	FX_File_GetPosition(FX_HFILE hFile);
FX_FILESIZE	FX_File_SetPosition(FX_HFILE hFile, FX_FILESIZE pos);
size_t		FX_File_Read(FX_HFILE hFile, void* pBuffer, size_t szBuffer);
size_t		FX_File_ReadPos(FX_HFILE hFile, void* pBuffer, size_t szBuffer, FX_FILESIZE pos);
size_t		FX_File_Write(FX_HFILE hFile, const void* pBuffer, size_t szBuffer);
size_t		FX_File_WritePos(FX_HFILE hFile, const void* pBuffer, size_t szBuffer, FX_FILESIZE pos);
FX_BOOL		FX_File_Flush(FX_HFILE hFile);
FX_BOOL		FX_File_Truncate(FX_HFILE hFile, FX_FILESIZE szFile);
FX_BOOL		FX_File_Exist(FX_BSTR fileName);
FX_BOOL		FX_File_Exist(FX_WSTR fileName);
FX_BOOL		FX_File_Delete(FX_BSTR fileName);
FX_BOOL		FX_File_Delete(FX_WSTR fileName);
FX_BOOL		FX_File_Copy(FX_BSTR fileNameSrc, FX_BSTR fileNameDst);
FX_BOOL		FX_File_Copy(FX_WSTR fileNameSrc, FX_WSTR fileNameDst);
FX_BOOL		FX_File_Move(FX_BSTR fileNameSrc, FX_BSTR fileNameDst);
FX_BOOL		FX_File_Move(FX_WSTR fileNameSrc, FX_WSTR fileNameDst);
class IFX_StreamWrite
{
public:
    virtual ~IFX_StreamWrite() { }
    virtual void		Release() = 0;

    virtual	FX_BOOL		WriteBlock(const void* pData, size_t size) = 0;
};
class IFX_FileWrite : public IFX_StreamWrite
{
public:

    virtual void			Release() = 0;

    virtual FX_FILESIZE		GetSize() = 0;

    virtual FX_BOOL			Flush() = 0;

    virtual	FX_BOOL			WriteBlock(const void* pData, FX_FILESIZE offset, size_t size) = 0;
    virtual	FX_BOOL			WriteBlock(const void* pData, size_t size)
    {
        return WriteBlock(pData, GetSize(), size);
    }
};
IFX_FileWrite* FX_CreateFileWrite(FX_LPCSTR filename);
IFX_FileWrite* FX_CreateFileWrite(FX_LPCWSTR filename);
class IFX_StreamRead
{
public:
    virtual ~IFX_StreamRead() { }

    virtual void			Release() = 0;

    virtual FX_BOOL			IsEOF() = 0;

    virtual FX_FILESIZE		GetPosition() = 0;

    virtual size_t			ReadBlock(void* buffer, size_t size) = 0;
};
class IFX_FileRead : IFX_StreamRead
{
public:
    virtual void			Release() = 0;

    virtual FX_FILESIZE		GetSize() = 0;

    virtual FX_BOOL			IsEOF()
    {
        return FALSE;
    }

    virtual FX_FILESIZE		GetPosition()
    {
        return 0;
    }

    virtual FX_BOOL			SetRange(FX_FILESIZE offset, FX_FILESIZE size)
    {
        return FALSE;
    }

    virtual void			ClearRange() {}

    virtual FX_BOOL			ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) = 0;

    virtual size_t			ReadBlock(void* buffer, size_t size)
    {
        return 0;
    }
};
IFX_FileRead* FX_CreateFileRead(FX_LPCSTR filename);
IFX_FileRead* FX_CreateFileRead(FX_LPCWSTR filename);
class IFX_FileStream : public IFX_FileRead, public IFX_FileWrite
{
public:

    virtual IFX_FileStream*		Retain() = 0;

    virtual void				Release() = 0;

    virtual FX_FILESIZE			GetSize() = 0;

    virtual FX_BOOL				IsEOF() = 0;

    virtual FX_FILESIZE			GetPosition() = 0;

    virtual FX_BOOL				ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) = 0;

    virtual size_t				ReadBlock(void* buffer, size_t size) = 0;

    virtual	FX_BOOL				WriteBlock(const void* buffer, FX_FILESIZE offset, size_t size) = 0;
    virtual	FX_BOOL				WriteBlock(const void* buffer, size_t size)
    {
        return WriteBlock(buffer, GetSize(), size);
    }

    virtual FX_BOOL				Flush() = 0;
};
IFX_FileStream*		FX_CreateFileStream(FX_LPCSTR filename, FX_DWORD dwModes);
IFX_FileStream*		FX_CreateFileStream(FX_LPCWSTR filename, FX_DWORD dwModes);
class IFX_FileAccess
{
public:
	virtual void				Release() = 0;	
	virtual IFX_FileAccess*		Retain() = 0;
	virtual void				GetPath(CFX_WideString& wsPath) = 0;
	virtual IFX_FileStream*		CreateFileStream(FX_DWORD dwModes) = 0;
};
IFX_FileAccess* FX_CreateDefaultFileAccess(FX_WSTR wsPath);
class IFX_MemoryStream : public IFX_FileStream
{
public:

    virtual FX_BOOL			IsConsecutive() const = 0;

    virtual void			EstimateSize(size_t nInitSize, size_t nGrowSize) = 0;

    virtual FX_LPBYTE		GetBuffer() const = 0;

    virtual void			AttachBuffer(FX_LPBYTE pBuffer, size_t nSize, FX_BOOL bTakeOver = FALSE) = 0;

    virtual void			DetachBuffer() = 0;
};
IFX_MemoryStream*	FX_CreateMemoryStream(FX_LPBYTE pBuffer, size_t nSize, FX_BOOL bTakeOver = FALSE);
IFX_MemoryStream*	FX_CreateMemoryStream(FX_BOOL bConsecutive = FALSE);
class IFX_BufferRead : public IFX_StreamRead
{
public:

    virtual void			Release() = 0;

    virtual FX_BOOL			IsEOF() = 0;

    virtual FX_FILESIZE		GetPosition() = 0;

    virtual size_t			ReadBlock(void* buffer, size_t size) = 0;

    virtual FX_BOOL			ReadNextBlock(FX_BOOL bRestart = FALSE) = 0;

    virtual FX_LPCBYTE		GetBlockBuffer() = 0;

    virtual size_t			GetBlockSize() = 0;

    virtual FX_FILESIZE		GetBlockOffset() = 0;
};
#endif