summaryrefslogtreecommitdiff
path: root/sw/source
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2024-02-16 23:58:01 +0600
committerMike Kaganski <mike.kaganski@collabora.com>2024-02-17 10:07:38 +0100
commit1f5efbf8b9ba3fd5887c58574dfed3bf31cd020e (patch)
tree766fdcfb4d76b101c168e70ef342b07cb6e146df /sw/source
parent39048e0c0e9af455197ff57cc2947f8fb23e8542 (diff)
Generalize search algorithms in sorted_vector
This allows to simplify the code somewhat, and also to relax requirements to the arguments, e.g. allowing to pass const objects to search in vector containing non-const objects. Change-Id: Id34911a8694bbdec275d22b51ca4a0845c9fa4c4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/163519 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'sw/source')
-rw-r--r--sw/source/core/doc/docredln.cxx2
-rw-r--r--sw/source/core/doc/doctxm.cxx4
-rw-r--r--sw/source/core/docnode/ndnum.cxx8
-rw-r--r--sw/source/core/docnode/node.cxx5
-rw-r--r--sw/source/core/edit/ednumber.cxx3
-rw-r--r--sw/source/core/inc/docfld.hxx2
-rw-r--r--sw/source/core/inc/swblocks.hxx2
-rw-r--r--sw/source/filter/html/htmlfly.hxx2
-rw-r--r--sw/source/filter/html/wrthtml.hxx2
-rw-r--r--sw/source/filter/inc/wrtswtbl.hxx7
-rw-r--r--sw/source/filter/xml/xmltble.cxx2
-rw-r--r--sw/source/uibase/docvw/OutlineContentVisibilityWin.cxx3
-rw-r--r--sw/source/uibase/inc/dbinsdlg.hxx2
-rw-r--r--sw/source/uibase/inc/redlndlg.hxx2
-rw-r--r--sw/source/uibase/utlui/content.cxx2
15 files changed, 23 insertions, 25 deletions
diff --git a/sw/source/core/doc/docredln.cxx b/sw/source/core/doc/docredln.cxx
index 2c4ba6096c48..32696630e591 100644
--- a/sw/source/core/doc/docredln.cxx
+++ b/sw/source/core/doc/docredln.cxx
@@ -646,7 +646,7 @@ bool SwRedlineTable::InsertWithValidRanges(SwRangeRedline*& p, size_type* pInsPo
return bAnyIns;
}
-bool CompareSwRedlineTable::operator()(SwRangeRedline* const &lhs, SwRangeRedline* const &rhs) const
+bool CompareSwRedlineTable::operator()(const SwRangeRedline* lhs, const SwRangeRedline* rhs) const
{
return *lhs < *rhs;
}
diff --git a/sw/source/core/doc/doctxm.cxx b/sw/source/core/doc/doctxm.cxx
index 4b0ca5d323f1..af957c8a7318 100644
--- a/sw/source/core/doc/doctxm.cxx
+++ b/sw/source/core/doc/doctxm.cxx
@@ -754,7 +754,7 @@ static bool IsHeadingContained(const SwTextNode* pChptrNd, const SwNode& rNd)
bool bCheckFirst = false;
SwOutlineNodes::size_type nPos;
- if (!rONds.Seek_Entry(const_cast<SwNode*>(pNd), &nPos))
+ if (!rONds.Seek_Entry(pNd, &nPos))
{
if (nPos == 0)
bCheckFirst = true;
@@ -785,7 +785,7 @@ static bool IsHeadingContained(const SwTextNode* pChptrNd, const SwNode& rNd)
if (bIsHeadingContained)
{
const SwNode* aChptrNd = pChptrNd;
- if (!rONds.Seek_Entry(const_cast<SwNode*>(aChptrNd), &nPos) && nPos)
+ if (!rONds.Seek_Entry(aChptrNd, &nPos) && nPos)
nPos--;
// Search for the next outline node with a larger level than the specified chapter node
while (nPos < rONds.size() - 1
diff --git a/sw/source/core/docnode/ndnum.cxx b/sw/source/core/docnode/ndnum.cxx
index af17a2a68e15..58b4cbff6488 100644
--- a/sw/source/core/docnode/ndnum.cxx
+++ b/sw/source/core/docnode/ndnum.cxx
@@ -24,12 +24,12 @@
#include <fldbas.hxx>
#include <osl/diagnose.h>
-bool CompareSwOutlineNodes::operator()( SwNode* const& lhs, SwNode* const& rhs) const
+bool CompareSwOutlineNodes::operator()(const SwNode* lhs, const SwNode* rhs) const
{
return lhs->GetIndex() < rhs->GetIndex();
}
-bool SwOutlineNodes::Seek_Entry(SwNode* rP, size_type* pnPos) const
+bool SwOutlineNodes::Seek_Entry(const SwNode* rP, size_type* pnPos) const
{
const_iterator it = lower_bound(rP);
*pnPos = it - begin();
@@ -79,10 +79,8 @@ void SwNodes::UpdateOutlineIdx( const SwNode& rNd )
if( m_aOutlineNodes.empty() ) // no OutlineNodes present ?
return;
- SwNode* const pSrch = const_cast<SwNode*>(&rNd);
-
SwOutlineNodes::size_type nPos;
- if (!m_aOutlineNodes.Seek_Entry(pSrch, &nPos))
+ if (!m_aOutlineNodes.Seek_Entry(&rNd, &nPos))
return;
if( nPos == m_aOutlineNodes.size() ) // none present for updating ?
return;
diff --git a/sw/source/core/docnode/node.cxx b/sw/source/core/docnode/node.cxx
index 0acdc1db91c3..ba3d9fdb6812 100644
--- a/sw/source/core/docnode/node.cxx
+++ b/sw/source/core/docnode/node.cxx
@@ -796,9 +796,8 @@ const SwTextNode* SwNode::FindOutlineNodeOfLevel(sal_uInt8 const nLvl,
if( MAXLEVEL > nLvl && !rONds.empty() )
{
SwOutlineNodes::size_type nPos;
- SwNode* pNd = const_cast<SwNode*>(this);
bool bCheckFirst = false;
- if( !rONds.Seek_Entry( pNd, &nPos ))
+ if (!rONds.Seek_Entry(this, &nPos))
{
if (nPos == 0)
bCheckFirst = true;
@@ -2002,7 +2001,7 @@ bool SwContentNode::IsAnyCondition( SwCollCondition& rTmp ) const
const SwOutlineNodes& rOutlNds = rNds.GetOutLineNds();
if( !rOutlNds.empty() )
{
- if( !rOutlNds.Seek_Entry( const_cast<SwContentNode*>(this), &nPos ) && nPos )
+ if (!rOutlNds.Seek_Entry(this, &nPos) && nPos)
--nPos;
if( nPos < rOutlNds.size() &&
rOutlNds[ nPos ]->GetIndex() < GetIndex() )
diff --git a/sw/source/core/edit/ednumber.cxx b/sw/source/core/edit/ednumber.cxx
index c272aa5f8eec..625cd43cb1c8 100644
--- a/sw/source/core/edit/ednumber.cxx
+++ b/sw/source/core/edit/ednumber.cxx
@@ -556,11 +556,10 @@ bool SwEditShell::IsProtectedOutlinePara() const
if( rNd.IsTextNode() )
{
const SwOutlineNodes& rOutlNd = GetDoc()->GetNodes().GetOutLineNds();
- SwNode* pNd = const_cast<SwNode*>(&rNd);
bool bFirst = true;
SwOutlineNodes::size_type nPos;
int nLvl(0);
- if( !rOutlNd.Seek_Entry( pNd, &nPos ) && nPos )
+ if (!rOutlNd.Seek_Entry(&rNd, &nPos) && nPos)
--nPos;
for( ; nPos < rOutlNd.size(); ++nPos )
diff --git a/sw/source/core/inc/docfld.hxx b/sw/source/core/inc/docfld.hxx
index f09116978fb5..f0b4b261a8fe 100644
--- a/sw/source/core/inc/docfld.hxx
+++ b/sw/source/core/inc/docfld.hxx
@@ -114,7 +114,7 @@ public:
void SetBodyPos( const SwContentFrame& rFrame );
};
-class SetGetExpFields : public o3tl::sorted_vector<std::unique_ptr<SetGetExpField>, o3tl::less_uniqueptr_to<SetGetExpField> >
+class SetGetExpFields : public o3tl::sorted_vector<std::unique_ptr<SetGetExpField>, o3tl::less_ptr_to >
{
};
diff --git a/sw/source/core/inc/swblocks.hxx b/sw/source/core/inc/swblocks.hxx
index 7bd877ad653d..364f5f1a9ee8 100644
--- a/sw/source/core/inc/swblocks.hxx
+++ b/sw/source/core/inc/swblocks.hxx
@@ -49,7 +49,7 @@ public:
bool operator< ( const SwBlockName& r ) const { return m_aShort < r.m_aShort; }
};
-class SwBlockNames : public o3tl::sorted_vector<std::unique_ptr<SwBlockName>, o3tl::less_uniqueptr_to<SwBlockName> > {};
+class SwBlockNames : public o3tl::sorted_vector<std::unique_ptr<SwBlockName>, o3tl::less_ptr_to > {};
class SwImpBlocks
{
diff --git a/sw/source/filter/html/htmlfly.hxx b/sw/source/filter/html/htmlfly.hxx
index 666f7730ecf9..4038ac2a2dcf 100644
--- a/sw/source/filter/html/htmlfly.hxx
+++ b/sw/source/filter/html/htmlfly.hxx
@@ -121,7 +121,7 @@ public:
class SwHTMLPosFlyFrames
: public o3tl::sorted_vector<std::unique_ptr<SwHTMLPosFlyFrame>,
- o3tl::less_uniqueptr_to<SwHTMLPosFlyFrame>,
+ o3tl::less_ptr_to,
o3tl::find_partialorder_ptrequals>
{};
diff --git a/sw/source/filter/html/wrthtml.hxx b/sw/source/filter/html/wrthtml.hxx
index a62bff941a1d..51bd462d08d3 100644
--- a/sw/source/filter/html/wrthtml.hxx
+++ b/sw/source/filter/html/wrthtml.hxx
@@ -204,7 +204,7 @@ struct HTMLControl
}
};
-class HTMLControls : public o3tl::sorted_vector<std::unique_ptr<HTMLControl>, o3tl::less_uniqueptr_to<HTMLControl> > {
+class HTMLControls : public o3tl::sorted_vector<std::unique_ptr<HTMLControl>, o3tl::less_ptr_to > {
};
struct SwHTMLFormatInfo
diff --git a/sw/source/filter/inc/wrtswtbl.hxx b/sw/source/filter/inc/wrtswtbl.hxx
index e3391e7ce74c..83a40c0f681d 100644
--- a/sw/source/filter/inc/wrtswtbl.hxx
+++ b/sw/source/filter/inc/wrtswtbl.hxx
@@ -151,7 +151,7 @@ inline bool SwWriteTableRow::operator<( const SwWriteTableRow& rRow ) const
}
using SwWriteTableRows
- = o3tl::sorted_vector< std::unique_ptr<SwWriteTableRow>, o3tl::less_uniqueptr_to<SwWriteTableRow> >;
+ = o3tl::sorted_vector< std::unique_ptr<SwWriteTableRow>, o3tl::less_ptr_to >;
class SwWriteTableCol
{
@@ -199,7 +199,10 @@ inline bool SwWriteTableCol::operator<( const SwWriteTableCol& rCol ) const
}
struct SwWriteTableColLess {
- bool operator()(std::unique_ptr<SwWriteTableCol> const & lhs, std::unique_ptr<SwWriteTableCol> const & rhs) {
+ template <typename T1, typename T2>
+ requires o3tl::is_reference_to<T1, SwWriteTableCol>
+ && o3tl::is_reference_to<T2, SwWriteTableCol>
+ bool operator()(T1 const& lhs, T2 const& rhs) const {
return lhs->GetPos() < rhs->GetPos();
}
};
diff --git a/sw/source/filter/xml/xmltble.cxx b/sw/source/filter/xml/xmltble.cxx
index 1341bbbe37ad..ab61f071ce79 100644
--- a/sw/source/filter/xml/xmltble.cxx
+++ b/sw/source/filter/xml/xmltble.cxx
@@ -99,7 +99,7 @@ struct SwXMLTableColumnCmpWidth_Impl
}
};
-class SwXMLTableColumns_Impl : public o3tl::sorted_vector<std::unique_ptr<SwXMLTableColumn_Impl>, o3tl::less_uniqueptr_to<SwXMLTableColumn_Impl> > {
+class SwXMLTableColumns_Impl : public o3tl::sorted_vector<std::unique_ptr<SwXMLTableColumn_Impl>, o3tl::less_ptr_to > {
};
}
diff --git a/sw/source/uibase/docvw/OutlineContentVisibilityWin.cxx b/sw/source/uibase/docvw/OutlineContentVisibilityWin.cxx
index 998548550274..b7a21add98be 100644
--- a/sw/source/uibase/docvw/OutlineContentVisibilityWin.cxx
+++ b/sw/source/uibase/docvw/OutlineContentVisibilityWin.cxx
@@ -111,8 +111,7 @@ void SwOutlineContentVisibilityWin::Set()
SwWrtShell& rSh = GetEditWin()->GetView().GetWrtShell();
const SwOutlineNodes& rOutlineNodes = rSh.GetNodes().GetOutLineNds();
- (void)rOutlineNodes.Seek_Entry(static_cast<SwNode*>(const_cast<SwTextNode*>(pTextNode)),
- &m_nOutlinePos);
+ (void)rOutlineNodes.Seek_Entry(pTextNode, &m_nOutlinePos);
// set symbol displayed on button
bool bVisible = true;
diff --git a/sw/source/uibase/inc/dbinsdlg.hxx b/sw/source/uibase/inc/dbinsdlg.hxx
index 035bf49c6181..5694057990eb 100644
--- a/sw/source/uibase/inc/dbinsdlg.hxx
+++ b/sw/source/uibase/inc/dbinsdlg.hxx
@@ -73,7 +73,7 @@ struct SwInsDBColumn
bool operator<( const SwInsDBColumn& rCmp ) const;
};
-class SwInsDBColumns : public o3tl::sorted_vector<std::unique_ptr<SwInsDBColumn>, o3tl::less_uniqueptr_to<SwInsDBColumn> >
+class SwInsDBColumns : public o3tl::sorted_vector<std::unique_ptr<SwInsDBColumn>, o3tl::less_ptr_to >
{
};
diff --git a/sw/source/uibase/inc/redlndlg.hxx b/sw/source/uibase/inc/redlndlg.hxx
index c8cfd8cc8262..d3944e9f81d9 100644
--- a/sw/source/uibase/inc/redlndlg.hxx
+++ b/sw/source/uibase/inc/redlndlg.hxx
@@ -51,7 +51,7 @@ struct SwRedlineDataParent
{ return (pData && pData->GetSeqNo() < rObj.pData->GetSeqNo()); }
};
-class SwRedlineDataParentSortArr : public o3tl::sorted_vector<SwRedlineDataParent*, o3tl::less_ptr_to<SwRedlineDataParent> > {};
+class SwRedlineDataParentSortArr : public o3tl::sorted_vector<SwRedlineDataParent*, o3tl::less_ptr_to > {};
class SW_DLLPUBLIC SwRedlineAcceptDlg final
{
diff --git a/sw/source/uibase/utlui/content.cxx b/sw/source/uibase/utlui/content.cxx
index fa1c7e10d447..8e301753b236 100644
--- a/sw/source/uibase/utlui/content.cxx
+++ b/sw/source/uibase/utlui/content.cxx
@@ -153,7 +153,7 @@ constexpr char NAVI_BOOKMARK_DELIM = '\x01';
}
class SwContentArr
- : public o3tl::sorted_vector<std::unique_ptr<SwContent>, o3tl::less_uniqueptr_to<SwContent>,
+ : public o3tl::sorted_vector<std::unique_ptr<SwContent>, o3tl::less_ptr_to,
o3tl::find_partialorder_ptrequals>
{
};