o3tl/inc/o3tl/sorted_vector.hxx | 86 ++++++++++----- o3tl/qa/test-sorted_vector.cxx | 114 ++++++++++++++++++++ sc/workben/result.hxx | 1 svl/Library_svl.mk | 1 svl/Package_inc.mk | 1 svl/inc/svl/svarray.hxx | 202 ------------------------------------- svl/source/memtools/svarray.cxx | 97 ----------------- svx/source/inc/fmshimp.hxx | 1 sw/inc/docary.hxx | 5 sw/inc/flypos.hxx | 2 sw/inc/ndhints.hxx | 34 ++++-- sw/source/core/doc/docfld.cxx | 22 +--- sw/source/core/doc/docsort.cxx | 43 ++++--- sw/source/core/text/redlnitr.cxx | 12 +- sw/source/core/text/redlnitr.hxx | 2 sw/source/core/txtnode/ndhints.cxx | 143 +++++++------------------- sw/source/filter/html/htmlfly.hxx | 7 + sw/source/ui/utlui/content.cxx | 4 18 files changed, 290 insertions(+), 487 deletions(-)
New commits: commit 28a48f2aab4aa32ce8a7d46b8b5e6f26b732afd3 Author: Michael Stahl <[email protected]> Date: Tue Jul 31 20:18:22 2012 +0200 svarray.hxx: 'e's pining for the fjords... Change-Id: I3eeb257092a76744482ebd2d0eccaa29ead8a644 diff --git a/svl/Library_svl.mk b/svl/Library_svl.mk index 41f91b5..768f2db 100644 --- a/svl/Library_svl.mk +++ b/svl/Library_svl.mk @@ -105,7 +105,6 @@ $(eval $(call gb_Library_add_exception_objects,svl,\ svl/source/items/szitem \ svl/source/items/visitem \ svl/source/items/whiter \ - svl/source/memtools/svarray \ svl/source/misc/PasswordHelper \ svl/source/misc/adrparse \ svl/source/misc/documentlockfile \ diff --git a/svl/Package_inc.mk b/svl/Package_inc.mk index 2cb3544..ae63792 100644 --- a/svl/Package_inc.mk +++ b/svl/Package_inc.mk @@ -98,7 +98,6 @@ $(eval $(call gb_Package_add_file,svl_inc,inc/svl/strmadpt.hxx,svl/strmadpt.hxx) $(eval $(call gb_Package_add_file,svl_inc,inc/svl/style.hrc,svl/style.hrc)) $(eval $(call gb_Package_add_file,svl_inc,inc/svl/style.hxx,svl/style.hxx)) $(eval $(call gb_Package_add_file,svl_inc,inc/svl/stylepool.hxx,svl/stylepool.hxx)) -$(eval $(call gb_Package_add_file,svl_inc,inc/svl/svarray.hxx,svl/svarray.hxx)) $(eval $(call gb_Package_add_file,svl_inc,inc/svl/svdde.hxx,svl/svdde.hxx)) $(eval $(call gb_Package_add_file,svl_inc,inc/svl/svl.hrc,svl/svl.hrc)) $(eval $(call gb_Package_add_file,svl_inc,inc/svl/svldllapi.h,svl/svldllapi.h)) diff --git a/svl/inc/svl/svarray.hxx b/svl/inc/svl/svarray.hxx deleted file mode 100644 index 23e702b..0000000 --- a/svl/inc/svl/svarray.hxx +++ /dev/null @@ -1,202 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#ifndef _SVARRAY_HXX -#define _SVARRAY_HXX - -/*********************************************************************** -* -* Hier folgt die Beschreibung fuer die exportierten Makros: -* -* SV_DECL_PTRARR_SORT(nm, AE, IS, GS) -* SV_IMPL_OP_PTRARR_SORT( nm,AE ) -* defieniere/implementiere ein Sort-Array mit Pointern, das nach -* Objecten sortiert ist. Basiert auf einem PTRARR. -* Sortierung mit Hilfe der Object-operatoren "<" und "==" -* -***********************************************************************/ - -#include "svl/svldllapi.h" - -#include <limits.h> // USHRT_MAX -#include <osl/diagnose.h> -#include <rtl/alloc.h> -#include <tools/solar.h> - -typedef void* VoidPtr; -class SVL_DLLPUBLIC SvPtrarr -{ -protected: - VoidPtr *pData; - sal_uInt16 nFree; - sal_uInt16 nA; - - void _resize(size_t n); - -public: - SvPtrarr( sal_uInt16= 0 ); - ~SvPtrarr() { rtl_freeMemory( pData ); } - - VoidPtr& operator[](sal_uInt16 nP) const { return *(pData+nP); } - - void Insert( const SvPtrarr * pI, sal_uInt16 nP, - sal_uInt16 nS = 0, sal_uInt16 nE = USHRT_MAX ); - - VoidPtr& GetObject(sal_uInt16 nP) const { return (*this)[nP]; } - - void Insert( const VoidPtr& aE, sal_uInt16 nP ); - void Insert( const VoidPtr *pE, sal_uInt16 nL, sal_uInt16 nP ); - void Remove( sal_uInt16 nP, sal_uInt16 nL = 1 ); - sal_uInt16 Count() const { return nA; } - const VoidPtr* GetData() const { return (const VoidPtr*)pData; } - sal_uInt16 GetPos( const VoidPtr & aE ) const; -}; - -// SORTARR - Begin - -#define _SV_IMPL_SORTAR_ALG(nm, AE)\ -sal_Bool nm::Insert( const AE & aE )\ -{\ - sal_uInt16 nP;\ - sal_Bool bExist;\ - bExist = Seek_Entry( aE, &nP );\ - if( ! bExist )\ - nm##_SAR::Insert( aE, nP );\ - return !bExist;\ -}\ -\ -void nm::Remove( sal_uInt16 nP, sal_uInt16 nL )\ -{\ - if( nL )\ - nm##_SAR::Remove( nP, nL);\ -} - -#define SV_DECL_PTRARR_SORT(nm, AE, IS)\ -class nm##_SAR: public SvPtrarr \ -{\ -public:\ - nm##_SAR( sal_uInt16 nIni=IS )\ - : SvPtrarr(nIni) {}\ - void Insert( const nm##_SAR *pI, sal_uInt16 nP, \ - sal_uInt16 nS = 0, sal_uInt16 nE = USHRT_MAX ) {\ - SvPtrarr::Insert((const SvPtrarr*)pI, nP, nS, nE);\ - }\ - void Insert( const AE & aE, sal_uInt16 nP ) {\ - SvPtrarr::Insert( (const VoidPtr &)aE, nP );\ - }\ - void Insert( const AE *pE, sal_uInt16 nL, sal_uInt16 nP ) {\ - SvPtrarr::Insert( (const VoidPtr*)pE, nL, nP );\ - }\ - void Remove( sal_uInt16 nP, sal_uInt16 nL = 1) {\ - SvPtrarr::Remove(nP,nL);\ - }\ - const AE* GetData() const {\ - return (const AE*)SvPtrarr::GetData();\ - }\ - AE operator[]( sal_uInt16 nP )const { \ - return (AE)SvPtrarr::operator[](nP); }\ - AE GetObject(sal_uInt16 nP) const { \ - return (AE)SvPtrarr::GetObject(nP); }\ - \ - sal_uInt16 GetPos( const AE & aE ) const { \ - return SvPtrarr::GetPos((const VoidPtr &)aE);\ - }\ - void DeleteAndDestroy( sal_uInt16 nP, sal_uInt16 nL=1 );\ -private:\ - nm##_SAR( const nm##_SAR& );\ - nm##_SAR& operator=( const nm##_SAR& );\ -};\ -\ -class nm : private nm##_SAR \ -{\ -public:\ - nm(sal_uInt16 nSize = IS)\ - : nm##_SAR(nSize) {}\ - sal_Bool Insert( const AE& aE );\ - void Remove( sal_uInt16 nP, sal_uInt16 nL = 1 );\ - sal_uInt16 Count() const { return nm##_SAR::Count(); }\ - const AE* GetData() const { return (const AE*)pData; }\ - AE operator[](sal_uInt16 nP) const {\ - return nm##_SAR::operator[]( nP );\ - }\ - AE GetObject(sal_uInt16 nP) const {\ - return nm##_SAR::GetObject( nP );\ - }\ - sal_Bool Seek_Entry( const AE aE, sal_uInt16* pP = 0 ) const;\ - void DeleteAndDestroy( sal_uInt16 nP, sal_uInt16 nL=1 ); \ - sal_uInt16 GetPos( const AE& aE ) const { \ - return SvPtrarr::GetPos((const VoidPtr&)aE);\ - }\ -private:\ - nm( const nm& );\ - nm& operator=( const nm& );\ -}; - -#define SV_IMPL_OP_PTRARR_SORT( nm,AE )\ -_SV_IMPL_SORTAR_ALG( nm,AE )\ -void nm::DeleteAndDestroy( sal_uInt16 nP, sal_uInt16 nL ) { \ - if( nL ) {\ - OSL_ENSURE( nP < nA && nP + nL <= nA, "ERR_VAR_DEL" );\ - for( sal_uInt16 n=nP; n < nP + nL; n++ ) \ - delete *((AE*)pData+n); \ - SvPtrarr::Remove( nP, nL ); \ - } \ -} \ -sal_Bool nm::Seek_Entry( const AE aE, sal_uInt16* pP ) const\ -{\ - register sal_uInt16 nO = nm##_SAR::Count(),\ - nM, \ - nU = 0;\ - if( nO > 0 )\ - {\ - nO--;\ - while( nU <= nO )\ - {\ - nM = nU + ( nO - nU ) / 2;\ - if( *(*((AE*)pData + nM)) == *(aE) )\ - {\ - if( pP ) *pP = nM;\ - return sal_True;\ - }\ - else if( *(*((AE*)pData + nM)) < *(aE) )\ - nU = nM + 1;\ - else if( nM == 0 )\ - {\ - if( pP ) *pP = nU;\ - return sal_False;\ - }\ - else\ - nO = nM - 1;\ - }\ - }\ - if( pP ) *pP = nU;\ - return sal_False;\ -} - - - -#if defined(ICC) || defined(GCC) || (defined(WNT) && _MSC_VER >= 1400) -#define C40_INSERT( c, p, n ) Insert( (c const *&) p, n ) -#else -#define C40_INSERT( c, p, n ) Insert( p, n ) -#endif - -#endif //_SVARRAY_HXX - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/memtools/svarray.cxx b/svl/source/memtools/svarray.cxx deleted file mode 100644 index 6f1f1cb..0000000 --- a/svl/source/memtools/svarray.cxx +++ /dev/null @@ -1,97 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#include <svl/svarray.hxx> -#include <string.h> // memmove() - -SvPtrarr::SvPtrarr( sal_uInt16 nInit ) - : pData (0), - nFree (nInit), - nA (0) -{ - if( nInit ) - { - pData = (VoidPtr*)(rtl_allocateMemory(sizeof(VoidPtr) * nInit)); - OSL_ENSURE( pData, "CTOR, allocate"); - } -} - -void SvPtrarr::_resize (size_t n) -{ - sal_uInt16 nL = ((n < USHRT_MAX) ? sal_uInt16(n) : USHRT_MAX); - VoidPtr* pE = (VoidPtr*)(rtl_reallocateMemory (pData, sizeof(VoidPtr) * nL)); - if ((pE != 0) || (nL == 0)) - { - pData = pE; - nFree = nL - nA; - } -} - -void SvPtrarr::Insert( const VoidPtr& aE, sal_uInt16 nP ) -{ - OSL_ENSURE(nP <= nA && nA < USHRT_MAX, "Ins 1"); - if (nFree < 1) - _resize (nA + ((nA > 1) ? nA : 1)); - if( pData && nP < nA ) - memmove( pData+nP+1, pData+nP, (nA-nP) * sizeof( VoidPtr )); - *(pData+nP) = (VoidPtr&)aE; - ++nA; --nFree; -} - -void SvPtrarr::Insert( const VoidPtr* pE, sal_uInt16 nL, sal_uInt16 nP ) -{ - OSL_ENSURE(nP<=nA && ((long)nA+nL)<USHRT_MAX,"Ins n"); - if (nFree < nL) - _resize (nA + ((nA > nL) ? nA : nL)); - if( pData && nP < nA ) - memmove( pData+nP+nL, pData+nP, (nA-nP) * sizeof( VoidPtr )); - if( pE ) - memcpy( pData+nP, pE, nL * sizeof( VoidPtr )); - nA = nA + nL; nFree = nFree - nL; -} - -void SvPtrarr::Insert( const SvPtrarr * pI, sal_uInt16 nP, - sal_uInt16 nS, sal_uInt16 nE ) -{ - if( USHRT_MAX == nE ) - nE = pI->nA; - if( nS < nE ) - Insert( (const VoidPtr*)pI->pData+nS, (sal_uInt16)nE-nS, nP ); -} - -void SvPtrarr::Remove( sal_uInt16 nP, sal_uInt16 nL ) -{ - if( !nL ) - return; - OSL_ENSURE( nP < nA && nP + nL <= nA,"Del"); - if( pData && nP+1 < nA ) - memmove( pData+nP, pData+nP+nL, (nA-nP-nL) * sizeof( VoidPtr )); - nA = nA - nL; nFree = nFree + nL; - if (nFree > nA) - _resize (nA); -} - -sal_uInt16 SvPtrarr::GetPos( const VoidPtr& aElement ) const -{ - sal_uInt16 n; - for( n=0; n < nA && *(GetData()+n) != aElement; ) n++; - return ( n >= nA ? USHRT_MAX : n ); -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ commit dd5bea1d8200a566d59029fbf0c15ddd1e25098e Author: Michael Stahl <[email protected]> Date: Tue Jul 31 20:06:03 2012 +0200 remove commented out SV_DECL_OBJARR Change-Id: Ie89a34c9dd8c71f25102cfb6f304c32fed99b4a8 diff --git a/sc/workben/result.hxx b/sc/workben/result.hxx index bb1fd86..f29b7e7 100644 --- a/sc/workben/result.hxx +++ b/sc/workben/result.hxx @@ -29,7 +29,6 @@ #ifndef SC_RESULT_HXX #define SC_RESULT_HXX -#include <svl/svarray.hxx> #include <vcl/timer.hxx> #include <tools/string.hxx> #include <boost/ptr_container/ptr_vector.hpp> diff --git a/svx/source/inc/fmshimp.hxx b/svx/source/inc/fmshimp.hxx index 94a0839..8b2a90e 100644 --- a/svx/source/inc/fmshimp.hxx +++ b/svx/source/inc/fmshimp.hxx @@ -75,7 +75,6 @@ #include <boost/ptr_container/ptr_vector.hpp> typedef std::vector<SdrObject*> SdrObjArray; -// SV_DECL_OBJARR(FmFormArray, ::com::sun::star::uno::Reference< ::com::sun::star::form::XForm>, 32, 16); DECLARE_STL_VECTOR( ::com::sun::star::uno::Reference< ::com::sun::star::form::XForm > ,FmFormArray); // catch database exceptions if they occur commit 4cbb646ddb9e075f3ac47214aae020a96b84267e Author: Michael Stahl <[email protected]> Date: Tue Jul 31 19:55:46 2012 +0200 convert SwSortElements to boost::ptr_multiset Change-Id: Ia52f23a4bdad60a89c70e47089a82ef5dbd8dfda diff --git a/sw/source/core/doc/docsort.cxx b/sw/source/core/doc/docsort.cxx index 88d791a..0f23d50 100644 --- a/sw/source/core/doc/docsort.cxx +++ b/sw/source/core/doc/docsort.cxx @@ -26,10 +26,10 @@ * ************************************************************************/ +#include <boost/ptr_container/ptr_set.hpp> #include <hintids.hxx> #include <rtl/math.hxx> -#include <svl/svarray.hxx> #include <unotools/collatorwrapper.hxx> #include <unotools/localedatawrapper.hxx> #include <com/sun/star/lang/XMultiServiceFactory.hpp> @@ -71,9 +71,8 @@ LocaleDataWrapper* SwSortElement::pLclData = 0; // List of all sorted elements typedef SwSortElement* SwSortElementPtr; -SV_DECL_PTRARR_SORT(SwSortElements, SwSortElementPtr, 0) - -SV_IMPL_OP_PTRARR_SORT( SwSortElements, SwSortElementPtr ); +typedef ::boost::ptr_multiset<SwSortTxtElement> SwSortTxtElements; +typedef ::boost::ptr_multiset<SwSortBoxElement> SwSortBoxElements; /*-------------------------------------------------------------------- Description: Construct a SortElement for the Sort @@ -404,12 +403,12 @@ sal_Bool SwDoc::SortText(const SwPaM& rPaM, const SwSortOptions& rOpt) SwNodeIndex aStart(pStart->nNode); SwSortElement::Init( this, rOpt ); - SwSortElements aSortArr; + SwSortTxtElements aSortSet; while( aStart <= pEnd->nNode ) { // Iterate over a selected Area SwSortTxtElement* pSE = new SwSortTxtElement( aStart ); - aSortArr.Insert(pSE); + aSortSet.insert(pSE); aStart++; } @@ -425,11 +424,12 @@ sal_Bool SwDoc::SortText(const SwPaM& rPaM, const SwSortOptions& rOpt) GetIDocumentUndoRedo().DoUndo(false); - for ( sal_uInt16 n = 0; n < aSortArr.Count(); ++n ) + size_t n = 0; + for (SwSortTxtElements::const_iterator it = aSortSet.begin(); + it != aSortSet.end(); ++it, ++n) { - SwSortTxtElement* pBox = (SwSortTxtElement*)aSortArr[n]; aStart = nBeg + n; - aRg.aStart = pBox->aPos.GetIndex(); + aRg.aStart = it->aPos.GetIndex(); aRg.aEnd = aRg.aStart.GetIndex() + 1; // Move Nodes @@ -438,10 +438,12 @@ sal_Bool SwDoc::SortText(const SwPaM& rPaM, const SwSortOptions& rOpt) // Insert Move in Undo if(pUndoSort) - pUndoSort->Insert(pBox->nOrg, nBeg + n); + { + pUndoSort->Insert(it->nOrg, nBeg + n); + } } // Delete all elements from the SortArray - aSortArr.DeleteAndDestroy(0, aSortArr.Count()); + aSortSet.clear(); SwSortElement::Finit(); if( pRedlPam ) @@ -585,7 +587,7 @@ sal_Bool SwDoc::SortTbl(const SwSelBoxes& rBoxes, const SwSortOptions& rOpt) // Sort SortList by Key SwSortElement::Init( this, rOpt, &aFlatBox ); - SwSortElements aSortList; + SwSortBoxElements aSortList; // When sorting, do not include the first row if the HeaderLine is repeated sal_uInt16 i; @@ -593,18 +595,23 @@ sal_Bool SwDoc::SortTbl(const SwSelBoxes& rBoxes, const SwSortOptions& rOpt) for( i = nStart; i < nCount; ++i) { SwSortBoxElement* pEle = new SwSortBoxElement( i ); - aSortList.Insert(pEle); + aSortList.insert(pEle); } // Move after Sorting SwMovedBoxes aMovedList; - for(i=0; i < aSortList.Count(); ++i) + i = 0; + for (SwSortBoxElements::const_iterator it = aSortList.begin(); + it != aSortList.end(); ++i, ++it) { - SwSortBoxElement* pBox = (SwSortBoxElement*)aSortList[i]; if(rOpt.eDirection == SRT_ROWS) - MoveRow(this, aFlatBox, pBox->nRow, i + nStart, aMovedList, pUndoSort); + { + MoveRow(this, aFlatBox, it->nRow, i+nStart, aMovedList, pUndoSort); + } else - MoveCol(this, aFlatBox, pBox->nRow, i + nStart, aMovedList, pUndoSort); + { + MoveCol(this, aFlatBox, it->nRow, i+nStart, aMovedList, pUndoSort); + } } // Restore table frames: @@ -617,7 +624,7 @@ sal_Bool SwDoc::SortTbl(const SwSelBoxes& rBoxes, const SwSortOptions& rOpt) UpdateCharts( pTblNd->GetTable().GetFrmFmt()->GetName() ); // Delete all Elements in the SortArray - aSortList.DeleteAndDestroy( 0, aSortList.Count() ); + aSortList.clear(); SwSortElement::Finit(); SetModified(); commit 3bf99d6c62e14880ecfaea298eaa2a40918ce333 Author: Michael Stahl <[email protected]> Date: Tue Jul 31 19:21:43 2012 +0200 SwHTMLPosFlyFrms: fix STL conversion: It appears that the operator== for SwPosFlyFrm always returns false, so cf0e08c6b8d739b8b17dc533efc3e12505b2d5a9 changed the semantics; use std::mulitset to fix it. Change-Id: Ib7a8ebe56e146d21c265e60ad68c6b4a319dfe98 diff --git a/sw/inc/flypos.hxx b/sw/inc/flypos.hxx index e979ab8..b172054 100644 --- a/sw/inc/flypos.hxx +++ b/sw/inc/flypos.hxx @@ -55,7 +55,7 @@ public: sal_uInt32 GetOrdNum() const { return nOrdNum; } }; -class SW_DLLPUBLIC SwPosFlyFrms : public std::set<SwPosFlyFrm*> {}; +class SwPosFlyFrms : public std::multiset<SwPosFlyFrm*> {}; #endif // _FLYPOS_HXX commit 3a1d91045b339c00267771acd60ed5d53a90c409 Author: Michael Stahl <[email protected]> Date: Tue Jul 31 19:13:45 2012 +0200 SwContentArr: fix STL conversion: It appears that the operator== for SwContent always returns false, so 81181891c93faee024799991317ac2c451f4c0c4 changed the semantics; use o3tl::find_partialorder_ptrequals to fix it. Change-Id: Ib4f040f03a9eaeec9a2973f5a93a22a387232017 diff --git a/sw/source/ui/utlui/content.cxx b/sw/source/ui/utlui/content.cxx index 8e6ea32..f150239 100644 --- a/sw/source/ui/utlui/content.cxx +++ b/sw/source/ui/utlui/content.cxx @@ -105,7 +105,9 @@ using namespace ::com::sun::star::container; #define NAVI_BOOKMARK_DELIM (sal_Unicode)1 class SwContentArr - : public o3tl::sorted_vector<SwContent*, o3tl::less_ptr_to<SwContent> > + : public o3tl::sorted_vector<SwContent*, o3tl::less_ptr_to<SwContent>, + o3tl::find_partialorder_ptrequals<SwContent*, + o3tl::less_ptr_to<SwContent> > > { public: ~SwContentArr() { DeleteAndDestroyAll(); } commit 24a8ad1591e11e2905318d31106a5568f92cac2b Author: Michael Stahl <[email protected]> Date: Tue Jul 31 19:01:29 2012 +0200 SwHTMLPosFlyFrms: fix STL conversion: It appears that the operator== for SwHTMLPosFlyFrm always returns false, so fbabbcefd8f8575c7b08c7a7ac7fe0b665038214 changed the semantics; use o3tl::find_partialorder_ptrequals to fix it. Change-Id: I43797d62eb95a6c5012dd486fab98a0a8b88b768 diff --git a/sw/source/filter/html/htmlfly.hxx b/sw/source/filter/html/htmlfly.hxx index 81f3ced..19b14e0 100644 --- a/sw/source/filter/html/htmlfly.hxx +++ b/sw/source/filter/html/htmlfly.hxx @@ -127,7 +127,12 @@ public: sal_uInt8 GetOutCntnr() const { return nOutputMode & HTML_CNTNR_MASK; } }; -class SwHTMLPosFlyFrms : public o3tl::sorted_vector<SwHTMLPosFlyFrm*, o3tl::less_ptr_to<SwHTMLPosFlyFrm> > {}; +class SwHTMLPosFlyFrms + : public o3tl::sorted_vector<SwHTMLPosFlyFrm*, + o3tl::less_ptr_to<SwHTMLPosFlyFrm>, + o3tl::find_partialorder_ptrequals<SwHTMLPosFlyFrm*, + o3tl::less_ptr_to<SwHTMLPosFlyFrm> > > +{}; #endif commit 64b2207025388b6a87462f912584228a10301628 Author: Michael Stahl <[email protected]> Date: Tue Jul 31 18:53:04 2012 +0200 _SwRedlineTbl: fix STL conversion: It appears that the operator== for SwRedline does pointer equality check, so ddd84d08c9bb6e00fbd9a73bd52a28688a8c1ba7 changed the semantics; use o3tl::find_partialorder_ptrequals to fix it. Change-Id: I8d4a13da9543ef8a7f6e38c05eef3a2c9918e421 diff --git a/sw/inc/docary.hxx b/sw/inc/docary.hxx index 8270a74..7c9f928 100644 --- a/sw/inc/docary.hxx +++ b/sw/inc/docary.hxx @@ -143,7 +143,10 @@ struct CompareSwRedlineTbl { bool operator()(SwRedline* const &lhs, SwRedline* const &rhs) const; }; -class _SwRedlineTbl : public o3tl::sorted_vector<SwRedline*, CompareSwRedlineTbl> { +class _SwRedlineTbl + : public o3tl::sorted_vector<SwRedline*, CompareSwRedlineTbl, + o3tl::find_partialorder_ptrequals<SwRedline*, CompareSwRedlineTbl> > +{ public: ~_SwRedlineTbl(); }; commit 2815396a1813cb3956c5aba066de49a7f34bc657 Author: Michael Stahl <[email protected]> Date: Tue Jul 31 17:25:44 2012 +0200 _SetGetExpFlds: this looks simpler with upper_bound Change-Id: I37dd291aaa229493141fbb8b426488e8e4427185 diff --git a/sw/source/core/doc/docfld.cxx b/sw/source/core/doc/docfld.cxx index 6f1fdf6..aa5156e 100644 --- a/sw/source/core/doc/docfld.cxx +++ b/sw/source/core/doc/docfld.cxx @@ -1106,12 +1106,10 @@ void SwDoc::FldsToCalc( SwCalc& rCalc, const _SetGetExpFld& rToThisFld ) if( !pUpdtFlds->GetSortLst()->empty() ) { - _SetGetExpFlds::const_iterator itLast = pUpdtFlds->GetSortLst()->lower_bound( (_SetGetExpFld*)&rToThisFld ); - if (pUpdtFlds->GetSortLst()->end() != itLast && **itLast == rToThisFld) - { - ++itLast; - } - + _SetGetExpFlds::const_iterator const itLast = std::upper_bound( + pUpdtFlds->GetSortLst()->begin(), + pUpdtFlds->GetSortLst()->end(), + const_cast<_SetGetExpFld*>(&rToThisFld)); for( _SetGetExpFlds::const_iterator it = pUpdtFlds->GetSortLst()->begin(); it != itLast; ++it ) lcl_CalcFld( *this, rCalc, **it, pMgr ); } @@ -1154,14 +1152,10 @@ void SwDoc::FldsToExpand( SwHash**& ppHashTbl, sal_uInt16& rTblSize, ppHashTbl = new SwHash*[ rTblSize ]; memset( ppHashTbl, 0, sizeof( _HashStr* ) * rTblSize ); - _SetGetExpFlds::const_iterator itLast; - { - itLast = pUpdtFlds->GetSortLst()->lower_bound( (_SetGetExpFld*)&rToThisFld ); - if (pUpdtFlds->GetSortLst()->end() != itLast && **itLast == rToThisFld) - { - ++itLast; - } - } + _SetGetExpFlds::const_iterator const itLast = std::upper_bound( + pUpdtFlds->GetSortLst()->begin(), + pUpdtFlds->GetSortLst()->end(), + const_cast<_SetGetExpFld*>(&rToThisFld)); for( _SetGetExpFlds::const_iterator it = pUpdtFlds->GetSortLst()->begin(); it != itLast; ++it ) { commit b60285e916e1c4102ef990f9aacb85307973d55e Author: Michael Stahl <[email protected]> Date: Tue Jul 31 16:34:50 2012 +0200 SwpHintsArray: deploy some asserts Change-Id: I16f416cb63221860ff743ce2e2291af99cd19de2 diff --git a/sw/source/core/txtnode/ndhints.cxx b/sw/source/core/txtnode/ndhints.cxx index 88ea48f..29efd9f 100644 --- a/sw/source/core/txtnode/ndhints.cxx +++ b/sw/source/core/txtnode/ndhints.cxx @@ -130,14 +130,10 @@ bool CompareSwpHtEnd::operator()(SwTxtAttr* const lhs, SwTxtAttr* const rhs) con void SwpHintsArray::Insert( const SwTxtAttr *pHt ) { Resort(); -#if OSL_DEBUG_LEVEL > 0 - OSL_ENSURE( - m_HintStarts.find(const_cast<SwTxtAttr*>(pHt)) == m_HintStarts.end(), - "Insert: hint already in HtStart"); - OSL_ENSURE( - m_HintEnds.find(const_cast<SwTxtAttr*>(pHt)) == m_HintEnds.end(), - "Insert: hint already in HtEnd"); -#endif + assert(m_HintStarts.find(const_cast<SwTxtAttr*>(pHt)) + == m_HintStarts.end()); // "Insert: hint already in HtStart" + assert(m_HintEnds.find(const_cast<SwTxtAttr*>(pHt)) + == m_HintEnds.end()); // "Insert: hint already in HtEnd" m_HintStarts.insert( const_cast<SwTxtAttr*>(pHt) ); m_HintEnds .insert( const_cast<SwTxtAttr*>(pHt) ); } commit 43377e09d86dfcf800270a4c469ea5bd373392c6 Author: Michael Stahl <[email protected]> Date: Tue Jul 31 15:52:38 2012 +0200 fix some problems in previous STL conversion: - use o3tl::find_partialorder_ptrequals to allow multiple hints on same position - GetPos must not dereference its argument - unused IsEquals Change-Id: I274203be96ff90d1e9a46bab17fd00355514a4fa diff --git a/sw/inc/ndhints.hxx b/sw/inc/ndhints.hxx index 75df3f7..154c957 100644 --- a/sw/inc/ndhints.hxx +++ b/sw/inc/ndhints.hxx @@ -75,13 +75,15 @@ struct CompareSwpHtStart { bool operator()(SwTxtAttr* const lhs, SwTxtAttr* const rhs) const; }; -class SwpHtStart : public o3tl::sorted_vector<SwTxtAttr*, CompareSwpHtStart> {}; +class SwpHtStart : public o3tl::sorted_vector<SwTxtAttr*, CompareSwpHtStart, + o3tl::find_partialorder_ptrequals<SwTxtAttr*, CompareSwpHtStart> > {}; struct CompareSwpHtEnd { bool operator()(SwTxtAttr* const lhs, SwTxtAttr* const rhs) const; }; -class SwpHtEnd : public o3tl::sorted_vector<SwTxtAttr*, CompareSwpHtEnd> {}; +class SwpHtEnd : public o3tl::sorted_vector<SwTxtAttr*, CompareSwpHtEnd, + o3tl::find_partialorder_ptrequals<SwTxtAttr*, CompareSwpHtEnd> > {}; // Class SwpHintsArr @@ -212,7 +214,8 @@ SvStream &operator<<(SvStream &aS, const SwpHints &rHints); //$ ostream inline sal_uInt16 SwpHintsArray::GetStartOf( const SwTxtAttr *pHt ) const { - SwpHtStart::const_iterator it = m_HintStarts.find( (SwTxtAttr*)pHt ); + SwpHtStart::const_iterator const it = + m_HintStarts.find(const_cast<SwTxtAttr*>(pHt)); if ( it == m_HintStarts.end() ) { return USHRT_MAX; diff --git a/sw/source/core/txtnode/ndhints.cxx b/sw/source/core/txtnode/ndhints.cxx index f3b8c9d..88ea48f 100644 --- a/sw/source/core/txtnode/ndhints.cxx +++ b/sw/source/core/txtnode/ndhints.cxx @@ -39,15 +39,6 @@ inline void DumpHints(const SwpHtStart &, const SwpHtEnd &) { } /************************************************************************* - * inline IsEqual() - *************************************************************************/ - -static bool IsEqual( const SwTxtAttr &rHt1, const SwTxtAttr &rHt2 ) -{ - return &rHt1 == &rHt2; -} - -/************************************************************************* * IsLessStart() *************************************************************************/ @@ -140,13 +131,15 @@ void SwpHintsArray::Insert( const SwTxtAttr *pHt ) { Resort(); #if OSL_DEBUG_LEVEL > 0 - OSL_ENSURE(m_HintStarts.find( (SwTxtAttr*)pHt ) == m_HintStarts.end(), + OSL_ENSURE( + m_HintStarts.find(const_cast<SwTxtAttr*>(pHt)) == m_HintStarts.end(), "Insert: hint already in HtStart"); - OSL_ENSURE(m_HintEnds.find( (SwTxtAttr*)pHt ) == m_HintEnds.end(), + OSL_ENSURE( + m_HintEnds.find(const_cast<SwTxtAttr*>(pHt)) == m_HintEnds.end(), "Insert: hint already in HtEnd"); #endif - m_HintStarts.insert( (SwTxtAttr*)pHt ); - m_HintEnds.insert( (SwTxtAttr*)pHt ); + m_HintStarts.insert( const_cast<SwTxtAttr*>(pHt) ); + m_HintEnds .insert( const_cast<SwTxtAttr*>(pHt) ); } void SwpHintsArray::DeleteAtPos( const sal_uInt16 nPos ) @@ -157,15 +150,23 @@ void SwpHintsArray::DeleteAtPos( const sal_uInt16 nPos ) Resort(); - m_HintEnds.erase( pHt ); + bool const done = m_HintEnds.erase(pHt); + assert(done); } sal_uInt16 SwpHintsArray::GetPos( const SwTxtAttr *pHt ) const { - SwpHtStart::const_iterator it = m_HintStarts.find( (SwTxtAttr*)pHt ); - if( it == m_HintStarts.end() ) - return USHRT_MAX; - return it - m_HintStarts.begin(); + // DO NOT use find() here! + // if called from SwTxtNode::InsertItem, pHt has already been deleted, + // so it cannot be dereferenced + for (size_t i = 0; i < m_HintStarts.size(); ++i) + { + if (m_HintStarts[i] == pHt) + { + return i; + } + } + return USHRT_MAX; } #ifdef DBG_UTIL @@ -234,13 +235,13 @@ bool SwpHintsArray::Check() const // --- Ueberkreuzungen --- // 5) gleiche Pointer in beiden Arrays - if( m_HintStarts.find( (SwTxtAttr*)pHt ) == m_HintStarts.end() ) + if (m_HintStarts.find(const_cast<SwTxtAttr*>(pHt)) == m_HintStarts.end()) nIdx = STRING_LEN; CHECK_ERR( STRING_LEN != nIdx, "HintsCheck: no GetStartOf" ); // 6) gleiche Pointer in beiden Arrays - if( m_HintEnds.find( (SwTxtAttr*)pHt ) == m_HintEnds.end() ) + if (m_HintEnds.find(const_cast<SwTxtAttr*>(pHt)) == m_HintEnds.end()) nIdx = STRING_LEN; CHECK_ERR( STRING_LEN != nIdx, "HintsCheck: no GetEndOf" ); commit 4623c603bde7678004fe6019f9d9e4b816a3d6c6 Author: Noel Grandin <[email protected]> Date: Mon Jul 30 23:00:44 2012 +0200 sw: convert SwpHtStart SwpHtEnd to sorted_vector Change-Id: I74696094ef066687582bd961d61a4877673016fd diff --git a/sw/inc/ndhints.hxx b/sw/inc/ndhints.hxx index 6f0d896..75df3f7 100644 --- a/sw/inc/ndhints.hxx +++ b/sw/inc/ndhints.hxx @@ -29,8 +29,8 @@ #define _NDHINTS_HXX -#include <svl/svarray.hxx> #include <tools/mempool.hxx> +#include <o3tl/sorted_vector.hxx> #include "swtypes.hxx" @@ -71,9 +71,17 @@ MakeRedlineTxtAttr( SwDoc & rDoc, SfxPoolItem& rAttr ); // Class SwpHtStart/End +struct CompareSwpHtStart +{ + bool operator()(SwTxtAttr* const lhs, SwTxtAttr* const rhs) const; +}; +class SwpHtStart : public o3tl::sorted_vector<SwTxtAttr*, CompareSwpHtStart> {}; -SV_DECL_PTRARR_SORT(SwpHtStart,SwTxtAttr*,1) -SV_DECL_PTRARR_SORT(SwpHtEnd,SwTxtAttr*,1) +struct CompareSwpHtEnd +{ + bool operator()(SwTxtAttr* const lhs, SwTxtAttr* const rhs) const; +}; +class SwpHtEnd : public o3tl::sorted_vector<SwTxtAttr*, CompareSwpHtEnd> {}; // Class SwpHintsArr @@ -102,18 +110,17 @@ public: inline SwTxtAttr * GetEnd ( const sal_uInt16 nPos ) { return m_HintEnds [nPos]; } - inline sal_uInt16 GetEndCount() const { return m_HintEnds .Count(); } - inline sal_uInt16 GetStartCount() const { return m_HintStarts.Count(); } + inline sal_uInt16 GetEndCount() const { return m_HintEnds .size(); } + inline sal_uInt16 GetStartCount() const { return m_HintStarts.size(); } inline sal_uInt16 GetStartOf( const SwTxtAttr *pHt ) const; - inline sal_uInt16 GetPos( const SwTxtAttr *pHt ) const - { return m_HintStarts.GetPos( pHt ); } + sal_uInt16 GetPos( const SwTxtAttr *pHt ) const; inline SwTxtAttr * GetTextHint( const sal_uInt16 nIdx ) { return GetStart(nIdx); } inline const SwTxtAttr * operator[]( const sal_uInt16 nIdx ) const { return m_HintStarts[nIdx]; } - inline sal_uInt16 Count() const { return m_HintStarts.Count(); } + inline sal_uInt16 Count() const { return m_HintStarts.size(); } #ifdef DBG_UTIL bool Check() const; @@ -205,12 +212,12 @@ SvStream &operator<<(SvStream &aS, const SwpHints &rHints); //$ ostream inline sal_uInt16 SwpHintsArray::GetStartOf( const SwTxtAttr *pHt ) const { - sal_uInt16 nPos; - if ( !m_HintStarts.Seek_Entry( pHt, &nPos ) ) + SwpHtStart::const_iterator it = m_HintStarts.find( (SwTxtAttr*)pHt ); + if ( it == m_HintStarts.end() ) { - nPos = USHRT_MAX; + return USHRT_MAX; } - return nPos; + return it - m_HintStarts.begin(); } inline SwTxtAttr *SwpHintsArray::Cut( const sal_uInt16 nPosInStart ) diff --git a/sw/source/core/txtnode/ndhints.cxx b/sw/source/core/txtnode/ndhints.cxx index 02c0cfd..f3b8c9d 100644 --- a/sw/source/core/txtnode/ndhints.cxx +++ b/sw/source/core/txtnode/ndhints.cxx @@ -36,9 +36,6 @@ #endif -_SV_IMPL_SORTAR_ALG( SwpHtStart, SwTxtAttr* ) -_SV_IMPL_SORTAR_ALG( SwpHtEnd, SwTxtAttr* ) - inline void DumpHints(const SwpHtStart &, const SwpHtEnd &) { } /************************************************************************* @@ -125,76 +122,14 @@ static sal_Bool lcl_IsLessEnd( const SwTxtAttr &rHt1, const SwTxtAttr &rHt2 ) return ( nHt1 < nHt2 ); } -/************************************************************************* - * SwpHtStart::Seek_Entry() - *************************************************************************/ - -sal_Bool SwpHtStart::Seek_Entry( const SwTxtAttr *pElement, sal_uInt16 *pPos ) const +bool CompareSwpHtStart::operator()(SwTxtAttr* const lhs, SwTxtAttr* const rhs) const { - sal_uInt16 nOben = Count(), nMitte, nUnten = 0; - if( nOben > 0 ) - { - nOben--; - while( nUnten <= nOben ) - { - nMitte = nUnten + ( nOben - nUnten ) / 2; - const SwTxtAttr *pMitte = (*this)[nMitte]; - if( IsEqual( *pMitte, *pElement ) ) - { - *pPos = nMitte; - return sal_True; - } - else - if( lcl_IsLessStart( *pMitte, *pElement ) ) - nUnten = nMitte + 1; - else - if( nMitte == 0 ) - { - *pPos = nUnten; - return sal_False; - } - else - nOben = nMitte - 1; - } - } - *pPos = nUnten; - return sal_False; + return lcl_IsLessStart( *lhs, *rhs ); } -/************************************************************************* - * SwpHtEnd::Seek_Entry() - *************************************************************************/ - -sal_Bool SwpHtEnd::Seek_Entry( const SwTxtAttr *pElement, sal_uInt16 *pPos ) const +bool CompareSwpHtEnd::operator()(SwTxtAttr* const lhs, SwTxtAttr* const rhs) const { - sal_uInt16 nOben = Count(), nMitte, nUnten = 0; - if( nOben > 0 ) - { - nOben--; - while( nUnten <= nOben ) - { - nMitte = nUnten + ( nOben - nUnten ) / 2; - const SwTxtAttr *pMitte = (*this)[nMitte]; - if( IsEqual( *pMitte, *pElement ) ) - { - *pPos = nMitte; - return sal_True; - } - else - if( lcl_IsLessEnd( *pMitte, *pElement ) ) - nUnten = nMitte + 1; - else - if( nMitte == 0 ) - { - *pPos = nUnten; - return sal_False; - } - else - nOben = nMitte - 1; - } - } - *pPos = nUnten; - return sal_False; + return lcl_IsLessEnd( *lhs, *rhs ); } /************************************************************************* @@ -205,27 +140,32 @@ void SwpHintsArray::Insert( const SwTxtAttr *pHt ) { Resort(); #if OSL_DEBUG_LEVEL > 0 - sal_uInt16 nPos; - OSL_ENSURE(!m_HintStarts.Seek_Entry( pHt, &nPos ), + OSL_ENSURE(m_HintStarts.find( (SwTxtAttr*)pHt ) == m_HintStarts.end(), "Insert: hint already in HtStart"); - OSL_ENSURE(!m_HintEnds.Seek_Entry( pHt, &nPos ), + OSL_ENSURE(m_HintEnds.find( (SwTxtAttr*)pHt ) == m_HintEnds.end(), "Insert: hint already in HtEnd"); #endif - m_HintStarts.Insert( pHt ); - m_HintEnds.Insert( pHt ); + m_HintStarts.insert( (SwTxtAttr*)pHt ); + m_HintEnds.insert( (SwTxtAttr*)pHt ); } void SwpHintsArray::DeleteAtPos( const sal_uInt16 nPos ) { // optimization: nPos is the position in the Starts array - const SwTxtAttr *pHt = m_HintStarts[ nPos ]; - m_HintStarts.Remove( nPos ); + SwTxtAttr *pHt = m_HintStarts[ nPos ]; + m_HintStarts.erase( m_HintStarts.begin() + nPos ); Resort(); - sal_uInt16 nEndPos; - m_HintEnds.Seek_Entry( pHt, &nEndPos ); - m_HintEnds.Remove( nEndPos ); + m_HintEnds.erase( pHt ); +} + +sal_uInt16 SwpHintsArray::GetPos( const SwTxtAttr *pHt ) const +{ + SwpHtStart::const_iterator it = m_HintStarts.find( (SwTxtAttr*)pHt ); + if( it == m_HintStarts.end() ) + return USHRT_MAX; + return it - m_HintStarts.begin(); } #ifdef DBG_UTIL @@ -246,7 +186,7 @@ void SwpHintsArray::DeleteAtPos( const sal_uInt16 nPos ) bool SwpHintsArray::Check() const { // 1) gleiche Anzahl in beiden Arrays - CHECK_ERR( m_HintStarts.Count() == m_HintEnds.Count(), + CHECK_ERR( m_HintStarts.size() == m_HintEnds.size(), "HintsCheck: wrong sizes" ); xub_StrLen nLastStart = 0; xub_StrLen nLastEnd = 0; @@ -294,13 +234,13 @@ bool SwpHintsArray::Check() const // --- Ueberkreuzungen --- // 5) gleiche Pointer in beiden Arrays - if( !m_HintStarts.Seek_Entry( pHt, &nIdx ) ) + if( m_HintStarts.find( (SwTxtAttr*)pHt ) == m_HintStarts.end() ) nIdx = STRING_LEN; CHECK_ERR( STRING_LEN != nIdx, "HintsCheck: no GetStartOf" ); // 6) gleiche Pointer in beiden Arrays - if( !m_HintEnds.Seek_Entry( pHt, &nIdx ) ) + if( m_HintEnds.find( (SwTxtAttr*)pHt ) == m_HintEnds.end() ) nIdx = STRING_LEN; CHECK_ERR( STRING_LEN != nIdx, "HintsCheck: no GetEndOf" ); @@ -386,13 +326,13 @@ bool SwpHintsArray::Resort() const SwTxtAttr *pLast = 0; sal_uInt16 i; - for ( i = 0; i < m_HintStarts.Count(); ++i ) + for ( i = 0; i < m_HintStarts.size(); ++i ) { - const SwTxtAttr *pHt = m_HintStarts[i]; + SwTxtAttr *pHt = m_HintStarts[i]; if( pLast && !lcl_IsLessStart( *pLast, *pHt ) ) { - m_HintStarts.Remove( i ); - m_HintStarts.Insert( pHt ); + m_HintStarts.erase( m_HintStarts.begin() + i ); + m_HintStarts.insert( pHt ); pHt = m_HintStarts[i]; if ( pHt != pLast ) --i; @@ -402,13 +342,13 @@ bool SwpHintsArray::Resort() } pLast = 0; - for ( i = 0; i < m_HintEnds.Count(); ++i ) + for ( i = 0; i < m_HintEnds.size(); ++i ) { - const SwTxtAttr *pHt = m_HintEnds[i]; + SwTxtAttr *pHt = m_HintEnds[i]; if( pLast && !lcl_IsLessEnd( *pLast, *pHt ) ) { - m_HintEnds.Remove( i ); - m_HintEnds.Insert( pHt ); + m_HintEnds.erase( m_HintEnds.begin() + i ); + m_HintEnds.insert( pHt ); pHt = m_HintEnds[i]; // normalerweise == pLast // Wenn die Unordnung etwas groesser ist (24200), // muessen wir Position i erneut vergleichen. commit 7ee95c521007e28ea827e8196062abb74f5c519a Author: Michael Stahl <[email protected]> Date: Tue Jul 31 15:41:57 2012 +0200 sorted_vector: add an additional template parameter: The Find parameter allows to implement sorted_vector that uses the obvious std::less-like semantics, and also allows for a different semantics where the array is sorted like std::less but duplicate values (according to std::less) are allowed except if they're actually the same object (pointer equality). Change-Id: Id54871c336ddbc2d0a2272bcc81c56914943b449 diff --git a/o3tl/inc/o3tl/sorted_vector.hxx b/o3tl/inc/o3tl/sorted_vector.hxx index 0fe46cf..4d442dd 100644 --- a/o3tl/inc/o3tl/sorted_vector.hxx +++ b/o3tl/inc/o3tl/sorted_vector.hxx @@ -17,12 +17,18 @@ namespace o3tl { +// forward declared because it's default tempate arg for sorted_vector +template<class Value, class Compare> +struct find_unique; + /** Represents a sorted vector of values. @tpl Value class of item to be stored in container @tpl Compare comparison method + @tpl Find look up index of a Value in the array */ -template <class Value, class Compare = std::less<Value> > +template<class Value, class Compare = std::less<Value>, + class Find = find_unique<Value, Compare> > class sorted_vector : private std::vector<Value> { @@ -41,21 +47,22 @@ public: std::pair<const_iterator,bool> insert( const Value& x ) { - iterator it = lower_bound_nonconst( x ); - if (it == base_t::end() || less_than(x, *it)) + std::pair<const_iterator, bool> const ret(Find()(begin(), end(), x)); + if (!ret.second) { - it = base_t::insert( it, x ); - return std::make_pair( it, true ); + const_iterator const it = base_t::insert( + begin_nonconst() + (ret.first - begin()), x); + return std::make_pair(it, true); } - return std::make_pair( it, false ); + return std::make_pair(ret.first, false); } size_type erase( const Value& x ) { - iterator it = lower_bound_nonconst( x ); - if (it != base_t::end() && !less_than(x, *it)) + std::pair<const_iterator, bool> const ret(Find()(begin(), end(), x)); + if (ret.second) { - base_t::erase(it); + base_t::erase(begin_nonconst() + (ret.first - begin())); return 1; } return 0; @@ -122,15 +129,11 @@ public: */ const_iterator find( const Value& x ) const { - const_iterator it = lower_bound( x ); - if (it == base_t::end() || less_than(x, *it)) - { - return base_t::end(); - } - return it; + std::pair<const_iterator, bool> const ret(Find()(begin(), end(), x)); + return (ret.second) ? ret.first : end(); } - void insert( sorted_vector<Value,Compare> &rOther ) + void insert( sorted_vector<Value,Compare,Find> &rOther ) { // optimisation for the rather common case that we are overwriting this with the contents // of another sorted vector @@ -153,16 +156,6 @@ public: } private: - /** just makes the code easier to read */ - bool less_than(const Value& lhs, const Value& rhs) const - { - return Compare().operator()(lhs, rhs); - } - - iterator lower_bound_nonconst( const Value& x ) - { - return std::lower_bound( base_t::begin(), base_t::end(), x, Compare() ); - } typename base_t::iterator begin_nonconst() { return base_t::begin(); } typename base_t::iterator end_nonconst() { return base_t::end(); } @@ -181,6 +174,47 @@ template <class T> struct less_ptr_to : public std::binary_function <T*,T*,bool> } }; +/** the elements are totally ordered by Compare, + for no 2 elements !Compare(a,b) && !Compare(b,a) is true + */ +template<class Value, class Compare> +struct find_unique +{ + typedef typename sorted_vector<Value, Compare, find_unique> + ::const_iterator const_iterator; + std::pair<const_iterator, bool> operator()( + const_iterator first, const_iterator last, + Value const& v) + { + const_iterator const it = std::lower_bound(first, last, v, Compare()); + return std::make_pair(it, (it != last && !Compare()(v, *it))); + } +}; + +/** the elments are partially ordered by Compare, + 2 elements are allowed if they are not the same element (pointer equal) + */ +template<class Value, class Compare> +struct find_partialorder_ptrequals +{ + typedef typename sorted_vector<Value, Compare, find_partialorder_ptrequals> + ::const_iterator const_iterator; + std::pair<const_iterator, bool> operator()( + const_iterator first, const_iterator last, + Value const& v) + { + std::pair<const_iterator, const_iterator> const its = + std::equal_range(first, last, v, Compare()); + for (const_iterator it = its.first; it != its.second; ++it) + { + if (v == *it) + { + return std::make_pair(it, true); + } + } + return std::make_pair(its.first, false); + } +}; } // namespace o3tl #endif diff --git a/o3tl/qa/test-sorted_vector.cxx b/o3tl/qa/test-sorted_vector.cxx index 5641ad2..1b321c9 100644 --- a/o3tl/qa/test-sorted_vector.cxx +++ b/o3tl/qa/test-sorted_vector.cxx @@ -133,6 +133,118 @@ public: CPPUNIT_ASSERT( aVec.lower_bound(p4) == aVec.end() ); } + void testBasics_FindPtr() + { + o3tl::sorted_vector<SwContent*, o3tl::less_ptr_to<SwContent>, + o3tl::find_partialorder_ptrequals<SwContent*, + o3tl::less_ptr_to<SwContent> > > aVec; + SwContent *p1 = new SwContent(1); + SwContent *p2 = new SwContent(2); + SwContent *p2_2 = new SwContent(2); + SwContent *p2_3 = new SwContent(2); + SwContent *p2_4 = new SwContent(2); + SwContent *p3 = new SwContent(3); + SwContent *p4 = new SwContent(4); + + CPPUNIT_ASSERT( aVec.insert(p3).second ); + CPPUNIT_ASSERT( aVec.insert(p1).second ); + CPPUNIT_ASSERT( !aVec.insert(p3).second ); + + CPPUNIT_ASSERT( aVec.size() == 2 ); + + CPPUNIT_ASSERT( aVec[0] == p1 ); + CPPUNIT_ASSERT( aVec[1] == p3 ); + + CPPUNIT_ASSERT( aVec.insert(p2_2).second ); + CPPUNIT_ASSERT( aVec.insert(p2_3).second ); + CPPUNIT_ASSERT( !aVec.insert(p2_2).second ); + CPPUNIT_ASSERT( aVec.insert(p2_4).second ); + CPPUNIT_ASSERT( aVec.size() == 5 ); + + CPPUNIT_ASSERT( *aVec.begin() == p1 ); + CPPUNIT_ASSERT( *(aVec.end()-1) == p3 ); + + CPPUNIT_ASSERT( aVec.front() == p1 ); + CPPUNIT_ASSERT( aVec.back() == p3 ); + + CPPUNIT_ASSERT( aVec.find(p1) != aVec.end() ); + CPPUNIT_ASSERT( aVec.find(p1) - aVec.begin() == 0 ); + CPPUNIT_ASSERT( aVec.find(p3) != aVec.end() ); + CPPUNIT_ASSERT( aVec.find(p3) - aVec.begin() == 4 ); + CPPUNIT_ASSERT( aVec.find(p2) == aVec.end() ); + CPPUNIT_ASSERT( aVec.find(p4) == aVec.end() ); + CPPUNIT_ASSERT( aVec.find(p2_2) != aVec.end() ); + CPPUNIT_ASSERT( aVec.find(p2_2) - aVec.begin() >= 1 ); + CPPUNIT_ASSERT( aVec.find(p2_2) - aVec.begin() < 4 ); + CPPUNIT_ASSERT( aVec.find(p2_3) != aVec.end() ); + CPPUNIT_ASSERT( aVec.find(p2_3) - aVec.begin() >= 1 ); + CPPUNIT_ASSERT( aVec.find(p2_3) - aVec.begin() < 4 ); + CPPUNIT_ASSERT( aVec.find(p2_4) != aVec.end() ); + CPPUNIT_ASSERT( aVec.find(p2_4) - aVec.begin() >= 1 ); + CPPUNIT_ASSERT( aVec.find(p2_4) - aVec.begin() < 4 ); + + CPPUNIT_ASSERT( aVec.erase(p1) == 1 ); + CPPUNIT_ASSERT( aVec.size() == 4 ); + CPPUNIT_ASSERT( aVec.erase(p2) == 0 ); + CPPUNIT_ASSERT( aVec.erase(p2_3) == 1 ); + CPPUNIT_ASSERT( aVec.size() == 3 ); + + aVec.DeleteAndDestroyAll(); + } + + void testErase_FindPtr() + { + o3tl::sorted_vector<SwContent*, o3tl::less_ptr_to<SwContent>, + o3tl::find_partialorder_ptrequals<SwContent*, + o3tl::less_ptr_to<SwContent> > > aVec; + SwContent *p1 = new SwContent(1); + SwContent *p1_2 = new SwContent(1); + SwContent *p1_3 = new SwContent(1); + SwContent *p2 = new SwContent(2); + SwContent *p3 = new SwContent(3); + SwContent *p4 = new SwContent(4); + + aVec.insert(p1); + aVec.insert(p2); + aVec.insert(p3); + + CPPUNIT_ASSERT( aVec.erase(p1) == 1 ); + CPPUNIT_ASSERT( aVec.size() == 2 ); + + aVec.erase(1); + CPPUNIT_ASSERT( aVec.size() == 1 ); + + CPPUNIT_ASSERT( aVec.erase(p4) == 0 ); + + aVec.clear(); + CPPUNIT_ASSERT( aVec.size() == 0 ); + + aVec.insert(p1); + aVec.insert(p2); + aVec.insert(p3); + aVec.insert(p1_2); + CPPUNIT_ASSERT( aVec.size() == 4 ); + aVec.insert(p1_3); + CPPUNIT_ASSERT( aVec.size() == 5 ); + CPPUNIT_ASSERT( aVec.erase(p1) == 1 ); + CPPUNIT_ASSERT( aVec.find(p1) == aVec.end() ); + CPPUNIT_ASSERT( aVec.find(p1_2) != aVec.end() ); + CPPUNIT_ASSERT( aVec.find(p1_3) != aVec.end() ); + CPPUNIT_ASSERT( aVec.erase(p1_3) == 1 ); + CPPUNIT_ASSERT( aVec.find(p1) == aVec.end() ); + CPPUNIT_ASSERT( aVec.find(p1_2) != aVec.end() ); + CPPUNIT_ASSERT( aVec.find(p1_3) == aVec.end() ); + CPPUNIT_ASSERT( aVec.erase(p1_3) == 0 ); + CPPUNIT_ASSERT( aVec.find(p1) == aVec.end() ); + CPPUNIT_ASSERT( aVec.find(p1_2) != aVec.end() ); + CPPUNIT_ASSERT( aVec.find(p1_3) == aVec.end() ); + + aVec.DeleteAndDestroyAll(); + CPPUNIT_ASSERT( aVec.size() == 0 ); + } + + + // Change the following lines only, if you add, remove or rename // member functions of the current class, // because these macros are need by auto register mechanism. @@ -142,6 +254,8 @@ public: CPPUNIT_TEST(testErase); CPPUNIT_TEST(testInsertRange); CPPUNIT_TEST(testLowerBound); + CPPUNIT_TEST(testBasics_FindPtr); + CPPUNIT_TEST(testErase_FindPtr); CPPUNIT_TEST_SUITE_END(); }; commit 51bbbc6a58d0d9cfd39a2d95ce60871a619bea64 Author: Michael Stahl <[email protected]> Date: Mon Jul 30 22:14:52 2012 +0200 SwRedlineItr: convert to STL Change-Id: Idf3031a0a39d9154ba2894684ea51125553776b3 diff --git a/sw/source/core/text/redlnitr.cxx b/sw/source/core/text/redlnitr.cxx index 0e63f76..05f0cc9 100644 --- a/sw/source/core/text/redlnitr.cxx +++ b/sw/source/core/text/redlnitr.cxx @@ -275,7 +275,7 @@ short SwRedlineItr::_Seek( SwFont& rFnt, xub_StrLen nNew, xub_StrLen nOld ) const_cast<SwDoc&>(rDoc), *const_cast<SfxPoolItem*>(pItem) ); pAttr->SetPriorityAttr( sal_True ); - aHints.C40_INSERT( SwTxtAttr, pAttr, aHints.Count()); + m_Hints.push_back(pAttr); rAttrHandler.PushAndChg( *pAttr, rFnt ); if( RES_CHRATR_COLOR == nWhich ) rFnt.SetNoCol( sal_True ); @@ -338,10 +338,10 @@ void SwRedlineItr::_Clear( SwFont* pFnt ) { OSL_ENSURE( bOn, "SwRedlineItr::Clear: Off?" ); bOn = sal_False; - while( aHints.Count() ) + while (!m_Hints.empty()) { - SwTxtAttr *pPos = aHints[ 0 ]; - aHints.Remove(0); + SwTxtAttr *pPos = m_Hints.front(); + m_Hints.pop_front(); if( pFnt ) rAttrHandler.PopAndChg( *pPos, *pFnt ); else @@ -377,9 +377,9 @@ sal_Bool SwRedlineItr::_ChkSpecialUnderline() const // Wenn die Unterstreichung oder das Escapement vom Redling kommt, // wenden wir immer das SpecialUnderlining, d.h. die Unterstreichung // unter der Grundlinie an. - for( MSHORT i = 0; i < aHints.Count(); ++i ) + for (MSHORT i = 0; i < m_Hints.size(); ++i) { - MSHORT nWhich = aHints[i]->Which(); + MSHORT nWhich = m_Hints[i]->Which(); if( RES_CHRATR_UNDERLINE == nWhich || RES_CHRATR_ESCAPEMENT == nWhich ) return sal_True; diff --git a/sw/source/core/text/redlnitr.hxx b/sw/source/core/text/redlnitr.hxx index 8cbc117..42f1c24 100644 --- a/sw/source/core/text/redlnitr.hxx +++ b/sw/source/core/text/redlnitr.hxx @@ -66,7 +66,7 @@ public: class SwRedlineItr { - SwpHtStart_SAR aHints; + std::deque<SwTxtAttr *> m_Hints; const SwDoc& rDoc; const SwTxtNode& rNd; SwAttrHandler& rAttrHandler; _______________________________________________ Libreoffice-commits mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
