summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorBjoern Michaelsen <bjoern.michaelsen@canonical.com>2014-12-19 02:05:44 +0100
committerBjoern Michaelsen <bjoern.michaelsen@canonical.com>2014-12-23 04:02:11 +0100
commit82ef5f9eab317171d4b08f5471222cce8f1fcdbf (patch)
tree52ee226b30daaa94e20e40612ec88fd912ef611c /sw
parentdfffff2a59983466748211944bc02013f4eba4b4 (diff)
use sw::Ring instead
Diffstat (limited to 'sw')
-rw-r--r--sw/inc/ndarr.hxx4
-rw-r--r--sw/inc/ndindex.hxx7
-rw-r--r--sw/inc/ring.hxx2
-rw-r--r--sw/source/core/docnode/ndindex.cxx5
-rw-r--r--sw/source/core/docnode/nodes.cxx78
5 files changed, 27 insertions, 69 deletions
diff --git a/sw/inc/ndarr.hxx b/sw/inc/ndarr.hxx
index e60b9eed8550..c7979dae5be9 100644
--- a/sw/inc/ndarr.hxx
+++ b/sw/inc/ndarr.hxx
@@ -21,6 +21,7 @@
#define INCLUDED_SW_INC_NDARR_HXX
#include <vector>
+#include <memory>
#include <boost/utility.hpp>
@@ -31,6 +32,7 @@
#include <bparr.hxx>
#include <ndtyp.hxx>
#include <o3tl/sorted_vector.hxx>
+#include <ring.hxx>
class Graphic;
class GraphicObject;
@@ -93,7 +95,7 @@ class SW_DLLPUBLIC SwNodes
friend class SwStartNode;
friend class ::sw::DocumentContentOperationsManager;
- SwNodeIndex* pRoot; ///< List of all indices on nodes.
+ SwNodeIndex* vIndices; ///< ring of all indices on nodes.
void InsertNode( const SwNodePtr pNode,
const SwNodeIndex& rPos );
diff --git a/sw/inc/ndindex.hxx b/sw/inc/ndindex.hxx
index 836e4b836e45..e0439ccdfa4d 100644
--- a/sw/inc/ndindex.hxx
+++ b/sw/inc/ndindex.hxx
@@ -25,19 +25,16 @@
#include <tools/solar.h>
#include <node.hxx>
+#include <ring.hxx>
class SwNode;
class SwNodes;
/// Marks a node in the document model.
-class SW_DLLPUBLIC SwNodeIndex SAL_FINAL
+class SW_DLLPUBLIC SwNodeIndex SAL_FINAL : public sw::Ring<SwNodeIndex>
{
- friend void SwNodes::RegisterIndex( SwNodeIndex& );
friend void SwNodes::DeRegisterIndex( SwNodeIndex& );
- friend void SwNodes::RemoveNode( sal_uLong, sal_uLong, bool );
-
SwNode* pNd;
- SwNodeIndex *pNext, *pPrev;
void Remove();
diff --git a/sw/inc/ring.hxx b/sw/inc/ring.hxx
index e4c62f5af146..85f62bde0af4 100644
--- a/sw/inc/ring.hxx
+++ b/sw/inc/ring.hxx
@@ -216,7 +216,7 @@ namespace sw
private:
friend class boost::iterator_core_access;
void increment()
- { m_pCurrent = m_pCurrent ? m_pCurrent->GetNextInRing() : m_pStart->GetNext(); }
+ { m_pCurrent = m_pCurrent ? m_pCurrent->GetNextInRing() : m_pStart->GetNextInRing(); }
bool equal(RingIterator const& other) const
{
// we never want to compare iterators from
diff --git a/sw/source/core/docnode/ndindex.cxx b/sw/source/core/docnode/ndindex.cxx
index 03e98bee77e2..36560001d857 100644
--- a/sw/source/core/docnode/ndindex.cxx
+++ b/sw/source/core/docnode/ndindex.cxx
@@ -42,13 +42,13 @@ SwNodeRange::SwNodeRange( const SwNode& rS, long nSttDiff,
{}
SwNodeIndex::SwNodeIndex( SwNodes& rNds, sal_uLong nIdx )
- : pNd( rNds[ nIdx ] ), pNext( 0 ), pPrev( 0 )
+ : pNd( rNds[ nIdx ] )
{
rNds.RegisterIndex( *this );
}
SwNodeIndex::SwNodeIndex( const SwNodeIndex& rIdx, long nDiff )
- : pNext( 0 ), pPrev( 0 )
+ : sw::Ring<SwNodeIndex>()
{
if( nDiff )
pNd = rIdx.GetNodes()[ rIdx.GetIndex() + nDiff ];
@@ -59,7 +59,6 @@ SwNodeIndex::SwNodeIndex( const SwNodeIndex& rIdx, long nDiff )
}
SwNodeIndex::SwNodeIndex( const SwNode& rNd, long nDiff )
- : pNext( 0 ), pPrev( 0 )
{
if( nDiff )
pNd = rNd.GetNodes()[ rNd.GetIndex() + nDiff ];
diff --git a/sw/source/core/docnode/nodes.cxx b/sw/source/core/docnode/nodes.cxx
index 00b9a873bd07..3167f8a676f4 100644
--- a/sw/source/core/docnode/nodes.cxx
+++ b/sw/source/core/docnode/nodes.cxx
@@ -57,7 +57,7 @@ sal_uInt16 HighestLevel( SwNodes & rNodes, const SwNodeRange & rRange );
* @param pDocument TODO: provide documentation
*/
SwNodes::SwNodes( SwDoc* pDocument )
- : pRoot( 0 ), pMyDoc( pDocument )
+ : vIndices(nullptr), pMyDoc( pDocument )
{
bInNodesDel = bInDelUpdOutl = bInDelUpdNum = false;
@@ -2212,29 +2212,11 @@ void SwNodes::RemoveNode( sal_uLong nDelPos, sal_uLong nSz, bool bDel )
sal_uLong nEnd = nDelPos + nSz;
SwNode* pNew = (*this)[ nEnd ];
- if( pRoot )
+ for(SwNodeIndex& rIndex : vIndices->GetRingContainer())
{
- SwNodeIndex *p = pRoot;
- while( p )
- {
- sal_uLong nIdx = p->GetIndex();
- SwNodeIndex* pNext = p->pNext;
- if( nDelPos <= nIdx && nIdx < nEnd )
- (*p) = *pNew;
-
- p = pNext;
- }
-
- p = pRoot->pPrev;
- while( p )
- {
- sal_uLong nIdx = p->GetIndex();
- SwNodeIndex* pPrev = p->pPrev;
- if( nDelPos <= nIdx && nIdx < nEnd )
- (*p) = *pNew;
-
- p = pPrev;
- }
+ sal_uLong nIdx = rIndex.GetIndex();
+ if( nDelPos <= nIdx && nIdx < nEnd )
+ rIndex = *pNew;
}
{
@@ -2288,42 +2270,6 @@ void SwNodes::RemoveNode( sal_uLong nDelPos, sal_uLong nSz, bool bDel )
BigPtrArray::Remove( nDelPos, nSz );
}
-void SwNodes::RegisterIndex( SwNodeIndex& rIdx )
-{
- if( !pRoot ) // no root set, yet?
- {
- pRoot = &rIdx;
- pRoot->pPrev = 0;
- pRoot->pNext = 0;
- }
- else
- {
- // add always after root
- rIdx.pNext = pRoot->pNext;
- pRoot->pNext = &rIdx;
- rIdx.pPrev = pRoot;
- if( rIdx.pNext )
- rIdx.pNext->pPrev = &rIdx;
- }
-}
-
-void SwNodes::DeRegisterIndex( SwNodeIndex& rIdx )
-{
- SwNodeIndex* pN = rIdx.pNext;
- SwNodeIndex* pP = rIdx.pPrev;
-
- if( pRoot == &rIdx )
- pRoot = pP ? pP : pN;
-
- if( pP )
- pP->pNext = pN;
- if( pN )
- pN->pPrev = pP;
-
- rIdx.pNext = 0;
- rIdx.pPrev = 0;
-}
-
void SwNodes::InsertNode( const SwNodePtr pNode,
const SwNodeIndex& rPos )
{
@@ -2367,4 +2313,18 @@ bool SwNodes::IsDocNodes() const
return this == &pMyDoc->GetNodes();
}
+void SwNodes::RegisterIndex( SwNodeIndex& rIdx )
+{
+ if(!vIndices)
+ vIndices = &rIdx;
+ rIdx.MoveTo(vIndices);
+}
+void SwNodes::DeRegisterIndex( SwNodeIndex& rIdx )
+{
+ if(vIndices == &rIdx)
+ vIndices = vIndices->GetNextInRing();
+ rIdx.MoveTo(nullptr);
+ if(vIndices == &rIdx)
+ vIndices = nullptr;
+}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */