[Libreoffice-commits] .: 2 commits - sw/inc sw/source

Nigel Hawkins nhawkins at kemper.freedesktop.org
Tue Feb 22 02:40:22 PST 2011


 sw/inc/tabcol.hxx                 |    1 
 sw/inc/undobj.hxx                 |    1 
 sw/source/core/layout/layact.cxx  |    3 
 sw/source/filter/rtf/swparrtf.hxx |    4 -
 sw/source/filter/ww8/wrtww8.cxx   |  136 ++++++++++++++++++--------------------
 sw/source/filter/xml/xmltbli.hxx  |    3 
 6 files changed, 68 insertions(+), 80 deletions(-)

New commits:
commit c6ee79559c7abea4c628430efc37437693bc6049
Author: Nigel Hawkins <n.hawkins at gmx.com>
Date:   Mon Feb 21 20:56:57 2011 +0000

    Remove last traces of SvBools from sw

diff --git a/sw/inc/tabcol.hxx b/sw/inc/tabcol.hxx
index b7c47f4..ad179f3 100644
--- a/sw/inc/tabcol.hxx
+++ b/sw/inc/tabcol.hxx
@@ -30,7 +30,6 @@
 
 #ifndef _SVSTDARR_HXX
 #define _SVSTDARR_LONGS
-#define _SVSTDARR_BOOLS
 #include <svl/svstdarr.hxx>
 #endif
 
diff --git a/sw/inc/undobj.hxx b/sw/inc/undobj.hxx
index fb2ddf4..d9d34f6 100644
--- a/sw/inc/undobj.hxx
+++ b/sw/inc/undobj.hxx
@@ -39,7 +39,6 @@
 #ifndef _SVSTDARR_HXX
 #define _SVSTDARR_USHORTS
 #define _SVSTDARR_ULONGS
-#define _SVSTDARR_BOOLS
 #define _SVSTDARR_USHORTSSORT
 #include <svl/svstdarr.hxx>
 #endif
diff --git a/sw/source/core/layout/layact.cxx b/sw/source/core/layout/layact.cxx
index 7fffe95..57af311 100644
--- a/sw/source/core/layout/layact.cxx
+++ b/sw/source/core/layout/layact.cxx
@@ -64,9 +64,6 @@
 #include <editeng/brshitem.hxx>
 #include <SwSmartTagMgr.hxx>
 
-#define _SVSTDARR_BOOLS
-#include <svl/svstdarr.hxx>
-
 #define _LAYACT_CXX
 #include "layact.hxx"
 #include <swwait.hxx>
diff --git a/sw/source/filter/rtf/swparrtf.hxx b/sw/source/filter/rtf/swparrtf.hxx
index 82e78d5..7372562 100644
--- a/sw/source/filter/rtf/swparrtf.hxx
+++ b/sw/source/filter/rtf/swparrtf.hxx
@@ -33,10 +33,6 @@
 #include <deque>
 #include <vector>
 
-#ifndef _SVSTDARR_HXX
-#define _SVSTDARR_BOOLS
-#include <svl/svstdarr.hxx>
-#endif
 #include <editeng/svxrtf.hxx>
 #include <editeng/numitem.hxx>
 #include <editeng/boxitem.hxx>
diff --git a/sw/source/filter/ww8/wrtww8.cxx b/sw/source/filter/ww8/wrtww8.cxx
index 01c0786..3b6a075 100644
--- a/sw/source/filter/ww8/wrtww8.cxx
+++ b/sw/source/filter/ww8/wrtww8.cxx
@@ -42,7 +42,6 @@
 #include <osl/endian.h>
 #include <docsh.hxx>
 
-#define _SVSTDARR_BOOLS
 #include <svl/svstdarr.hxx>
 
 #include <unotools/fltrcfg.hxx>
diff --git a/sw/source/filter/xml/xmltbli.hxx b/sw/source/filter/xml/xmltbli.hxx
index 9ad4970..8028cc5 100644
--- a/sw/source/filter/xml/xmltbli.hxx
+++ b/sw/source/filter/xml/xmltbli.hxx
@@ -35,9 +35,8 @@
 #include <boost/unordered_map.hpp>
 #include <vector>
 
-#if !defined(_SVSTDARR_USHORTS_DECL) || !defined(_SVSTDARR_BOOLS_DECL) || !defined(_SVSTDARR_STRINGSDTOR_DECL)
+#if !defined(_SVSTDARR_USHORTS_DECL) || !defined(_SVSTDARR_STRINGSDTOR_DECL)
 #define _SVSTDARR_USHORTS
-#define _SVSTDARR_BOOLS
 #define _SVSTDARR_STRINGSDTOR
 #include <svl/svstdarr.hxx>
 #endif
commit 0283b93214055dac91aa2c751b6d4ffe6e30b493
Author: Nigel Hawkins <n.hawkins at gmx.com>
Date:   Mon Feb 21 14:11:10 2011 +0000

    Remove use of SvBools in wrtww8.cxx

