diff options
author | Tom Sepez <tsepez@chromium.org> | 2015-02-11 12:44:01 -0800 |
---|---|---|
committer | Tom Sepez <tsepez@chromium.org> | 2015-02-11 12:44:01 -0800 |
commit | 6e7ceb8225de25b66d27d620c9521e19de023504 (patch) | |
tree | 190b5d98583d5f11ae01af4d8928a9c13bf30927 | |
parent | 0c61a738d2a8bef13c8fbe08c6df0b27238960ab (diff) | |
download | pdfium-6e7ceb8225de25b66d27d620c9521e19de023504.tar.xz |
CPDF_Object() constructor should set its internal m_Type variable.
Follow-on from https://codereview.chromium.org/911293002/
Currently, all the subclass constructors are reaching up
into the parent class to do this. Fix this, just because.
R=thestig@chromium.org
Review URL: https://codereview.chromium.org/880233005
-rw-r--r-- | core/include/fpdfapi/fpdf_objects.h | 83 | ||||
-rw-r--r-- | core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp | 35 |
2 files changed, 31 insertions, 87 deletions
diff --git a/core/include/fpdfapi/fpdf_objects.h b/core/include/fpdfapi/fpdf_objects.h index ec052af41a..bb449dd457 100644 --- a/core/include/fpdfapi/fpdf_objects.h +++ b/core/include/fpdfapi/fpdf_objects.h @@ -91,20 +91,15 @@ public: return FALSE; } protected: - FX_DWORD m_Type; - CPDF_Object() - { - m_ObjNum = 0; - m_GenNum = 0; - } - - FX_DWORD m_ObjNum; - FX_DWORD m_GenNum; + CPDF_Object(FX_DWORD type) : m_Type(type), m_ObjNum(0), m_GenNum(0) { } + ~CPDF_Object() { } void Destroy(); + FX_DWORD m_Type; + FX_DWORD m_ObjNum; + FX_DWORD m_GenNum; - ~CPDF_Object() {} friend class CPDF_IndirectObjects; friend class CPDF_Parser; friend class CPDF_SyntaxParser; @@ -121,16 +116,8 @@ public: return FX_NEW CPDF_Boolean(value); } - CPDF_Boolean() - { - m_Type = PDFOBJ_BOOLEAN; - } - - CPDF_Boolean(FX_BOOL value) - { - m_Type = PDFOBJ_BOOLEAN; - m_bValue = value; - } + CPDF_Boolean() : CPDF_Object(PDFOBJ_BOOLEAN), m_bValue(false) { } + CPDF_Boolean(FX_BOOL value) : CPDF_Object(PDFOBJ_BOOLEAN), m_bValue(value) { } FX_BOOL Identical(CPDF_Boolean* pOther) const { @@ -165,10 +152,7 @@ public: return FX_NEW CPDF_Number(bInteger, pData); } - CPDF_Number(): m_Integer(0) - { - m_Type = PDFOBJ_NUMBER; - } + CPDF_Number() : CPDF_Object(PDFOBJ_NUMBER), m_bInteger(false), m_Integer(0) { } CPDF_Number(FX_BOOL bInteger, void* pData); @@ -236,16 +220,10 @@ public: return FX_NEW CPDF_String(str); } - CPDF_String() - { - m_Type = PDFOBJ_STRING; - m_bHex = FALSE; - } + CPDF_String() : CPDF_Object(PDFOBJ_STRING), m_bHex(FALSE) { } - CPDF_String(const CFX_ByteString& str, FX_BOOL bHex = FALSE) : m_String(str) - { - m_Type = PDFOBJ_STRING; - m_bHex = bHex; + CPDF_String(const CFX_ByteString& str, FX_BOOL bHex = FALSE) + : CPDF_Object(PDFOBJ_STRING), m_String(str), m_bHex(bHex) { } CPDF_String(const CFX_WideString& str); @@ -290,20 +268,9 @@ public: return FX_NEW CPDF_Name(str); } - CPDF_Name(const CFX_ByteString& str) : m_Name(str) - { - m_Type = PDFOBJ_NAME; - } - - CPDF_Name(FX_BSTR str) : m_Name(str) - { - m_Type = PDFOBJ_NAME; - } - - CPDF_Name(FX_LPCSTR str) : m_Name(str) - { - m_Type = PDFOBJ_NAME; - } + CPDF_Name(const CFX_ByteString& str) : CPDF_Object(PDFOBJ_NAME), m_Name(str) { } + CPDF_Name(FX_BSTR str) : CPDF_Object(PDFOBJ_NAME), m_Name(str) { } + CPDF_Name(FX_LPCSTR str) : CPDF_Object(PDFOBJ_NAME), m_Name(str) { } CFX_ByteString& GetString() { @@ -328,10 +295,7 @@ public: return FX_NEW CPDF_Array(); } - CPDF_Array() - { - m_Type = PDFOBJ_ARRAY; - } + CPDF_Array() : CPDF_Object(PDFOBJ_ARRAY) { } FX_DWORD GetCount() const { @@ -428,12 +392,7 @@ public: return FX_NEW CPDF_Dictionary(); } - CPDF_Dictionary() - { - m_Type = PDFOBJ_DICTIONARY; - } - - + CPDF_Dictionary() : CPDF_Object(PDFOBJ_DICTIONARY) { } CPDF_Object* GetElement(FX_BSTR key) const; @@ -708,10 +667,7 @@ public: return FX_NEW CPDF_Null(); } - CPDF_Null() - { - m_Type = PDFOBJ_NULL; - } + CPDF_Null() : CPDF_Object(PDFOBJ_NULL) { } }; class CPDF_Reference : public CPDF_Object { @@ -723,10 +679,7 @@ public: } CPDF_Reference(CPDF_IndirectObjects* pDoc, int objnum) - { - m_Type = PDFOBJ_REFERENCE; - m_pObjList = pDoc; - m_RefObjNum = objnum; + : CPDF_Object(PDFOBJ_REFERENCE), m_pObjList(pDoc), m_RefObjNum(objnum) { } CPDF_IndirectObjects* GetObjList() const diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp index c477ba6f6e..18f06d6a14 100644 --- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp +++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp @@ -5,6 +5,8 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com #include "../../../include/fpdfapi/fpdf_parser.h" +#include "../../../include/fxcrt/fx_string.h" + void CPDF_Object::Release() { if (m_ObjNum) { @@ -331,30 +333,23 @@ void CPDF_Object::SetUnicodeText(FX_LPCWSTR pUnicodes, int len) ((CPDF_Stream*)this)->SetData((FX_LPBYTE)result.c_str(), result.GetLength(), FALSE, FALSE); } } + CPDF_Number::CPDF_Number(int value) -{ - m_Type = PDFOBJ_NUMBER; - m_bInteger = TRUE; - m_Integer = value; + : CPDF_Object(PDFOBJ_NUMBER), m_bInteger(TRUE), m_Integer(value) { } + CPDF_Number::CPDF_Number(FX_FLOAT value) -{ - m_Type = PDFOBJ_NUMBER; - m_bInteger = FALSE; - m_Float = value; + : CPDF_Object(PDFOBJ_NUMBER), m_bInteger(FALSE), m_Float(value) { } + CPDF_Number::CPDF_Number(FX_BOOL bInteger, void* pData) -{ - m_Type = PDFOBJ_NUMBER; - m_bInteger = bInteger; - m_Integer = *(int*)pData; + : CPDF_Object(PDFOBJ_NUMBER), m_bInteger(bInteger), m_Integer(*(int*)pData) { } -extern void FX_atonum(FX_BSTR, FX_BOOL&, void*); -CPDF_Number::CPDF_Number(FX_BSTR str) -{ - m_Type = PDFOBJ_NUMBER; + +CPDF_Number::CPDF_Number(FX_BSTR str) : CPDF_Object(PDFOBJ_NUMBER) { FX_atonum(str, m_bInteger, &m_Integer); } + void CPDF_Number::SetString(FX_BSTR str) { FX_atonum(str, m_bInteger, &m_Integer); @@ -372,11 +367,8 @@ void CPDF_Number::SetNumber(FX_FLOAT value) m_bInteger = FALSE; m_Float = value; } -CPDF_String::CPDF_String(const CFX_WideString& str) -{ - m_Type = PDFOBJ_STRING; +CPDF_String::CPDF_String(const CFX_WideString& str) : CPDF_Object(PDFOBJ_STRING), m_bHex(FALSE) { m_String = PDF_EncodeText(str, str.GetLength()); - m_bHex = FALSE; } CPDF_Array::~CPDF_Array() { @@ -859,8 +851,7 @@ void CPDF_Dictionary::SetAtMatrix(FX_BSTR key, const CFX_AffineMatrix& matrix) SetAt(key, pArray); } CPDF_Stream::CPDF_Stream(FX_LPBYTE pData, FX_DWORD size, CPDF_Dictionary* pDict) -{ - m_Type = PDFOBJ_STREAM; + : CPDF_Object(PDFOBJ_STREAM) { m_pDict = pDict; m_dwSize = size; m_GenNum = (FX_DWORD) - 1; |