diff options
author | Bjoern Michaelsen <bjoern.michaelsen@canonical.com> | 2016-03-13 14:40:53 +0100 |
---|---|---|
committer | Bjoern Michaelsen <bjoern.michaelsen@canonical.com> | 2016-03-17 23:54:43 +0100 |
commit | 34bad3a7241946d364114dce97f8efe3cb251dc4 (patch) | |
tree | db6e6222f85e6a7ec5d8bc25a81565e3d85355ff | |
parent | refactor out to limit scope: RES_BACKGROUND, OWN_ATTR_FILLBMP_MODE, default (diff) | |
download | core-34bad3a7241946d364114dce97f8efe3cb251dc4.tar.gz core-34bad3a7241946d364114dce97f8efe3cb251dc4.zip |
use dynamic dispatch table
Change-Id: I087947aac261d905f547914bda605ce11df5dfa2
-rw-r--r-- | sw/source/core/unocore/unostyle.cxx | 86 |
1 files changed, 28 insertions, 58 deletions
diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx index 85b7d83654b1..bda235b41a66 100644 --- a/sw/source/core/unocore/unostyle.cxx +++ b/sw/source/core/unocore/unostyle.cxx @@ -1959,6 +1959,9 @@ SfxStyleSheetBase* SwXStyle::GetStyleSheetBase() return pBase; } template<> +uno::Any SwXStyle::GetStyleProperty<HINT_BEGIN>(const SfxItemPropertySimpleEntry& rEntry, const SfxItemPropertySet& rPropSet, SwStyleBase_Impl& rBase) + throw(uno::RuntimeException, std::exception); +template<> uno::Any SwXStyle::GetStyleProperty<FN_UNO_IS_PHYSICAL>(const SfxItemPropertySimpleEntry&, const SfxItemPropertySet&, SwStyleBase_Impl&) throw(uno::RuntimeException, std::exception) { @@ -2035,12 +2038,12 @@ uno::Any SwXStyle::GetStyleProperty<FN_UNO_FOLLOW_STYLE>(const SfxItemPropertySi return uno::makeAny(aString); } template<> -uno::Any SwXStyle::GetStyleProperty<RES_PAGEDESC>(const SfxItemPropertySimpleEntry& rEntry, const SfxItemPropertySet&, SwStyleBase_Impl& rBase) +uno::Any SwXStyle::GetStyleProperty<RES_PAGEDESC>(const SfxItemPropertySimpleEntry& rEntry, const SfxItemPropertySet& rPropSet, SwStyleBase_Impl& rBase) throw(uno::RuntimeException, std::exception) { const sal_uInt8 nMemberId(rEntry.nMemberId & (~SFX_METRIC_ITEM)); if(MID_PAGEDESC_PAGEDESCNAME != nMemberId) - return uno::Any(); + return GetStyleProperty<HINT_BEGIN>(rEntry, rPropSet, rBase); // special handling for RES_PAGEDESC const SfxPoolItem* pItem; if(SfxItemState::SET != rBase.GetItemSet().GetItemState(RES_PAGEDESC, true, &pItem)) @@ -2216,64 +2219,31 @@ uno::Any SwXStyle::lcl_GetStyleProperty(const SfxItemPropertySimpleEntry& rEntry rBase.setNewBase(new SwDocStyleSheet( *static_cast<SwDocStyleSheet*>(pBase) )); } - - switch(rEntry.nWID) + using propertytype_t = decltype(rEntry.nWID); + using coresetter_t = std::function<uno::Any(SwXStyle&, const SfxItemPropertySimpleEntry&, const SfxItemPropertySet&, SwStyleBase_Impl&)>; + static std::unique_ptr<std::map<propertytype_t, coresetter_t>> pUnoToCore; + if(!pUnoToCore) { - case RES_PAPER_BIN: - { - return GetStyleProperty<RES_PAPER_BIN>(rEntry, rPropSet, rBase); - } - case FN_UNO_NUM_RULES: // special handling for a SvxNumRuleItem: - { - return GetStyleProperty<FN_UNO_NUM_RULES>(rEntry, rPropSet, rBase); - } - case RES_PARATR_OUTLINELEVEL: - { - return GetStyleProperty<RES_PARATR_OUTLINELEVEL>(rEntry, rPropSet, rBase); - } - case FN_UNO_FOLLOW_STYLE: - { - return GetStyleProperty<FN_UNO_FOLLOW_STYLE>(rEntry, rPropSet, rBase); - } - case RES_PAGEDESC: - { - //UUUU - const sal_uInt8 nMemberId(rEntry.nMemberId & (~SFX_METRIC_ITEM)); - if (MID_PAGEDESC_PAGEDESCNAME != nMemberId) - return GetStyleProperty<HINT_BEGIN>(rEntry, rPropSet, rBase); - return GetStyleProperty<RES_PAGEDESC>(rEntry, rPropSet, rBase); - } - case FN_UNO_IS_AUTO_UPDATE: - { - return GetStyleProperty<FN_UNO_IS_AUTO_UPDATE>(rEntry, rPropSet, rBase); - } - case FN_UNO_DISPLAY_NAME: - { - return GetStyleProperty<FN_UNO_DISPLAY_NAME>(rEntry, rPropSet, rBase); - } - case FN_UNO_PARA_STYLE_CONDITIONS: - { - return GetStyleProperty<FN_UNO_PARA_STYLE_CONDITIONS>(rEntry, rPropSet, rBase); - } - case FN_UNO_CATEGORY: - { - return GetStyleProperty<FN_UNO_CATEGORY>(rEntry, rPropSet, rBase); - } - case SID_SWREGISTER_COLLECTION: - { - return GetStyleProperty<SID_SWREGISTER_COLLECTION>(rEntry, rPropSet, rBase); - } - case RES_BACKGROUND: - { - return GetStyleProperty<RES_BACKGROUND>(rEntry, rPropSet, rBase); - } - case OWN_ATTR_FILLBMP_MODE: - { - return GetStyleProperty<OWN_ATTR_FILLBMP_MODE>(rEntry, rPropSet, rBase); - } - default: - return GetStyleProperty<HINT_BEGIN>(rEntry, rPropSet, rBase); + pUnoToCore.reset(new std::map<propertytype_t, coresetter_t> { + // these explicit std::mem_fn() calls shouldn't be needed, but apparently MSVC is currently too stupid for C++11 again + { RES_PAPER_BIN, std::mem_fn(&SwXStyle::GetStyleProperty<RES_PAPER_BIN>) }, + { FN_UNO_NUM_RULES, std::mem_fn(&SwXStyle::GetStyleProperty<FN_UNO_NUM_RULES>) }, + { RES_PARATR_OUTLINELEVEL, std::mem_fn(&SwXStyle::GetStyleProperty<RES_PARATR_OUTLINELEVEL>) }, + { FN_UNO_FOLLOW_STYLE, std::mem_fn(&SwXStyle::GetStyleProperty<FN_UNO_FOLLOW_STYLE>) }, + { RES_PAGEDESC, std::mem_fn(&SwXStyle::GetStyleProperty<RES_PAGEDESC>) }, + { FN_UNO_IS_AUTO_UPDATE, std::mem_fn(&SwXStyle::GetStyleProperty<FN_UNO_IS_AUTO_UPDATE>) }, + { FN_UNO_DISPLAY_NAME, std::mem_fn(&SwXStyle::GetStyleProperty<FN_UNO_DISPLAY_NAME>) }, + { FN_UNO_PARA_STYLE_CONDITIONS, std::mem_fn(&SwXStyle::GetStyleProperty<FN_UNO_PARA_STYLE_CONDITIONS>) }, + { FN_UNO_CATEGORY, std::mem_fn(&SwXStyle::GetStyleProperty<FN_UNO_CATEGORY>) }, + { SID_SWREGISTER_COLLECTION, std::mem_fn(&SwXStyle::GetStyleProperty<SID_SWREGISTER_COLLECTION>) }, + { RES_BACKGROUND, std::mem_fn(&SwXStyle::GetStyleProperty<RES_BACKGROUND>) }, + { OWN_ATTR_FILLBMP_MODE, std::mem_fn(&SwXStyle::GetStyleProperty<OWN_ATTR_FILLBMP_MODE>) } + }); } + const auto pUnoToCoreIt(pUnoToCore->find(rEntry.nWID)); + if(pUnoToCoreIt != pUnoToCore->end()) + return pUnoToCoreIt->second(*this, rEntry, rPropSet, rBase); + return GetStyleProperty<HINT_BEGIN>(rEntry, rPropSet, rBase); } uno::Sequence< uno::Any > SAL_CALL SwXStyle::GetPropertyValues_Impl( |