sw/inc/node.hxx                                         |    7 +++++++
 sw/source/core/doc/DocumentContentOperationsManager.cxx |    2 +-
 sw/source/core/doc/dbgoutsw.cxx                         |    2 +-
 sw/source/core/docnode/ndsect.cxx                       |    2 +-
 sw/source/core/docnode/nodes.cxx                        |    2 +-
 sw/source/core/text/itratr.cxx                          |   12 ++++++------
 sw/source/core/text/txtfrm.cxx                          |    6 +++---
 sw/source/core/txtnode/ndtxt.cxx                        |   10 +++++-----
 sw/source/core/undo/undel.cxx                           |    2 +-
 sw/source/core/unocore/unotbl.cxx                       |    2 +-
 sw/source/filter/ww8/ww8par2.cxx                        |    2 +-
 sw/source/uibase/wrtsh/wrtsh1.cxx                       |    2 +-
 12 files changed, 29 insertions(+), 22 deletions(-)

New commits:
commit 133b9db4d68ba48eeb3682f4decba5689f6c0c1b
Author:     Noel Grandin <noelgran...@gmail.com>
AuthorDate: Mon Aug 15 18:46:53 2022 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Wed Aug 17 07:44:03 2022 +0200

    add comparison operators for SwNode
    
    which will make it easier when I do more conversion of code doing
    stuff like
       rPos.nNode ==
    to
       rPos.GetNode() ==
    
    Add an assert to make sure we are talking about nodes from the
    same parent node array.
    
    Change-Id: I12011768d67e7fbe5a87663c661a5cc444f1deb4
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138320
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sw/inc/node.hxx b/sw/inc/node.hxx
index 91b18e30ed66..62f6da8ef308 100644
--- a/sw/inc/node.hxx
+++ b/sw/inc/node.hxx
@@ -308,6 +308,13 @@ public:
      */
     virtual void dumpAsXml(xmlTextWriterPtr pWriter) const;
 
+    bool operator==(const SwNode& rOther) const { assert(&GetNodes() == 
&rOther.GetNodes()); return this == &rOther; }
+    bool operator!=(const SwNode& rOther) const { assert(&GetNodes() == 
&rOther.GetNodes()); return this != &rOther; }
+    bool operator<(const SwNode& rOther) const { assert(&GetNodes() == 
&rOther.GetNodes()); return GetIndex() < rOther.GetIndex(); }
+    bool operator<=(const SwNode& rOther) const { assert(&GetNodes() == 
&rOther.GetNodes()); return GetIndex() <= rOther.GetIndex(); }
+    bool operator>(const SwNode& rOther) const { assert(&GetNodes() == 
&rOther.GetNodes()); return GetIndex() > rOther.GetIndex(); }
+    bool operator>=(const SwNode& rOther) const { assert(&GetNodes() == 
&rOther.GetNodes()); return GetIndex() >= rOther.GetIndex(); }
+
 private:
     SwNode( const SwNode & rNodes ) = delete;
     SwNode & operator= ( const SwNode & rNodes ) = delete;
