Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Side by Side Diff: xfa/fgas/crt/fgas_stream.cpp

Issue 1998453002: Remove Release() from CFX_StreamImp, rename to IFX_StreamImp (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Dropped a ! Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | 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 #include "xfa/fgas/crt/fgas_stream.h" 7 #include "xfa/fgas/crt/fgas_stream.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory>
10 11
11 #include "xfa/fgas/crt/fgas_codepage.h" 12 #include "xfa/fgas/crt/fgas_codepage.h"
12 #include "xfa/fgas/crt/fgas_system.h" 13 #include "xfa/fgas/crt/fgas_system.h"
13 14
14 namespace { 15 namespace {
15 16
16 class CFX_StreamImp { 17 class IFX_StreamImp {
17 public: 18 public:
18 virtual void Release() { delete this; } 19 virtual ~IFX_StreamImp() {}
19 virtual uint32_t GetAccessModes() const { return m_dwAccess; } 20
20 virtual int32_t GetLength() const = 0; 21 virtual int32_t GetLength() const = 0;
21 virtual int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) = 0; 22 virtual int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) = 0;
22 virtual int32_t GetPosition() = 0; 23 virtual int32_t GetPosition() = 0;
23 virtual FX_BOOL IsEOF() const = 0; 24 virtual FX_BOOL IsEOF() const = 0;
24 virtual int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) = 0; 25 virtual int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) = 0;
25 virtual int32_t ReadString(FX_WCHAR* pStr, 26 virtual int32_t ReadString(FX_WCHAR* pStr,
26 int32_t iMaxLength, 27 int32_t iMaxLength,
27 FX_BOOL& bEOS) = 0; 28 FX_BOOL& bEOS) = 0;
28 virtual int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) = 0; 29 virtual int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) = 0;
29 virtual int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) = 0; 30 virtual int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) = 0;
30 virtual void Flush() = 0; 31 virtual void Flush() = 0;
31 virtual FX_BOOL SetLength(int32_t iLength) = 0; 32 virtual FX_BOOL SetLength(int32_t iLength) = 0;
32 33
33 protected: 34 protected:
34 CFX_StreamImp(); 35 IFX_StreamImp();
35 virtual ~CFX_StreamImp() {} 36
37 uint32_t GetAccessModes() const { return m_dwAccess; }
38 void SetAccessModes(uint32_t modes) { m_dwAccess = modes; }
39
40 private:
36 uint32_t m_dwAccess; 41 uint32_t m_dwAccess;
37 }; 42 };
38 43
39 class CFX_FileStreamImp : public CFX_StreamImp { 44 class CFX_FileStreamImp : public IFX_StreamImp {
40 public: 45 public:
41 CFX_FileStreamImp(); 46 CFX_FileStreamImp();
42 virtual ~CFX_FileStreamImp(); 47 ~CFX_FileStreamImp() override;
48
43 FX_BOOL LoadFile(const FX_WCHAR* pszSrcFileName, uint32_t dwAccess); 49 FX_BOOL LoadFile(const FX_WCHAR* pszSrcFileName, uint32_t dwAccess);
44 virtual int32_t GetLength() const; 50
45 virtual int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset); 51 // IFX_StreamImp:
46 virtual int32_t GetPosition(); 52 int32_t GetLength() const override;
47 virtual FX_BOOL IsEOF() const; 53 int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) override;
48 virtual int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize); 54 int32_t GetPosition() override;
49 virtual int32_t ReadString(FX_WCHAR* pStr, int32_t iMaxLength, FX_BOOL& bEOS); 55 FX_BOOL IsEOF() const override;
50 virtual int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize); 56 int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) override;
51 virtual int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength); 57 int32_t ReadString(FX_WCHAR* pStr,
52 virtual void Flush(); 58 int32_t iMaxLength,
53 virtual FX_BOOL SetLength(int32_t iLength); 59 FX_BOOL& bEOS) override;
60 int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) override;
61 int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) override;
62 void Flush() override;
63 FX_BOOL SetLength(int32_t iLength) override;
54 64
55 protected: 65 protected:
56 FXSYS_FILE* m_hFile; 66 FXSYS_FILE* m_hFile;
57 int32_t m_iLength; 67 int32_t m_iLength;
58 }; 68 };
59 69
60 class CFX_BufferStreamImp : public CFX_StreamImp { 70 class CFX_BufferStreamImp : public IFX_StreamImp {
61 public: 71 public:
62 CFX_BufferStreamImp(); 72 CFX_BufferStreamImp();
63 virtual ~CFX_BufferStreamImp() {} 73 ~CFX_BufferStreamImp() override {}
74
64 FX_BOOL LoadBuffer(uint8_t* pData, int32_t iTotalSize, uint32_t dwAccess); 75 FX_BOOL LoadBuffer(uint8_t* pData, int32_t iTotalSize, uint32_t dwAccess);
65 virtual int32_t GetLength() const; 76
66 virtual int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset); 77 // IFX_StreamImp:
67 virtual int32_t GetPosition(); 78 int32_t GetLength() const override;
68 virtual FX_BOOL IsEOF() const; 79 int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) override;
69 virtual int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize); 80 int32_t GetPosition() override;
70 virtual int32_t ReadString(FX_WCHAR* pStr, int32_t iMaxLength, FX_BOOL& bEOS); 81 FX_BOOL IsEOF() const override;
71 virtual int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize); 82 int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) override;
72 virtual int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength); 83 int32_t ReadString(FX_WCHAR* pStr,
73 virtual void Flush() {} 84 int32_t iMaxLength,
74 virtual FX_BOOL SetLength(int32_t iLength) { return FALSE; } 85 FX_BOOL& bEOS) override;
86 int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) override;
87 int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) override;
88 void Flush() override {}
89 FX_BOOL SetLength(int32_t iLength) override { return FALSE; }
75 90
76 protected: 91 protected:
77 uint8_t* m_pData; 92 uint8_t* m_pData;
78 int32_t m_iTotalSize; 93 int32_t m_iTotalSize;
79 int32_t m_iPosition; 94 int32_t m_iPosition;
80 int32_t m_iLength; 95 int32_t m_iLength;
81 }; 96 };
82 97
83 class CFX_FileReadStreamImp : public CFX_StreamImp { 98 class CFX_FileReadStreamImp : public IFX_StreamImp {
84 public: 99 public:
85 CFX_FileReadStreamImp(); 100 CFX_FileReadStreamImp();
86 virtual ~CFX_FileReadStreamImp() {} 101 ~CFX_FileReadStreamImp() override {}
102
87 FX_BOOL LoadFileRead(IFX_FileRead* pFileRead, uint32_t dwAccess); 103 FX_BOOL LoadFileRead(IFX_FileRead* pFileRead, uint32_t dwAccess);
88 virtual int32_t GetLength() const;
89 virtual int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset);
90 virtual int32_t GetPosition() { return m_iPosition; }
91 virtual FX_BOOL IsEOF() const;
92 104
93 virtual int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize); 105 // IFX_StreamImp:
94 virtual int32_t ReadString(FX_WCHAR* pStr, int32_t iMaxLength, FX_BOOL& bEOS); 106 int32_t GetLength() const override;
95 virtual int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) { 107 int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) override;
108 int32_t GetPosition() override { return m_iPosition; }
109 FX_BOOL IsEOF() const override;
110 int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) override;
111 int32_t ReadString(FX_WCHAR* pStr,
112 int32_t iMaxLength,
113 FX_BOOL& bEOS) override;
114 int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) override {
96 return 0; 115 return 0;
97 } 116 }
98 virtual int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) { 117 int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) override {
99 return 0; 118 return 0;
100 } 119 }
101 virtual void Flush() {} 120 void Flush() override {}
102 virtual FX_BOOL SetLength(int32_t iLength) { return FALSE; } 121 FX_BOOL SetLength(int32_t iLength) override { return FALSE; }
103 122
104 protected: 123 protected:
105 IFX_FileRead* m_pFileRead; 124 IFX_FileRead* m_pFileRead;
106 int32_t m_iPosition; 125 int32_t m_iPosition;
107 int32_t m_iLength; 126 int32_t m_iLength;
108 }; 127 };
109 128
110 class CFX_BufferReadStreamImp : public CFX_StreamImp { 129 class CFX_BufferReadStreamImp : public IFX_StreamImp {
111 public: 130 public:
112 CFX_BufferReadStreamImp(); 131 CFX_BufferReadStreamImp();
113 ~CFX_BufferReadStreamImp(); 132 ~CFX_BufferReadStreamImp() override;
133
114 FX_BOOL LoadBufferRead(IFX_BufferRead* pBufferRead, 134 FX_BOOL LoadBufferRead(IFX_BufferRead* pBufferRead,
115 int32_t iFileSize, 135 int32_t iFileSize,
116 uint32_t dwAccess, 136 uint32_t dwAccess,
117 FX_BOOL bReleaseBufferRead); 137 FX_BOOL bReleaseBufferRead);
118 138
119 virtual int32_t GetLength() const; 139 // IFX_StreamImp:
120 virtual int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset); 140 int32_t GetLength() const override;
121 virtual int32_t GetPosition() { return m_iPosition; } 141 int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) override;
122 virtual FX_BOOL IsEOF() const; 142 int32_t GetPosition() override { return m_iPosition; }
123 143 FX_BOOL IsEOF() const override;
124 virtual int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize); 144 int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) override;
125 virtual int32_t ReadString(FX_WCHAR* pStr, int32_t iMaxLength, FX_BOOL& bEOS); 145 int32_t ReadString(FX_WCHAR* pStr,
126 virtual int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) { 146 int32_t iMaxLength,
147 FX_BOOL& bEOS) override;
148 int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) override {
127 return 0; 149 return 0;
128 } 150 }
129 virtual int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) { 151 int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) override {
130 return 0; 152 return 0;
131 } 153 }
132 virtual void Flush() {} 154 void Flush() override {}
133 virtual FX_BOOL SetLength(int32_t iLength) { return FALSE; } 155 FX_BOOL SetLength(int32_t iLength) override { return FALSE; }
134 156
135 private: 157 private:
136 IFX_BufferRead* m_pBufferRead; 158 IFX_BufferRead* m_pBufferRead;
137 FX_BOOL m_bReleaseBufferRead; 159 FX_BOOL m_bReleaseBufferRead;
138 int32_t m_iPosition; 160 int32_t m_iPosition;
139 int32_t m_iBufferSize; 161 int32_t m_iBufferSize;
140 }; 162 };
141 163
142 class CFX_FileWriteStreamImp : public CFX_StreamImp { 164 class CFX_FileWriteStreamImp : public IFX_StreamImp {
143 public: 165 public:
144 CFX_FileWriteStreamImp(); 166 CFX_FileWriteStreamImp();
145 virtual ~CFX_FileWriteStreamImp() {} 167 ~CFX_FileWriteStreamImp() override {}
168
146 FX_BOOL LoadFileWrite(IFX_FileWrite* pFileWrite, uint32_t dwAccess); 169 FX_BOOL LoadFileWrite(IFX_FileWrite* pFileWrite, uint32_t dwAccess);
147 virtual int32_t GetLength() const; 170
148 virtual int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset); 171 // IFX_StreamImp:
149 virtual int32_t GetPosition() { return m_iPosition; } 172 int32_t GetLength() const override;
150 virtual FX_BOOL IsEOF() const; 173 int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) override;
151 virtual int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) { return 0; } 174 int32_t GetPosition() override { return m_iPosition; }
152 virtual int32_t ReadString(FX_WCHAR* pStr, 175 FX_BOOL IsEOF() const override;
153 int32_t iMaxLength, 176 int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) override { return 0; }
154 FX_BOOL& bEOS) { 177 int32_t ReadString(FX_WCHAR* pStr,
178 int32_t iMaxLength,
179 FX_BOOL& bEOS) override {
155 return 0; 180 return 0;
156 } 181 }
157 virtual int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize); 182 int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) override;
158 virtual int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength); 183 int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) override;
159 virtual void Flush(); 184 void Flush() override;
160 virtual FX_BOOL SetLength(int32_t iLength) { return FALSE; } 185 FX_BOOL SetLength(int32_t iLength) override { return FALSE; }
161 186
162 protected: 187 protected:
163 IFX_FileWrite* m_pFileWrite; 188 IFX_FileWrite* m_pFileWrite;
164 int32_t m_iPosition; 189 int32_t m_iPosition;
165 }; 190 };
166 191
167 enum FX_STREAMTYPE { 192 enum FX_STREAMTYPE {
168 FX_SREAMTYPE_Unknown = 0, 193 FX_SREAMTYPE_Unknown = 0,
169 FX_STREAMTYPE_File, 194 FX_STREAMTYPE_File,
170 FX_STREAMTYPE_Buffer, 195 FX_STREAMTYPE_Buffer,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 virtual FX_BOOL SetLength(int32_t iLength); 227 virtual FX_BOOL SetLength(int32_t iLength);
203 virtual int32_t GetBOM(uint8_t bom[4]) const; 228 virtual int32_t GetBOM(uint8_t bom[4]) const;
204 virtual uint16_t GetCodePage() const; 229 virtual uint16_t GetCodePage() const;
205 virtual uint16_t SetCodePage(uint16_t wCodePage); 230 virtual uint16_t SetCodePage(uint16_t wCodePage);
206 virtual IFX_Stream* CreateSharedStream(uint32_t dwAccess, 231 virtual IFX_Stream* CreateSharedStream(uint32_t dwAccess,
207 int32_t iOffset, 232 int32_t iOffset,
208 int32_t iLength); 233 int32_t iLength);
209 234
210 protected: 235 protected:
211 FX_STREAMTYPE m_eStreamType; 236 FX_STREAMTYPE m_eStreamType;
212 CFX_StreamImp* m_pStreamImp; 237 IFX_StreamImp* m_pStreamImp;
213 uint32_t m_dwAccess; 238 uint32_t m_dwAccess;
214 int32_t m_iTotalSize; 239 int32_t m_iTotalSize;
215 int32_t m_iPosition; 240 int32_t m_iPosition;
216 int32_t m_iStart; 241 int32_t m_iStart;
217 int32_t m_iLength; 242 int32_t m_iLength;
218 int32_t m_iRefCount; 243 int32_t m_iRefCount;
219 }; 244 };
220 245
221 class CFX_TextStream : public IFX_Stream { 246 class CFX_TextStream : public IFX_Stream {
222 public: 247 public:
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 if (!pSR->LoadBuffer(pData, length, dwAccess)) { 392 if (!pSR->LoadBuffer(pData, length, dwAccess)) {
368 pSR->Release(); 393 pSR->Release();
369 return NULL; 394 return NULL;
370 } 395 }
371 if (dwAccess & FX_STREAMACCESS_Text) { 396 if (dwAccess & FX_STREAMACCESS_Text) {
372 return new CFX_TextStream(pSR, TRUE); 397 return new CFX_TextStream(pSR, TRUE);
373 } 398 }
374 return pSR; 399 return pSR;
375 } 400 }
376 401
377 CFX_StreamImp::CFX_StreamImp() : m_dwAccess(0) {} 402 IFX_StreamImp::IFX_StreamImp() : m_dwAccess(0) {}
378 CFX_FileStreamImp::CFX_FileStreamImp() 403
379 : CFX_StreamImp(), m_hFile(NULL), m_iLength(0) {} 404 CFX_FileStreamImp::CFX_FileStreamImp() : m_hFile(nullptr), m_iLength(0) {}
405
380 CFX_FileStreamImp::~CFX_FileStreamImp() { 406 CFX_FileStreamImp::~CFX_FileStreamImp() {
381 if (m_hFile != NULL) { 407 if (m_hFile)
382 FXSYS_fclose(m_hFile); 408 FXSYS_fclose(m_hFile);
383 }
384 } 409 }
410
385 FX_BOOL CFX_FileStreamImp::LoadFile(const FX_WCHAR* pszSrcFileName, 411 FX_BOOL CFX_FileStreamImp::LoadFile(const FX_WCHAR* pszSrcFileName,
386 uint32_t dwAccess) { 412 uint32_t dwAccess) {
387 ASSERT(m_hFile == NULL); 413 ASSERT(m_hFile == NULL);
388 ASSERT(pszSrcFileName != NULL && FXSYS_wcslen(pszSrcFileName) > 0); 414 ASSERT(pszSrcFileName != NULL && FXSYS_wcslen(pszSrcFileName) > 0);
389 #if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN32_MOBILE_ || \ 415 #if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN32_MOBILE_ || \
390 _FX_OS_ == _FX_WIN64_ 416 _FX_OS_ == _FX_WIN64_
391 const FX_WCHAR* wsMode; 417 const FX_WCHAR* wsMode;
392 if (dwAccess & FX_STREAMACCESS_Write) { 418 if (dwAccess & FX_STREAMACCESS_Write) {
393 if (dwAccess & FX_STREAMACCESS_Append) { 419 if (dwAccess & FX_STREAMACCESS_Append) {
394 wsMode = L"a+b"; 420 wsMode = L"a+b";
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 } 470 }
445 if (dwAccess & FX_STREAMACCESS_Truncate) { 471 if (dwAccess & FX_STREAMACCESS_Truncate) {
446 FX_fsetsize(m_hFile, 0); 472 FX_fsetsize(m_hFile, 0);
447 } 473 }
448 } 474 }
449 } else { 475 } else {
450 return FALSE; 476 return FALSE;
451 } 477 }
452 } 478 }
453 #endif 479 #endif
454 m_dwAccess = dwAccess; 480 SetAccessModes(dwAccess);
455 if ((dwAccess & (FX_STREAMACCESS_Write | FX_STREAMACCESS_Truncate)) == 481 if ((dwAccess & (FX_STREAMACCESS_Write | FX_STREAMACCESS_Truncate)) ==
456 (FX_STREAMACCESS_Write | FX_STREAMACCESS_Truncate)) { 482 (FX_STREAMACCESS_Write | FX_STREAMACCESS_Truncate)) {
457 m_iLength = 0; 483 m_iLength = 0;
458 } else { 484 } else {
459 m_iLength = FX_filelength(m_hFile); 485 m_iLength = FX_filelength(m_hFile);
460 } 486 }
461 return TRUE; 487 return TRUE;
462 } 488 }
463 int32_t CFX_FileStreamImp::GetLength() const { 489 int32_t CFX_FileStreamImp::GetLength() const {
464 ASSERT(m_hFile != NULL); 490 ASSERT(m_hFile != NULL);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 } 528 }
503 iPosition += iCount * 2; 529 iPosition += iCount * 2;
504 if (FXSYS_ftell(m_hFile) != iPosition) { 530 if (FXSYS_ftell(m_hFile) != iPosition) {
505 FXSYS_fseek(m_hFile, iPosition, 0); 531 FXSYS_fseek(m_hFile, iPosition, 0);
506 } 532 }
507 bEOS = (iPosition >= m_iLength); 533 bEOS = (iPosition >= m_iLength);
508 return iCount; 534 return iCount;
509 } 535 }
510 int32_t CFX_FileStreamImp::WriteData(const uint8_t* pBuffer, 536 int32_t CFX_FileStreamImp::WriteData(const uint8_t* pBuffer,
511 int32_t iBufferSize) { 537 int32_t iBufferSize) {
512 ASSERT(m_hFile != NULL && (m_dwAccess & FX_STREAMACCESS_Write) != 0); 538 ASSERT(m_hFile && (GetAccessModes() & FX_STREAMACCESS_Write) != 0);
513 ASSERT(pBuffer != NULL && iBufferSize > 0); 539 ASSERT(pBuffer && iBufferSize > 0);
514 int32_t iRet = FXSYS_fwrite(pBuffer, 1, iBufferSize, m_hFile); 540 int32_t iRet = FXSYS_fwrite(pBuffer, 1, iBufferSize, m_hFile);
515 if (iRet != 0) { 541 if (iRet != 0) {
516 int32_t iPos = FXSYS_ftell(m_hFile); 542 int32_t iPos = FXSYS_ftell(m_hFile);
517 if (iPos > m_iLength) { 543 if (iPos > m_iLength) {
518 m_iLength = iPos; 544 m_iLength = iPos;
519 } 545 }
520 } 546 }
521 return iRet; 547 return iRet;
522 } 548 }
523 int32_t CFX_FileStreamImp::WriteString(const FX_WCHAR* pStr, int32_t iLength) { 549 int32_t CFX_FileStreamImp::WriteString(const FX_WCHAR* pStr, int32_t iLength) {
524 ASSERT(m_hFile != NULL && (m_dwAccess & FX_STREAMACCESS_Write) != 0); 550 ASSERT(m_hFile && (GetAccessModes() & FX_STREAMACCESS_Write) != 0);
525 ASSERT(pStr != NULL && iLength > 0); 551 ASSERT(pStr && iLength > 0);
526 int32_t iRet = FXSYS_fwrite(pStr, 2, iLength, m_hFile); 552 int32_t iRet = FXSYS_fwrite(pStr, 2, iLength, m_hFile);
527 if (iRet != 0) { 553 if (iRet != 0) {
528 int32_t iPos = FXSYS_ftell(m_hFile); 554 int32_t iPos = FXSYS_ftell(m_hFile);
529 if (iPos > m_iLength) { 555 if (iPos > m_iLength) {
530 m_iLength = iPos; 556 m_iLength = iPos;
531 } 557 }
532 } 558 }
533 return iRet; 559 return iRet;
534 } 560 }
535 void CFX_FileStreamImp::Flush() { 561 void CFX_FileStreamImp::Flush() {
536 ASSERT(m_hFile != NULL && (m_dwAccess & FX_STREAMACCESS_Write) != 0); 562 ASSERT(m_hFile && (GetAccessModes() & FX_STREAMACCESS_Write) != 0);
537 FXSYS_fflush(m_hFile); 563 FXSYS_fflush(m_hFile);
538 } 564 }
539 FX_BOOL CFX_FileStreamImp::SetLength(int32_t iLength) { 565 FX_BOOL CFX_FileStreamImp::SetLength(int32_t iLength) {
540 ASSERT(m_hFile != NULL && (m_dwAccess & FX_STREAMACCESS_Write) != 0); 566 ASSERT(m_hFile && (GetAccessModes() & FX_STREAMACCESS_Write) != 0);
541 FX_BOOL bRet = FX_fsetsize(m_hFile, iLength); 567 FX_BOOL bRet = FX_fsetsize(m_hFile, iLength);
542 m_iLength = FX_filelength(m_hFile); 568 m_iLength = FX_filelength(m_hFile);
543 return bRet; 569 return bRet;
544 } 570 }
545 CFX_FileReadStreamImp::CFX_FileReadStreamImp() 571 CFX_FileReadStreamImp::CFX_FileReadStreamImp()
546 : m_pFileRead(NULL), m_iPosition(0), m_iLength(0) {} 572 : m_pFileRead(NULL), m_iPosition(0), m_iLength(0) {}
547 FX_BOOL CFX_FileReadStreamImp::LoadFileRead(IFX_FileRead* pFileRead, 573 FX_BOOL CFX_FileReadStreamImp::LoadFileRead(IFX_FileRead* pFileRead,
548 uint32_t dwAccess) { 574 uint32_t dwAccess) {
549 ASSERT(m_pFileRead == NULL && pFileRead != NULL); 575 ASSERT(m_pFileRead == NULL && pFileRead != NULL);
550 if (dwAccess & FX_STREAMACCESS_Write) { 576 if (dwAccess & FX_STREAMACCESS_Write) {
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
793 int32_t CFX_FileWriteStreamImp::WriteString(const FX_WCHAR* pStr, 819 int32_t CFX_FileWriteStreamImp::WriteString(const FX_WCHAR* pStr,
794 int32_t iLength) { 820 int32_t iLength) {
795 return WriteData((const uint8_t*)pStr, iLength * sizeof(FX_WCHAR)); 821 return WriteData((const uint8_t*)pStr, iLength * sizeof(FX_WCHAR));
796 } 822 }
797 void CFX_FileWriteStreamImp::Flush() { 823 void CFX_FileWriteStreamImp::Flush() {
798 if (m_pFileWrite) { 824 if (m_pFileWrite) {
799 m_pFileWrite->Flush(); 825 m_pFileWrite->Flush();
800 } 826 }
801 } 827 }
802 CFX_BufferStreamImp::CFX_BufferStreamImp() 828 CFX_BufferStreamImp::CFX_BufferStreamImp()
803 : CFX_StreamImp(), 829 : m_pData(nullptr), m_iTotalSize(0), m_iPosition(0), m_iLength(0) {}
804 m_pData(NULL), 830
805 m_iTotalSize(0),
806 m_iPosition(0),
807 m_iLength(0) {}
808 FX_BOOL CFX_BufferStreamImp::LoadBuffer(uint8_t* pData, 831 FX_BOOL CFX_BufferStreamImp::LoadBuffer(uint8_t* pData,
809 int32_t iTotalSize, 832 int32_t iTotalSize,
810 uint32_t dwAccess) { 833 uint32_t dwAccess) {
811 ASSERT(m_pData == NULL); 834 ASSERT(!m_pData && pData && iTotalSize > 0);
812 ASSERT(pData != NULL && iTotalSize > 0); 835 SetAccessModes(dwAccess);
813 m_dwAccess = dwAccess;
814 m_pData = pData; 836 m_pData = pData;
815 m_iTotalSize = iTotalSize; 837 m_iTotalSize = iTotalSize;
816 m_iPosition = 0; 838 m_iPosition = 0;
817 m_iLength = (dwAccess & FX_STREAMACCESS_Write) != 0 ? 0 : iTotalSize; 839 m_iLength = (dwAccess & FX_STREAMACCESS_Write) != 0 ? 0 : iTotalSize;
818 return TRUE; 840 return TRUE;
819 } 841 }
820 int32_t CFX_BufferStreamImp::GetLength() const { 842 int32_t CFX_BufferStreamImp::GetLength() const {
821 ASSERT(m_pData != NULL); 843 ASSERT(m_pData != NULL);
822 return m_iLength; 844 return m_iLength;
823 } 845 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
871 while (*pSrc && iCount < iLen) { 893 while (*pSrc && iCount < iLen) {
872 *pStr++ = *pSrc++; 894 *pStr++ = *pSrc++;
873 iCount++; 895 iCount++;
874 } 896 }
875 m_iPosition += iCount * 2; 897 m_iPosition += iCount * 2;
876 bEOS = (*pSrc == L'\0') || (m_iPosition >= m_iLength); 898 bEOS = (*pSrc == L'\0') || (m_iPosition >= m_iLength);
877 return iCount; 899 return iCount;
878 } 900 }
879 int32_t CFX_BufferStreamImp::WriteData(const uint8_t* pBuffer, 901 int32_t CFX_BufferStreamImp::WriteData(const uint8_t* pBuffer,
880 int32_t iBufferSize) { 902 int32_t iBufferSize) {
881 ASSERT(m_pData != NULL && (m_dwAccess & FX_STREAMACCESS_Write) != 0); 903 ASSERT(m_pData && (GetAccessModes() & FX_STREAMACCESS_Write) != 0);
882 ASSERT(pBuffer != NULL && iBufferSize > 0); 904 ASSERT(pBuffer && iBufferSize > 0);
883 int32_t iLen = std::min(m_iTotalSize - m_iPosition, iBufferSize); 905 int32_t iLen = std::min(m_iTotalSize - m_iPosition, iBufferSize);
884 if (iLen <= 0) { 906 if (iLen <= 0) {
885 return 0; 907 return 0;
886 } 908 }
887 FXSYS_memcpy(m_pData + m_iPosition, pBuffer, iLen); 909 FXSYS_memcpy(m_pData + m_iPosition, pBuffer, iLen);
888 m_iPosition += iLen; 910 m_iPosition += iLen;
889 if (m_iPosition > m_iLength) { 911 if (m_iPosition > m_iLength) {
890 m_iLength = m_iPosition; 912 m_iLength = m_iPosition;
891 } 913 }
892 return iLen; 914 return iLen;
893 } 915 }
894 int32_t CFX_BufferStreamImp::WriteString(const FX_WCHAR* pStr, 916 int32_t CFX_BufferStreamImp::WriteString(const FX_WCHAR* pStr,
895 int32_t iLength) { 917 int32_t iLength) {
896 ASSERT(m_pData != NULL && (m_dwAccess & FX_STREAMACCESS_Write) != 0); 918 ASSERT(m_pData && (GetAccessModes() & FX_STREAMACCESS_Write) != 0);
897 ASSERT(pStr != NULL && iLength > 0); 919 ASSERT(pStr && iLength > 0);
898 int32_t iLen = std::min((m_iTotalSize - m_iPosition) / 2, iLength); 920 int32_t iLen = std::min((m_iTotalSize - m_iPosition) / 2, iLength);
899 if (iLen <= 0) { 921 if (iLen <= 0) {
900 return 0; 922 return 0;
901 } 923 }
902 FXSYS_memcpy(m_pData + m_iPosition, pStr, iLen * 2); 924 FXSYS_memcpy(m_pData + m_iPosition, pStr, iLen * 2);
903 m_iPosition += iLen * 2; 925 m_iPosition += iLen * 2;
904 if (m_iPosition > m_iLength) { 926 if (m_iPosition > m_iLength) {
905 m_iLength = m_iPosition; 927 m_iLength = m_iPosition;
906 } 928 }
907 return iLen; 929 return iLen;
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
1117 } 1139 }
1118 CFX_Stream::CFX_Stream() 1140 CFX_Stream::CFX_Stream()
1119 : m_eStreamType(FX_SREAMTYPE_Unknown), 1141 : m_eStreamType(FX_SREAMTYPE_Unknown),
1120 m_pStreamImp(NULL), 1142 m_pStreamImp(NULL),
1121 m_dwAccess(0), 1143 m_dwAccess(0),
1122 m_iTotalSize(0), 1144 m_iTotalSize(0),
1123 m_iPosition(0), 1145 m_iPosition(0),
1124 m_iStart(0), 1146 m_iStart(0),
1125 m_iLength(0), 1147 m_iLength(0),
1126 m_iRefCount(1) {} 1148 m_iRefCount(1) {}
1149
1127 CFX_Stream::~CFX_Stream() { 1150 CFX_Stream::~CFX_Stream() {
1128 if (m_eStreamType != FX_STREAMTYPE_Stream && m_pStreamImp != NULL) { 1151 if (m_eStreamType != FX_STREAMTYPE_Stream)
1129 m_pStreamImp->Release(); 1152 delete m_pStreamImp;
1130 }
1131 } 1153 }
1154
1132 FX_BOOL CFX_Stream::LoadFile(const FX_WCHAR* pszSrcFileName, 1155 FX_BOOL CFX_Stream::LoadFile(const FX_WCHAR* pszSrcFileName,
1133 uint32_t dwAccess) { 1156 uint32_t dwAccess) {
1134 if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp != NULL) { 1157 if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp)
1135 return FALSE; 1158 return FALSE;
1136 } 1159
1137 if (pszSrcFileName == NULL || FXSYS_wcslen(pszSrcFileName) < 1) { 1160 if (!pszSrcFileName || FXSYS_wcslen(pszSrcFileName) < 1)
1138 return FALSE; 1161 return FALSE;
1139 } 1162
1140 m_pStreamImp = new CFX_FileStreamImp(); 1163 std::unique_ptr<CFX_FileStreamImp> pImp(new CFX_FileStreamImp());
1141 FX_BOOL bRet = 1164 if (!pImp->LoadFile(pszSrcFileName, dwAccess))
1142 ((CFX_FileStreamImp*)m_pStreamImp)->LoadFile(pszSrcFileName, dwAccess); 1165 return FALSE;
1143 if (!bRet) { 1166
1144 m_pStreamImp->Release(); 1167 m_pStreamImp = pImp.release();
1145 m_pStreamImp = NULL; 1168 m_eStreamType = FX_STREAMTYPE_File;
1146 } else { 1169 m_dwAccess = dwAccess;
1147 m_eStreamType = FX_STREAMTYPE_File; 1170 m_iLength = m_pStreamImp->GetLength();
1148 m_dwAccess = dwAccess; 1171 return TRUE;
1149 m_iLength = m_pStreamImp->GetLength();
1150 }
1151 return bRet;
1152 } 1172 }
1173
1153 FX_BOOL CFX_Stream::LoadFileRead(IFX_FileRead* pFileRead, uint32_t dwAccess) { 1174 FX_BOOL CFX_Stream::LoadFileRead(IFX_FileRead* pFileRead, uint32_t dwAccess) {
1154 if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp != NULL) { 1175 if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp)
1155 return FALSE; 1176 return FALSE;
1156 } 1177
1157 if (pFileRead == NULL) { 1178 if (!pFileRead)
1158 return FALSE; 1179 return FALSE;
1159 } 1180
1160 m_pStreamImp = new CFX_FileReadStreamImp(); 1181 std::unique_ptr<CFX_FileReadStreamImp> pImp(new CFX_FileReadStreamImp());
1161 FX_BOOL bRet = 1182 if (!pImp->LoadFileRead(pFileRead, dwAccess))
1162 ((CFX_FileReadStreamImp*)m_pStreamImp)->LoadFileRead(pFileRead, dwAccess); 1183 return FALSE;
1163 if (!bRet) { 1184
1164 m_pStreamImp->Release(); 1185 m_pStreamImp = pImp.release();
1165 m_pStreamImp = NULL; 1186 m_eStreamType = FX_STREAMTYPE_File;
1166 } else { 1187 m_dwAccess = dwAccess;
1167 m_eStreamType = FX_STREAMTYPE_File; 1188 m_iLength = m_pStreamImp->GetLength();
1168 m_dwAccess = dwAccess; 1189 return TRUE;
1169 m_iLength = m_pStreamImp->GetLength();
1170 }
1171 return bRet;
1172 } 1190 }
1191
1173 FX_BOOL CFX_Stream::LoadFileWrite(IFX_FileWrite* pFileWrite, 1192 FX_BOOL CFX_Stream::LoadFileWrite(IFX_FileWrite* pFileWrite,
1174 uint32_t dwAccess) { 1193 uint32_t dwAccess) {
1175 if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp != NULL) { 1194 if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp)
1176 return FALSE; 1195 return FALSE;
1177 } 1196
1178 if (pFileWrite == NULL) { 1197 if (!pFileWrite)
1179 return FALSE; 1198 return FALSE;
1180 } 1199
1181 m_pStreamImp = new CFX_FileWriteStreamImp(); 1200 std::unique_ptr<CFX_FileWriteStreamImp> pImp(new CFX_FileWriteStreamImp());
1182 FX_BOOL bRet = ((CFX_FileWriteStreamImp*)m_pStreamImp) 1201 if (!pImp->LoadFileWrite(pFileWrite, dwAccess))
1183 ->LoadFileWrite(pFileWrite, dwAccess); 1202 return FALSE;
1184 if (!bRet) { 1203
1185 m_pStreamImp->Release(); 1204 m_pStreamImp = pImp.release();
1186 m_pStreamImp = NULL; 1205 m_eStreamType = FX_STREAMTYPE_File;
1187 } else { 1206 m_dwAccess = dwAccess;
1188 m_eStreamType = FX_STREAMTYPE_File; 1207 m_iLength = m_pStreamImp->GetLength();
1189 m_dwAccess = dwAccess; 1208 return TRUE;
1190 m_iLength = m_pStreamImp->GetLength();
1191 }
1192 return bRet;
1193 } 1209 }
1210
1194 FX_BOOL CFX_Stream::LoadBuffer(uint8_t* pData, 1211 FX_BOOL CFX_Stream::LoadBuffer(uint8_t* pData,
1195 int32_t iTotalSize, 1212 int32_t iTotalSize,
1196 uint32_t dwAccess) { 1213 uint32_t dwAccess) {
1197 if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp != NULL) { 1214 if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp)
1198 return FALSE; 1215 return FALSE;
1199 } 1216
1200 if (pData == NULL || iTotalSize < 1) { 1217 if (!pData || iTotalSize < 1)
1201 return FALSE; 1218 return FALSE;
1202 } 1219
1203 m_pStreamImp = new CFX_BufferStreamImp(); 1220 std::unique_ptr<CFX_BufferStreamImp> pImp(new CFX_BufferStreamImp());
1204 FX_BOOL bRet = ((CFX_BufferStreamImp*)m_pStreamImp) 1221 if (!pImp->LoadBuffer(pData, iTotalSize, dwAccess))
1205 ->LoadBuffer(pData, iTotalSize, dwAccess); 1222 return FALSE;
1206 if (!bRet) { 1223
1207 m_pStreamImp->Release(); 1224 m_pStreamImp = pImp.release();
1208 m_pStreamImp = NULL; 1225 m_eStreamType = FX_STREAMTYPE_Buffer;
1209 } else { 1226 m_dwAccess = dwAccess;
1210 m_eStreamType = FX_STREAMTYPE_Buffer; 1227 m_iLength = m_pStreamImp->GetLength();
1211 m_dwAccess = dwAccess; 1228 return TRUE;
1212 m_iLength = m_pStreamImp->GetLength();
1213 }
1214 return bRet;
1215 } 1229 }
1230
1216 FX_BOOL CFX_Stream::LoadBufferRead(IFX_BufferRead* pBufferRead, 1231 FX_BOOL CFX_Stream::LoadBufferRead(IFX_BufferRead* pBufferRead,
1217 int32_t iFileSize, 1232 int32_t iFileSize,
1218 uint32_t dwAccess, 1233 uint32_t dwAccess,
1219 FX_BOOL bReleaseBufferRead) { 1234 FX_BOOL bReleaseBufferRead) {
1220 if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp != NULL) { 1235 if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp)
1221 return FALSE; 1236 return FALSE;
1222 } 1237
1223 if (!pBufferRead) { 1238 if (!pBufferRead)
1224 return FALSE; 1239 return FALSE;
1225 } 1240
1226 m_pStreamImp = new CFX_BufferReadStreamImp; 1241 std::unique_ptr<CFX_BufferReadStreamImp> pImp(new CFX_BufferReadStreamImp);
1227 FX_BOOL bRet = ((CFX_BufferReadStreamImp*)m_pStreamImp) 1242 if (!pImp->LoadBufferRead(pBufferRead, iFileSize, dwAccess,
1228 ->LoadBufferRead(pBufferRead, iFileSize, dwAccess, 1243 bReleaseBufferRead))
1229 bReleaseBufferRead); 1244 return FALSE;
1230 if (!bRet) { 1245
1231 m_pStreamImp->Release(); 1246 m_pStreamImp = pImp.release();
1232 m_pStreamImp = NULL; 1247 m_eStreamType = FX_STREAMTYPE_BufferRead;
1233 } else { 1248 m_dwAccess = dwAccess;
1234 m_eStreamType = FX_STREAMTYPE_BufferRead; 1249 m_iLength = m_pStreamImp->GetLength();
1235 m_dwAccess = dwAccess; 1250 return TRUE;
1236 m_iLength = m_pStreamImp->GetLength();
1237 }
1238 return bRet;
1239 } 1251 }
1252
1240 void CFX_Stream::Release() { 1253 void CFX_Stream::Release() {
1241 if (--m_iRefCount < 1) { 1254 if (--m_iRefCount < 1) {
1242 delete this; 1255 delete this;
1243 } 1256 }
1244 } 1257 }
1245 IFX_Stream* CFX_Stream::Retain() { 1258 IFX_Stream* CFX_Stream::Retain() {
1246 m_iRefCount++; 1259 m_iRefCount++;
1247 return this; 1260 return this;
1248 } 1261 }
1249 int32_t CFX_Stream::GetLength() const { 1262 int32_t CFX_Stream::GetLength() const {
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
1617 return m_pStream->WriteData((const uint8_t*)pData, (int32_t)size) == 1630 return m_pStream->WriteData((const uint8_t*)pData, (int32_t)size) ==
1618 (int32_t)size; 1631 (int32_t)size;
1619 } 1632 }
1620 FX_BOOL CFGAS_FileWrite::WriteBlock(const void* pData, 1633 FX_BOOL CFGAS_FileWrite::WriteBlock(const void* pData,
1621 FX_FILESIZE offset, 1634 FX_FILESIZE offset,
1622 size_t size) { 1635 size_t size) {
1623 m_pStream->Seek(FX_STREAMSEEK_Begin, offset); 1636 m_pStream->Seek(FX_STREAMSEEK_Begin, offset);
1624 int32_t iLen = m_pStream->WriteData((uint8_t*)pData, (int32_t)size); 1637 int32_t iLen = m_pStream->WriteData((uint8_t*)pData, (int32_t)size);
1625 return iLen == (int32_t)size; 1638 return iLen == (int32_t)size;
1626 } 1639 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698