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

Unified 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: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: xfa/fgas/crt/fgas_stream.cpp
diff --git a/xfa/fgas/crt/fgas_stream.cpp b/xfa/fgas/crt/fgas_stream.cpp
index c05e81ade32442c0cf0adaa780450e5a379795f4..6950b1f4fb992288ff0f79bbf11563efe4620523 100644
--- a/xfa/fgas/crt/fgas_stream.cpp
+++ b/xfa/fgas/crt/fgas_stream.cpp
@@ -7,15 +7,17 @@
#include "xfa/fgas/crt/fgas_stream.h"
#include <algorithm>
+#include <memory>
#include "xfa/fgas/crt/fgas_codepage.h"
#include "xfa/fgas/crt/fgas_system.h"
namespace {
-class CFX_StreamImp {
+class IFX_StreamImp {
public:
- virtual void Release() { delete this; }
+ virtual ~IFX_StreamImp() {}
+
virtual uint32_t GetAccessModes() const { return m_dwAccess; }
Lei Zhang 2016/05/18 23:02:30 This doesn't need to be virtual?
Tom Sepez 2016/05/18 23:29:56 Done.
virtual int32_t GetLength() const = 0;
virtual int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) = 0;
@@ -31,47 +33,57 @@ class CFX_StreamImp {
virtual FX_BOOL SetLength(int32_t iLength) = 0;
protected:
- CFX_StreamImp();
- virtual ~CFX_StreamImp() {}
+ IFX_StreamImp();
+
uint32_t m_dwAccess;
Lei Zhang 2016/05/18 23:02:30 Should be private with GetAccessModes() and a sett
Tom Sepez 2016/05/18 23:29:56 Done. PTAL.
};
-class CFX_FileStreamImp : public CFX_StreamImp {
+class CFX_FileStreamImp : public IFX_StreamImp {
public:
CFX_FileStreamImp();
- virtual ~CFX_FileStreamImp();
+ ~CFX_FileStreamImp() override;
+
FX_BOOL LoadFile(const FX_WCHAR* pszSrcFileName, uint32_t dwAccess);
- virtual int32_t GetLength() const;
- virtual int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset);
- virtual int32_t GetPosition();
- virtual FX_BOOL IsEOF() const;
- virtual int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize);
- virtual int32_t ReadString(FX_WCHAR* pStr, int32_t iMaxLength, FX_BOOL& bEOS);
- virtual int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize);
- virtual int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength);
- virtual void Flush();
- virtual FX_BOOL SetLength(int32_t iLength);
+
+ // IFX_StreamImp:
+ int32_t GetLength() const override;
+ int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) override;
+ int32_t GetPosition() override;
+ FX_BOOL IsEOF() const override;
+ int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) override;
+ int32_t ReadString(FX_WCHAR* pStr,
+ int32_t iMaxLength,
+ FX_BOOL& bEOS) override;
+ int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) override;
+ int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) override;
+ void Flush() override;
+ FX_BOOL SetLength(int32_t iLength) override;
protected:
FXSYS_FILE* m_hFile;
int32_t m_iLength;
};
-class CFX_BufferStreamImp : public CFX_StreamImp {
+class CFX_BufferStreamImp : public IFX_StreamImp {
public:
CFX_BufferStreamImp();
- virtual ~CFX_BufferStreamImp() {}
+ ~CFX_BufferStreamImp() override {}
+
FX_BOOL LoadBuffer(uint8_t* pData, int32_t iTotalSize, uint32_t dwAccess);
- virtual int32_t GetLength() const;
- virtual int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset);
- virtual int32_t GetPosition();
- virtual FX_BOOL IsEOF() const;
- virtual int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize);
- virtual int32_t ReadString(FX_WCHAR* pStr, int32_t iMaxLength, FX_BOOL& bEOS);
- virtual int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize);
- virtual int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength);
- virtual void Flush() {}
- virtual FX_BOOL SetLength(int32_t iLength) { return FALSE; }
+
+ // IFX_StreamImp:
+ int32_t GetLength() const override;
+ int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) override;
+ int32_t GetPosition() override;
+ FX_BOOL IsEOF() const override;
+ int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) override;
+ int32_t ReadString(FX_WCHAR* pStr,
+ int32_t iMaxLength,
+ FX_BOOL& bEOS) override;
+ int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) override;
+ int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) override;
+ void Flush() override {}
+ FX_BOOL SetLength(int32_t iLength) override { return FALSE; }
protected:
uint8_t* m_pData;
@@ -80,26 +92,31 @@ class CFX_BufferStreamImp : public CFX_StreamImp {
int32_t m_iLength;
};
-class CFX_FileReadStreamImp : public CFX_StreamImp {
+class CFX_FileReadStreamImp : public IFX_StreamImp {
public:
CFX_FileReadStreamImp();
- virtual ~CFX_FileReadStreamImp() {}
+ ~CFX_FileReadStreamImp() override {}
+
FX_BOOL LoadFileRead(IFX_FileRead* pFileRead, uint32_t dwAccess);
- virtual int32_t GetLength() const;
- virtual int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset);
- virtual int32_t GetPosition() { return m_iPosition; }
- virtual FX_BOOL IsEOF() const;
- virtual int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize);
- virtual int32_t ReadString(FX_WCHAR* pStr, int32_t iMaxLength, FX_BOOL& bEOS);
- virtual int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) {
+ // IFX_StreamImp:
+ int32_t GetLength() const override;
+ int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) override;
+ int32_t GetPosition() override { return m_iPosition; }
+ FX_BOOL IsEOF() const override;
+
+ int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) override;
+ int32_t ReadString(FX_WCHAR* pStr,
+ int32_t iMaxLength,
+ FX_BOOL& bEOS) override;
+ int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) override {
return 0;
}
- virtual int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) {
+ int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) override {
return 0;
}
- virtual void Flush() {}
- virtual FX_BOOL SetLength(int32_t iLength) { return FALSE; }
+ void Flush() override {}
+ FX_BOOL SetLength(int32_t iLength) override { return FALSE; }
protected:
IFX_FileRead* m_pFileRead;
@@ -107,30 +124,33 @@ class CFX_FileReadStreamImp : public CFX_StreamImp {
int32_t m_iLength;
};
-class CFX_BufferReadStreamImp : public CFX_StreamImp {
+class CFX_BufferReadStreamImp : public IFX_StreamImp {
public:
CFX_BufferReadStreamImp();
- ~CFX_BufferReadStreamImp();
+ ~CFX_BufferReadStreamImp() override;
+
FX_BOOL LoadBufferRead(IFX_BufferRead* pBufferRead,
int32_t iFileSize,
uint32_t dwAccess,
FX_BOOL bReleaseBufferRead);
- virtual int32_t GetLength() const;
- virtual int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset);
- virtual int32_t GetPosition() { return m_iPosition; }
- virtual FX_BOOL IsEOF() const;
-
- virtual int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize);
- virtual int32_t ReadString(FX_WCHAR* pStr, int32_t iMaxLength, FX_BOOL& bEOS);
- virtual int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) {
+ // IFX_StreamImp:
+ int32_t GetLength() const override;
+ int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) override;
+ int32_t GetPosition() override { return m_iPosition; }
+ FX_BOOL IsEOF() const override;
+ int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) override;
+ int32_t ReadString(FX_WCHAR* pStr,
+ int32_t iMaxLength,
+ FX_BOOL& bEOS) override;
+ int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) override {
return 0;
}
- virtual int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) {
+ int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) override {
return 0;
}
- virtual void Flush() {}
- virtual FX_BOOL SetLength(int32_t iLength) { return FALSE; }
+ void Flush() override {}
+ FX_BOOL SetLength(int32_t iLength) override { return FALSE; }
private:
IFX_BufferRead* m_pBufferRead;
@@ -139,25 +159,28 @@ class CFX_BufferReadStreamImp : public CFX_StreamImp {
int32_t m_iBufferSize;
};
-class CFX_FileWriteStreamImp : public CFX_StreamImp {
+class CFX_FileWriteStreamImp : public IFX_StreamImp {
public:
CFX_FileWriteStreamImp();
- virtual ~CFX_FileWriteStreamImp() {}
+ ~CFX_FileWriteStreamImp() override {}
+
FX_BOOL LoadFileWrite(IFX_FileWrite* pFileWrite, uint32_t dwAccess);
- virtual int32_t GetLength() const;
- virtual int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset);
- virtual int32_t GetPosition() { return m_iPosition; }
- virtual FX_BOOL IsEOF() const;
- virtual int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) { return 0; }
- virtual int32_t ReadString(FX_WCHAR* pStr,
- int32_t iMaxLength,
- FX_BOOL& bEOS) {
+
+ // IFX_StreamImp:
+ int32_t GetLength() const override;
+ int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) override;
+ int32_t GetPosition() override { return m_iPosition; }
+ FX_BOOL IsEOF() const override;
+ int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) override { return 0; }
+ int32_t ReadString(FX_WCHAR* pStr,
+ int32_t iMaxLength,
+ FX_BOOL& bEOS) override {
return 0;
}
- virtual int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize);
- virtual int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength);
- virtual void Flush();
- virtual FX_BOOL SetLength(int32_t iLength) { return FALSE; }
+ int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) override;
+ int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) override;
+ void Flush() override;
+ FX_BOOL SetLength(int32_t iLength) override { return FALSE; }
protected:
IFX_FileWrite* m_pFileWrite;
@@ -209,7 +232,7 @@ class CFX_Stream : public IFX_Stream {
protected:
FX_STREAMTYPE m_eStreamType;
- CFX_StreamImp* m_pStreamImp;
+ IFX_StreamImp* m_pStreamImp;
uint32_t m_dwAccess;
int32_t m_iTotalSize;
int32_t m_iPosition;
@@ -374,9 +397,9 @@ IFX_Stream* IFX_Stream::CreateStream(uint8_t* pData,
return pSR;
}
-CFX_StreamImp::CFX_StreamImp() : m_dwAccess(0) {}
+IFX_StreamImp::IFX_StreamImp() : m_dwAccess(0) {}
CFX_FileStreamImp::CFX_FileStreamImp()
- : CFX_StreamImp(), m_hFile(NULL), m_iLength(0) {}
+ : IFX_StreamImp(), m_hFile(NULL), m_iLength(0) {}
CFX_FileStreamImp::~CFX_FileStreamImp() {
if (m_hFile != NULL) {
FXSYS_fclose(m_hFile);
@@ -800,11 +823,8 @@ void CFX_FileWriteStreamImp::Flush() {
}
}
CFX_BufferStreamImp::CFX_BufferStreamImp()
- : CFX_StreamImp(),
- m_pData(NULL),
- m_iTotalSize(0),
- m_iPosition(0),
- m_iLength(0) {}
+ : m_pData(nullptr), m_iTotalSize(0), m_iPosition(0), m_iLength(0) {}
+
FX_BOOL CFX_BufferStreamImp::LoadBuffer(uint8_t* pData,
int32_t iTotalSize,
uint32_t dwAccess) {
@@ -1124,119 +1144,110 @@ CFX_Stream::CFX_Stream()
m_iStart(0),
m_iLength(0),
m_iRefCount(1) {}
+
CFX_Stream::~CFX_Stream() {
- if (m_eStreamType != FX_STREAMTYPE_Stream && m_pStreamImp != NULL) {
- m_pStreamImp->Release();
- }
+ if (m_eStreamType != FX_STREAMTYPE_Stream)
+ delete m_pStreamImp;
}
+
FX_BOOL CFX_Stream::LoadFile(const FX_WCHAR* pszSrcFileName,
uint32_t dwAccess) {
- if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp != NULL) {
+ if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp)
return FALSE;
- }
- if (pszSrcFileName == NULL || FXSYS_wcslen(pszSrcFileName) < 1) {
+
+ if (!pszSrcFileName || FXSYS_wcslen(pszSrcFileName) < 1)
return FALSE;
- }
- m_pStreamImp = new CFX_FileStreamImp();
- FX_BOOL bRet =
- ((CFX_FileStreamImp*)m_pStreamImp)->LoadFile(pszSrcFileName, dwAccess);
- if (!bRet) {
- m_pStreamImp->Release();
- m_pStreamImp = NULL;
- } else {
- m_eStreamType = FX_STREAMTYPE_File;
- m_dwAccess = dwAccess;
- m_iLength = m_pStreamImp->GetLength();
- }
- return bRet;
+
+ std::unique_ptr<CFX_FileStreamImp> pImp(new CFX_FileStreamImp());
+ if (!pImp->LoadFile(pszSrcFileName, dwAccess))
+ return FALSE;
+
+ m_pStreamImp = pImp.release();
+ m_eStreamType = FX_STREAMTYPE_File;
+ m_dwAccess = dwAccess;
+ m_iLength = m_pStreamImp->GetLength();
+ return TRUE;
}
+
FX_BOOL CFX_Stream::LoadFileRead(IFX_FileRead* pFileRead, uint32_t dwAccess) {
- if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp != NULL) {
+ if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp)
return FALSE;
- }
- if (pFileRead == NULL) {
+
+ if (!pFileRead)
return FALSE;
- }
- m_pStreamImp = new CFX_FileReadStreamImp();
- FX_BOOL bRet =
- ((CFX_FileReadStreamImp*)m_pStreamImp)->LoadFileRead(pFileRead, dwAccess);
- if (!bRet) {
- m_pStreamImp->Release();
- m_pStreamImp = NULL;
- } else {
- m_eStreamType = FX_STREAMTYPE_File;
- m_dwAccess = dwAccess;
- m_iLength = m_pStreamImp->GetLength();
- }
- return bRet;
+
+ std::unique_ptr<CFX_FileReadStreamImp> pImp(new CFX_FileReadStreamImp());
+ if (!pImp->LoadFileRead(pFileRead, dwAccess))
+ return FALSE;
+
+ m_pStreamImp = pImp.release();
+ m_eStreamType = FX_STREAMTYPE_File;
+ m_dwAccess = dwAccess;
+ m_iLength = m_pStreamImp->GetLength();
+ return TRUE;
}
+
FX_BOOL CFX_Stream::LoadFileWrite(IFX_FileWrite* pFileWrite,
uint32_t dwAccess) {
- if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp != NULL) {
+ if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp)
return FALSE;
- }
- if (pFileWrite == NULL) {
+
+ if (!pFileWrite)
return FALSE;
- }
- m_pStreamImp = new CFX_FileWriteStreamImp();
- FX_BOOL bRet = ((CFX_FileWriteStreamImp*)m_pStreamImp)
- ->LoadFileWrite(pFileWrite, dwAccess);
- if (!bRet) {
- m_pStreamImp->Release();
- m_pStreamImp = NULL;
- } else {
- m_eStreamType = FX_STREAMTYPE_File;
- m_dwAccess = dwAccess;
- m_iLength = m_pStreamImp->GetLength();
- }
- return bRet;
+
+ std::unique_ptr<CFX_FileWriteStreamImp> pImp(new CFX_FileWriteStreamImp());
+ if (!pImp->LoadFileWrite(pFileWrite, dwAccess))
+ return FALSE;
+
+ m_pStreamImp = pImp.release();
+ m_eStreamType = FX_STREAMTYPE_File;
+ m_dwAccess = dwAccess;
+ m_iLength = m_pStreamImp->GetLength();
+ return TRUE;
}
+
FX_BOOL CFX_Stream::LoadBuffer(uint8_t* pData,
int32_t iTotalSize,
uint32_t dwAccess) {
- if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp != NULL) {
+ if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp)
return FALSE;
- }
- if (pData == NULL || iTotalSize < 1) {
+
+ if (!pData || iTotalSize < 1)
return FALSE;
- }
- m_pStreamImp = new CFX_BufferStreamImp();
- FX_BOOL bRet = ((CFX_BufferStreamImp*)m_pStreamImp)
- ->LoadBuffer(pData, iTotalSize, dwAccess);
- if (!bRet) {
- m_pStreamImp->Release();
- m_pStreamImp = NULL;
- } else {
- m_eStreamType = FX_STREAMTYPE_Buffer;
- m_dwAccess = dwAccess;
- m_iLength = m_pStreamImp->GetLength();
- }
- return bRet;
+
+ std::unique_ptr<CFX_BufferStreamImp> pImp(new CFX_BufferStreamImp());
+ if (!pImp->LoadBuffer(pData, iTotalSize, dwAccess))
+ return FALSE;
+
+ m_pStreamImp = pImp.release();
+ m_eStreamType = FX_STREAMTYPE_Buffer;
+ m_dwAccess = dwAccess;
+ m_iLength = m_pStreamImp->GetLength();
+ return TRUE;
}
+
FX_BOOL CFX_Stream::LoadBufferRead(IFX_BufferRead* pBufferRead,
int32_t iFileSize,
uint32_t dwAccess,
FX_BOOL bReleaseBufferRead) {
- if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp != NULL) {
+ if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp)
return FALSE;
- }
- if (!pBufferRead) {
+
+ if (!pBufferRead)
return FALSE;
- }
- m_pStreamImp = new CFX_BufferReadStreamImp;
- FX_BOOL bRet = ((CFX_BufferReadStreamImp*)m_pStreamImp)
- ->LoadBufferRead(pBufferRead, iFileSize, dwAccess,
- bReleaseBufferRead);
- if (!bRet) {
- m_pStreamImp->Release();
- m_pStreamImp = NULL;
- } else {
- m_eStreamType = FX_STREAMTYPE_BufferRead;
- m_dwAccess = dwAccess;
- m_iLength = m_pStreamImp->GetLength();
- }
- return bRet;
+
+ std::unique_ptr<CFX_BufferReadStreamImp> pImp(new CFX_BufferReadStreamImp);
+ if (!pImp->LoadBufferRead(pBufferRead, iFileSize, dwAccess,
+ bReleaseBufferRead))
+ return FALSE;
+
+ m_pStreamImp = pImp.release();
+ m_eStreamType = FX_STREAMTYPE_BufferRead;
+ m_dwAccess = dwAccess;
+ m_iLength = m_pStreamImp->GetLength();
+ return TRUE;
}
+
void CFX_Stream::Release() {
if (--m_iRefCount < 1) {
delete this;
« 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