diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2017-11-16 14:19:47 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-11-16 14:19:47 +0000 |
commit | ce7ccd5f638eff42c6c79da682061fa2c39b028f (patch) | |
tree | c150e99f3c7ffb4e2d611e33aba743b43d718ac9 /fxjs | |
parent | 8873a4dffed0ae3ccd961ada58c588f92b210bf2 (diff) | |
download | pdfium-ce7ccd5f638eff42c6c79da682061fa2c39b028f.tar.xz |
Convert CJX_Node::TryMeasure to pdfium::Optional
This CL converts TryMeasure to return a pdfium::Optional instead of a
bool with an out parameter.
Change-Id: I6e92e53aa0eaa7a6b855253061acca8a59db49fd
Reviewed-on: https://pdfium-review.googlesource.com/18550
Commit-Queue: dsinclair <dsinclair@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'fxjs')
-rw-r--r-- | fxjs/cjx_node.cpp | 29 | ||||
-rw-r--r-- | fxjs/cjx_node.h | 5 |
2 files changed, 14 insertions, 20 deletions
diff --git a/fxjs/cjx_node.cpp b/fxjs/cjx_node.cpp index e207ae488d..ac93397b77 100644 --- a/fxjs/cjx_node.cpp +++ b/fxjs/cjx_node.cpp @@ -303,11 +303,12 @@ pdfium::Optional<WideString> CJX_Node::TryAttribute(XFA_Attribute eAttr, return {wsValue}; } case XFA_AttributeType::Measure: { - CXFA_Measurement mValue; - if (!TryMeasure(pAttr->eName, mValue, bUseDefault)) + pdfium::Optional<CXFA_Measurement> value = + TryMeasure(pAttr->eName, bUseDefault); + if (!value) return {}; - return {mValue.ToString()}; + return {value->ToString()}; } default: break; @@ -3072,30 +3073,24 @@ bool CJX_Node::SetMeasure(XFA_Attribute eAttr, return true; } -bool CJX_Node::TryMeasure(XFA_Attribute eAttr, - CXFA_Measurement& mValue, - bool bUseDefault) const { +pdfium::Optional<CXFA_Measurement> CJX_Node::TryMeasure( + XFA_Attribute eAttr, + bool bUseDefault) const { void* pKey = GetMapKey_Element(GetXFANode()->GetElementType(), eAttr); void* pValue; int32_t iBytes; if (GetMapModuleBuffer(pKey, pValue, iBytes, true) && - iBytes == sizeof(mValue)) { - memcpy(&mValue, pValue, sizeof(mValue)); - return true; + iBytes == sizeof(CXFA_Measurement)) { + return {*reinterpret_cast<CXFA_Measurement*>(pValue)}; } if (!bUseDefault) - return false; + return {}; - pdfium::Optional<CXFA_Measurement> measure = - GetXFANode()->GetDefaultMeasurement(eAttr); - if (measure) - mValue = *measure; - return !!measure; + return GetXFANode()->GetDefaultMeasurement(eAttr); } CXFA_Measurement CJX_Node::GetMeasure(XFA_Attribute eAttr) const { - CXFA_Measurement mValue; - return TryMeasure(eAttr, mValue, true) ? mValue : CXFA_Measurement(); + return TryMeasure(eAttr, true).value_or(CXFA_Measurement()); } WideString CJX_Node::GetCData(XFA_Attribute eAttr) { diff --git a/fxjs/cjx_node.h b/fxjs/cjx_node.h index 8cf167938c..cb6b6867fd 100644 --- a/fxjs/cjx_node.h +++ b/fxjs/cjx_node.h @@ -92,9 +92,8 @@ class CJX_Node : public CJX_Object { bool SetBoolean(XFA_Attribute eAttr, bool bValue, bool bNotify); bool GetBoolean(XFA_Attribute eAttr); - bool TryMeasure(XFA_Attribute eAttr, - CXFA_Measurement& mValue, - bool bUseDefault) const; + pdfium::Optional<CXFA_Measurement> TryMeasure(XFA_Attribute eAttr, + bool bUseDefault) const; bool SetMeasure(XFA_Attribute eAttr, CXFA_Measurement mValue, bool bNotify); CXFA_Measurement GetMeasure(XFA_Attribute eAttr) const; |