Chromium Code Reviews

Side by Side Diff: core/src/fxcrt/extension.h

Issue 454983003: Add FX_OVERRIDE and use it for virtual functions of FX_FINAL classes. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: mark m_FileAccess private. Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
« no previous file with comments | « core/src/fpdfapi/fpdf_font/ttgsubtable.h ('k') | core/src/fxcrt/fx_arabic.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 _FXCRT_EXTENSION_IMP_ 7 #ifndef _FXCRT_EXTENSION_IMP_
8 #define _FXCRT_EXTENSION_IMP_ 8 #define _FXCRT_EXTENSION_IMP_
9 9
10 class IFXCRT_FileAccess 10 class IFXCRT_FileAccess
(...skipping 18 matching lines...)
29 class CFX_CRTFileStream FX_FINAL : public IFX_FileStream, public CFX_Object 29 class CFX_CRTFileStream FX_FINAL : public IFX_FileStream, public CFX_Object
30 { 30 {
31 public: 31 public:
32 CFX_CRTFileStream(IFXCRT_FileAccess* pFA) : m_pFile(pFA), m_dwCount(1), m_bU seRange(FALSE), m_nOffset(0), m_nSize(0) {} 32 CFX_CRTFileStream(IFXCRT_FileAccess* pFA) : m_pFile(pFA), m_dwCount(1), m_bU seRange(FALSE), m_nOffset(0), m_nSize(0) {}
33 ~CFX_CRTFileStream() 33 ~CFX_CRTFileStream()
34 { 34 {
35 if (m_pFile) { 35 if (m_pFile) {
36 m_pFile->Release(); 36 m_pFile->Release();
37 } 37 }
38 } 38 }
39 virtual IFX_FileStream*» » Retain() 39 virtual IFX_FileStream*» » Retain() FX_OVERRIDE
40 { 40 {
41 m_dwCount ++; 41 m_dwCount ++;
42 return this; 42 return this;
43 } 43 }
44 virtual void» » » » Release() 44 virtual void» » » » Release() FX_OVERRIDE
45 { 45 {
46 FX_DWORD nCount = -- m_dwCount; 46 FX_DWORD nCount = -- m_dwCount;
47 if (!nCount) { 47 if (!nCount) {
48 delete this; 48 delete this;
49 } 49 }
50 } 50 }
51 virtual FX_FILESIZE»» » GetSize() 51 virtual FX_FILESIZE»» » GetSize() FX_OVERRIDE
52 { 52 {
53 return m_bUseRange ? m_nSize : m_pFile->GetSize(); 53 return m_bUseRange ? m_nSize : m_pFile->GetSize();
54 } 54 }
55 virtual FX_BOOL» » » » IsEOF() 55 virtual FX_BOOL» » » » IsEOF() FX_OVERRIDE
56 { 56 {
57 return GetPosition() >= GetSize(); 57 return GetPosition() >= GetSize();
58 } 58 }
59 virtual FX_FILESIZE»» » GetPosition() 59 virtual FX_FILESIZE»» » GetPosition() FX_OVERRIDE
60 { 60 {
61 FX_FILESIZE pos = m_pFile->GetPosition(); 61 FX_FILESIZE pos = m_pFile->GetPosition();
62 if (m_bUseRange) { 62 if (m_bUseRange) {
63 pos -= m_nOffset; 63 pos -= m_nOffset;
64 } 64 }
65 return pos; 65 return pos;
66 } 66 }
67 virtual FX_BOOL» » » » SetRange(FX_FILESIZE offset, FX_ FILESIZE size) 67 virtual FX_BOOL» » » » SetRange(FX_FILESIZE offset, FX_ FILESIZE size) FX_OVERRIDE
68 { 68 {
69 if (offset < 0 || size < 0) { 69 if (offset < 0 || size < 0) {
70 return FALSE; 70 return FALSE;
71 } 71 }
72 72
73 FX_SAFE_FILESIZE pos = size; 73 FX_SAFE_FILESIZE pos = size;
74 pos += offset; 74 pos += offset;
75 75
76 if (!pos.IsValid() || pos.ValueOrDie() > m_pFile->GetSize()) { 76 if (!pos.IsValid() || pos.ValueOrDie() > m_pFile->GetSize()) {
77 return FALSE; 77 return FALSE;
78 } 78 }
79 79
80 m_nOffset = offset, m_nSize = size; 80 m_nOffset = offset, m_nSize = size;
81 m_bUseRange = TRUE; 81 m_bUseRange = TRUE;
82 m_pFile->SetPosition(m_nOffset); 82 m_pFile->SetPosition(m_nOffset);
83 return TRUE; 83 return TRUE;
84 } 84 }
85 virtual void» » » » ClearRange() 85 virtual void» » » » ClearRange() FX_OVERRIDE
86 { 86 {
87 m_bUseRange = FALSE; 87 m_bUseRange = FALSE;
88 } 88 }
89 virtual FX_BOOL» » » » ReadBlock(void* buffer, FX_FILES IZE offset, size_t size) 89 virtual FX_BOOL» » » » ReadBlock(void* buffer, FX_FILES IZE offset, size_t size) FX_OVERRIDE
90 { 90 {
91 if (m_bUseRange && offset < 0) { 91 if (m_bUseRange && offset < 0) {
92 return FALSE; 92 return FALSE;
93 } 93 }
94 FX_SAFE_FILESIZE pos = offset; 94 FX_SAFE_FILESIZE pos = offset;
95 95
96 if (m_bUseRange) { 96 if (m_bUseRange) {
97 pos += m_nOffset; 97 pos += m_nOffset;
98 if (!pos.IsValid() || pos.ValueOrDie() > (size_t)GetSize()) { 98 if (!pos.IsValid() || pos.ValueOrDie() > (size_t)GetSize()) {
99 return FALSE; 99 return FALSE;
100 } 100 }
101 } 101 }
102 return (FX_BOOL)m_pFile->ReadPos(buffer, size, pos.ValueOrDie()); 102 return (FX_BOOL)m_pFile->ReadPos(buffer, size, pos.ValueOrDie());
103 } 103 }
104 virtual size_t» » » » ReadBlock(void* buffer, size_t s ize) 104 virtual size_t» » » » ReadBlock(void* buffer, size_t s ize) FX_OVERRIDE
105 { 105 {
106 if (m_bUseRange) { 106 if (m_bUseRange) {
107 FX_FILESIZE availSize = m_nOffset + m_nSize - m_pFile->GetPosition() ; 107 FX_FILESIZE availSize = m_nOffset + m_nSize - m_pFile->GetPosition() ;
108 if ((size_t)availSize < size) { 108 if ((size_t)availSize < size) {
109 size -= size - (size_t)availSize; 109 size -= size - (size_t)availSize;
110 } 110 }
111 } 111 }
112 return m_pFile->Read(buffer, size); 112 return m_pFile->Read(buffer, size);
113 } 113 }
114 virtual» FX_BOOL»» » » WriteBlock(const void* buffer, F X_FILESIZE offset, size_t size) 114 virtual» FX_BOOL»» » » WriteBlock(const void* buffer, F X_FILESIZE offset, size_t size) FX_OVERRIDE
115 { 115 {
116 if (m_bUseRange) { 116 if (m_bUseRange) {
117 offset += m_nOffset; 117 offset += m_nOffset;
118 } 118 }
119 return (FX_BOOL)m_pFile->WritePos(buffer, size, offset); 119 return (FX_BOOL)m_pFile->WritePos(buffer, size, offset);
120 } 120 }
121 virtual FX_BOOL» » » » Flush() 121 virtual FX_BOOL» » » » Flush() FX_OVERRIDE
122 { 122 {
123 return m_pFile->Flush(); 123 return m_pFile->Flush();
124 } 124 }
125 IFXCRT_FileAccess* m_pFile; 125 IFXCRT_FileAccess* m_pFile;
126 FX_DWORD m_dwCount; 126 FX_DWORD m_dwCount;
127 FX_BOOL m_bUseRange; 127 FX_BOOL m_bUseRange;
128 FX_FILESIZE m_nOffset; 128 FX_FILESIZE m_nOffset;
129 FX_FILESIZE m_nSize; 129 FX_FILESIZE m_nSize;
130 }; 130 };
131 #define FX_MEMSTREAM_BlockSize (64 * 1024) 131 #define FX_MEMSTREAM_BlockSize (64 * 1024)
(...skipping 25 matching lines...)
157 } 157 }
158 ~CFX_MemoryStream() 158 ~CFX_MemoryStream()
159 { 159 {
160 if (m_dwFlags & FX_MEMSTREAM_TakeOver) { 160 if (m_dwFlags & FX_MEMSTREAM_TakeOver) {
161 for (FX_INT32 i = 0; i < m_Blocks.GetSize(); i++) { 161 for (FX_INT32 i = 0; i < m_Blocks.GetSize(); i++) {
162 FX_Free((FX_LPBYTE)m_Blocks[i]); 162 FX_Free((FX_LPBYTE)m_Blocks[i]);
163 } 163 }
164 } 164 }
165 m_Blocks.RemoveAll(); 165 m_Blocks.RemoveAll();
166 } 166 }
167 virtual IFX_FileStream*» » Retain() 167 virtual IFX_FileStream*» » Retain() FX_OVERRIDE
168 { 168 {
169 m_dwCount ++; 169 m_dwCount ++;
170 return this; 170 return this;
171 } 171 }
172 virtual void» » » » Release() 172 virtual void» » » » Release() FX_OVERRIDE
173 { 173 {
174 FX_DWORD nCount = -- m_dwCount; 174 FX_DWORD nCount = -- m_dwCount;
175 if (nCount) { 175 if (nCount) {
176 return; 176 return;
177 } 177 }
178 delete this; 178 delete this;
179 } 179 }
180 virtual FX_FILESIZE»» » GetSize() 180 virtual FX_FILESIZE»» » GetSize() FX_OVERRIDE
181 { 181 {
182 return m_bUseRange ? (FX_FILESIZE) m_nSize : (FX_FILESIZE)m_nCurSize; 182 return m_bUseRange ? (FX_FILESIZE) m_nSize : (FX_FILESIZE)m_nCurSize;
183 } 183 }
184 virtual FX_BOOL» » » » IsEOF() 184 virtual FX_BOOL» » » » IsEOF() FX_OVERRIDE
185 { 185 {
186 return m_nCurPos >= (size_t)GetSize(); 186 return m_nCurPos >= (size_t)GetSize();
187 } 187 }
188 virtual FX_FILESIZE»» » GetPosition() 188 virtual FX_FILESIZE»» » GetPosition() FX_OVERRIDE
189 { 189 {
190 FX_FILESIZE pos = (FX_FILESIZE)m_nCurPos; 190 FX_FILESIZE pos = (FX_FILESIZE)m_nCurPos;
191 if (m_bUseRange) { 191 if (m_bUseRange) {
192 pos -= (FX_FILESIZE)m_nOffset; 192 pos -= (FX_FILESIZE)m_nOffset;
193 } 193 }
194 return pos; 194 return pos;
195 } 195 }
196 virtual FX_BOOL» » » » SetRange(FX_FILESIZE offset, FX_ FILESIZE size) 196 virtual FX_BOOL» » » » SetRange(FX_FILESIZE offset, FX_ FILESIZE size) FX_OVERRIDE
197 { 197 {
198 if (offset < 0 || size < 0) { 198 if (offset < 0 || size < 0) {
199 return FALSE; 199 return FALSE;
200 } 200 }
201 FX_SAFE_FILESIZE range = size; 201 FX_SAFE_FILESIZE range = size;
202 range += offset; 202 range += offset;
203 if (!range.IsValid() || range.ValueOrDie() > m_nCurSize) { 203 if (!range.IsValid() || range.ValueOrDie() > m_nCurSize) {
204 return FALSE; 204 return FALSE;
205 } 205 }
206 206
207 m_nOffset = (size_t)offset, m_nSize = (size_t)size; 207 m_nOffset = (size_t)offset, m_nSize = (size_t)size;
208 m_bUseRange = TRUE; 208 m_bUseRange = TRUE;
209 m_nCurPos = m_nOffset; 209 m_nCurPos = m_nOffset;
210 return TRUE; 210 return TRUE;
211 } 211 }
212 virtual void» » » » ClearRange() 212 virtual void» » » » ClearRange() FX_OVERRIDE
213 { 213 {
214 m_bUseRange = FALSE; 214 m_bUseRange = FALSE;
215 } 215 }
216 virtual FX_BOOL» » » » ReadBlock(void* buffer, FX_FILES IZE offset, size_t size) 216 virtual FX_BOOL» » » » ReadBlock(void* buffer, FX_FILES IZE offset, size_t size) FX_OVERRIDE
217 { 217 {
218 if (!buffer || !size) { 218 if (!buffer || !size) {
219 return FALSE; 219 return FALSE;
220 } 220 }
221 221
222 FX_SAFE_FILESIZE safeOffset = offset; 222 FX_SAFE_FILESIZE safeOffset = offset;
223 if (m_bUseRange) { 223 if (m_bUseRange) {
224 safeOffset += m_nOffset; 224 safeOffset += m_nOffset;
225 } 225 }
226 226
(...skipping 22 matching lines...)
249 nRead = size; 249 nRead = size;
250 } 250 }
251 FXSYS_memcpy32(buffer, (FX_LPBYTE)m_Blocks[(int)nStartBlock] + (size _t)offset, nRead); 251 FXSYS_memcpy32(buffer, (FX_LPBYTE)m_Blocks[(int)nStartBlock] + (size _t)offset, nRead);
252 buffer = ((FX_LPBYTE)buffer) + nRead; 252 buffer = ((FX_LPBYTE)buffer) + nRead;
253 size -= nRead; 253 size -= nRead;
254 nStartBlock ++; 254 nStartBlock ++;
255 offset = 0; 255 offset = 0;
256 } 256 }
257 return TRUE; 257 return TRUE;
258 } 258 }
259 virtual size_t» » » » ReadBlock(void* buffer, size_t s ize) 259 virtual size_t» » » » ReadBlock(void* buffer, size_t s ize) FX_OVERRIDE
260 { 260 {
261 if (m_nCurPos >= m_nCurSize) { 261 if (m_nCurPos >= m_nCurSize) {
262 return 0; 262 return 0;
263 } 263 }
264 if (m_bUseRange) { 264 if (m_bUseRange) {
265 size_t availSize = m_nOffset + m_nSize - m_nCurPos; 265 size_t availSize = m_nOffset + m_nSize - m_nCurPos;
266 if (availSize < size) { 266 if (availSize < size) {
267 size -= size - (size_t)availSize; 267 size -= size - (size_t)availSize;
268 } 268 }
269 } 269 }
270 size_t nRead = FX_MIN(size, m_nCurSize - m_nCurPos); 270 size_t nRead = FX_MIN(size, m_nCurSize - m_nCurPos);
271 if (!ReadBlock(buffer, (FX_INT32)m_nCurPos, nRead)) { 271 if (!ReadBlock(buffer, (FX_INT32)m_nCurPos, nRead)) {
272 return 0; 272 return 0;
273 } 273 }
274 return nRead; 274 return nRead;
275 } 275 }
276 virtual» FX_BOOL»» » » WriteBlock(const void* buffer, F X_FILESIZE offset, size_t size) 276 virtual» FX_BOOL»» » » WriteBlock(const void* buffer, F X_FILESIZE offset, size_t size) FX_OVERRIDE
277 { 277 {
278 if (!buffer || !size) { 278 if (!buffer || !size) {
279 return FALSE; 279 return FALSE;
280 } 280 }
281 if (m_bUseRange) { 281 if (m_bUseRange) {
282 offset += (FX_FILESIZE)m_nOffset; 282 offset += (FX_FILESIZE)m_nOffset;
283 } 283 }
284 if (m_dwFlags & FX_MEMSTREAM_Consecutive) { 284 if (m_dwFlags & FX_MEMSTREAM_Consecutive) {
285 FX_SAFE_SIZE_T newPos = size; 285 FX_SAFE_SIZE_T newPos = size;
286 newPos += offset; 286 newPos += offset;
(...skipping 39 matching lines...)
326 nWrite = size; 326 nWrite = size;
327 } 327 }
328 FXSYS_memcpy32((FX_LPBYTE)m_Blocks[(int)nStartBlock] + (size_t)offse t, buffer, nWrite); 328 FXSYS_memcpy32((FX_LPBYTE)m_Blocks[(int)nStartBlock] + (size_t)offse t, buffer, nWrite);
329 buffer = ((FX_LPBYTE)buffer) + nWrite; 329 buffer = ((FX_LPBYTE)buffer) + nWrite;
330 size -= nWrite; 330 size -= nWrite;
331 nStartBlock ++; 331 nStartBlock ++;
332 offset = 0; 332 offset = 0;
333 } 333 }
334 return TRUE; 334 return TRUE;
335 } 335 }
336 virtual FX_BOOL» » » » Flush() 336 virtual FX_BOOL» » » » Flush() FX_OVERRIDE
337 { 337 {
338 return TRUE; 338 return TRUE;
339 } 339 }
340 virtual FX_BOOL» » » » IsConsecutive() const 340 virtual FX_BOOL» » » » IsConsecutive() const FX_OVERRI DE
341 { 341 {
342 return m_dwFlags & FX_MEMSTREAM_Consecutive; 342 return m_dwFlags & FX_MEMSTREAM_Consecutive;
343 } 343 }
344 virtual void» » » » EstimateSize(size_t nInitSize, s ize_t nGrowSize) 344 virtual void» » » » EstimateSize(size_t nInitSize, s ize_t nGrowSize) FX_OVERRIDE
345 { 345 {
346 if (m_dwFlags & FX_MEMSTREAM_Consecutive) { 346 if (m_dwFlags & FX_MEMSTREAM_Consecutive) {
347 if (m_Blocks.GetSize() < 1) { 347 if (m_Blocks.GetSize() < 1) {
348 FX_LPBYTE pBlock = FX_Alloc(FX_BYTE, FX_MAX(nInitSize, 4096)); 348 FX_LPBYTE pBlock = FX_Alloc(FX_BYTE, FX_MAX(nInitSize, 4096));
349 if (pBlock) { 349 if (pBlock) {
350 m_Blocks.Add(pBlock); 350 m_Blocks.Add(pBlock);
351 } 351 }
352 } 352 }
353 m_nGrowSize = FX_MAX(nGrowSize, 4096); 353 m_nGrowSize = FX_MAX(nGrowSize, 4096);
354 } else if (m_Blocks.GetSize() < 1) { 354 } else if (m_Blocks.GetSize() < 1) {
355 m_nGrowSize = FX_MAX(nGrowSize, 4096); 355 m_nGrowSize = FX_MAX(nGrowSize, 4096);
356 } 356 }
357 } 357 }
358 virtual FX_LPBYTE» » » GetBuffer() const 358 virtual FX_LPBYTE» » » GetBuffer() const FX_OVERRIDE
359 { 359 {
360 return m_Blocks.GetSize() ? (FX_LPBYTE)m_Blocks[0] : NULL; 360 return m_Blocks.GetSize() ? (FX_LPBYTE)m_Blocks[0] : NULL;
361 } 361 }
362 virtual void» » » » AttachBuffer(FX_LPBYTE pBuffer, size_t nSize, FX_BOOL bTakeOver = FALSE) 362 virtual void» » » » AttachBuffer(FX_LPBYTE pBuffer, size_t nSize, FX_BOOL bTakeOver = FALSE) FX_OVERRIDE
363 { 363 {
364 if (!(m_dwFlags & FX_MEMSTREAM_Consecutive)) { 364 if (!(m_dwFlags & FX_MEMSTREAM_Consecutive)) {
365 return; 365 return;
366 } 366 }
367 m_Blocks.RemoveAll(); 367 m_Blocks.RemoveAll();
368 m_Blocks.Add(pBuffer); 368 m_Blocks.Add(pBuffer);
369 m_nTotalSize = m_nCurSize = nSize; 369 m_nTotalSize = m_nCurSize = nSize;
370 m_nCurPos = 0; 370 m_nCurPos = 0;
371 m_dwFlags = FX_MEMSTREAM_Consecutive | (bTakeOver ? FX_MEMSTREAM_TakeOve r : 0); 371 m_dwFlags = FX_MEMSTREAM_Consecutive | (bTakeOver ? FX_MEMSTREAM_TakeOve r : 0);
372 ClearRange(); 372 ClearRange();
373 } 373 }
374 virtual void» » » » DetachBuffer() 374 virtual void» » » » DetachBuffer() FX_OVERRIDE
375 { 375 {
376 if (!(m_dwFlags & FX_MEMSTREAM_Consecutive)) { 376 if (!(m_dwFlags & FX_MEMSTREAM_Consecutive)) {
377 return; 377 return;
378 } 378 }
379 m_Blocks.RemoveAll(); 379 m_Blocks.RemoveAll();
380 m_nTotalSize = m_nCurSize = m_nCurPos = 0; 380 m_nTotalSize = m_nCurSize = m_nCurPos = 0;
381 m_dwFlags = FX_MEMSTREAM_TakeOver; 381 m_dwFlags = FX_MEMSTREAM_TakeOver;
382 ClearRange(); 382 ClearRange();
383 } 383 }
384 protected: 384 protected:
(...skipping 48 matching lines...)
433 FX_DWORD mt[MT_N]; 433 FX_DWORD mt[MT_N];
434 } FX_MTRANDOMCONTEXT, * FX_LPMTRANDOMCONTEXT; 434 } FX_MTRANDOMCONTEXT, * FX_LPMTRANDOMCONTEXT;
435 typedef FX_MTRANDOMCONTEXT const * FX_LPCMTRANDOMCONTEXT; 435 typedef FX_MTRANDOMCONTEXT const * FX_LPCMTRANDOMCONTEXT;
436 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ 436 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
437 FX_BOOL FX_GenerateCryptoRandom(FX_LPDWORD pBuffer, FX_INT32 iCount); 437 FX_BOOL FX_GenerateCryptoRandom(FX_LPDWORD pBuffer, FX_INT32 iCount);
438 #endif 438 #endif
439 #ifdef __cplusplus 439 #ifdef __cplusplus
440 } 440 }
441 #endif 441 #endif
442 #endif 442 #endif
OLDNEW
« no previous file with comments | « core/src/fpdfapi/fpdf_font/ttgsubtable.h ('k') | core/src/fxcrt/fx_arabic.h » ('j') | no next file with comments »

Powered by Google App Engine