[Libreoffice-commits] core.git: 8 commits - sw/inc sw/source

Bjoern Michaelsen bjoern.michaelsen at canonical.com
Fri Nov 27 09:02:25 PST 2015


 sw/inc/shellio.hxx                  |   44 +---
 sw/inc/unostyle.hxx                 |    6 
 sw/source/core/unocore/unostyle.cxx |  332 +++++++++++-------------------------
 3 files changed, 128 insertions(+), 254 deletions(-)

New commits:
commit 08bd772ce46a2e31019058bcd991580338093c65
Author: Bjoern Michaelsen <bjoern.michaelsen at canonical.com>
Date:   Fri Nov 27 17:34:48 2015 +0100

    type punning is all fun, but lets only use it when its really needed
    
    Change-Id: Id6726d85f8f99020b7d13d7dc15448379249b2fa

diff --git a/sw/inc/shellio.hxx b/sw/inc/shellio.hxx
index a234095..cd05f4e 100644
--- a/sw/inc/shellio.hxx
+++ b/sw/inc/shellio.hxx
@@ -104,44 +104,36 @@ typedef Reader *SwRead;
 class SwgReaderOption
 {
     SwAsciiOptions aASCIIOpts;
-    union
-    {
-        bool bFormatsOnly;
-        struct
-        {
-            bool bFrameFormats: 1;
-            bool bPageDescs: 1;
-            bool bTextFormats: 1;
-            bool bNumRules: 1;
-            bool bMerge:1;
-        }  Formats;
-    } What;
-
+    bool m_bFrameFormats;
+    bool m_bPageDescs;
+    bool m_bTextFormats;
+    bool m_bNumRules;
+    bool m_bMerge;
 public:
-    void ResetAllFormatsOnly() { What.bFormatsOnly = false; }
-    bool IsFormatsOnly() const { return What.bFormatsOnly; }
+    void ResetAllFormatsOnly() { m_bFrameFormats = m_bPageDescs = m_bTextFormats = m_bNumRules = m_bMerge = false; }
+    bool IsFormatsOnly() const { return m_bFrameFormats || m_bPageDescs || m_bTextFormats || m_bNumRules || m_bMerge; }
 
-    bool IsFrameFormats() const { return What.Formats.bFrameFormats; }
-    void SetFrameFormats( const bool bNew) { What.Formats.bFrameFormats = bNew; }
+    bool IsFrameFormats() const { return m_bFrameFormats; }
+    void SetFrameFormats( const bool bNew) { m_bFrameFormats = bNew; }
 
-    bool IsPageDescs() const { return What.Formats.bPageDescs; }
-    void SetPageDescs( const bool bNew) { What.Formats.bPageDescs = bNew; }
+    bool IsPageDescs() const { return m_bPageDescs; }
+    void SetPageDescs( const bool bNew) { m_bPageDescs = bNew; }
 
-    bool IsTextFormats() const { return What.Formats.bTextFormats; }
-    void SetTextFormats( const bool bNew) { What.Formats.bTextFormats = bNew; }
+    bool IsTextFormats() const { return m_bTextFormats; }
+    void SetTextFormats( const bool bNew) { m_bTextFormats = bNew; }
 
-    bool IsNumRules() const { return What.Formats.bNumRules; }
-    void SetNumRules( const bool bNew) { What.Formats.bNumRules = bNew; }
+    bool IsNumRules() const { return m_bNumRules; }
+    void SetNumRules( const bool bNew) { m_bNumRules = bNew; }
 
-    bool IsMerge() const { return What.Formats.bMerge; }
-    void SetMerge( const bool bNew ) { What.Formats.bMerge = bNew; }
+    bool IsMerge() const { return m_bMerge; }
+    void SetMerge( const bool bNew ) { m_bMerge = bNew; }
 
     const SwAsciiOptions& GetASCIIOpts() const { return aASCIIOpts; }
     void SetASCIIOpts( const SwAsciiOptions& rOpts ) { aASCIIOpts = rOpts; }
     void ResetASCIIOpts() { aASCIIOpts.Reset(); }
 
     SwgReaderOption()
-    {   ResetAllFormatsOnly(); aASCIIOpts.Reset(); }
+        { ResetAllFormatsOnly(); aASCIIOpts.Reset(); }
 };
 
 class SW_DLLPUBLIC SwReader: public SwDocFac
commit 08fdc4f365e84bcb7fa22a96b0399d4c2e902e28
Author: Bjoern Michaelsen <bjoern.michaelsen at canonical.com>
Date:   Fri Nov 27 14:20:33 2015 +0100

    simplify options here
    
    Change-Id: I9faa4ea8aec6ecd439751323b76bf2d8b071e4ac

diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx
index 9aca6e1..814138b 100644
--- a/sw/source/core/unocore/unostyle.cxx
+++ b/sw/source/core/unocore/unostyle.cxx
@@ -212,49 +212,33 @@ void SwXStyleFamilies::loadStylesFromURL(const OUString& rURL,
            std::exception)
 {
     SolarMutexGuard aGuard;
-    if(IsValid() && !rURL.isEmpty())
+    if(!IsValid() || rURL.isEmpty())
+        throw uno::RuntimeException();
+    SwgReaderOption aOpt;
+    aOpt.SetFrameFormats(true);
+    aOpt.SetTextFormats(true);
+    aOpt.SetPageDescs(true);
+    aOpt.SetNumRules(true);
+    aOpt.SetMerge(false);
+    for(const auto& rProperty: aOptions)
     {
-        bool    bLoadStyleText = true;
-        bool    bLoadStylePage = true;
-        bool    bLoadStyleOverwrite = true;
-        bool    bLoadStyleNumbering = true;
-        bool    bLoadStyleFrame = true;
-
-        int nCount = aOptions.getLength();
-        const beans::PropertyValue* pArray = aOptions.getConstArray();
-        for(int i = 0; i < nCount; i++)
-        {
-            const uno::Any* pVal = &pArray[i].Value;
-            if( pVal->getValueType() == cppu::UnoType<bool>::get() )
-            {
-                const OUString sName = pArray[i].Name;
-                bool bVal = *static_cast<sal_Bool const *>(pVal->getValue());
-                if( sName == UNO_NAME_OVERWRITE_STYLES )
-                    bLoadStyleOverwrite = bVal;
-                else if( sName == UNO_NAME_LOAD_NUMBERING_STYLES )
-                    bLoadStyleNumbering = bVal;
-                else if( sName == UNO_NAME_LOAD_PAGE_STYLES )
-                    bLoadStylePage = bVal;
-                else if( sName == UNO_NAME_LOAD_FRAME_STYLES )
-                    bLoadStyleFrame = bVal;
-                else if( sName == UNO_NAME_LOAD_TEXT_STYLES )
-                    bLoadStyleText = bVal;
-            }
-        }
-
-        SwgReaderOption aOpt;
-        aOpt.SetFrameFormats( bLoadStyleFrame );
-        aOpt.SetTextFormats( bLoadStyleText );
-        aOpt.SetPageDescs( bLoadStylePage );
-        aOpt.SetNumRules( bLoadStyleNumbering );
-        aOpt.SetMerge( !bLoadStyleOverwrite );
-
-        sal_uLong nErr = m_pDocShell->LoadStylesFromFile( rURL, aOpt, true );
-        if( nErr )
-            throw io::IOException();
+        if(rProperty.Value.getValueType() != cppu::UnoType<bool>::get())
+            continue;
+        const bool bValue = rProperty.Value.get<bool>();
+        if(rProperty.Name == UNO_NAME_OVERWRITE_STYLES)
+            aOpt.SetMerge(!bValue);
+        else if(rProperty.Name == UNO_NAME_LOAD_NUMBERING_STYLES)
+            aOpt.SetNumRules(bValue);
+        else if(rProperty.Name == UNO_NAME_LOAD_PAGE_STYLES)
+            aOpt.SetPageDescs(bValue);
+        else if(rProperty.Name == UNO_NAME_LOAD_FRAME_STYLES)
+            aOpt.SetFrameFormats(bValue);
+        else if(rProperty.Name == UNO_NAME_LOAD_TEXT_STYLES)
+            aOpt.SetTextFormats(bValue);
     }
-    else
-        throw uno::RuntimeException();
+    const sal_uLong nErr = m_pDocShell->LoadStylesFromFile( rURL, aOpt, true );
+    if(nErr)
+        throw io::IOException();
 }
 
 uno::Sequence< beans::PropertyValue > SwXStyleFamilies::getStyleLoaderOptions()
commit 0168313e95c7c00fb92e30088c8a12353e82c2c2
Author: Bjoern Michaelsen <bjoern.michaelsen at canonical.com>
Date:   Fri Nov 27 13:46:31 2015 +0100

    reorder as we are touching this already
    
    Change-Id: Ie00f27203a28a139de073102428fe9b99db507ea

diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx
index 23dad41..9aca6e1 100644
--- a/sw/source/core/unocore/unostyle.cxx
+++ b/sw/source/core/unocore/unostyle.cxx
@@ -114,15 +114,6 @@ namespace
     };
 }
 
