Anonymous avatar Anonymous committed 37df708

itemsets: using ::std::for_each where possible

Comments (0)

Files changed (1)

svtools/source/items1/itemset.cxx

                 { return m_bExists; }
     };
 
+    class SVL_DLLPRIVATE InvalidItemClearer
+    {
+        public:
+            InvalidItemClearer(ItemVector* pItems, SfxItemPool* pPool, const bool bHardDefault)
+                : m_pItems(pItems), m_pPool(pPool), m_bHardDefault(bHardDefault)
+            {};
+            void operator()(const ItemEntry& rItemEntry)
+            {
+                if(IsInvalidItem(rItemEntry.GetItem()))
+                {
+                    if(m_bHardDefault)
+                    {
+                        SfxPoolItem* pDefault = const_cast<SfxPoolItem*>(&m_pPool->GetDefaultItem(rItemEntry.GetWhich()));
+                        if(pDefault)
+                        {
+                            ItemEntry aDefaultEntry(rItemEntry.GetWhich());
+                            aDefaultEntry.SetItem(pDefault, m_pPool);
+                            m_pItems->push_back(aDefaultEntry);
+                        }
+                    }
+                }
+                else
+                    m_pItems->push_back(rItemEntry);
+            };
+        private:
+            ItemVector* const m_pItems;
+            SfxItemPool* const m_pPool;
+            const bool m_bHardDefault;
+    };
+
     static bool lcl_InRange(const vector<sal_uInt16>& rWhichRanges, const sal_uInt16 nWhichId)
     {
         if(rWhichRanges.empty())
     auto_ptr<ItemVector> pOldItems = m_pItems;
     m_pItems.reset(new ItemVector());
     m_pItems->reserve(pOldItems->size());
-    for(ItemVector::iterator pItemEntry = pOldItems->begin();
-        pItemEntry != pOldItems->end();
-        ++pItemEntry)
-    {
-        if(IsInvalidItem(pItemEntry->GetItem()))
-        {
-            if(bHardDefault)
-            {
-                SfxPoolItem* pDefault = const_cast<SfxPoolItem*>(&m_pPool->GetDefaultItem(pItemEntry->GetWhich()));
-                if(pDefault)
-                {
-                    ItemEntry aDefaultEntry(pItemEntry->GetWhich());
-                    aDefaultEntry.SetItem(pDefault, m_pPool);
-                    m_pItems->push_back(aDefaultEntry);
-                }
-            }
-        }
-        else
-            m_pItems->push_back(*pItemEntry);
-    }
+    for_each(pOldItems->begin(), pOldItems->end(), InvalidItemClearer(m_pItems.get(), m_pPool, bHardDefault));
 }
 
 void SfxItemSet::InvalidateAllItems()
     OSL_POSTCOND(lcl_ValidateItemVector(m_pItems.get(), m_vWhichRanges), "<itemset.cxx> - itemset validation failed.");
     return rStream;
 }
+
 SvStream& SfxItemSet::Load(SvStream& rStream, bool bDirect, const SfxItemPool* pRefPool)
 {
     OSL_ENSURE(m_pPool == m_pPool->GetMasterPool(), "<SfxItemSet::Load(..)>"
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.