[Libreoffice-commits] core.git: Branch 'feature/fixstyles3' - sw/source

Bjoern Michaelsen bjoern.michaelsen at canonical.com
Fri Jan 15 16:57:00 PST 2016


Rebased ref, commits from common ancestor:
commit 7bcc1c9206b0877151e9a3b4f59b320f4f90d97e
Author: Bjoern Michaelsen <bjoern.michaelsen at canonical.com>
Date:   Thu Jan 14 22:28:52 2016 +0100

    use a map for dispatch
    
    Change-Id: I29c88c834a01f8d04a2998ea3edfa95cd0cadb85

diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx
index 50ca5ae..04ecf9e 100644
--- a/sw/source/core/unocore/unostyle.cxx
+++ b/sw/source/core/unocore/unostyle.cxx
@@ -1812,72 +1812,48 @@ void SwXStyle::SetPropertyValue<RES_PARATR_NUMRULE>(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<void(SwXStyle&, const SfxItemPropertySimpleEntry&, const SfxItemPropertySet&, const uno::Any&, SwStyleBase_Impl&)>;
+    static std::unique_ptr<std::map<propertytype_t, coresetter_t>> pUnoToCore;
+    if(!pUnoToCore)
     {
-        case FN_UNO_HIDDEN:
-            SetPropertyValue<FN_UNO_HIDDEN>(rEntry, rPropSet, rValue, rBase);
-            break;
-        case FN_UNO_STYLE_INTEROP_GRAB_BAG:
-            SetPropertyValue<FN_UNO_STYLE_INTEROP_GRAB_BAG>(rEntry, rPropSet, rValue, rBase);
-            break;
-        case XATTR_FILLGRADIENT:
-        case XATTR_FILLHATCH:
-        case XATTR_FILLBITMAP:
-        case XATTR_FILLFLOATTRANSPARENCE:
-            SetPropertyValue<XATTR_FILLGRADIENT>(rEntry, rPropSet, rValue, rBase);
-            break;
-        case RES_BACKGROUND:
-            SetPropertyValue<RES_BACKGROUND>(rEntry, rPropSet, rValue, rBase);
-            break;
-        case OWN_ATTR_FILLBMP_MODE:
-            SetPropertyValue<OWN_ATTR_FILLBMP_MODE>(rEntry, rPropSet, rValue, rBase);
-            break;
-        case RES_PAPER_BIN:
-            SetPropertyValue<RES_PAPER_BIN>(rEntry, rPropSet, rValue, rBase);
-            break;
-        case FN_UNO_NUM_RULES: // special handling for a SvxNumRuleItem:
-            SetPropertyValue<FN_UNO_NUM_RULES>(rEntry, rPropSet, rValue, rBase);
-            break;
-        case RES_PARATR_OUTLINELEVEL:
-            SetPropertyValue<RES_PARATR_OUTLINELEVEL>(rEntry, rPropSet, rValue, rBase);
-            break;
-        case FN_UNO_FOLLOW_STYLE:
-            SetPropertyValue<FN_UNO_FOLLOW_STYLE>(rEntry, rPropSet, rValue, rBase);
-            break;
-        case RES_PAGEDESC:
-            SetPropertyValue<RES_PAGEDESC>(rEntry, rPropSet, rValue, rBase);
-            break;
-        case RES_TEXT_VERT_ADJUST:
-            SetPropertyValue<RES_TEXT_VERT_ADJUST>(rEntry, rPropSet, rValue, rBase);
-            break;
-        case FN_UNO_IS_AUTO_UPDATE:
-            SetPropertyValue<FN_UNO_IS_AUTO_UPDATE>(rEntry, rPropSet, rValue, rBase);
-            break;
-        case FN_UNO_PARA_STYLE_CONDITIONS:
-            SetPropertyValue<FN_UNO_PARA_STYLE_CONDITIONS>(rEntry, rPropSet, rValue, rBase);
-            break;
-        case FN_UNO_CATEGORY:
-            SetPropertyValue<FN_UNO_CATEGORY>(rEntry, rPropSet, rValue, rBase);
-            break;
-        case SID_SWREGISTER_COLLECTION:
-            SetPropertyValue<SID_SWREGISTER_COLLECTION>(rEntry, rPropSet, rValue, rBase);
-            break;
-        case RES_TXTATR_CJK_RUBY:
-            SetPropertyValue<RES_TXTATR_CJK_RUBY>(rEntry, rPropSet, rValue, rBase);
-            break;
-        case RES_PARATR_DROP:
-            SetPropertyValue<RES_PARATR_DROP>(rEntry, rPropSet, rValue, rBase);
-            break;
-        case RES_PARATR_NUMRULE:
-            SetPropertyValue<RES_PARATR_NUMRULE>(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;
+        std::function<void(SwXStyle&, const SfxItemPropertySimpleEntry&, const SfxItemPropertySet&, const uno::Any&, SwStyleBase_Impl&)> func = &SwXStyle::SetPropertyValue<FN_UNO_HIDDEN>; // lets see wtf MSVC complains about
+        pUnoToCore.reset(new std::map<propertytype_t, coresetter_t> {
+            // these explicit make_pair constructions shouldnt be needed, but apparently MSVC is currently too stupid for C++11 again
+            std::make_pair<propertytype_t, coresetter_t>( FN_UNO_HIDDEN,                 &SwXStyle::SetPropertyValue<FN_UNO_HIDDEN>                 ),
+            std::make_pair<propertytype_t, coresetter_t>( FN_UNO_STYLE_INTEROP_GRAB_BAG, &SwXStyle::SetPropertyValue<FN_UNO_STYLE_INTEROP_GRAB_BAG> ),
+            std::make_pair<propertytype_t, coresetter_t>( XATTR_FILLGRADIENT,            &SwXStyle::SetPropertyValue<XATTR_FILLGRADIENT>            ),
+            std::make_pair<propertytype_t, coresetter_t>( XATTR_FILLHATCH,               &SwXStyle::SetPropertyValue<XATTR_FILLGRADIENT>            ),
+            std::make_pair<propertytype_t, coresetter_t>( XATTR_FILLBITMAP,              &SwXStyle::SetPropertyValue<XATTR_FILLGRADIENT>            ),
+            std::make_pair<propertytype_t, coresetter_t>( XATTR_FILLFLOATTRANSPARENCE,   &SwXStyle::SetPropertyValue<XATTR_FILLGRADIENT>            ),
+            std::make_pair<propertytype_t, coresetter_t>( RES_BACKGROUND,                &SwXStyle::SetPropertyValue<RES_BACKGROUND>                ),
+            std::make_pair<propertytype_t, coresetter_t>( OWN_ATTR_FILLBMP_MODE,         &SwXStyle::SetPropertyValue<OWN_ATTR_FILLBMP_MODE>         ),
+            std::make_pair<propertytype_t, coresetter_t>( RES_PAPER_BIN,                 &SwXStyle::SetPropertyValue<RES_PAPER_BIN>                 ),
+            std::make_pair<propertytype_t, coresetter_t>( FN_UNO_NUM_RULES,              &SwXStyle::SetPropertyValue<FN_UNO_NUM_RULES>              ),
+            std::make_pair<propertytype_t, coresetter_t>( RES_PARATR_OUTLINELEVEL,       &SwXStyle::SetPropertyValue<RES_PARATR_OUTLINELEVEL>       ),
+            std::make_pair<propertytype_t, coresetter_t>( FN_UNO_FOLLOW_STYLE,           &SwXStyle::SetPropertyValue<FN_UNO_FOLLOW_STYLE>           ),
+            std::make_pair<propertytype_t, coresetter_t>( RES_PAGEDESC,                  &SwXStyle::SetPropertyValue<RES_PAGEDESC>                  ),
+            std::make_pair<propertytype_t, coresetter_t>( RES_TEXT_VERT_ADJUST,          &SwXStyle::SetPropertyValue<RES_TEXT_VERT_ADJUST>          ),
+            std::make_pair<propertytype_t, coresetter_t>( FN_UNO_IS_AUTO_UPDATE,         &SwXStyle::SetPropertyValue<FN_UNO_IS_AUTO_UPDATE>         ),
+            std::make_pair<propertytype_t, coresetter_t>( FN_UNO_PARA_STYLE_CONDITIONS,  &SwXStyle::SetPropertyValue<FN_UNO_PARA_STYLE_CONDITIONS>  ),
+            std::make_pair<propertytype_t, coresetter_t>( FN_UNO_CATEGORY,               &SwXStyle::SetPropertyValue<FN_UNO_CATEGORY>               ),
+            std::make_pair<propertytype_t, coresetter_t>( SID_SWREGISTER_COLLECTION,     &SwXStyle::SetPropertyValue<SID_SWREGISTER_COLLECTION>     ),
+            std::make_pair<propertytype_t, coresetter_t>( RES_TXTATR_CJK_RUBY,           &SwXStyle::SetPropertyValue<RES_TXTATR_CJK_RUBY>           ),
+            std::make_pair<propertytype_t, coresetter_t>( RES_PARATR_DROP,               &SwXStyle::SetPropertyValue<RES_PARATR_DROP>               ),
+            std::make_pair<propertytype_t, coresetter_t>( RES_PARATR_DROP,               &SwXStyle::SetPropertyValue<RES_PARATR_DROP>               ),
+            std::make_pair<propertytype_t, coresetter_t>( RES_PARATR_NUMRULE,            &SwXStyle::SetPropertyValue<RES_PARATR_NUMRULE>            )
+        });
+    }
+    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);
     }
 }
 


More information about the Libreoffice-commits mailing list