diff --git a/sw/source/core/doc/DocumentContentOperationsManager.cxx 
b/sw/source/core/doc/DocumentContentOperationsManager.cxx
index fb33ec5103f4..9e6d8ab0ad46 100644
--- a/sw/source/core/doc/DocumentContentOperationsManager.cxx
+++ b/sw/source/core/doc/DocumentContentOperationsManager.cxx
@@ -3922,7 +3922,7 @@ void DocumentContentOperationsManager::CopyFlyInFlyImpl(
             const SwNode& aEndOfContentNd =
                                     
aIdx.GetNode().GetNodes().GetEndOfContent();
             while ( nAnchorTextNdNumInRange > 0 &&
-                    &(aIdx.GetNode()) != &aEndOfContentNd )
+                    aIdx.GetNode() != aEndOfContentNd )
             {
                 if ( aIdx.GetNode().IsTextNode() )
                 {
diff --git a/sw/source/core/doc/dbgoutsw.cxx b/sw/source/core/doc/dbgoutsw.cxx
index 9139da0996e1..5a3d7c86518b 100644
--- a/sw/source/core/doc/dbgoutsw.cxx
+++ b/sw/source/core/doc/dbgoutsw.cxx
@@ -423,7 +423,7 @@ static OUString lcl_AnchoredFrames(const SwNode & rNode)
             const SwFormatAnchor & rAnchor = (*i)->GetAnchor();
             const SwPosition * pPos = rAnchor.GetContentAnchor();
 
-            if (pPos && &pPos->GetNode() == &rNode)
+            if (pPos && pPos->GetNode() == rNode)
             {
                 if (! bFirst)
                     aResult.append(", ");
diff --git a/sw/source/core/docnode/ndsect.cxx 
b/sw/source/core/docnode/ndsect.cxx
index 555e550a14a8..47eef09cef10 100644
--- a/sw/source/core/docnode/ndsect.cxx
+++ b/sw/source/core/docnode/ndsect.cxx
@@ -848,7 +848,7 @@ SwSectionNode* SwNodes::InsertTextSection(SwNode& rNd,
     if( pEnd )
     {
         // Special case for the Reader/Writer
-        if( &pEnd->GetNode() != &GetEndOfContent() )
+        if( pEnd->GetNode() != GetEndOfContent() )
             aInsPos = pEnd->GetIndex()+1;
         // #i58710: We created a RTF document with a section break inside a 
table cell
         // We are not able to handle a section start inside a table and the 
section end outside.
diff --git a/sw/source/core/docnode/nodes.cxx b/sw/source/core/docnode/nodes.cxx
index 739ef2932241..98e1ac29de2a 100644
--- a/sw/source/core/docnode/nodes.cxx
+++ b/sw/source/core/docnode/nodes.cxx
@@ -1676,7 +1676,7 @@ void SwNodes::MoveRange( SwPaM & rPam, SwPosition & rPos, 
SwNodes& rNodes )
 
     // if the StartNode was moved to whom the cursor pointed, so
     // the content must be registered in the current content!
-    if ( &pStt->GetNode() == &GetEndOfContent() )
+    if ( pStt->GetNode() == GetEndOfContent() )
     {
         const bool bSuccess = GoPrevious( &pStt->nNode );
         OSL_ENSURE( bSuccess, "Move() - no ContentNode here" );
diff --git a/sw/source/core/text/itratr.cxx b/sw/source/core/text/itratr.cxx
index 4feae7547841..7e10a29d5629 100644
--- a/sw/source/core/text/itratr.cxx
+++ b/sw/source/core/text/itratr.cxx
@@ -471,14 +471,14 @@ static bool CanSkipOverRedline(
     // can't compare the SwFont that's stored somewhere, it doesn't have 
compare
     // operator, so try to recreate the situation with some temp arrays here
     SfxPoolItem const* activeCharAttrsStart[RES_CHRATR_END - RES_CHRATR_BEGIN 
+ 1] = { nullptr, };
-    if (&rStartNode != &pRLEnd->GetNode())
+    if (rStartNode != pRLEnd->GetNode())
     {   // nodes' attributes are only needed if there are different nodes
         InsertCharAttrs(activeCharAttrsStart, rStartNode.GetSwAttrSet());
     }
     if (SwpHints const*const pStartHints = rStartNode.GetpSwpHints())
     {
         // check hint ends of hints that start before and end within
-        sal_Int32 const nRedlineEnd(&rStartNode == &pRLEnd->GetNode()
+        sal_Int32 const nRedlineEnd(rStartNode == pRLEnd->GetNode()
                 ? pRLEnd->GetContentIndex()
                 : rStartNode.Len());
         for ( ; nEndIndex < pStartHints->Count(); ++nEndIndex)
@@ -544,7 +544,7 @@ static bool CanSkipOverRedline(
             pRLEnd->GetContentIndex() < 
pStartHints->GetSortedByEnd(nEndIndex)->GetAnyEnd());
     }
 
-    if (&rStartNode != &pRLEnd->GetNode())
+    if (rStartNode != pRLEnd->GetNode())
     {
         nStartIndex = 0;
         nEndIndex = 0;
@@ -556,7 +556,7 @@ static bool CanSkipOverRedline(
         // ... and the charfmt must be *nominally* the same
 
     SfxPoolItem const* activeCharAttrsEnd[RES_CHRATR_END - RES_CHRATR_BEGIN + 
1] = { nullptr, };
-    if (&rStartNode != &pRLEnd->GetNode())
+    if (rStartNode != pRLEnd->GetNode())
     {   // nodes' attributes are only needed if there are different nodes
         InsertCharAttrs(activeCharAttrsEnd,
                 pRLEnd->GetNode().GetTextNode()->GetSwAttrSet());
@@ -566,7 +566,7 @@ static bool CanSkipOverRedline(
     {
         // check hint starts of hints that start within and end after
 #ifndef NDEBUG
-        sal_Int32 const nRedlineStart(&rStartNode == &pRLEnd->GetNode()
+        sal_Int32 const nRedlineStart(rStartNode == pRLEnd->GetNode()
                 ? nStartRedline
                 : 0);
 #endif
@@ -632,7 +632,7 @@ static bool CanSkipOverRedline(
                 default: assert(false);
             }
         }
-        if (&rStartNode != &pRLEnd->GetNode())
+        if (rStartNode != pRLEnd->GetNode())
         {
             // need to iterate the nEndIndex forward too so the loop in the
             // caller can look for the right ends in the next iteration
diff --git a/sw/source/core/text/txtfrm.cxx b/sw/source/core/text/txtfrm.cxx
index 7a81ea514757..a34c57fbde5f 100644
--- a/sw/source/core/text/txtfrm.cxx
+++ b/sw/source/core/text/txtfrm.cxx
@@ -815,9 +815,9 @@ void RemoveFootnotesForNode(
     rFootnoteIdxs.SeekEntry( rTextNode, &nPos );
     if (nPos < rFootnoteIdxs.size())
     {
-        while (nPos && &rTextNode == &(rFootnoteIdxs[ nPos ]->GetTextNode()))
+        while (nPos && rTextNode == (rFootnoteIdxs[ nPos ]->GetTextNode()))
             --nPos;
-        if (nPos || &rTextNode != &(rFootnoteIdxs[ nPos ]->GetTextNode()))
+        if (nPos || rTextNode != (rFootnoteIdxs[ nPos ]->GetTextNode()))
             ++nPos;
     }
     size_t iter(0);
@@ -2334,7 +2334,7 @@ void SwTextFrame::SwClientNotify(SwModify const& rModify, 
SfxHint const& rHint)
             {   // the hint may be sent from the anchor node, or from a
                 // node in the footnote; the anchor index is only valid in the
                 // anchor node!
-                assert(&rNode == &static_cast<const 
SwFormatFootnote*>(pNew)->GetTextFootnote()->GetTextNode());
+                assert(rNode == static_cast<const 
SwFormatFootnote*>(pNew)->GetTextFootnote()->GetTextNode());
                 nPos = MapModelToView(&rNode,
                     static_cast<const 
SwFormatFootnote*>(pNew)->GetTextFootnote()->GetStart());
             }
diff --git a/sw/source/core/txtnode/ndtxt.cxx b/sw/source/core/txtnode/ndtxt.cxx
index b567ec4d17cc..a085334c5bf4 100644
--- a/sw/source/core/txtnode/ndtxt.cxx
+++ b/sw/source/core/txtnode/ndtxt.cxx
@@ -1427,7 +1427,7 @@ void SwTextNode::Update(
             if ( pRedl->HasMark() )
             {
                 SwPosition* const pEnd = pRedl->End();
-                if ( this == &pEnd->GetNode() &&
+                if ( *this == pEnd->GetNode() &&
                      *pRedl->GetPoint() != *pRedl->GetMark() )
                 {
                     SwContentIndex & rIdx = pEnd->nContent;
@@ -1472,7 +1472,7 @@ void SwTextNode::Update(
                     continue;
                 const SwPosition* pEnd = &pMark->GetMarkEnd();
                 SwContentIndex & rEndIdx = 
const_cast<SwContentIndex&>(pEnd->nContent);
-                if( this == &pEnd->GetNode() &&
+                if( *this == pEnd->GetNode() &&
                     rPos.GetIndex() == rEndIdx.GetIndex() )
                 {
                     if (&rEndIdx == next) // nasty corner case:
@@ -1514,7 +1514,7 @@ void SwTextNode::Update(
                 {
                     // The fly is at-char anchored and has an anchor position.
                     SwContentIndex& rEndIdx = 
const_cast<SwContentIndex&>(pContentAnchor->nContent);
-                    if (&pContentAnchor->GetNode() == this && 
rEndIdx.GetIndex() == rPos.GetIndex())
+                    if (pContentAnchor->GetNode() == *this && 
rEndIdx.GetIndex() == rPos.GetIndex())
                     {
                         // The anchor position is exactly our insert position.
                         rEndIdx.Assign(&aTmpIdxReg, rEndIdx.GetIndex());
@@ -1539,7 +1539,7 @@ void SwTextNode::Update(
                         continue;
 
                     SwContentIndex& rIndex = pCursor->Start()->nContent;
-                    if (&pCursor->Start()->GetNode() == this && 
rIndex.GetIndex() == rPos.GetIndex())
+                    if (pCursor->Start()->GetNode() == *this && 
rIndex.GetIndex() == rPos.GetIndex())
                     {
                         // The cursor position of this other shell is exactly 
our insert position.
                         rIndex.Assign(&aTmpIdxReg, rIndex.GetIndex());
@@ -1592,7 +1592,7 @@ void SwTextNode::Update(
         SwRangeRedline* pRedln = rTable[nRedlnPos];
         if (pRedln->HasMark())
         {
-            if (this == &pRedln->End()->GetNode() && *pRedln->GetPoint() != 
*pRedln->GetMark())
+            if (*this == pRedln->End()->GetNode() && *pRedln->GetPoint() != 
*pRedln->GetMark())
             {
                 // Redline is changed only when some change occurs before it
                 if (nChangePos <= pRedln->Start()->GetContentIndex())
diff --git a/sw/source/core/undo/undel.cxx b/sw/source/core/undo/undel.cxx
index 42e60dd60302..fd73708de12d 100644
--- a/sw/source/core/undo/undel.cxx
+++ b/sw/source/core/undo/undel.cxx
@@ -308,7 +308,7 @@ SwUndoDelete::SwUndoDelete(
         SwNodes& rDocNds = rDoc.GetNodes();
         SwNodeRange aRg( rDocNds, m_nSttNode - m_nNdDiff, m_nEndNode - 
m_nNdDiff );
         if( !bFullPara && !pEndTextNd &&
-            &aRg.aEnd.GetNode() != &rDoc.GetNodes().GetEndOfContent() )
+            aRg.aEnd.GetNode() != rDoc.GetNodes().GetEndOfContent() )
         {
             SwNode* pNode = aRg.aEnd.GetNode().StartOfSectionNode();
             if( pNode->GetIndex() >= m_nSttNode - m_nNdDiff )
diff --git a/sw/source/core/unocore/unotbl.cxx 
b/sw/source/core/unocore/unotbl.cxx
index bc13a833cd4c..3349b54ed361 100644
--- a/sw/source/core/unocore/unotbl.cxx
+++ b/sw/source/core/unocore/unotbl.cxx
@@ -321,7 +321,7 @@ static uno::Any lcl_GetSpecialProperty(SwFrameFormat* 
pFormat, const SfxItemProp
             {
                 const SwNode& rRedPointNode = pRedline->GetPointNode();
                 const SwNode& rRedMarkNode = pRedline->GetMarkNode();
-                if(&rRedPointNode == pTableNode || &rRedMarkNode == pTableNode)
+                if(rRedPointNode == *pTableNode || rRedMarkNode == *pTableNode)
                 {
                     const SwNode& rStartOfRedline = SwNodeIndex(rRedPointNode) 
<= SwNodeIndex(rRedMarkNode) ?
                         rRedPointNode : rRedMarkNode;
diff --git a/sw/source/filter/ww8/ww8par2.cxx b/sw/source/filter/ww8/ww8par2.cxx
index 2cff6ea67ef2..7021a7d53633 100644
--- a/sw/source/filter/ww8/ww8par2.cxx
+++ b/sw/source/filter/ww8/ww8par2.cxx
@@ -2389,7 +2389,7 @@ void WW8TabDesc::CreateSwTable()
     {
         const SwPosition* pAPos =
             pFormat->GetAnchor().GetContentAnchor();
-        if (pAPos && &pAPos->GetNode() == &pPoint->GetNode())
+        if (pAPos && pAPos->GetNode() == pPoint->GetNode())
         {
             bInsNode = true;
             bSetMinHeight = true;
diff --git a/sw/source/uibase/wrtsh/wrtsh1.cxx 
b/sw/source/uibase/wrtsh/wrtsh1.cxx
index d2b02f64478c..044c2790f2d1 100644
--- a/sw/source/uibase/wrtsh/wrtsh1.cxx
+++ b/sw/source/uibase/wrtsh/wrtsh1.cxx
@@ -2315,7 +2315,7 @@ bool SwWrtShell::IsOutlineContentVisible(const size_t 
nPos)
 
     // try the next node to determine if this outline node has visible content
     SwNodeIndex aIdx(*pOutlineNode, +1);
-    if (&aIdx.GetNode() == &aIdx.GetNodes().GetEndOfContent()) // end of 
regular content
+    if (aIdx.GetNode() == aIdx.GetNodes().GetEndOfContent()) // end of regular 
content
         return false;
 
     if (aIdx.GetNode().IsTextNode() || aIdx.GetNode().IsTableNode() ||

Reply via email to