-// Already implemented autostyle families: 3
-#define AUTOSTYLE_FAMILY_COUNT 3
-const IStyleAccess::SwAutoStyleFamily aAutoStyleByIndex[] =
-{
-    IStyleAccess::AUTO_STYLE_CHAR,
-    IStyleAccess::AUTO_STYLE_RUBY,
-    IStyleAccess::AUTO_STYLE_PARA
-};
-
 using namespace ::com::sun::star;
 
 static SwGetPoolIdFromName lcl_GetSwEnumFromSfxEnum(SfxStyleFamily eFamily)
@@ -135,20 +126,6 @@ static SwGetPoolIdFromName lcl_GetSwEnumFromSfxEnum(SfxStyleFamily eFamily)
     return nsSwGetPoolIdFromName::GET_POOLID_CHRFMT;
 }
 
-class SwAutoStylesEnumImpl
-{
-    std::vector<SfxItemSet_Pointer_t> mAutoStyles;
-    std::vector<SfxItemSet_Pointer_t>::iterator aIter;
-    SwDoc* pDoc;
-    IStyleAccess::SwAutoStyleFamily eFamily;
-public:
-    SwAutoStylesEnumImpl( SwDoc* pInitDoc, IStyleAccess::SwAutoStyleFamily eFam );
-    bool hasMoreElements() { return aIter != mAutoStyles.end(); }
-    SfxItemSet_Pointer_t nextElement() { return *(aIter++); }
-    IStyleAccess::SwAutoStyleFamily getFamily() const { return eFamily; }
-    SwDoc* getDoc() const { return pDoc; }
-};
-
 OUString SwXStyleFamilies::getImplementationName() throw( uno::RuntimeException, std::exception )
     { return {"SwXStyleFamilies"}; }
 
