Add missing operators for CFX_WideStringC.
[pdfium.git] / core / include / fxcrt / fx_stream.h
1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7 #ifndef _FX_STREAM_H_
8 #define _FX_STREAM_H_
9
10 #include "fx_memory.h"
11 #include "fx_string.h"
12
13 void* FX_OpenFolder(FX_LPCSTR path);
14 void* FX_OpenFolder(FX_LPCWSTR path);
15 FX_BOOL FX_GetNextFile(void* handle, CFX_ByteString& filename, FX_BOOL& bFolder);
16 FX_BOOL FX_GetNextFile(void* handle, CFX_WideString& filename, FX_BOOL& bFolder);
17 void FX_CloseFolder(void* handle);
18 FX_WCHAR FX_GetFolderSeparator();
19 FX_DEFINEHANDLE(FX_HFILE)
20 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
21 #define FX_FILESIZE                     FX_INT32
22 #else
23 #include <fcntl.h>
24 #include <unistd.h>
25 #include <sys/stat.h>
26 #ifndef O_BINARY
27 #define O_BINARY                0
28 #endif
29 #ifndef O_LARGEFILE
30 #define O_LARGEFILE             0
31 #endif
32 #define FX_FILESIZE                     off_t
33 #endif
34 #define FX_GETBYTEOFFSET32(a)   0
35 #define FX_GETBYTEOFFSET40(a)   0
36 #define FX_GETBYTEOFFSET48(a)   0
37 #define FX_GETBYTEOFFSET56(a)   0
38 #define FX_GETBYTEOFFSET24(a)  ((FX_BYTE)(a>>24))
39 #define FX_GETBYTEOFFSET16(a)  ((FX_BYTE)(a>>16))
40 #define FX_GETBYTEOFFSET8(a)   ((FX_BYTE)(a>>8))
41 #define FX_GETBYTEOFFSET0(a)   ((FX_BYTE)(a))
42 #define FX_FILEMODE_Write               0
43 #define FX_FILEMODE_ReadOnly    1
44 #define FX_FILEMODE_Truncate    2
45 FX_HFILE        FX_File_Open(FX_BSTR fileName, FX_DWORD dwMode);
46 FX_HFILE        FX_File_Open(FX_WSTR fileName, FX_DWORD dwMode);
47 void            FX_File_Close(FX_HFILE hFile);
48 FX_FILESIZE     FX_File_GetSize(FX_HFILE hFile);
49 FX_FILESIZE     FX_File_GetPosition(FX_HFILE hFile);
50 FX_FILESIZE     FX_File_SetPosition(FX_HFILE hFile, FX_FILESIZE pos);
51 size_t          FX_File_Read(FX_HFILE hFile, void* pBuffer, size_t szBuffer);
52 size_t          FX_File_ReadPos(FX_HFILE hFile, void* pBuffer, size_t szBuffer, FX_FILESIZE pos);
53 size_t          FX_File_Write(FX_HFILE hFile, const void* pBuffer, size_t szBuffer);
54 size_t          FX_File_WritePos(FX_HFILE hFile, const void* pBuffer, size_t szBuffer, FX_FILESIZE pos);
55 FX_BOOL         FX_File_Flush(FX_HFILE hFile);
56 FX_BOOL         FX_File_Truncate(FX_HFILE hFile, FX_FILESIZE szFile);
57 FX_BOOL         FX_File_Exist(FX_BSTR fileName);
58 FX_BOOL         FX_File_Exist(FX_WSTR fileName);
59 FX_BOOL         FX_File_Delete(FX_BSTR fileName);
60 FX_BOOL         FX_File_Delete(FX_WSTR fileName);
61 FX_BOOL         FX_File_Copy(FX_BSTR fileNameSrc, FX_BSTR fileNameDst);
62 FX_BOOL         FX_File_Copy(FX_WSTR fileNameSrc, FX_WSTR fileNameDst);
63 FX_BOOL         FX_File_Move(FX_BSTR fileNameSrc, FX_BSTR fileNameDst);
64 FX_BOOL         FX_File_Move(FX_WSTR fileNameSrc, FX_WSTR fileNameDst);
65 class IFX_StreamWrite
66 {
67 public:
68     virtual ~IFX_StreamWrite() { }
69     virtual void                Release() = 0;
70
71     virtual     FX_BOOL         WriteBlock(const void* pData, size_t size) = 0;
72 };
73 class IFX_FileWrite : public IFX_StreamWrite
74 {
75 public:
76
77     virtual void                        Release() = 0;
78
79     virtual FX_FILESIZE         GetSize() = 0;
80
81     virtual FX_BOOL                     Flush() = 0;
82
83     virtual     FX_BOOL                 WriteBlock(const void* pData, FX_FILESIZE offset, size_t size) = 0;
84     virtual     FX_BOOL                 WriteBlock(const void* pData, size_t size)
85     {
86         return WriteBlock(pData, GetSize(), size);
87     }
88 };
89 IFX_FileWrite* FX_CreateFileWrite(FX_LPCSTR filename);
90 IFX_FileWrite* FX_CreateFileWrite(FX_LPCWSTR filename);
91 class IFX_StreamRead
92 {
93 public:
94     virtual ~IFX_StreamRead() { }
95
96     virtual void                        Release() = 0;
97
98     virtual FX_BOOL                     IsEOF() = 0;
99
100     virtual FX_FILESIZE         GetPosition() = 0;
101
102     virtual size_t                      ReadBlock(void* buffer, size_t size) = 0;
103 };
104 class IFX_FileRead : IFX_StreamRead
105 {
106 public:
107     virtual void                        Release() = 0;
108
109     virtual FX_FILESIZE         GetSize() = 0;
110
111     virtual FX_BOOL                     IsEOF()
112     {
113         return FALSE;
114     }
115
116     virtual FX_FILESIZE         GetPosition()
117     {
118         return 0;
119     }
120
121     virtual FX_BOOL                     SetRange(FX_FILESIZE offset, FX_FILESIZE size)
122     {
123         return FALSE;
124     }
125
126     virtual void                        ClearRange() {}
127
128     virtual FX_BOOL                     ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) = 0;
129
130     virtual size_t                      ReadBlock(void* buffer, size_t size)
131     {
132         return 0;
133     }
134 };
135 IFX_FileRead* FX_CreateFileRead(FX_LPCSTR filename);
136 IFX_FileRead* FX_CreateFileRead(FX_LPCWSTR filename);
137 class IFX_FileStream : public IFX_FileRead, public IFX_FileWrite
138 {
139 public:
140
141     virtual IFX_FileStream*             Retain() = 0;
142
143     virtual void                                Release() = 0;
144
145     virtual FX_FILESIZE                 GetSize() = 0;
146
147     virtual FX_BOOL                             IsEOF() = 0;
148
149     virtual FX_FILESIZE                 GetPosition() = 0;
150
151     virtual FX_BOOL                             ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) = 0;
152
153     virtual size_t                              ReadBlock(void* buffer, size_t size) = 0;
154
155     virtual     FX_BOOL                         WriteBlock(const void* buffer, FX_FILESIZE offset, size_t size) = 0;
156     virtual     FX_BOOL                         WriteBlock(const void* buffer, size_t size)
157     {
158         return WriteBlock(buffer, GetSize(), size);
159     }
160
161     virtual FX_BOOL                             Flush() = 0;
162 };
163 IFX_FileStream*         FX_CreateFileStream(FX_LPCSTR filename, FX_DWORD dwModes);
164 IFX_FileStream*         FX_CreateFileStream(FX_LPCWSTR filename, FX_DWORD dwModes);
165 class IFX_MemoryStream : public IFX_FileStream
166 {
167 public:
168
169     virtual FX_BOOL                     IsConsecutive() const = 0;
170
171     virtual void                        EstimateSize(size_t nInitSize, size_t nGrowSize) = 0;
172
173     virtual FX_LPBYTE           GetBuffer() const = 0;
174
175     virtual void                        AttachBuffer(FX_LPBYTE pBuffer, size_t nSize, FX_BOOL bTakeOver = FALSE) = 0;
176
177     virtual void                        DetachBuffer() = 0;
178 };
179 IFX_MemoryStream*       FX_CreateMemoryStream(FX_LPBYTE pBuffer, size_t nSize, FX_BOOL bTakeOver = FALSE);
180 IFX_MemoryStream*       FX_CreateMemoryStream(FX_BOOL bConsecutive = FALSE);
181 class IFX_BufferRead : public IFX_StreamRead
182 {
183 public:
184
185     virtual void                        Release() = 0;
186
187     virtual FX_BOOL                     IsEOF() = 0;
188
189     virtual FX_FILESIZE         GetPosition() = 0;
190
191     virtual size_t                      ReadBlock(void* buffer, size_t size) = 0;
192
193     virtual FX_BOOL                     ReadNextBlock(FX_BOOL bRestart = FALSE) = 0;
194
195     virtual FX_LPCBYTE          GetBlockBuffer() = 0;
196
197     virtual size_t                      GetBlockSize() = 0;
198
199     virtual FX_FILESIZE         GetBlockOffset() = 0;
200 };
201 #endif