summaryrefslogtreecommitdiff
path: root/fxjs/cjx_node.cpp
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2017-11-16 14:19:47 +0000
committerChromium commit bot <commit-bot@chromium.org>2017-11-16 14:19:47 +0000
commitce7ccd5f638eff42c6c79da682061fa2c39b028f (patch)
treec150e99f3c7ffb4e2d611e33aba743b43d718ac9 /fxjs/cjx_node.cpp
parent8873a4dffed0ae3ccd961ada58c588f92b210bf2 (diff)
downloadpdfium-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/cjx_node.cpp')
-rw-r--r--fxjs/cjx_node.cpp29
1 files changed, 12 insertions, 17 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) {