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

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: Tidy 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() {}
20
19 virtual uint32_t GetAccessModes() const { return m_dwAccess; } 21 virtual uint32_t GetAccessModes() const { return m_dwAccess; }
20 virtual int32_t GetLength() const = 0; 22 virtual int32_t GetLength() const = 0;
21 virtual int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) = 0; 23 virtual int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) = 0;
22 virtual int32_t GetPosition() = 0; 24 virtual int32_t GetPosition() = 0;
23 virtual FX_BOOL IsEOF() const = 0; 25 virtual FX_BOOL IsEOF() const = 0;
24 virtual int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) = 0; 26 virtual int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) = 0;
25 virtual int32_t ReadString(FX_WCHAR* pStr, 27 virtual int32_t ReadString(FX_WCHAR* pStr,
26 int32_t iMaxLength, 28 int32_t iMaxLength,
27 FX_BOOL& bEOS) = 0; 29 FX_BOOL& bEOS) = 0;
28 virtual int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) = 0; 30 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; 31 virtual int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) = 0;
30 virtual void Flush() = 0; 32 virtual void Flush() = 0;
31 virtual FX_BOOL SetLength(int32_t iLength) = 0; 33 virtual FX_BOOL SetLength(int32_t iLength) = 0;
32 34
33 protected: 35 protected:
34 CFX_StreamImp(); 36 IFX_StreamImp();
35 virtual ~CFX_StreamImp() {} 37
36 uint32_t m_dwAccess; 38 uint32_t m_dwAccess;
37 }; 39 };
38 40
39 class CFX_FileStreamImp : public CFX_StreamImp { 41 class CFX_FileStreamImp : public IFX_StreamImp {
40 public: 42 public:
41 CFX_FileStreamImp(); 43 CFX_FileStreamImp();
42 virtual ~CFX_FileStreamImp(); 44 ~CFX_FileStreamImp() override;
45
43 FX_BOOL LoadFile(const FX_WCHAR* pszSrcFileName, uint32_t dwAccess); 46 FX_BOOL LoadFile(const FX_WCHAR* pszSrcFileName, uint32_t dwAccess);
44 virtual int32_t GetLength() const; 47
45 virtual int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset); 48 // IFX_StreamImp:
46 virtual int32_t GetPosition(); 49 int32_t GetLength() const override;
47 virtual FX_BOOL IsEOF() const; 50 int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) override;
48 virtual int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize); 51 int32_t GetPosition() override;
49 virtual int32_t ReadString(FX_WCHAR* pStr, int32_t iMaxLength, FX_BOOL& bEOS); 52 FX_BOOL IsEOF() const override;
50 virtual int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize); 53 int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) override;
51 virtual int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength); 54 int32_t ReadString(FX_WCHAR* pStr,
52 virtual void Flush(); 55 int32_t iMaxLength,
53 virtual FX_BOOL SetLength(int32_t iLength); 56 FX_BOOL& bEOS) override;
57 int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) override;
58 int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) override;
59 void Flush() override;
60 FX_BOOL SetLength(int32_t iLength) override;
54 61
55 protected: 62 protected:
56 FXSYS_FILE* m_hFile; 63 FXSYS_FILE* m_hFile;
57 int32_t m_iLength; 64 int32_t m_iLength;
58 }; 65 };
59 66
60 class CFX_BufferStreamImp : public CFX_StreamImp { 67 class CFX_BufferStreamImp : public IFX_StreamImp {
61 public: 68 public:
62 CFX_BufferStreamImp(); 69 CFX_BufferStreamImp();
63 virtual ~CFX_BufferStreamImp() {} 70 ~CFX_BufferStreamImp() override {}
71
64 FX_BOOL LoadBuffer(uint8_t* pData, int32_t iTotalSize, uint32_t dwAccess); 72 FX_BOOL LoadBuffer(uint8_t* pData, int32_t iTotalSize, uint32_t dwAccess);
65 virtual int32_t GetLength() const; 73
66 virtual int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset); 74 // IFX_StreamImp:
67 virtual int32_t GetPosition(); 75 int32_t GetLength() const override;
68 virtual FX_BOOL IsEOF() const; 76 int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) override;
69 virtual int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize); 77 int32_t GetPosition() override;
70 virtual int32_t ReadString(FX_WCHAR* pStr, int32_t iMaxLength, FX_BOOL& bEOS); 78 FX_BOOL IsEOF() const override;
71 virtual int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize); 79 int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) override;
72 virtual int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength); 80 int32_t ReadString(FX_WCHAR* pStr,
73 virtual void Flush() {} 81 int32_t iMaxLength,
74 virtual FX_BOOL SetLength(int32_t iLength) { return FALSE; } 82 FX_BOOL& bEOS) override;
83 int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) override;
84 int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) override;
85 void Flush() override {}
86 FX_BOOL SetLength(int32_t iLength) override { return FALSE; }
75 87
76 protected: 88 protected:
77 uint8_t* m_pData; 89 uint8_t* m_pData;
78 int32_t m_iTotalSize; 90 int32_t m_iTotalSize;
79 int32_t m_iPosition; 91 int32_t m_iPosition;
80 int32_t m_iLength; 92 int32_t m_iLength;
81 }; 93 };
82 94
83 class CFX_FileReadStreamImp : public CFX_StreamImp { 95 class CFX_FileReadStreamImp : public IFX_StreamImp {
84 public: 96 public:
85 CFX_FileReadStreamImp(); 97 CFX_FileReadStreamImp();
86 virtual ~CFX_FileReadStreamImp() {} 98 ~CFX_FileReadStreamImp() override {}
99
87 FX_BOOL LoadFileRead(IFX_FileRead* pFileRead, uint32_t dwAccess); 100 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 101
93 virtual int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize); 102 // IFX_StreamImp:
94 virtual int32_t ReadString(FX_WCHAR* pStr, int32_t iMaxLength, FX_BOOL& bEOS); 103 int32_t GetLength() const override;
95 virtual int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) { 104 int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) override;
105 int32_t GetPosition() override { return m_iPosition; }
106 FX_BOOL IsEOF() const override;
107 int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) override;
108 int32_t ReadString(FX_WCHAR* pStr,
109 int32_t iMaxLength,
110 FX_BOOL& bEOS) override;
111 int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) override {
96 return 0; 112 return 0;
97 } 113 }
98 virtual int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) { 114 int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) override {
99 return 0; 115 return 0;
100 } 116 }
101 virtual void Flush() {} 117 void Flush() override {}
102 virtual FX_BOOL SetLength(int32_t iLength) { return FALSE; } 118 FX_BOOL SetLength(int32_t iLength) override { return FALSE; }
103 119
104 protected: 120 protected:
105 IFX_FileRead* m_pFileRead; 121 IFX_FileRead* m_pFileRead;
106 int32_t m_iPosition; 122 int32_t m_iPosition;
107 int32_t m_iLength; 123 int32_t m_iLength;
108 }; 124 };
109 125
110 class CFX_BufferReadStreamImp : public CFX_StreamImp { 126 class CFX_BufferReadStreamImp : public IFX_StreamImp {
111 public: 127 public:
112 CFX_BufferReadStreamImp(); 128 CFX_BufferReadStreamImp();
113 ~CFX_BufferReadStreamImp(); 129 ~CFX_BufferReadStreamImp() override;
130
114 FX_BOOL LoadBufferRead(IFX_BufferRead* pBufferRead, 131 FX_BOOL LoadBufferRead(IFX_BufferRead* pBufferRead,
115 int32_t iFileSize, 132 int32_t iFileSize,
116 uint32_t dwAccess, 133 uint32_t dwAccess,
117 FX_BOOL bReleaseBufferRead); 134 FX_BOOL bReleaseBufferRead);
118 135
119 virtual int32_t GetLength() const; 136 // IFX_StreamImp:
120 virtual int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset); 137 int32_t GetLength() const override;
121 virtual int32_t GetPosition() { return m_iPosition; } 138 int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) override;
122 virtual FX_BOOL IsEOF() const; 139 int32_t GetPosition() override { return m_iPosition; }
123 140 FX_BOOL IsEOF() const override;
124 virtual int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize); 141 int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) override;
125 virtual int32_t ReadString(FX_WCHAR* pStr, int32_t iMaxLength, FX_BOOL& bEOS); 142 int32_t ReadString(FX_WCHAR* pStr,
126 virtual int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) { 143 int32_t iMaxLength,
144 FX_BOOL& bEOS) override;
145 int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) override {
127 return 0; 146 return 0;
128 } 147 }
129 virtual int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) { 148 int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) override {
130 return 0; 149 return 0;
131 } 150 }
132 virtual void Flush() {} 151 void Flush() override {}
133 virtual FX_BOOL SetLength(int32_t iLength) { return FALSE; } 152 FX_BOOL SetLength(int32_t iLength) override { return FALSE; }
134 153
135 private: 154 private:
136 IFX_BufferRead* m_pBufferRead; 155 IFX_BufferRead* m_pBufferRead;
137 FX_BOOL m_bReleaseBufferRead; 156 FX_BOOL m_bReleaseBufferRead;
138 int32_t m_iPosition; 157 int32_t m_iPosition;
139 int32_t m_iBufferSize; 158 int32_t m_iBufferSize;
140 }; 159 };
141 160
142 class CFX_FileWriteStreamImp : public CFX_StreamImp { 161 class CFX_FileWriteStreamImp : public IFX_StreamImp {
143 public: 162 public:
144 CFX_FileWriteStreamImp(); 163 CFX_FileWriteStreamImp();
145 virtual ~CFX_FileWriteStreamImp() {} 164 ~CFX_FileWriteStreamImp() override {}
165
146 FX_BOOL LoadFileWrite(IFX_FileWrite* pFileWrite, uint32_t dwAccess); 166 FX_BOOL LoadFileWrite(IFX_FileWrite* pFileWrite, uint32_t dwAccess);
147 virtual int32_t GetLength() const; 167
148 virtual int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset); 168 // IFX_StreamImp:
149 virtual int32_t GetPosition() { return m_iPosition; } 169 int32_t GetLength() const override;
150 virtual FX_BOOL IsEOF() const; 170 int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) override;
151 virtual int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) { return 0; } 171 int32_t GetPosition() override { return m_iPosition; }
152 virtual int32_t ReadString(FX_WCHAR* pStr, 172 FX_BOOL IsEOF() const override;
153 int32_t iMaxLength, 173 int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) override { return 0; }
154 FX_BOOL& bEOS) { 174 int32_t ReadString(FX_WCHAR* pStr,
175 int32_t iMaxLength,
176 FX_BOOL& bEOS) override {
155 return 0; 177 return 0;
156 } 178 }
157 virtual int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize); 179 int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) override;
158 virtual int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength); 180 int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) override;
159 virtual void Flush(); 181 void Flush() override;
160 virtual FX_BOOL SetLength(int32_t iLength) { return FALSE; } 182 FX_BOOL SetLength(int32_t iLength) override { return FALSE; }
161 183
162 protected: 184 protected:
163 IFX_FileWrite* m_pFileWrite; 185 IFX_FileWrite* m_pFileWrite;
164 int32_t m_iPosition; 186 int32_t m_iPosition;
165 }; 187 };
166 188
167 enum FX_STREAMTYPE { 189 enum FX_STREAMTYPE {
168 FX_SREAMTYPE_Unknown = 0, 190 FX_SREAMTYPE_Unknown = 0,
169 FX_STREAMTYPE_File, 191 FX_STREAMTYPE_File,
170 FX_STREAMTYPE_Buffer, 192 FX_STREAMTYPE_Buffer,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 virtual FX_BOOL SetLength(int32_t iLength); 224 virtual FX_BOOL SetLength(int32_t iLength);
203 virtual int32_t GetBOM(uint8_t bom[4]) const; 225 virtual int32_t GetBOM(uint8_t bom[4]) const;
204 virtual uint16_t GetCodePage() const; 226 virtual uint16_t GetCodePage() const;
205 virtual uint16_t SetCodePage(uint16_t wCodePage); 227 virtual uint16_t SetCodePage(uint16_t wCodePage);
206 virtual IFX_Stream* CreateSharedStream(uint32_t dwAccess, 228 virtual IFX_Stream* CreateSharedStream(uint32_t dwAccess,
207 int32_t iOffset, 229 int32_t iOffset,
208 int32_t iLength); 230 int32_t iLength);
209 231
210 protected: 232 protected:
211 FX_STREAMTYPE m_eStreamType; 233 FX_STREAMTYPE m_eStreamType;
212 CFX_StreamImp* m_pStreamImp; 234 IFX_StreamImp* m_pStreamImp;
213 uint32_t m_dwAccess; 235 uint32_t m_dwAccess;
214 int32_t m_iTotalSize; 236 int32_t m_iTotalSize;
215 int32_t m_iPosition; 237 int32_t m_iPosition;
216 int32_t m_iStart; 238 int32_t m_iStart;
217 int32_t m_iLength; 239 int32_t m_iLength;
218 int32_t m_iRefCount; 240 int32_t m_iRefCount;
219 }; 241 };
220 242
221 class CFX_TextStream : public IFX_Stream { 243 class CFX_TextStream : public IFX_Stream {
222 public: 244 public:
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 if (!pSR->LoadBuffer(pData, length, dwAccess)) { 389 if (!pSR->LoadBuffer(pData, length, dwAccess)) {
368 pSR->Release(); 390 pSR->Release();
369 return NULL; 391 return NULL;
370 } 392 }
371 if (dwAccess & FX_STREAMACCESS_Text) { 393 if (dwAccess & FX_STREAMACCESS_Text) {
372 return new CFX_TextStream(pSR, TRUE); 394 return new CFX_TextStream(pSR, TRUE);
373 } 395 }
374 return pSR; 396 return pSR;
375 } 397 }
376 398
377 CFX_StreamImp::CFX_StreamImp() : m_dwAccess(0) {} 399 IFX_StreamImp::IFX_StreamImp() : m_dwAccess(0) {}
Lei Zhang 2016/05/18 23:02:30 Add some blank lines?
Tom Sepez 2016/05/18 23:29:56 Done.
378 CFX_FileStreamImp::CFX_FileStreamImp() 400 CFX_FileStreamImp::CFX_FileStreamImp() : m_hFile(nullptr), m_iLength(0) {}
379 : CFX_StreamImp(), m_hFile(NULL), m_iLength(0) {}
380 CFX_FileStreamImp::~CFX_FileStreamImp() { 401 CFX_FileStreamImp::~CFX_FileStreamImp() {
381 if (m_hFile != NULL) { 402 if (m_hFile != NULL) {
Lei Zhang 2016/05/18 23:02:30 Omit != NULL
Tom Sepez 2016/05/18 23:29:56 Done.
382 FXSYS_fclose(m_hFile); 403 FXSYS_fclose(m_hFile);
383 } 404 }
384 } 405 }
385 FX_BOOL CFX_FileStreamImp::LoadFile(const FX_WCHAR* pszSrcFileName, 406 FX_BOOL CFX_FileStreamImp::LoadFile(const FX_WCHAR* pszSrcFileName,
386 uint32_t dwAccess) { 407 uint32_t dwAccess) {
387 ASSERT(m_hFile == NULL); 408 ASSERT(m_hFile == NULL);
388 ASSERT(pszSrcFileName != NULL && FXSYS_wcslen(pszSrcFileName) > 0); 409 ASSERT(pszSrcFileName != NULL && FXSYS_wcslen(pszSrcFileName) > 0);
389 #if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN32_MOBILE_ || \ 410 #if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN32_MOBILE_ || \
390 _FX_OS_ == _FX_WIN64_ 411 _FX_OS_ == _FX_WIN64_
391 const FX_WCHAR* wsMode; 412 const FX_WCHAR* wsMode;
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
793 int32_t CFX_FileWriteStreamImp::WriteString(const FX_WCHAR* pStr, 814 int32_t CFX_FileWriteStreamImp::WriteString(const FX_WCHAR* pStr,
794 int32_t iLength) { 815 int32_t iLength) {
795 return WriteData((const uint8_t*)pStr, iLength * sizeof(FX_WCHAR)); 816 return WriteData((const uint8_t*)pStr, iLength * sizeof(FX_WCHAR));
796 } 817 }
797 void CFX_FileWriteStreamImp::Flush() { 818 void CFX_FileWriteStreamImp::Flush() {
798 if (m_pFileWrite) { 819 if (m_pFileWrite) {
799 m_pFileWrite->Flush(); 820 m_pFileWrite->Flush();
800 } 821 }
801 } 822 }
802 CFX_BufferStreamImp::CFX_BufferStreamImp() 823 CFX_BufferStreamImp::CFX_BufferStreamImp()
803 : CFX_StreamImp(), 824 : m_pData(nullptr), m_iTotalSize(0), m_iPosition(0), m_iLength(0) {}
804 m_pData(NULL), 825
805 m_iTotalSize(0),
806 m_iPosition(0),
807 m_iLength(0) {}
808 FX_BOOL CFX_BufferStreamImp::LoadBuffer(uint8_t* pData, 826 FX_BOOL CFX_BufferStreamImp::LoadBuffer(uint8_t* pData,
809 int32_t iTotalSize, 827 int32_t iTotalSize,
810 uint32_t dwAccess) { 828 uint32_t dwAccess) {
811 ASSERT(m_pData == NULL); 829 ASSERT(m_pData == NULL);
812 ASSERT(pData != NULL && iTotalSize > 0); 830 ASSERT(pData != NULL && iTotalSize > 0);
813 m_dwAccess = dwAccess; 831 m_dwAccess = dwAccess;
814 m_pData = pData; 832 m_pData = pData;
815 m_iTotalSize = iTotalSize; 833 m_iTotalSize = iTotalSize;
816 m_iPosition = 0; 834 m_iPosition = 0;
817 m_iLength = (dwAccess & FX_STREAMACCESS_Write) != 0 ? 0 : iTotalSize; 835 m_iLength = (dwAccess & FX_STREAMACCESS_Write) != 0 ? 0 : iTotalSize;
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
1117 } 1135 }
1118 CFX_Stream::CFX_Stream() 1136 CFX_Stream::CFX_Stream()
1119 : m_eStreamType(FX_SREAMTYPE_Unknown), 1137 : m_eStreamType(FX_SREAMTYPE_Unknown),
1120 m_pStreamImp(NULL), 1138 m_pStreamImp(NULL),
1121 m_dwAccess(0), 1139 m_dwAccess(0),
1122 m_iTotalSize(0), 1140 m_iTotalSize(0),
1123 m_iPosition(0), 1141 m_iPosition(0),
1124 m_iStart(0), 1142 m_iStart(0),
1125 m_iLength(0), 1143 m_iLength(0),
1126 m_iRefCount(1) {} 1144 m_iRefCount(1) {}
1145
1127 CFX_Stream::~CFX_Stream() { 1146 CFX_Stream::~CFX_Stream() {
1128 if (m_eStreamType != FX_STREAMTYPE_Stream && m_pStreamImp != NULL) { 1147 if (m_eStreamType != FX_STREAMTYPE_Stream)
1129 m_pStreamImp->Release(); 1148 delete m_pStreamImp;
1130 }
1131 } 1149 }
1150
1132 FX_BOOL CFX_Stream::LoadFile(const FX_WCHAR* pszSrcFileName, 1151 FX_BOOL CFX_Stream::LoadFile(const FX_WCHAR* pszSrcFileName,
1133 uint32_t dwAccess) { 1152 uint32_t dwAccess) {
1134 if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp != NULL) { 1153 if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp)
1135 return FALSE; 1154 return FALSE;
1136 } 1155
1137 if (pszSrcFileName == NULL || FXSYS_wcslen(pszSrcFileName) < 1) { 1156 if (!pszSrcFileName || FXSYS_wcslen(pszSrcFileName) < 1)
1138 return FALSE; 1157 return FALSE;
1139 } 1158
1140 m_pStreamImp = new CFX_FileStreamImp(); 1159 std::unique_ptr<CFX_FileStreamImp> pImp(new CFX_FileStreamImp());
1141 FX_BOOL bRet = 1160 if (!pImp->LoadFile(pszSrcFileName, dwAccess))
1142 ((CFX_FileStreamImp*)m_pStreamImp)->LoadFile(pszSrcFileName, dwAccess); 1161 return FALSE;
1143 if (!bRet) { 1162
1144 m_pStreamImp->Release(); 1163 m_pStreamImp = pImp.release();
1145 m_pStreamImp = NULL; 1164 m_eStreamType = FX_STREAMTYPE_File;
1146 } else { 1165 m_dwAccess = dwAccess;
1147 m_eStreamType = FX_STREAMTYPE_File; 1166 m_iLength = m_pStreamImp->GetLength();
1148 m_dwAccess = dwAccess; 1167 return TRUE;
1149 m_iLength = m_pStreamImp->GetLength();
1150 }
1151 return bRet;
1152 } 1168 }
1169
1153 FX_BOOL CFX_Stream::LoadFileRead(IFX_FileRead* pFileRead, uint32_t dwAccess) { 1170 FX_BOOL CFX_Stream::LoadFileRead(IFX_FileRead* pFileRead, uint32_t dwAccess) {
1154 if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp != NULL) { 1171 if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp)
1155 return FALSE; 1172 return FALSE;
1156 } 1173
1157 if (pFileRead == NULL) { 1174 if (!pFileRead)
1158 return FALSE; 1175 return FALSE;
1159 } 1176
1160 m_pStreamImp = new CFX_FileReadStreamImp(); 1177 std::unique_ptr<CFX_FileReadStreamImp> pImp(new CFX_FileReadStreamImp());
1161 FX_BOOL bRet = 1178 if (!pImp->LoadFileRead(pFileRead, dwAccess))
1162 ((CFX_FileReadStreamImp*)m_pStreamImp)->LoadFileRead(pFileRead, dwAccess); 1179 return FALSE;
1163 if (!bRet) { 1180
1164 m_pStreamImp->Release(); 1181 m_pStreamImp = pImp.release();
1165 m_pStreamImp = NULL; 1182 m_eStreamType = FX_STREAMTYPE_File;
1166 } else { 1183 m_dwAccess = dwAccess;
1167 m_eStreamType = FX_STREAMTYPE_File; 1184 m_iLength = m_pStreamImp->GetLength();
1168 m_dwAccess = dwAccess; 1185 return TRUE;
1169 m_iLength = m_pStreamImp->GetLength();
1170 }
1171 return bRet;
1172 } 1186 }
1187
1173 FX_BOOL CFX_Stream::LoadFileWrite(IFX_FileWrite* pFileWrite, 1188 FX_BOOL CFX_Stream::LoadFileWrite(IFX_FileWrite* pFileWrite,
1174 uint32_t dwAccess) { 1189 uint32_t dwAccess) {
1175 if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp != NULL) { 1190 if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp)
1176 return FALSE; 1191 return FALSE;
1177 } 1192
1178 if (pFileWrite == NULL) { 1193 if (!pFileWrite)
1179 return FALSE; 1194 return FALSE;
1180 } 1195
1181 m_pStreamImp = new CFX_FileWriteStreamImp(); 1196 std::unique_ptr<CFX_FileWriteStreamImp> pImp(new CFX_FileWriteStreamImp());
1182 FX_BOOL bRet = ((CFX_FileWriteStreamImp*)m_pStreamImp) 1197 if (!pImp->LoadFileWrite(pFileWrite, dwAccess))
1183 ->LoadFileWrite(pFileWrite, dwAccess); 1198 return FALSE;
1184 if (!bRet) { 1199
1185 m_pStreamImp->Release(); 1200 m_pStreamImp = pImp.release();
1186 m_pStreamImp = NULL; 1201 m_eStreamType = FX_STREAMTYPE_File;
1187 } else { 1202 m_dwAccess = dwAccess;
1188 m_eStreamType = FX_STREAMTYPE_File; 1203 m_iLength = m_pStreamImp->GetLength();
1189 m_dwAccess = dwAccess; 1204 return TRUE;
1190 m_iLength = m_pStreamImp->GetLength();
1191 }
1192 return bRet;
1193 } 1205 }
1206
1194 FX_BOOL CFX_Stream::LoadBuffer(uint8_t* pData, 1207 FX_BOOL CFX_Stream::LoadBuffer(uint8_t* pData,
1195 int32_t iTotalSize, 1208 int32_t iTotalSize,
1196 uint32_t dwAccess) { 1209 uint32_t dwAccess) {
1197 if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp != NULL) { 1210 if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp)
1198 return FALSE; 1211 return FALSE;
1199 } 1212
1200 if (pData == NULL || iTotalSize < 1) { 1213 if (!pData || iTotalSize < 1)
1201 return FALSE; 1214 return FALSE;
1202 } 1215
1203 m_pStreamImp = new CFX_BufferStreamImp(); 1216 std::unique_ptr<CFX_BufferStreamImp> pImp(new CFX_BufferStreamImp());
1204 FX_BOOL bRet = ((CFX_BufferStreamImp*)m_pStreamImp) 1217 if (!pImp->LoadBuffer(pData, iTotalSize, dwAccess))
1205 ->LoadBuffer(pData, iTotalSize, dwAccess); 1218 return FALSE;
1206 if (!bRet) { 1219
1207 m_pStreamImp->Release(); 1220 m_pStreamImp = pImp.release();
1208 m_pStreamImp = NULL; 1221 m_eStreamType = FX_STREAMTYPE_Buffer;
1209 } else { 1222 m_dwAccess = dwAccess;
1210 m_eStreamType = FX_STREAMTYPE_Buffer; 1223 m_iLength = m_pStreamImp->GetLength();
1211 m_dwAccess = dwAccess; 1224 return TRUE;
1212 m_iLength = m_pStreamImp->GetLength();
1213 }
1214 return bRet;
1215 } 1225 }
1226
1216 FX_BOOL CFX_Stream::LoadBufferRead(IFX_BufferRead* pBufferRead, 1227 FX_BOOL CFX_Stream::LoadBufferRead(IFX_BufferRead* pBufferRead,
1217 int32_t iFileSize, 1228 int32_t iFileSize,
1218 uint32_t dwAccess, 1229 uint32_t dwAccess,
1219 FX_BOOL bReleaseBufferRead) { 1230 FX_BOOL bReleaseBufferRead) {
1220 if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp != NULL) { 1231 if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp)
1221 return FALSE; 1232 return FALSE;
1222 } 1233
1223 if (!pBufferRead) { 1234 if (!pBufferRead)
1224 return FALSE; 1235 return FALSE;
1225 } 1236
1226 m_pStreamImp = new CFX_BufferReadStreamImp; 1237 std::unique_ptr<CFX_BufferReadStreamImp> pImp(new CFX_BufferReadStreamImp);
1227 FX_BOOL bRet = ((CFX_BufferReadStreamImp*)m_pStreamImp) 1238 if (!pImp->LoadBufferRead(pBufferRead, iFileSize, dwAccess,
1228 ->LoadBufferRead(pBufferRead, iFileSize, dwAccess, 1239 bReleaseBufferRead))
1229 bReleaseBufferRead); 1240 return FALSE;
1230 if (!bRet) { 1241
1231 m_pStreamImp->Release(); 1242 m_pStreamImp = pImp.release();
1232 m_pStreamImp = NULL; 1243 m_eStreamType = FX_STREAMTYPE_BufferRead;
1233 } else { 1244 m_dwAccess = dwAccess;
1234 m_eStreamType = FX_STREAMTYPE_BufferRead; 1245 m_iLength = m_pStreamImp->GetLength();
1235 m_dwAccess = dwAccess; 1246 return TRUE;
1236 m_iLength = m_pStreamImp->GetLength();
1237 }
1238 return bRet;
1239 } 1247 }
1248
1240 void CFX_Stream::Release() { 1249 void CFX_Stream::Release() {
1241 if (--m_iRefCount < 1) { 1250 if (--m_iRefCount < 1) {
1242 delete this; 1251 delete this;
1243 } 1252 }
1244 } 1253 }
1245 IFX_Stream* CFX_Stream::Retain() { 1254 IFX_Stream* CFX_Stream::Retain() {
1246 m_iRefCount++; 1255 m_iRefCount++;
1247 return this; 1256 return this;
1248 } 1257 }
1249 int32_t CFX_Stream::GetLength() const { 1258 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) == 1626 return m_pStream->WriteData((const uint8_t*)pData, (int32_t)size) ==
1618 (int32_t)size; 1627 (int32_t)size;
1619 } 1628 }
1620 FX_BOOL CFGAS_FileWrite::WriteBlock(const void* pData, 1629 FX_BOOL CFGAS_FileWrite::WriteBlock(const void* pData,
1621 FX_FILESIZE offset, 1630 FX_FILESIZE offset,
1622 size_t size) { 1631 size_t size) {
1623 m_pStream->Seek(FX_STREAMSEEK_Begin, offset); 1632 m_pStream->Seek(FX_STREAMSEEK_Begin, offset);
1624 int32_t iLen = m_pStream->WriteData((uint8_t*)pData, (int32_t)size); 1633 int32_t iLen = m_pStream->WriteData((uint8_t*)pData, (int32_t)size);
1625 return iLen == (int32_t)size; 1634 return iLen == (int32_t)size;
1626 } 1635 }
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