@@ -161,15 +138,12 @@ uno::Sequence< OUString > SwXStyleFamilies::getSupportedServiceNames() throw( un
     { return { "com.sun.star.style.StyleFamilies" }; }
 
 SwXStyleFamilies::SwXStyleFamilies(SwDocShell& rDocShell) :
-    SwUnoCollection(rDocShell.GetDoc()),
-    m_pDocShell(&rDocShell)
-{
-
-}
+        SwUnoCollection(rDocShell.GetDoc()),
+        m_pDocShell(&rDocShell)
+    { }
 
 SwXStyleFamilies::~SwXStyleFamilies()
-{
-}
+    { }
 
 uno::Any SAL_CALL SwXStyleFamilies::getByName(const OUString& Name)
     throw(
@@ -227,13 +201,10 @@ uno::Type SwXStyleFamilies::getElementType()
     throw( uno::RuntimeException, std::exception )
 {
     return cppu::UnoType<container::XNameContainer>::get();
-
 }
 
 sal_Bool SwXStyleFamilies::hasElements() throw( uno::RuntimeException, std::exception )
-{
-    return sal_True;
-}
+    { return true; }
 
 void SwXStyleFamilies::loadStylesFromURL(const OUString& rURL,
     const uno::Sequence< beans::PropertyValue >& aOptions)
@@ -312,6 +283,29 @@ sal_Bool SwXStyleFamily::supportsService(const OUString& rServiceName) throw( un
 uno::Sequence< OUString > SwXStyleFamily::getSupportedServiceNames() throw( uno::RuntimeException, std::exception )
     { return { "com.sun.star.style.StyleFamily" }; }
 
+// Already implemented autostyle families: 3
+#define AUTOSTYLE_FAMILY_COUNT 3
+const IStyleAccess::SwAutoStyleFamily aAutoStyleByIndex[] =
+{
+    IStyleAccess::AUTO_STYLE_CHAR,
+    IStyleAccess::AUTO_STYLE_RUBY,
+    IStyleAccess::AUTO_STYLE_PARA
+};
+
+class SwAutoStylesEnumImpl
+{
+    std::vector<SfxItemSet_Pointer_t> mAutoStyles;
+    std::vector<SfxItemSet_Pointer_t>::iterator aIter;
+    SwDoc* pDoc;
+    IStyleAccess::SwAutoStyleFamily eFamily;
+public:
+    SwAutoStylesEnumImpl( SwDoc* pInitDoc, IStyleAccess::SwAutoStyleFamily eFam );
+    bool hasMoreElements() { return aIter != mAutoStyles.end(); }
+    SfxItemSet_Pointer_t nextElement() { return *(aIter++); }
+    IStyleAccess::SwAutoStyleFamily getFamily() const { return eFamily; }
+    SwDoc* getDoc() const { return pDoc; }
+};
+
 SwXStyleFamily::SwXStyleFamily(SwDocShell* pDocSh, sal_uInt16 nFamily) :
         m_eFamily((SfxStyleFamily)nFamily),
         m_pBasePool(pDocSh->GetStyleSheetPool()),
commit fe151f719d33128139f01bed89271c02849336a4
Author: Bjoern Michaelsen <bjoern.michaelsen at canonical.com>
Date:   Fri Nov 27 13:07:09 2015 +0100

    keep containers in a map to simplify things
    
    Change-Id: I20db506fb232c408b7b96e3b1a54da44f342d8bd

diff --git a/sw/inc/unostyle.hxx b/sw/inc/unostyle.hxx
index 8aabdff..7a96fbb 100644
--- a/sw/inc/unostyle.hxx
+++ b/sw/inc/unostyle.hxx
@@ -62,11 +62,7 @@ class SwXStyleFamilies :  public cppu::WeakImplHelper
 {
     SwDocShell*         m_pDocShell;
 
-    css::uno::Reference< css::container::XNameContainer >   m_xCharStyles;
-    css::uno::Reference< css::container::XNameContainer >   m_xParaStyles;
-    css::uno::Reference< css::container::XNameContainer >   m_xFrameStyles;
-    css::uno::Reference< css::container::XNameContainer >   m_xPageStyles;
-    css::uno::Reference< css::container::XNameContainer >   m_xNumberingStyles;
+    std::map<SfxStyleFamily, css::uno::Reference<css::container::XNameContainer>> m_vContainers;
 protected:
     virtual ~SwXStyleFamilies();
 public:
diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx
index b2954c2..23dad41 100644
--- a/sw/source/core/unocore/unostyle.cxx
+++ b/sw/source/core/unocore/unostyle.cxx
@@ -162,12 +162,7 @@ uno::Sequence< OUString > SwXStyleFamilies::getSupportedServiceNames() throw( un
 
 SwXStyleFamilies::SwXStyleFamilies(SwDocShell& rDocShell) :
     SwUnoCollection(rDocShell.GetDoc()),
-    m_pDocShell(&rDocShell),
-    m_xCharStyles(),
-    m_xParaStyles(),
-    m_xFrameStyles(),
-    m_xPageStyles(),
-    m_xNumberingStyles()
+    m_pDocShell(&rDocShell)
 {
 
 }
@@ -216,68 +211,16 @@ uno::Any SwXStyleFamilies::getByIndex(sal_Int32 nIndex)
     throw( lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException, std::exception )
 {
     SolarMutexGuard aGuard;
-    uno::Any aRet;
     if(nIndex < 0 || nIndex >= static_cast<sal_Int32>(our_vStyleFamilyEntries.size()))
         throw lang::IndexOutOfBoundsException();
-    if(IsValid())
-    {
-        uno::Reference< container::XNameContainer >  aRef;
-        auto eFamily = our_vStyleFamilyEntries[nIndex].m_eFamily;
-        switch( eFamily )
-        {
-            case SFX_STYLE_FAMILY_CHAR:
-            {
-                if(!m_xCharStyles.is())
-                {
-                    m_xCharStyles = new SwXStyleFamily(m_pDocShell, eFamily);
-                }
-                aRef = m_xCharStyles;
-            }
-            break;
-            case SFX_STYLE_FAMILY_PARA:
-            {
-                if(!m_xParaStyles.is())
-                {
-                    m_xParaStyles = new SwXStyleFamily(m_pDocShell, eFamily);
-                }
-                aRef = m_xParaStyles;
-            }
-            break;
-            case SFX_STYLE_FAMILY_PAGE:
-            {
-                if(!m_xPageStyles.is())
-                {
-                    m_xPageStyles = new SwXStyleFamily(m_pDocShell, eFamily);
-                }
-                aRef = m_xPageStyles;
-            }
-            break;
-            case SFX_STYLE_FAMILY_FRAME:
-            {
-                if(!m_xFrameStyles.is())
-                {
-                    m_xFrameStyles = new SwXStyleFamily(m_pDocShell, eFamily);
-                }
-                aRef = m_xFrameStyles;
-            }
-            break;
-            case SFX_STYLE_FAMILY_PSEUDO:
-            {
-                if(!m_xNumberingStyles.is())
-                {
-                    m_xNumberingStyles = new SwXStyleFamily(m_pDocShell, eFamily);
-                }
-                aRef = m_xNumberingStyles;
-            }
-            break;
-            case SFX_STYLE_FAMILY_ALL:
-                assert(false);
-        }
-        aRet.setValue(&aRef, cppu::UnoType<container::XNameContainer>::get());
-    }
-    else
+    if(!IsValid())
         throw uno::RuntimeException();
-    return aRet;
+    auto eFamily = our_vStyleFamilyEntries[nIndex].m_eFamily;
+    assert(eFamily != SFX_STYLE_FAMILY_ALL);
+    auto& rxContainer = m_vContainers[eFamily];
+    if(!rxContainer.is())
+        rxContainer = new SwXStyleFamily(m_pDocShell, eFamily);
+    return uno::makeAny(rxContainer);
 }
 
 uno::Type SwXStyleFamilies::getElementType()
commit 1e44f3d60ebe3e31e2b4075c1a10dc6a6f2db449
Author: Bjoern Michaelsen <bjoern.michaelsen at canonical.com>
Date:   Fri Nov 27 13:06:34 2015 +0100

    make ResId another member of entries table
    
    Change-Id: I80e1047e43e6871520f004ec0f68f96d5a742115

diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx
index 62f2ac7..b2954c2 100644
--- a/sw/source/core/unocore/unostyle.cxx
+++ b/sw/source/core/unocore/unostyle.cxx
@@ -97,18 +97,20 @@ namespace
         const SfxStyleFamily m_eFamily;
         const SwGetPoolIdFromName m_aPoolId;
         const OUString m_sName;
-        StyleFamilyEntry(SfxStyleFamily eFamily, SwGetPoolIdFromName aPoolId, OUString sName)
+        const sal_uInt32 m_nRedId;
+        StyleFamilyEntry(SfxStyleFamily eFamily, SwGetPoolIdFromName aPoolId, OUString sName, sal_uInt32 nResId)
                 : m_eFamily(eFamily)
                 , m_aPoolId(aPoolId)
                 , m_sName(sName)
+                , m_nRedId(nResId)
             {}
     };
     static const std::vector<StyleFamilyEntry> our_vStyleFamilyEntries {
-        { SFX_STYLE_FAMILY_CHAR,   nsSwGetPoolIdFromName::GET_POOLID_CHRFMT,   "CharacterStyles" },
-        { SFX_STYLE_FAMILY_PARA,   nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL,  "ParagraphStyles" },
-        { SFX_STYLE_FAMILY_PAGE,   nsSwGetPoolIdFromName::GET_POOLID_PAGEDESC, "PageStyles" },
-        { SFX_STYLE_FAMILY_FRAME,  nsSwGetPoolIdFromName::GET_POOLID_FRMFMT,   "FrameStyles" },
-        { SFX_STYLE_FAMILY_PSEUDO, nsSwGetPoolIdFromName::GET_POOLID_NUMRULE,  "NumberingStyles" }
+        { SFX_STYLE_FAMILY_CHAR,   nsSwGetPoolIdFromName::GET_POOLID_CHRFMT,   "CharacterStyles", STR_STYLE_FAMILY_CHARACTER },
+        { SFX_STYLE_FAMILY_PARA,   nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL,  "ParagraphStyles", STR_STYLE_FAMILY_PARAGRAPH },
+        { SFX_STYLE_FAMILY_PAGE,   nsSwGetPoolIdFromName::GET_POOLID_PAGEDESC, "PageStyles",      STR_STYLE_FAMILY_PAGE},
+        { SFX_STYLE_FAMILY_FRAME,  nsSwGetPoolIdFromName::GET_POOLID_FRMFMT,   "FrameStyles",     STR_STYLE_FAMILY_FRAME},
+        { SFX_STYLE_FAMILY_PSEUDO, nsSwGetPoolIdFromName::GET_POOLID_NUMRULE,  "NumberingStyles", STR_STYLE_FAMILY_NUMBERING}
     };
 }
 
@@ -911,22 +913,11 @@ uno::Any SAL_CALL SwXStyleFamily::getPropertyValue( const OUString& sPropertyNam
     if ( sPropertyName == "DisplayName" )
     {
         SolarMutexGuard aGuard;
-        sal_uInt32 nResId = 0;
-        switch ( m_eFamily )
-        {
-            case SFX_STYLE_FAMILY_CHAR:
-                nResId = STR_STYLE_FAMILY_CHARACTER; break;
-            case SFX_STYLE_FAMILY_PARA:
-                nResId = STR_STYLE_FAMILY_PARAGRAPH; break;
-            case SFX_STYLE_FAMILY_FRAME:
-                nResId = STR_STYLE_FAMILY_FRAME; break;
-            case SFX_STYLE_FAMILY_PAGE:
-                nResId = STR_STYLE_FAMILY_PAGE; break;
-            case SFX_STYLE_FAMILY_PSEUDO:
-                nResId = STR_STYLE_FAMILY_NUMBERING; break;
-            default:
-                OSL_FAIL( "SwXStyleFamily::getPropertyValue(): invalid family" );
-        }
+        const auto pEntry = std::find_if(our_vStyleFamilyEntries.begin(), our_vStyleFamilyEntries.end(),
+                [this] (const StyleFamilyEntry& e) { return m_eFamily == e.m_eFamily; });
+        if(pEntry == our_vStyleFamilyEntries.end())
+            OSL_FAIL( "SwXStyleFamily::getPropertyValue(): invalid family" );
+        sal_uInt32 nResId = pEntry->m_nRedId;
         if ( nResId > 0 )
         {
             aRet = uno::makeAny( SW_RESSTR( nResId ) );
commit 5a43b7645f5c73620b3a25bb9e4d75c6f9114800
Author: Bjoern Michaelsen <bjoern.michaelsen at canonical.com>
Date:   Fri Nov 27 01:57:24 2015 +0100

    remove boilerplate
    
    Change-Id: Id06e8bfdff74a9cfecd74bcae4daa70782e684e0

diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx
index 5168aa7..62f2ac7 100644
--- a/sw/source/core/unocore/unostyle.cxx
+++ b/sw/source/core/unocore/unostyle.cxx
@@ -357,9 +357,7 @@ uno::Sequence< beans::PropertyValue > SwXStyleFamilies::getStyleLoaderOptions()
 }
 
 OUString SwXStyleFamily::getImplementationName() throw( uno::RuntimeException, std::exception )
-{
-    return OUString("SwXStyleFamily");
-}
+    { return {"SwXStyleFamily"}; }
 
 sal_Bool SwXStyleFamily::supportsService(const OUString& rServiceName) throw( uno::RuntimeException, std::exception )
 {
@@ -367,10 +365,7 @@ sal_Bool SwXStyleFamily::supportsService(const OUString& rServiceName) throw( un
 }
 
 uno::Sequence< OUString > SwXStyleFamily::getSupportedServiceNames() throw( uno::RuntimeException, std::exception )
-{
-    uno::Sequence<OUString> aRet { "com.sun.star.style.StyleFamily" };
-    return aRet;
-}
+    { return { "com.sun.star.style.StyleFamily" }; }
 
 SwXStyleFamily::SwXStyleFamily(SwDocShell* pDocSh, sal_uInt16 nFamily) :
         m_eFamily((SfxStyleFamily)nFamily),
commit 3ca42d8d51174010d5e8a32b96e9b4c0b3730a53
Author: Bjoern Michaelsen <bjoern.michaelsen at canonical.com>
Date:   Fri Nov 27 01:52:46 2015 +0100

    reduce boilerplate
    
    Change-Id: I726d824d6b6c42e7e395a99a6b3b6019d91e764d

diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx
index 9d5a2ad..5168aa7 100644
--- a/sw/source/core/unocore/unostyle.cxx
+++ b/sw/source/core/unocore/unostyle.cxx
@@ -148,9 +148,7 @@ public:
 };
 
 OUString SwXStyleFamilies::getImplementationName() throw( uno::RuntimeException, std::exception )
-{
-    return OUString("SwXStyleFamilies");
-}
+    { return {"SwXStyleFamilies"}; }
 
 sal_Bool SwXStyleFamilies::supportsService(const OUString& rServiceName) throw( uno::RuntimeException, std::exception )
 {
@@ -158,10 +156,7 @@ sal_Bool SwXStyleFamilies::supportsService(const OUString& rServiceName) throw(
 }
 
 uno::Sequence< OUString > SwXStyleFamilies::getSupportedServiceNames() throw( uno::RuntimeException, std::exception )
-{
-    uno::Sequence<OUString> aRet { "com.sun.star.style.StyleFamilies" };
-    return aRet;
-}
+    { return { "com.sun.star.style.StyleFamilies" }; }
 
 SwXStyleFamilies::SwXStyleFamilies(SwDocShell& rDocShell) :
     SwUnoCollection(rDocShell.GetDoc()),
commit c50e1c442b0be43f27a0f89ef33e524064d93456
Author: Bjoern Michaelsen <bjoern.michaelsen at canonical.com>
Date:   Fri Nov 27 01:34:18 2015 +0100

    use one styles vector instead of multiple tables
    
    Change-Id: I276f2fae8083f3131fa3ff92fc7633c0f88a3ed6

diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx
index d8b0037..9d5a2ad 100644
--- a/sw/source/core/unocore/unostyle.cxx
+++ b/sw/source/core/unocore/unostyle.cxx
@@ -90,16 +90,27 @@
 #include <memory>
 #include <set>
 
-#define STYLE_FAMILY_COUNT 5            // we have 5 style families
-
-const sal_uInt16 aStyleByIndex[] =
+namespace
 {
-    SFX_STYLE_FAMILY_CHAR,
-    SFX_STYLE_FAMILY_PARA,
-    SFX_STYLE_FAMILY_PAGE,
-    SFX_STYLE_FAMILY_FRAME,
-    SFX_STYLE_FAMILY_PSEUDO
-};
+    struct StyleFamilyEntry
+    {
+        const SfxStyleFamily m_eFamily;
+        const SwGetPoolIdFromName m_aPoolId;
+        const OUString m_sName;
+        StyleFamilyEntry(SfxStyleFamily eFamily, SwGetPoolIdFromName aPoolId, OUString sName)
+                : m_eFamily(eFamily)
+                , m_aPoolId(aPoolId)
+                , m_sName(sName)
+            {}
+    };
+    static const std::vector<StyleFamilyEntry> our_vStyleFamilyEntries {
+        { SFX_STYLE_FAMILY_CHAR,   nsSwGetPoolIdFromName::GET_POOLID_CHRFMT,   "CharacterStyles" },
+        { SFX_STYLE_FAMILY_PARA,   nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL,  "ParagraphStyles" },
+        { SFX_STYLE_FAMILY_PAGE,   nsSwGetPoolIdFromName::GET_POOLID_PAGEDESC, "PageStyles" },
+        { SFX_STYLE_FAMILY_FRAME,  nsSwGetPoolIdFromName::GET_POOLID_FRMFMT,   "FrameStyles" },
+        { SFX_STYLE_FAMILY_PSEUDO, nsSwGetPoolIdFromName::GET_POOLID_NUMRULE,  "NumberingStyles" }
+    };
+}
 
 // Already implemented autostyle families: 3
 #define AUTOSTYLE_FAMILY_COUNT 3
@@ -112,24 +123,14 @@ const IStyleAccess::SwAutoStyleFamily aAutoStyleByIndex[] =
 
 using namespace ::com::sun::star;
 
-static SwGetPoolIdFromName lcl_GetSwEnumFromSfxEnum ( SfxStyleFamily eFamily )
+static SwGetPoolIdFromName lcl_GetSwEnumFromSfxEnum(SfxStyleFamily eFamily)
 {
-    switch ( eFamily )
-    {
-        case SFX_STYLE_FAMILY_CHAR:
-            return nsSwGetPoolIdFromName::GET_POOLID_CHRFMT;
-        case SFX_STYLE_FAMILY_PARA:
-            return nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL;
-        case SFX_STYLE_FAMILY_FRAME:
-            return nsSwGetPoolIdFromName::GET_POOLID_FRMFMT;
-        case SFX_STYLE_FAMILY_PAGE:
-            return nsSwGetPoolIdFromName::GET_POOLID_PAGEDESC;
-        case SFX_STYLE_FAMILY_PSEUDO:
-            return nsSwGetPoolIdFromName::GET_POOLID_NUMRULE;
-        default:
-            OSL_ENSURE(false, "someone asking for all styles in unostyle.cxx!" );
-            return nsSwGetPoolIdFromName::GET_POOLID_CHRFMT;
-    }
+    const auto pEntry = std::find_if(our_vStyleFamilyEntries.begin(), our_vStyleFamilyEntries.end(),
+            [eFamily] (const StyleFamilyEntry& e) { return e.m_eFamily == eFamily; });
+    if(pEntry != our_vStyleFamilyEntries.end())
+        return pEntry->m_aPoolId;
+    SAL_WARN("sw.uno", "someone asking for all styles in unostyle.cxx!" );
+    return nsSwGetPoolIdFromName::GET_POOLID_CHRFMT;
 }
 
 class SwAutoStylesEnumImpl
@@ -185,52 +186,33 @@ uno::Any SAL_CALL SwXStyleFamilies::getByName(const OUString& Name)
         uno::RuntimeException, std::exception )
 {
     SolarMutexGuard aGuard;
-// the index comes from const unsigned short aStyleByIndex[] = ...
-    uno::Any aRet;
     if(!IsValid())
         throw uno::RuntimeException();
-    if(Name=="CharacterStyles" )
-        aRet = getByIndex(0);
-    else if(Name=="ParagraphStyles" )
-        aRet = getByIndex(1);
-    else if(Name=="FrameStyles" )
-        aRet = getByIndex(3);
-    else if(Name=="PageStyles" )
-        aRet = getByIndex(2);
-    else if(Name=="NumberingStyles" )
-        aRet = getByIndex(4);
-    else
+    const auto pEntry = std::find_if(our_vStyleFamilyEntries.begin(), our_vStyleFamilyEntries.end(),
+        [&Name] (const StyleFamilyEntry& e) { return e.m_sName == Name; });
+    if(pEntry == our_vStyleFamilyEntries.end())
         throw container::NoSuchElementException();
-    return aRet;
+    return getByIndex(pEntry-our_vStyleFamilyEntries.begin());
 }
 
 uno::Sequence< OUString > SwXStyleFamilies::getElementNames() throw( uno::RuntimeException, std::exception )
 {
-    uno::Sequence< OUString > aNames(STYLE_FAMILY_COUNT);
-    OUString* pNames = aNames.getArray();
-    pNames[0] = "CharacterStyles";
-    pNames[1] = "ParagraphStyles";
-    pNames[2] = "FrameStyles";
-    pNames[3] = "PageStyles";
-    pNames[4] = "NumberingStyles";
+    uno::Sequence< OUString > aNames(our_vStyleFamilyEntries.size());
+    std::transform(our_vStyleFamilyEntries.begin(), our_vStyleFamilyEntries.end(),
+            aNames.begin(), [] (const StyleFamilyEntry& e) { return e.m_sName; });
     return aNames;
 }
 
 sal_Bool SwXStyleFamilies::hasByName(const OUString& Name) throw( uno::RuntimeException, std::exception )
 {
-    if( Name=="CharacterStyles" ||
-        Name=="ParagraphStyles" ||
-        Name=="FrameStyles" ||
-        Name=="PageStyles" ||
-        Name=="NumberingStyles" )
-        return sal_True;
-    else
-        return sal_False;
+    const auto pEntry = std::find_if(our_vStyleFamilyEntries.begin(), our_vStyleFamilyEntries.end(),
+        [&Name] (const StyleFamilyEntry& e) { return e.m_sName == Name; });
+    return pEntry != our_vStyleFamilyEntries.end();
 }
 
 sal_Int32 SwXStyleFamilies::getCount() throw( uno::RuntimeException, std::exception )
 {
-    return STYLE_FAMILY_COUNT;
+    return our_vStyleFamilyEntries.size();
 }
 
 uno::Any SwXStyleFamilies::getByIndex(sal_Int32 nIndex)
@@ -238,19 +220,19 @@ uno::Any SwXStyleFamilies::getByIndex(sal_Int32 nIndex)
 {
     SolarMutexGuard aGuard;
     uno::Any aRet;
-    if(nIndex < 0 || nIndex >= STYLE_FAMILY_COUNT)
+    if(nIndex < 0 || nIndex >= static_cast<sal_Int32>(our_vStyleFamilyEntries.size()))
         throw lang::IndexOutOfBoundsException();
     if(IsValid())
     {
         uno::Reference< container::XNameContainer >  aRef;
-        const sal_uInt16 nType = aStyleByIndex[nIndex];
-        switch( nType )
+        auto eFamily = our_vStyleFamilyEntries[nIndex].m_eFamily;
+        switch( eFamily )
         {
             case SFX_STYLE_FAMILY_CHAR:
             {
                 if(!m_xCharStyles.is())
                 {
-                    m_xCharStyles = new SwXStyleFamily(m_pDocShell, nType);
+                    m_xCharStyles = new SwXStyleFamily(m_pDocShell, eFamily);
                 }
                 aRef = m_xCharStyles;
             }
@@ -259,25 +241,25 @@ uno::Any SwXStyleFamilies::getByIndex(sal_Int32 nIndex)
             {
                 if(!m_xParaStyles.is())
                 {
-                    m_xParaStyles = new SwXStyleFamily(m_pDocShell, nType);
+                    m_xParaStyles = new SwXStyleFamily(m_pDocShell, eFamily);
                 }
                 aRef = m_xParaStyles;
             }
             break;
-            case SFX_STYLE_FAMILY_PAGE     :
+            case SFX_STYLE_FAMILY_PAGE:
             {
                 if(!m_xPageStyles.is())
                 {
-                    m_xPageStyles = new SwXStyleFamily(m_pDocShell, nType);
+                    m_xPageStyles = new SwXStyleFamily(m_pDocShell, eFamily);
                 }
                 aRef = m_xPageStyles;
             }
             break;
-            case SFX_STYLE_FAMILY_FRAME    :
+            case SFX_STYLE_FAMILY_FRAME:
             {
                 if(!m_xFrameStyles.is())
                 {
-                    m_xFrameStyles = new SwXStyleFamily(m_pDocShell, nType);
+                    m_xFrameStyles = new SwXStyleFamily(m_pDocShell, eFamily);
                 }
                 aRef = m_xFrameStyles;
             }
@@ -286,11 +268,13 @@ uno::Any SwXStyleFamilies::getByIndex(sal_Int32 nIndex)
             {
                 if(!m_xNumberingStyles.is())
                 {
-                    m_xNumberingStyles = new SwXStyleFamily(m_pDocShell, nType);
+                    m_xNumberingStyles = new SwXStyleFamily(m_pDocShell, eFamily);
                 }
                 aRef = m_xNumberingStyles;
             }
             break;
+            case SFX_STYLE_FAMILY_ALL:
+                assert(false);
         }
         aRet.setValue(&aRef, cppu::UnoType<container::XNameContainer>::get());
     }


More information about the Libreoffice-commits mailing list