From c85d8b23c2339958f59dbc66a9ba4ec114125514 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Tue, 22 Jun 2021 19:59:00 +0200 Subject: SwFrameFormats::rangeFind does not, in fact return a range because the index it relies on, is a unique index. So make this explicit in the method call by returning a normal iterator. Change-Id: I428d1b14d1274079955eb4f893ca91d1745264e7 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117673 Tested-by: Jenkins Reviewed-by: Noel Grandin --- sw/inc/frameformats.hxx | 16 +++++----------- sw/source/core/doc/docfmt.cxx | 12 ++++++------ sw/source/core/doc/doclay.cxx | 33 ++++++++++++++++----------------- 3 files changed, 27 insertions(+), 34 deletions(-) (limited to 'sw') diff --git a/sw/inc/frameformats.hxx b/sw/inc/frameformats.hxx index 54ad87fa87f8..8ad02559a79b 100644 --- a/sw/inc/frameformats.hxx +++ b/sw/inc/frameformats.hxx @@ -49,17 +49,18 @@ class SW_DLLPUBLIC SwFrameFormats final : public SwFormatsBase // function updating ByName index via modify friend void SwFrameFormat::SetName(const OUString&, bool); +public: typedef SwFrameFormatsBase::nth_index<0>::type ByPos; typedef SwFrameFormatsBase::nth_index<1>::type ByTypeAndName; typedef ByPos::iterator iterator; +private: SwFrameFormatsBase m_Array; ByPos& m_PosIndex; ByTypeAndName& m_TypeAndNameIndex; public: typedef ByPos::const_iterator const_iterator; - typedef ByTypeAndName::const_iterator const_range_iterator; typedef SwFrameFormatsBase::size_type size_type; typedef SwFrameFormatsBase::value_type value_type; @@ -83,19 +84,12 @@ public: // There is also ContainsFormat, if you don't need the position. const_iterator find(const value_type& x) const; - // As this array is non-unique related to type and name, - // we always get ranges for the "key" values. - std::pair rangeFind(sal_uInt16 type, - const OUString& name) const; + ByTypeAndName::const_iterator findByTypeAndName(sal_uInt16 type, const OUString& name) const; // Convenience function, which just uses type and name! // To look for the exact object use find. - std::pair rangeFind(const value_type& x) const; + ByTypeAndName::const_iterator findSimilar(const value_type& x) const; // So we can actually check for end() - const_range_iterator rangeEnd() const { return m_TypeAndNameIndex.end(); } - const_iterator rangeProject(const_range_iterator const& position) - { - return m_Array.project<0>(position); - } + ByTypeAndName::const_iterator typeAndNameEnd() const { return m_TypeAndNameIndex.end(); } const value_type& operator[](size_t index_) const { return m_PosIndex.operator[](index_); } const value_type& front() const { return m_PosIndex.front(); } diff --git a/sw/source/core/doc/docfmt.cxx b/sw/source/core/doc/docfmt.cxx index bd0fb7dff196..f3c4b71653ac 100644 --- a/sw/source/core/doc/docfmt.cxx +++ b/sw/source/core/doc/docfmt.cxx @@ -2085,16 +2085,16 @@ SwFrameFormats::const_iterator SwFrameFormats::find( const value_type& x ) const return m_Array.project<0>( it ); } -std::pair -SwFrameFormats::rangeFind( sal_uInt16 type, const OUString& name ) const +SwFrameFormats::ByTypeAndName::const_iterator +SwFrameFormats::findByTypeAndName( sal_uInt16 type, const OUString& name ) const { - return m_TypeAndNameIndex.equal_range( boost::make_tuple(type, name) ); + return m_TypeAndNameIndex.find( boost::make_tuple(type, name) ); } -std::pair -SwFrameFormats::rangeFind( const value_type& x ) const +SwFrameFormats::ByTypeAndName::const_iterator +SwFrameFormats::findSimilar( const value_type& x ) const { - return rangeFind( x->Which(), x->GetName() ); + return findByTypeAndName( x->Which(), x->GetName() ); } void SwFrameFormats::DeleteAndDestroyAll( bool keepDefault ) diff --git a/sw/source/core/doc/doclay.cxx b/sw/source/core/doc/doclay.cxx index 556ff77fdb78..a566ee51e112 100644 --- a/sw/source/core/doc/doclay.cxx +++ b/sw/source/core/doc/doclay.cxx @@ -1393,27 +1393,26 @@ OUString SwDoc::GetUniqueDrawObjectName() const const SwFlyFrameFormat* SwDoc::FindFlyByName( const OUString& rName, SwNodeType nNdTyp ) const { - auto range = GetSpzFrameFormats()->rangeFind( RES_FLYFRMFMT, rName ); - for( auto it = range.first; it != range.second; it++ ) + auto it = GetSpzFrameFormats()->findByTypeAndName( RES_FLYFRMFMT, rName ); + if( it == GetSpzFrameFormats()->typeAndNameEnd() ) + return nullptr; + + const SwFrameFormat* pFlyFormat = *it; + assert( RES_FLYFRMFMT == pFlyFormat->Which() && pFlyFormat->GetName() == rName ); + const SwNodeIndex* pIdx = pFlyFormat->GetContent().GetContentIdx(); + if( pIdx && pIdx->GetNode().GetNodes().IsDocNodes() ) { - const SwFrameFormat* pFlyFormat = *it; - if( RES_FLYFRMFMT != pFlyFormat->Which() || pFlyFormat->GetName() != rName ) - continue; - const SwNodeIndex* pIdx = pFlyFormat->GetContent().GetContentIdx(); - if( pIdx && pIdx->GetNode().GetNodes().IsDocNodes() ) + if( nNdTyp != SwNodeType::NONE ) { - if( nNdTyp != SwNodeType::NONE ) - { - // query for the right NodeType - const SwNode* pNd = GetNodes()[ pIdx->GetIndex()+1 ]; - if( nNdTyp == SwNodeType::Text - ? !pNd->IsNoTextNode() - : nNdTyp == pNd->GetNodeType() ) - return static_cast(pFlyFormat); - } - else + // query for the right NodeType + const SwNode* pNd = GetNodes()[ pIdx->GetIndex()+1 ]; + if( nNdTyp == SwNodeType::Text + ? !pNd->IsNoTextNode() + : nNdTyp == pNd->GetNodeType() ) return static_cast(pFlyFormat); } + else + return static_cast(pFlyFormat); } return nullptr; } -- cgit