diff --git a/sw/source/filter/ww8/wrtww8.cxx b/sw/source/filter/ww8/wrtww8.cxx
index 6a2f8f1..01c0786 100644
--- a/sw/source/filter/ww8/wrtww8.cxx
+++ b/sw/source/filter/ww8/wrtww8.cxx
@@ -191,12 +191,21 @@ public:
 class WW8_WrtBookmarks
 {
 private:
-    SvULongs aSttCps, aEndCps;      // Array of Start- and End CPs
-    SvBools aFieldMarks;       // If the bookmark is in a field result
-    std::vector<String> maSwBkmkNms;    // Array of Sw - Bookmarknames
-    typedef std::vector<String>::iterator myIter;
+    //! Holds information about a single bookmark.
+    struct BookmarkInfo {
+        ULONG  startPos; //!< Starting character position.
+        ULONG  endPos;   //!< Ending character position.
+        bool   isField;  //!< True if the bookmark is in a field result.
+        String name;     //!< Name of this bookmark.
+        inline BookmarkInfo(ULONG start, ULONG end, bool isFld, const String& bkName) : startPos(start), endPos(end), isField(isFld), name(bkName) {};
+        //! Operator < is defined purely for sorting.
+        inline bool operator<(const BookmarkInfo &other) const { return startPos < other.startPos; }
+    };
+    std::vector<BookmarkInfo> aBookmarks;
+    typedef std::vector<BookmarkInfo>::iterator BkmIter;
 
-    USHORT GetPos( const String& rNm );
+    //! Return the position in aBookmarks where the string rNm can be found.
+    BkmIter GetPos( const String& rNm );
 
     //No copying
     WW8_WrtBookmarks(const WW8_WrtBookmarks&);
@@ -205,8 +214,11 @@ public:
     WW8_WrtBookmarks();
     ~WW8_WrtBookmarks();
 
+    //! Add a new bookmark to the list OR add an end position to an existing bookmark.
     void Append( WW8_CP nStartCp, const String& rNm, const ::sw::mark::IMark* pBkmk=NULL );
+    //! Write out bookmarks to file.
     void Write( WW8Export& rWrt );
+    //! Move existing field marks from one position to another.
     void MoveFieldMarks(ULONG nFrom,ULONG nTo);
 
 };
@@ -1257,7 +1269,6 @@ WW8_CP WW8_WrPct::Fc2Cp( ULONG nFc ) const
 /*  */
 
 WW8_WrtBookmarks::WW8_WrtBookmarks()
-    : aSttCps( 0, 16 ), aEndCps( 0, 16 )
 {
 }
 
