diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2014-04-06 17:19:03 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2014-04-06 18:14:03 +0200 |
commit | 69c950ae862f9ea9c5f56d8bdba895fb9a07ff0f (patch) | |
tree | a69698aadb7abdbbe252502cda5770f6eb23d8df /writerfilter/source | |
parent | 4bdd530984959ba0d0cacb43f7441d9a217dfd1f (diff) |
RTFSprms::set: replace two bool arguments with an enum
The primary motivation is that the two bools allow 4 combinations, but
we only handle 3 of them. Also, caller code is much more readable, now
that a non-default overwrite mode is written explicitly.
Change-Id: Iedf7dee1ab2d33de849aef6d7a51138d35048e5a
Diffstat (limited to 'writerfilter/source')
-rw-r--r-- | writerfilter/source/rtftok/rtfdocumentimpl.cxx | 65 | ||||
-rw-r--r-- | writerfilter/source/rtftok/rtfsprm.cxx | 8 | ||||
-rw-r--r-- | writerfilter/source/rtftok/rtfsprm.hxx | 16 |
3 files changed, 45 insertions, 44 deletions
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx index 287fb0393dde..39da5cc9bead 100644 --- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx +++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx @@ -75,7 +75,7 @@ static Id lcl_getParagraphBorder(sal_uInt32 nIndex) } static void lcl_putNestedAttribute(RTFSprms& rSprms, Id nParent, Id nId, RTFValue::Pointer_t pValue, - bool bOverwrite = true, bool bAttribute = true, bool bAppend = true) + RTFOverwrite eOverwrite = OVERWRITE_YES, bool bAttribute = true) { RTFValue::Pointer_t pParent = rSprms.find(nParent); if (!pParent.get()) @@ -88,16 +88,16 @@ static void lcl_putNestedAttribute(RTFSprms& rSprms, Id nParent, Id nId, RTFValu aAttributes.set(NS_ooxml::LN_CT_Shd_fill, RTFValue::Pointer_t(new RTFValue(0x0a))); } RTFValue::Pointer_t pParentValue(new RTFValue(aAttributes)); - rSprms.set(nParent, pParentValue, bOverwrite, bAppend); + rSprms.set(nParent, pParentValue, eOverwrite); pParent = pParentValue; } RTFSprms& rAttributes = (bAttribute ? pParent->getAttributes() : pParent->getSprms()); - rAttributes.set(nId, pValue, bOverwrite, bAppend); + rAttributes.set(nId, pValue, eOverwrite); } -static void lcl_putNestedSprm(RTFSprms& rSprms, Id nParent, Id nId, RTFValue::Pointer_t pValue, bool bOverwrite = false) +static void lcl_putNestedSprm(RTFSprms& rSprms, Id nParent, Id nId, RTFValue::Pointer_t pValue, RTFOverwrite eOverwrite = OVERWRITE_NO_APPEND) { - lcl_putNestedAttribute(rSprms, nParent, nId, pValue, bOverwrite, false); + lcl_putNestedAttribute(rSprms, nParent, nId, pValue, eOverwrite, false); } static RTFValue::Pointer_t lcl_getNestedAttribute(RTFSprms& rSprms, Id nParent, Id nId) @@ -2247,7 +2247,7 @@ void RTFDocumentImpl::restoreTableRowProperties() void RTFDocumentImpl::resetTableRowProperties() { m_aStates.top().aTableRowSprms = m_aDefaultState.aTableRowSprms; - m_aStates.top().aTableRowSprms.set(NS_ooxml::LN_CT_TblGridBase_gridCol, RTFValue::Pointer_t(new RTFValue(-1)), false); + m_aStates.top().aTableRowSprms.set(NS_ooxml::LN_CT_TblGridBase_gridCol, RTFValue::Pointer_t(new RTFValue(-1)), OVERWRITE_NO_APPEND); m_aStates.top().aTableRowAttributes = m_aDefaultState.aTableRowAttributes; if (DESTINATION_NESTEDTABLEPROPERTIES == m_aStates.top().nDestinationState) m_nNestedCurrentCellX = 0; @@ -3542,7 +3542,7 @@ int RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam) rCurrentCellX = nParam; RTFValue::Pointer_t pXValue(new RTFValue(nCellX)); - m_aStates.top().aTableRowSprms.set(NS_ooxml::LN_CT_TblGridBase_gridCol, pXValue, false); + m_aStates.top().aTableRowSprms.set(NS_ooxml::LN_CT_TblGridBase_gridCol, pXValue, OVERWRITE_NO_APPEND); if (DESTINATION_NESTEDTABLEPROPERTIES == m_aStates.top().nDestinationState) { m_nNestedCells++; @@ -3622,53 +3622,53 @@ int RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam) break; case RTF_PAPERH: // fall through: set the default + current value lcl_putNestedAttribute(m_aDefaultState.aSectionSprms, - NS_ooxml::LN_EG_SectPrContents_pgSz, NS_ooxml::LN_CT_PageSz_h, pIntValue, true); + NS_ooxml::LN_EG_SectPrContents_pgSz, NS_ooxml::LN_CT_PageSz_h, pIntValue, OVERWRITE_YES); case RTF_PGHSXN: lcl_putNestedAttribute(m_aStates.top().aSectionSprms, - NS_ooxml::LN_EG_SectPrContents_pgSz, NS_ooxml::LN_CT_PageSz_h, pIntValue, true); + NS_ooxml::LN_EG_SectPrContents_pgSz, NS_ooxml::LN_CT_PageSz_h, pIntValue, OVERWRITE_YES); break; case RTF_PAPERW: // fall through: set the default + current value lcl_putNestedAttribute(m_aDefaultState.aSectionSprms, - NS_ooxml::LN_EG_SectPrContents_pgSz, NS_ooxml::LN_CT_PageSz_w, pIntValue, true); + NS_ooxml::LN_EG_SectPrContents_pgSz, NS_ooxml::LN_CT_PageSz_w, pIntValue, OVERWRITE_YES); case RTF_PGWSXN: lcl_putNestedAttribute(m_aStates.top().aSectionSprms, - NS_ooxml::LN_EG_SectPrContents_pgSz, NS_ooxml::LN_CT_PageSz_w, pIntValue, true); + NS_ooxml::LN_EG_SectPrContents_pgSz, NS_ooxml::LN_CT_PageSz_w, pIntValue, OVERWRITE_YES); break; case RTF_MARGL: // fall through: set the default + current value lcl_putNestedAttribute(m_aDefaultState.aSectionSprms, - NS_ooxml::LN_EG_SectPrContents_pgMar, NS_ooxml::LN_CT_PageMar_left, pIntValue, true); + NS_ooxml::LN_EG_SectPrContents_pgMar, NS_ooxml::LN_CT_PageMar_left, pIntValue, OVERWRITE_YES); case RTF_MARGLSXN: lcl_putNestedAttribute(m_aStates.top().aSectionSprms, - NS_ooxml::LN_EG_SectPrContents_pgMar, NS_ooxml::LN_CT_PageMar_left, pIntValue, true); + NS_ooxml::LN_EG_SectPrContents_pgMar, NS_ooxml::LN_CT_PageMar_left, pIntValue, OVERWRITE_YES); break; case RTF_MARGR: // fall through: set the default + current value lcl_putNestedAttribute(m_aDefaultState.aSectionSprms, - NS_ooxml::LN_EG_SectPrContents_pgMar, NS_ooxml::LN_CT_PageMar_right, pIntValue, true); + NS_ooxml::LN_EG_SectPrContents_pgMar, NS_ooxml::LN_CT_PageMar_right, pIntValue, OVERWRITE_YES); case RTF_MARGRSXN: lcl_putNestedAttribute(m_aStates.top().aSectionSprms, - NS_ooxml::LN_EG_SectPrContents_pgMar, NS_ooxml::LN_CT_PageMar_right, pIntValue, true); + NS_ooxml::LN_EG_SectPrContents_pgMar, NS_ooxml::LN_CT_PageMar_right, pIntValue, OVERWRITE_YES); break; case RTF_MARGT: // fall through: set the default + current value lcl_putNestedAttribute(m_aDefaultState.aSectionSprms, - NS_ooxml::LN_EG_SectPrContents_pgMar, NS_ooxml::LN_CT_PageMar_top, pIntValue, true); + NS_ooxml::LN_EG_SectPrContents_pgMar, NS_ooxml::LN_CT_PageMar_top, pIntValue, OVERWRITE_YES); case RTF_MARGTSXN: lcl_putNestedAttribute(m_aStates.top().aSectionSprms, - NS_ooxml::LN_EG_SectPrContents_pgMar, NS_ooxml::LN_CT_PageMar_top, pIntValue, true); + NS_ooxml::LN_EG_SectPrContents_pgMar, NS_ooxml::LN_CT_PageMar_top, pIntValue, OVERWRITE_YES); break; case RTF_MARGB: // fall through: set the default + current value lcl_putNestedAttribute(m_aDefaultState.aSectionSprms, - NS_ooxml::LN_EG_SectPrContents_pgMar, NS_ooxml::LN_CT_PageMar_bottom, pIntValue, true); + NS_ooxml::LN_EG_SectPrContents_pgMar, NS_ooxml::LN_CT_PageMar_bottom, pIntValue, OVERWRITE_YES); case RTF_MARGBSXN: lcl_putNestedAttribute(m_aStates.top().aSectionSprms, - NS_ooxml::LN_EG_SectPrContents_pgMar, NS_ooxml::LN_CT_PageMar_bottom, pIntValue, true); + NS_ooxml::LN_EG_SectPrContents_pgMar, NS_ooxml::LN_CT_PageMar_bottom, pIntValue, OVERWRITE_YES); break; case RTF_HEADERY: lcl_putNestedAttribute(m_aStates.top().aSectionSprms, - NS_ooxml::LN_EG_SectPrContents_pgMar, NS_ooxml::LN_CT_PageMar_header, pIntValue, true); + NS_ooxml::LN_EG_SectPrContents_pgMar, NS_ooxml::LN_CT_PageMar_header, pIntValue, OVERWRITE_YES); break; case RTF_FOOTERY: lcl_putNestedAttribute(m_aStates.top().aSectionSprms, - NS_ooxml::LN_EG_SectPrContents_pgMar, NS_ooxml::LN_CT_PageMar_footer, pIntValue, true); + NS_ooxml::LN_EG_SectPrContents_pgMar, NS_ooxml::LN_CT_PageMar_footer, pIntValue, OVERWRITE_YES); break; case RTF_DEFTAB: m_aSettingsTableSprms.set(NS_ooxml::LN_CT_Settings_defaultTabStop, pIntValue); @@ -3825,11 +3825,11 @@ int RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam) break; case RTF_SB: lcl_putNestedAttribute(m_aStates.top().aParagraphSprms, - NS_ooxml::LN_CT_PPrBase_spacing, NS_ooxml::LN_CT_Spacing_before, pIntValue, true); + NS_ooxml::LN_CT_PPrBase_spacing, NS_ooxml::LN_CT_Spacing_before, pIntValue, OVERWRITE_YES); break; case RTF_SA: lcl_putNestedAttribute(m_aStates.top().aParagraphSprms, - NS_ooxml::LN_CT_PPrBase_spacing, NS_ooxml::LN_CT_Spacing_after, pIntValue, true); + NS_ooxml::LN_CT_PPrBase_spacing, NS_ooxml::LN_CT_Spacing_after, pIntValue, OVERWRITE_YES); break; case RTF_DPX: m_aStates.top().aDrawingObject.nLeft = TWIP_TO_MM100(nParam); @@ -3997,7 +3997,7 @@ int RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam) // It turns out \li should reset the \fi inherited from the stylesheet. // So set the direct formatting to zero, if we don't have such direct formatting yet. lcl_putNestedAttribute(m_aStates.top().aParagraphSprms, NS_ooxml::LN_CT_PPrBase_ind, NS_ooxml::LN_CT_Ind_firstLine, RTFValue::Pointer_t(new RTFValue(0)), - /*bOverwrite=*/false, /*bAttribute=*/true, /*bAppend=*/false); + OVERWRITE_NO_IGNORE, /*bAttribute=*/true); } break; case RTF_RI: @@ -4256,7 +4256,7 @@ int RTFDocumentImpl::popState() break; case DESTINATION_LISTENTRY: for (RTFSprms::Iterator_t i = aState.aListLevelEntries.begin(); i != aState.aListLevelEntries.end(); ++i) - aState.aTableSprms.set(i->first, i->second, false); + aState.aTableSprms.set(i->first, i->second, OVERWRITE_NO_APPEND); break; case DESTINATION_FIELDINSTRUCTION: { @@ -4917,7 +4917,7 @@ int RTFDocumentImpl::popState() case DESTINATION_LISTENTRY: { RTFValue::Pointer_t pValue(new RTFValue(aState.aTableAttributes, aState.aTableSprms)); - m_aListTableSprms.set(NS_ooxml::LN_CT_Numbering_abstractNum, pValue, false); + m_aListTableSprms.set(NS_ooxml::LN_CT_Numbering_abstractNum, pValue, OVERWRITE_NO_APPEND); } break; case DESTINATION_PARAGRAPHNUMBERING: @@ -4961,12 +4961,12 @@ int RTFDocumentImpl::popState() RTFSprms aAbstractSprms; aAbstractAttributes.set(NS_ooxml::LN_CT_AbstractNum_abstractNumId, pIdValue); RTFValue::Pointer_t pLevelValue(new RTFValue(aLevelAttributes, aLevelSprms)); - aAbstractSprms.set(NS_ooxml::LN_CT_AbstractNum_lvl, pLevelValue, false); + aAbstractSprms.set(NS_ooxml::LN_CT_AbstractNum_lvl, pLevelValue, OVERWRITE_NO_APPEND); RTFSprms aListTableSprms; RTFValue::Pointer_t pAbstractValue(new RTFValue(aAbstractAttributes, aAbstractSprms)); // It's important that Numbering_abstractNum and Numbering_num never overwrites previous values. - aListTableSprms.set(NS_ooxml::LN_CT_Numbering_abstractNum, pAbstractValue, false); + aListTableSprms.set(NS_ooxml::LN_CT_Numbering_abstractNum, pAbstractValue, OVERWRITE_NO_APPEND); // Numbering RTFSprms aNumberingAttributes; @@ -4974,7 +4974,7 @@ int RTFDocumentImpl::popState() aNumberingAttributes.set(NS_ooxml::LN_CT_AbstractNum_nsid, pIdValue); aNumberingSprms.set(NS_ooxml::LN_CT_Num_abstractNumId, pIdValue); RTFValue::Pointer_t pNumberingValue(new RTFValue(aNumberingAttributes, aNumberingSprms)); - aListTableSprms.set(NS_ooxml::LN_CT_Numbering_num, pNumberingValue, false); + aListTableSprms.set(NS_ooxml::LN_CT_Numbering_num, pNumberingValue, OVERWRITE_NO_APPEND); // Table RTFSprms aListTableAttributes; @@ -5010,7 +5010,7 @@ int RTFDocumentImpl::popState() RTFValue::Pointer_t pValue(new RTFValue(aState.aTableAttributes, aState.aTableSprms)); if (m_aStates.top().nDestinationState != DESTINATION_LFOLEVEL) - m_aStates.top().aListLevelEntries.set(NS_ooxml::LN_CT_AbstractNum_lvl, pValue, false); + m_aStates.top().aListLevelEntries.set(NS_ooxml::LN_CT_AbstractNum_lvl, pValue, OVERWRITE_NO_APPEND); else m_aStates.top().aTableSprms.set(NS_ooxml::LN_CT_NumLvl_lvl, pValue); } @@ -5036,8 +5036,7 @@ int RTFDocumentImpl::popState() { RTFValue::Pointer_t pValue(new RTFValue( aState.aTableAttributes, aState.aTableSprms)); - m_aListTableSprms.set(NS_ooxml::LN_CT_Numbering_num, - pValue, false); + m_aListTableSprms.set(NS_ooxml::LN_CT_Numbering_num, pValue, OVERWRITE_NO_APPEND); } } break; @@ -5090,7 +5089,7 @@ int RTFDocumentImpl::popState() // Dummy value, real picture is already sent to dmapper. aSprms.set(NS_ooxml::LN_CT_NumPicBullet_pict, RTFValue::Pointer_t(new RTFValue(0))); RTFValue::Pointer_t pValue(new RTFValue(aAttributes, aSprms)); - m_aListTableSprms.set(NS_ooxml::LN_CT_Numbering_numPicBullet, pValue, false); + m_aListTableSprms.set(NS_ooxml::LN_CT_Numbering_numPicBullet, pValue, OVERWRITE_NO_APPEND); } break; case DESTINATION_TITLE: diff --git a/writerfilter/source/rtftok/rtfsprm.cxx b/writerfilter/source/rtftok/rtfsprm.cxx index e7943912672f..776aa6eeb7c2 100644 --- a/writerfilter/source/rtftok/rtfsprm.cxx +++ b/writerfilter/source/rtftok/rtfsprm.cxx @@ -89,16 +89,16 @@ RTFValue::Pointer_t RTFSprms::find(Id nKeyword, bool bFirst) return pValue; } -void RTFSprms::set(Id nKeyword, RTFValue::Pointer_t pValue, bool bOverwrite, bool bAppend) +void RTFSprms::set(Id nKeyword, RTFValue::Pointer_t pValue, RTFOverwrite eOverwrite) { ensureCopyBeforeWrite(); bool bFound = false; - if (bOverwrite || !bAppend) + if (eOverwrite == OVERWRITE_YES || eOverwrite == OVERWRITE_NO_IGNORE) { for (RTFSprms::Iterator_t i = m_pSprms->begin(); i != m_pSprms->end(); ++i) if (i->first == nKeyword) { - if (bOverwrite) + if (eOverwrite == OVERWRITE_YES) { i->second = pValue; return; @@ -110,7 +110,7 @@ void RTFSprms::set(Id nKeyword, RTFValue::Pointer_t pValue, bool bOverwrite, boo } } } - if (bAppend || !bFound) + if (eOverwrite == OVERWRITE_NO_APPEND || !bFound) m_pSprms->push_back(std::make_pair(nKeyword, pValue)); } diff --git a/writerfilter/source/rtftok/rtfsprm.hxx b/writerfilter/source/rtftok/rtfsprm.hxx index 42cbd6b32483..6b25fa45d538 100644 --- a/writerfilter/source/rtftok/rtfsprm.hxx +++ b/writerfilter/source/rtftok/rtfsprm.hxx @@ -43,6 +43,13 @@ namespace writerfilter { delete p; } + enum RTFOverwrite + { + OVERWRITE_YES, ///< Yes, if an existing key is found, overwrite it. + OVERWRITE_NO_APPEND, ///< No, always append the value to the end of the list. + OVERWRITE_NO_IGNORE ///< No, if the key is already in the list, then ignore, otherwise append. + }; + /// A list of RTFSprm with a copy constructor that performs a deep copy. class RTFSprms { @@ -55,13 +62,8 @@ namespace writerfilter { ~RTFSprms(); RTFSprms& operator=(const RTFSprms& rOther); RTFValue::Pointer_t find(Id nKeyword, bool bFirst = true); - /** - * Does the same as ->push_back(), except that it can overwrite existing entries. - * - * @param bOverwrite if existing element should be overwritten or appended. - * @param bAppend if not overwriting, then append or NOP. - */ - void set(Id nKeyword, RTFValue::Pointer_t pValue, bool bOverwrite = true, bool bAppend = true); + /// Does the same as ->push_back(), except that it can overwrite or ignore existing entries. + void set(Id nKeyword, RTFValue::Pointer_t pValue, RTFOverwrite eOverwrite = OVERWRITE_YES); bool erase(Id nKeyword); /// Removes elements, which are already in the reference set. void deduplicate(RTFSprms& rReference); |