From 30e012000aa2005110233334325ff1bda5d6b20c Mon Sep 17 00:00:00 2001 From: Bjoern Michaelsen Date: Thu, 14 Jan 2016 22:28:52 +0100 Subject: use a map for dispatch Change-Id: I29c88c834a01f8d04a2998ea3edfa95cd0cadb85 --- sw/source/core/unocore/unostyle.cxx | 105 ++++++++++++++---------------------- 1 file changed, 40 insertions(+), 65 deletions(-) diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx index 50ca5aefc0b8..f18f9ef29fb8 100644 --- a/sw/source/core/unocore/unostyle.cxx +++ b/sw/source/core/unocore/unostyle.cxx @@ -1812,72 +1812,47 @@ void SwXStyle::SetPropertyValue(const SfxItemPropertySimpleE void SwXStyle::SetStyleProperty(const SfxItemPropertySimpleEntry& rEntry, const SfxItemPropertySet& rPropSet, const uno::Any& rValue, SwStyleBase_Impl& rBase) throw(beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException, std::exception) { - switch(rEntry.nWID) + using propertytype_t = decltype(rEntry.nWID); + using coresetter_t = std::function; + static std::unique_ptr> pUnoToCore; + if(!pUnoToCore) { - case FN_UNO_HIDDEN: - SetPropertyValue(rEntry, rPropSet, rValue, rBase); - break; - case FN_UNO_STYLE_INTEROP_GRAB_BAG: - SetPropertyValue(rEntry, rPropSet, rValue, rBase); - break; - case XATTR_FILLGRADIENT: - case XATTR_FILLHATCH: - case XATTR_FILLBITMAP: - case XATTR_FILLFLOATTRANSPARENCE: - SetPropertyValue(rEntry, rPropSet, rValue, rBase); - break; - case RES_BACKGROUND: - SetPropertyValue(rEntry, rPropSet, rValue, rBase); - break; - case OWN_ATTR_FILLBMP_MODE: - SetPropertyValue(rEntry, rPropSet, rValue, rBase); - break; - case RES_PAPER_BIN: - SetPropertyValue(rEntry, rPropSet, rValue, rBase); - break; - case FN_UNO_NUM_RULES: // special handling for a SvxNumRuleItem: - SetPropertyValue(rEntry, rPropSet, rValue, rBase); - break; - case RES_PARATR_OUTLINELEVEL: - SetPropertyValue(rEntry, rPropSet, rValue, rBase); - break; - case FN_UNO_FOLLOW_STYLE: - SetPropertyValue(rEntry, rPropSet, rValue, rBase); - break; - case RES_PAGEDESC: - SetPropertyValue(rEntry, rPropSet, rValue, rBase); - break; - case RES_TEXT_VERT_ADJUST: - SetPropertyValue(rEntry, rPropSet, rValue, rBase); - break; - case FN_UNO_IS_AUTO_UPDATE: - SetPropertyValue(rEntry, rPropSet, rValue, rBase); - break; - case FN_UNO_PARA_STYLE_CONDITIONS: - SetPropertyValue(rEntry, rPropSet, rValue, rBase); - break; - case FN_UNO_CATEGORY: - SetPropertyValue(rEntry, rPropSet, rValue, rBase); - break; - case SID_SWREGISTER_COLLECTION: - SetPropertyValue(rEntry, rPropSet, rValue, rBase); - break; - case RES_TXTATR_CJK_RUBY: - SetPropertyValue(rEntry, rPropSet, rValue, rBase); - break; - case RES_PARATR_DROP: - SetPropertyValue(rEntry, rPropSet, rValue, rBase); - break; - case RES_PARATR_NUMRULE: - SetPropertyValue(rEntry, rPropSet, rValue, rBase); - break; - default: - //UUUU adapted switch logic to a more readable state; removed goto's and made - // execution of standard setting of proerty in ItemSet dependent of this variable - uno::Any aValue(rValue); - lcl_TranslateMetric(rEntry, m_pDoc, aValue); - lcl_SetDefaultWay(rEntry, rPropSet, aValue, rBase); - break; + pUnoToCore.reset(new std::map { + // these explicit std::mem_fn() calls shouldnt be needed, but apparently MSVC is currently too stupid for C++11 again + { FN_UNO_HIDDEN, std::mem_fn(&SwXStyle::SetPropertyValue) }, + { FN_UNO_STYLE_INTEROP_GRAB_BAG, std::mem_fn(&SwXStyle::SetPropertyValue) }, + { XATTR_FILLGRADIENT, std::mem_fn(&SwXStyle::SetPropertyValue) }, + { XATTR_FILLHATCH, std::mem_fn(&SwXStyle::SetPropertyValue) }, + { XATTR_FILLBITMAP, std::mem_fn(&SwXStyle::SetPropertyValue) }, + { XATTR_FILLFLOATTRANSPARENCE, std::mem_fn(&SwXStyle::SetPropertyValue) }, + { RES_BACKGROUND, std::mem_fn(&SwXStyle::SetPropertyValue) }, + { OWN_ATTR_FILLBMP_MODE, std::mem_fn(&SwXStyle::SetPropertyValue) }, + { RES_PAPER_BIN, std::mem_fn(&SwXStyle::SetPropertyValue) }, + { FN_UNO_NUM_RULES, std::mem_fn(&SwXStyle::SetPropertyValue) }, + { RES_PARATR_OUTLINELEVEL, std::mem_fn(&SwXStyle::SetPropertyValue) }, + { FN_UNO_FOLLOW_STYLE, std::mem_fn(&SwXStyle::SetPropertyValue) }, + { RES_PAGEDESC, std::mem_fn(&SwXStyle::SetPropertyValue) }, + { RES_TEXT_VERT_ADJUST, std::mem_fn(&SwXStyle::SetPropertyValue) }, + { FN_UNO_IS_AUTO_UPDATE, std::mem_fn(&SwXStyle::SetPropertyValue) }, + { FN_UNO_PARA_STYLE_CONDITIONS, std::mem_fn(&SwXStyle::SetPropertyValue) }, + { FN_UNO_CATEGORY, std::mem_fn(&SwXStyle::SetPropertyValue) }, + { SID_SWREGISTER_COLLECTION, std::mem_fn(&SwXStyle::SetPropertyValue) }, + { RES_TXTATR_CJK_RUBY, std::mem_fn(&SwXStyle::SetPropertyValue) }, + { RES_PARATR_DROP, std::mem_fn(&SwXStyle::SetPropertyValue) }, + { RES_PARATR_DROP, std::mem_fn(&SwXStyle::SetPropertyValue) }, + { RES_PARATR_NUMRULE, std::mem_fn(&SwXStyle::SetPropertyValue) } + }); + } + const auto pUnoToCoreIt(pUnoToCore->find(rEntry.nWID)); + if(pUnoToCoreIt != pUnoToCore->end()) + pUnoToCoreIt->second(*this, rEntry, rPropSet, rValue, rBase); + else + { + //UUUU adapted switch logic to a more readable state; removed goto's and made + // execution of standard setting of proerty in ItemSet dependent of this variable + uno::Any aValue(rValue); + lcl_TranslateMetric(rEntry, m_pDoc, aValue); + lcl_SetDefaultWay(rEntry, rPropSet, aValue, rBase); } } -- cgit v1.2.3