Commits

Bjoern Michaelsen  committed eb14c55

itemsets: using ::std::for_each where possible

  • Participants
  • Parent commits 830eddd
  • Branches new_itemsets

Comments (0)

Files changed (2)

File svtools/inc/svtools/itemset.hxx

 #ifndef _SFXITEMSET_HXX
 #define _SFXITEMSET_HXX
 
+#include <algorithm>
+#include <boost/bind.hpp>
 #include <boost/operators.hpp>
 #include <cstdarg>  // std::va_list and friends
+#include <functional>
 #include <memory>
 #include <svtools/itempool.hxx>
 #include <svtools/poolitem.hxx>
 
             void ReleaseRefAll(SfxItemPool* const io_pPool)
             {
-                for(iterator pItemEntry = begin();
-                    pItemEntry != end();
-                    ++pItemEntry)
-                {
-                    pItemEntry->ReleaseItem(io_pPool);
-                }
+                ::std::for_each(begin(), end(), ::boost::bind(&ItemEntry::ReleaseItem, _1, io_pPool));
             }
         };
 }}

File svtools/source/items1/itemset.cxx

 #include "precompiled_svtools.hxx"
 
 #include <svtools/itemset.hxx>
-#include <algorithm>
-#include <cstdarg>
 #include <sal/types.h>
 #include <svtools/itemiter.hxx>
 #include <svtools/itempool.hxx>
 
 using namespace ::sfx::item;
 using namespace ::std;
+using namespace ::boost;
 
 namespace
 {
     };
 
 #if DEBUG
-    bool lcl_ValidateItemVector(ItemVector* const pItems, const vector<sal_uInt16>& rWhichRanges)
+    static bool lcl_ValidateItemVector(ItemVector* const pItems, const vector<sal_uInt16>& rWhichRanges)
     {
         ItemVector vItems(*pItems);
         sort(vItems.begin(), vItems.end());
         {
             OSL_ENSURE(lcl_InRange(rWhichRanges, pItemEntry->GetWhich()), "<itemset.cxx:lcl_ValidateItemVector>"
             " - itemset confused: which out of ranges.");
-            if(!IsInvalidItem(pItemEntry->GetItem()) && !pItemEntry->GetItem()->Which())
-            {
-                OSL_ENSURE(pItemEntry->GetItem()->IsA(TYPE(SfxVoidItem)),
-                    "<itemset.cxx:lcl_ValidateItemVector> - itemset confused: which zero, but not a void item");
-            }
+            OSL_ENSURE(IsInvalidItem(pItemEntry->GetItem() || pItemEntry->GetItem()->Which() || pItemEntry->GetItem()->IsA(TYPE(SfxVoidItem))),
+                "<itemset.cxx:lcl_ValidateItemVector> - itemset confused: item has to be invalid, have a WhichId or be a SfxVoidItem.");
         }
         return true;
     };
 #endif
 
-    void lcl_NormalizeRanges(vector<sal_uInt16>& o_rWhichRanges)
+    static void lcl_NormalizeRanges(vector<sal_uInt16>& o_rWhichRanges)
     {
         if(o_rWhichRanges.size() <= 3)
             return;
             {
                 if(*pCurrent == o_rWhichRanges.end()[-1]+1)
                 {
-                    //OSL_TRACE("<itemset.cxx:lcl_NormalizeRanges(..)>"
-                    //    " - merging ranges.");
                     o_rWhichRanges.end()[-1] = *(pCurrent+1);
                 }
                 else
             o_rWhichRanges.push_back(0);
             return;
         }
-        //const sal_uInt16* pWhichRangesEnd = pNewRanges;
-        //while(*pWhichRangesEnd++) {};
-        //copy(pNewRanges, pWhichRangesEnd, back_inserter(o_rWhichRanges));
         const sal_uInt16* pWhichCurrent = pNewRanges;
         while(*pWhichCurrent)
             o_rWhichRanges.push_back(*pWhichCurrent++);
     }
 }
 
-namespace sfx { namespace item {
-
-
-}}
-
 SfxItemSet::SfxItemSet(SfxItemPool& rPool, bool)
     : m_pPool(&rPool)
     , m_pParent(NULL)
     else
     {
         sal_uInt16 nDeletedItems = m_pItems->size();
-        for(ItemVector::iterator pItemEntry = m_pItems->begin();
-            pItemEntry != m_pItems->end();
-            ++pItemEntry)
-        {
-            pItemEntry->ReleaseItem(m_pPool);
-        }
         m_pItems->clear();
         return nDeletedItems;
     }
         pOldItems->begin(), pOldItems->end(),
         m_pItems->begin(), m_pItems->end(),
         back_inserter(vDeletedItems));
-    for(ItemVector::iterator pEntryToClear = vDeletedItems.begin();
-        pEntryToClear != vDeletedItems.end();
-        ++pEntryToClear)
-    {
-        pEntryToClear->ReleaseItem(m_pPool);
-    }
+    vDeletedItems.ReleaseRefAll(m_pPool);
     OSL_POSTCOND(lcl_ValidateItemVector(m_pItems.get(), m_vWhichRanges), "<itemset.cxx> - itemset validation failed.");
 }
 
         pOldItems->begin(), pOldItems->end(),
         m_pItems->begin(), m_pItems->end(),
         back_inserter(vDeletedItems));
-    for(ItemVector::iterator pEntryToClear = vDeletedItems.begin();
-        pEntryToClear != vDeletedItems.end();
-        ++pEntryToClear)
-    {
-        pEntryToClear->ReleaseItem(m_pPool);
-    }
+    vDeletedItems.ReleaseRefAll(m_pPool);
     OSL_POSTCOND(lcl_ValidateItemVector(m_pItems.get(), m_vWhichRanges), "<itemset.cxx> - itemset validation failed.");
 }