summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2015-10-20 16:44:57 -0400
committerDan Sinclair <dsinclair@chromium.org>2015-10-20 16:44:57 -0400
commit05d9e934b74c2d4e4f2983cb8d31e995a18cbe6a (patch)
tree928a7ccab88e351df14ae1e0cbff3c7c8fad3c89 /core
parentf1251c1ff2b3452854681d0648b4c1ca4180ff0d (diff)
downloadpdfium-05d9e934b74c2d4e4f2983cb8d31e995a18cbe6a.tar.xz
[Merge to XFA] Add type cast definitions for CPDF_Boolean.
This CL adds ToBoolean, CPDF_Object::AsBoolean and CPDF_Object::IsBoolean and updates the src to use them as needed. BUG=pdfium:201 TBR=thestig@chromium.org, tsepez@chromium.org Review URL: https://codereview.chromium.org/1417623005 . (cherry picked from commit ce4f95d61f5aa5fb9a5fc6cb8487999a9cf46458) Review URL: https://codereview.chromium.org/1419663004 .
Diffstat (limited to 'core')
-rw-r--r--core/include/fpdfapi/fpdf_objects.h11
-rw-r--r--core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp21
2 files changed, 25 insertions, 7 deletions
diff --git a/core/include/fpdfapi/fpdf_objects.h b/core/include/fpdfapi/fpdf_objects.h
index d64a0924f8..a5f52832a1 100644
--- a/core/include/fpdfapi/fpdf_objects.h
+++ b/core/include/fpdfapi/fpdf_objects.h
@@ -80,8 +80,12 @@ class CPDF_Object {
FX_BOOL IsModified() const { return FALSE; }
+ bool IsBoolean() const { return m_Type == PDFOBJ_BOOLEAN; }
bool IsDictionary() const { return m_Type == PDFOBJ_DICTIONARY; }
+ CPDF_Boolean* AsBoolean();
+ const CPDF_Boolean* AsBoolean() const;
+
CPDF_Dictionary* AsDictionary();
const CPDF_Dictionary* AsDictionary() const;
@@ -119,6 +123,13 @@ class CPDF_Boolean : public CPDF_Object {
FX_BOOL m_bValue;
friend class CPDF_Object;
};
+inline CPDF_Boolean* ToBoolean(CPDF_Object* obj) {
+ return obj ? obj->AsBoolean() : nullptr;
+}
+inline const CPDF_Boolean* ToBoolean(const CPDF_Object* obj) {
+ return obj ? obj->AsBoolean() : nullptr;
+}
+
class CPDF_Number : public CPDF_Object {
public:
static CPDF_Number* Create(int value) { return new CPDF_Number(value); }
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp
index 55c274ac0f..8afa011585 100644
--- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp
+++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp
@@ -40,7 +40,7 @@ void CPDF_Object::Destroy() {
CFX_ByteString CPDF_Object::GetString() const {
switch (m_Type) {
case PDFOBJ_BOOLEAN:
- return ((CPDF_Boolean*)this)->m_bValue ? "true" : "false";
+ return AsBoolean()->m_bValue ? "true" : "false";
case PDFOBJ_NUMBER:
return ((CPDF_Number*)this)->GetString();
case PDFOBJ_STRING:
@@ -114,7 +114,7 @@ int CPDF_Object::GetInteger() const {
}
switch (m_Type) {
case PDFOBJ_BOOLEAN:
- return ((CPDF_Boolean*)this)->m_bValue;
+ return this->AsBoolean()->m_bValue;
case PDFOBJ_NUMBER:
return ((CPDF_Number*)this)->GetInteger();
case PDFOBJ_REFERENCE: {
@@ -168,7 +168,7 @@ void CPDF_Object::SetString(const CFX_ByteString& str) {
ASSERT(this != NULL);
switch (m_Type) {
case PDFOBJ_BOOLEAN:
- ((CPDF_Boolean*)this)->m_bValue = str == FX_BSTRC("true") ? 1 : 0;
+ AsBoolean()->m_bValue = (str == FX_BSTRC("true"));
return;
case PDFOBJ_NUMBER:
((CPDF_Number*)this)->SetString(str);
@@ -207,7 +207,7 @@ FX_BOOL CPDF_Object::IsIdentical(CPDF_Object* pOther) const {
}
switch (m_Type) {
case PDFOBJ_BOOLEAN:
- return (((CPDF_Boolean*)this)->Identical((CPDF_Boolean*)pOther));
+ return this->AsBoolean()->Identical(pOther->AsBoolean());
case PDFOBJ_NUMBER:
return (((CPDF_Number*)this)->Identical((CPDF_Number*)pOther));
case PDFOBJ_STRING:
@@ -245,7 +245,7 @@ CPDF_Object* CPDF_Object::CloneInternal(FX_BOOL bDirect,
CFX_MapPtrToPtr* visited) const {
switch (m_Type) {
case PDFOBJ_BOOLEAN:
- return new CPDF_Boolean(((CPDF_Boolean*)this)->m_bValue);
+ return new CPDF_Boolean(this->AsBoolean()->m_bValue);
case PDFOBJ_NUMBER:
return new CPDF_Number(((CPDF_Number*)this)->m_bInteger,
&((CPDF_Number*)this)->m_Integer);
@@ -337,6 +337,14 @@ void CPDF_Object::SetUnicodeText(const FX_WCHAR* pUnicodes, int len) {
}
}
+CPDF_Boolean* CPDF_Object::AsBoolean() {
+ return IsBoolean() ? static_cast<CPDF_Boolean*>(this) : nullptr;
+}
+
+const CPDF_Boolean* CPDF_Object::AsBoolean() const {
+ return IsBoolean() ? static_cast<const CPDF_Boolean*>(this) : nullptr;
+}
+
CPDF_Dictionary* CPDF_Object::AsDictionary() {
return IsDictionary() ? static_cast<CPDF_Dictionary*>(this) : nullptr;
}
@@ -663,9 +671,8 @@ FX_BOOL CPDF_Dictionary::GetBoolean(const CFX_ByteStringC& key,
FX_BOOL bDefault) const {
CPDF_Object* p = NULL;
m_Map.Lookup(key, (void*&)p);
- if (p && p->GetType() == PDFOBJ_BOOLEAN) {
+ if (ToBoolean(p))
return p->GetInteger();
- }
return bDefault;
}
CPDF_Dictionary* CPDF_Dictionary::GetDict(const CFX_ByteStringC& key) const {