@@ -1267,71 +1278,63 @@ WW8_WrtBookmarks::~WW8_WrtBookmarks()
 
 void WW8_WrtBookmarks::Append( WW8_CP nStartCp, const String& rNm,  const ::sw::mark::IMark* )
 {
-    USHORT nPos = GetPos( rNm );
-    if( USHRT_MAX == nPos )
+    BkmIter bkIter = GetPos( rNm );
+    if( bkIter == aBookmarks.end() )
     {
-        // new -> insert as start position
-        nPos = aSttCps.Count();
-        myIter aIter = maSwBkmkNms.end();
-        // sort by startposition
-        //      theory: write continuous -> then the new position is at end
-        while( nPos && aSttCps[ nPos - 1 ] > ULONG( nStartCp ))
-        {
-            --nPos;
-            --aIter;
-        }
-
-        aSttCps.Insert(nStartCp, nPos);
-        aEndCps.Insert(nStartCp, nPos);
-        aFieldMarks.Insert(BOOL(false), nPos);
-        maSwBkmkNms.insert(aIter, rNm);
+        // new bookmark -> insert with start==end
+        aBookmarks.push_back( BookmarkInfo(nStartCp, nStartCp, false, rNm) );
     }
     else
     {
-        // old -> its the end position
-        OSL_ENSURE( aEndCps[ nPos ] == aSttCps[ nPos ], "end position is valid" );
+        // old bookmark -> this should be the end position
+        OSL_ENSURE( bkIter->endPos == bkIter->startPos, "end position is valid" );
 
         //If this bookmark was around a field in writer, then we want to move
         //it to the field result in word. The end is therefore one cp
         //backwards from the 0x15 end mark that was inserted.
-        if (aFieldMarks[nPos])
+        if (bkIter->isField)
             --nStartCp;
-
-        aEndCps.Replace( nStartCp, nPos );
+        bkIter->endPos = nStartCp;
     }
 }
 
 
 void WW8_WrtBookmarks::Write( WW8Export& rWrt )
 {
-    USHORT nCount = aSttCps.Count(), i;
-    if( nCount )
+    if (!aBookmarks.empty())
     {
-        SvULongs aEndSortTab( 255 < nCount ? 255 : nCount, 4 );
-        // sort then endpositions
-        for( i = 0; i < nCount; ++i )
-        {
-            ULONG nCP = aEndCps[ i ];
-            USHORT nPos = i;
-            while( nPos && aEndSortTab[ nPos - 1 ] > nCP )
-                --nPos;
-            aEndSortTab.Insert( nCP, nPos );
-        }
+        //Make sure the bookmarks are sorted in order of start position.
+        std::sort(aBookmarks.begin(), aBookmarks.end());
 
-        // we have some bookmarks found in the document -> write them
-        // first the Bookmark Name Stringtable
-        rWrt.WriteAsStringTable(maSwBkmkNms, rWrt.pFib->fcSttbfbkmk,
-            rWrt.pFib->lcbSttbfbkmk);
+        // First write the Bookmark Name Stringtable
+        std::vector<String> aNames;
+        aNames.reserve(aBookmarks.size());
+        for (BkmIter bIt = aBookmarks.begin(); bIt < aBookmarks.end(); ++bIt)
+            aNames.push_back(bIt->name);
+        rWrt.WriteAsStringTable(aNames, rWrt.pFib->fcSttbfbkmk, rWrt.pFib->lcbSttbfbkmk);
 
-        // second the Bookmark start positions as pcf of longs
+        // Second write the Bookmark start positions as pcf of longs
         SvStream& rStrm = rWrt.bWrtWW8 ? *rWrt.pTableStrm : rWrt.Strm();
         rWrt.pFib->fcPlcfbkf = rStrm.Tell();
-        for( i = 0; i < nCount; ++i )
-            SwWW8Writer::WriteLong( rStrm, aSttCps[ i ] );
+        for (BkmIter bIt = aBookmarks.begin(); bIt < aBookmarks.end(); ++bIt)
+            SwWW8Writer::WriteLong( rStrm, bIt->startPos );
         SwWW8Writer::WriteLong(rStrm, rWrt.pFib->ccpText + rWrt.pFib->ccpTxbx);
-        for( i = 0; i < nCount; ++i )
-        {
-            ULONG nEndCP = aEndCps[ i ];
+
+        //Lastly, need to write out the end positions (sorted by end position). But
+        //before that we need a lookup table (sorted by start position) to link
+        //start and end positions.
+        //   Start by sorting the end positions.
+        std::vector<ULONG> aEndSortTab;
+        aEndSortTab.reserve(aBookmarks.size());
+        for (BkmIter bIt = aBookmarks.begin(); bIt < aBookmarks.end(); ++bIt)
+            aEndSortTab.push_back(bIt->endPos);
+        std::sort(aEndSortTab.begin(), aEndSortTab.end());
+
+        //Now write out the lookups.
+        //Note that in most cases, the positions in both vectors will be very close.
+        for( ULONG i = 0; i < aBookmarks.size(); ++i )
+        {
+            ULONG nEndCP = aBookmarks[ i ].endPos;
             USHORT nPos = i;
             if( aEndSortTab[ nPos ] > nEndCP )
             {
@@ -1341,43 +1344,39 @@ void WW8_WrtBookmarks::Write( WW8Export& rWrt )
             else if( aEndSortTab[ nPos ] < nEndCP )
                 while( aEndSortTab[ ++nPos ] != nEndCP )
                     ;
-
             SwWW8Writer::WriteLong( rStrm, nPos );
         }
         rWrt.pFib->lcbPlcfbkf = rStrm.Tell() - rWrt.pFib->fcPlcfbkf;
 
-        // third the Bookmark end positions
+        // Finally, the actual Bookmark end positions.
         rWrt.pFib->fcPlcfbkl = rStrm.Tell();
-        for( i = 0; i < nCount; ++i )
+        for(ULONG i = 0; i < aEndSortTab.size(); ++i )
             SwWW8Writer::WriteLong( rStrm, aEndSortTab[ i ] );
         SwWW8Writer::WriteLong(rStrm, rWrt.pFib->ccpText + rWrt.pFib->ccpTxbx);
         rWrt.pFib->lcbPlcfbkl = rStrm.Tell() - rWrt.pFib->fcPlcfbkl;
     }
 }
 
-USHORT WW8_WrtBookmarks::GetPos( const String& rNm )
+WW8_WrtBookmarks::BkmIter WW8_WrtBookmarks::GetPos( const String& rNm )
 {
-    USHORT nRet = USHRT_MAX, n;
-    for (n = 0; n < aSttCps.Count(); ++n)
-        if (rNm == maSwBkmkNms[n])
-        {
-            nRet = n;
-            break;
-        }
-    return nRet;
+    for (BkmIter bIt = aBookmarks.begin(); bIt < aBookmarks.end(); ++bIt) {
+        if (rNm == bIt->name)
+            return bIt;
+    }
+    return aBookmarks.end();
 }
 
 void WW8_WrtBookmarks::MoveFieldMarks(ULONG nFrom, ULONG nTo)
 {
-    for (USHORT nI=0;nI<aSttCps.Count();++nI)
+    for (BkmIter i = aBookmarks.begin(); i < aBookmarks.end(); ++i)
     {
-        if (aSttCps[nI] == nFrom)
+        if (i->startPos == nFrom)
         {
-            aSttCps[nI] = nTo;
-            if (aEndCps[nI] == nFrom)
+            i->startPos = nTo;
+            if (i->endPos == nFrom)
             {
-                aFieldMarks[nI] = true;
-                aEndCps[nI] = nTo;
+                i->isField = true;
+                i->endPos = nTo;
             }
         }
     }


More information about the Libreoffice-commits mailing list