diff options
author | Jan-Marek Glogowski <glogow@fbihome.de> | 2014-05-12 16:00:02 +0200 |
---|---|---|
committer | Jan-Marek Glogowski <glogow@fbihome.de> | 2014-09-30 09:56:32 +0200 |
commit | 2a23c8d4366b9f4560c9b14c8ec562d8b5c4aa2c (patch) | |
tree | 000f4cf9793b18e0d703944e9c521f1eac5fc7c7 | |
parent | d2180aacc58112a6b41bb8ff93b382a735dc5aa4 (diff) |
Change SwPageDescs to o3tl::sorted_vector like API
This moves the SwPageDescs class to pagedesc.hxx, changes the
std::vector inheritance to private and extends the class to a
o3tl::sorted_vector compatible API.
The insert internally still uses push_back.
This should just be a cleanup patch and is a preparation for the
change of SwPageDescs from vector to o3tl::sorted_vector.
(cherry picked from commit 07cc52be8746eff7e77cb31f507fe0a847157f82)
Conflicts:
sw/inc/doc.hxx
sw/inc/pagedesc.hxx
sw/source/core/doc/docdesc.cxx
sw/source/core/layout/pagedesc.cxx
Change-Id: I08561c139d1af9bad6ca68be27466fac33fab384
-rw-r--r-- | sw/inc/doc.hxx | 15 | ||||
-rw-r--r-- | sw/inc/pagedesc.hxx | 54 | ||||
-rw-r--r-- | sw/source/core/doc/docdesc.cxx | 43 | ||||
-rw-r--r-- | sw/source/core/doc/docnew.cxx | 16 | ||||
-rw-r--r-- | sw/source/core/doc/poolfmt.cxx | 2 | ||||
-rw-r--r-- | sw/source/core/layout/pagedesc.cxx | 117 |
6 files changed, 196 insertions, 51 deletions
diff --git a/sw/inc/doc.hxx b/sw/inc/doc.hxx index fc6de624492b..d74de8974d70 100644 --- a/sw/inc/doc.hxx +++ b/sw/inc/doc.hxx @@ -68,6 +68,7 @@ class SwList; #include <com/sun/star/chart2/data/XDataProvider.hpp> #include <com/sun/star/linguistic2/XProofreadingIterator.hpp> #include <com/sun/star/script/vba/XVBAEventProcessor.hpp> +#include <pagedesc.hxx> #include <boost/unordered_map.hpp> #include <stringhash.hxx> @@ -142,7 +143,6 @@ class SwNodeRange; class SwNodes; class SwNumRule; class SwNumRuleTbl; -class SwPageDesc; class SwPagePreViewPrtData; class SwRedline; class SwRedlineTbl; @@ -229,14 +229,6 @@ namespace sfx2 { class LinkManager; } -/// PageDescriptor-interface, Array because of inlines. -class SwPageDescs : public std::vector<SwPageDesc*> -{ -public: - /// the destructor will free all objects still in the vector - ~SwPageDescs(); -}; - /// forward declaration void SetAllScriptItem( SfxItemSet& rSet, const SfxPoolItem& rItem ); @@ -1360,7 +1352,8 @@ public: sal_uInt16 GetPageDescCnt() const { return maPageDescs.size(); } const SwPageDesc& GetPageDesc( const sal_uInt16 i ) const { return *maPageDescs[i]; } SwPageDesc& GetPageDesc( sal_uInt16 i ) { return *maPageDescs[i]; } - SwPageDesc* FindPageDesc( const String& rName, sal_uInt16* pPos = NULL) const; + SwPageDesc* FindPageDesc( const OUString& rName, sal_uInt16* pPos = 0 ) const; + SwPageDesc* FindPageDesc( const OUString& rName, sal_uInt16* pPos = 0 ); /** Copy the complete PageDesc - beyond document and "deep"! Optionally copying of PoolFmtId, -HlpId can be prevented. */ @@ -1378,8 +1371,6 @@ public: { CopyPageDescHeaderFooterImpl( false, rSrcFmt, rDestFmt ); } //For Reader. - - SwPageDesc * GetPageDesc( const String & rName ); void ChgPageDesc( const String & rName, const SwPageDesc& ); void ChgPageDesc( sal_uInt16 i, const SwPageDesc& ); void DelPageDesc( const String & rName, bool bBroadcast = false); diff --git a/sw/inc/pagedesc.hxx b/sw/inc/pagedesc.hxx index 3864892050cf..0510a63cf9c6 100644 --- a/sw/inc/pagedesc.hxx +++ b/sw/inc/pagedesc.hxx @@ -30,6 +30,7 @@ class SfxPoolItem; class SwTxtFmtColl; class SwNode; +class SwPageDescs; /// Separator line adjustment. enum SwFtnAdj @@ -130,6 +131,9 @@ namespace nsUseOnPage class SW_DLLPUBLIC SwPageDesc : public SwModify { friend class SwDoc; + // How to define the friend functions _erase and insert + // to update the list member + friend class SwPageDescs; OUString aDescName; SvxNumberType aNumType; @@ -149,6 +153,9 @@ class SW_DLLPUBLIC SwPageDesc : public SwModify /// Footnote information. SwPageFtnInfo aFtnInfo; + // The assigned list. + SwPageDescs *list; + /** Called for mirroring of Chg (doc). No adjustment at any other place. */ SW_DLLPRIVATE void Mirror(); @@ -162,7 +169,7 @@ protected: public: OUString GetName() const { return aDescName; } - void SetName( const OUString& rNewName ) { aDescName = rNewName; } + void SetName( const OUString& rNewName ); sal_Bool GetLandscape() const { return bLandscape; } void SetLandscape( sal_Bool bNew ) { bLandscape = bNew; } @@ -336,9 +343,52 @@ public: operator SwPageDesc() const; // #i7983# }; +typedef std::vector<SwPageDesc*> SwPageDescsBase; + +// PageDescriptor-interface, Array because of inlines. +// Mimics o3tl::sorted_vector interface +class SwPageDescs : private SwPageDescsBase +{ +public: + typedef SwPageDescsBase::const_iterator const_iterator; + typedef SwPageDescsBase::size_type size_type; + typedef SwPageDescsBase::value_type value_type; + + // the destructor will free all objects still in the vector + ~SwPageDescs(); + + void DeleteAndDestroyAll(); + + using SwPageDescsBase::clear; + using SwPageDescsBase::empty; + using SwPageDescsBase::size; + + std::pair<const_iterator,bool> insert( const value_type& x ); + size_type erase( const value_type& x ); + void erase( size_type index ); + void erase( const_iterator const& position ); + + const value_type& front() const { return SwPageDescsBase::front(); } + const value_type& back() const { return SwPageDescsBase::back(); } + const value_type& operator[]( size_t index ) const + { return SwPageDescsBase::operator[]( index ); } + + const_iterator find( const OUString &name ) const; + const_iterator find( const value_type& x ) const; + + const_iterator begin() const { return SwPageDescsBase::begin(); } + const_iterator end() const { return SwPageDescsBase::end(); } + + bool Contains( const value_type& x ) const; + +private: + typedef SwPageDescsBase::iterator iterator; + iterator begin_nonconst() { return SwPageDescsBase::begin(); } + iterator end_nonconst() { return SwPageDescsBase::end(); } +}; SwPageDesc* GetPageDescByName_Impl(SwDoc& rDoc, const OUString& rName); -#endif //PAGEDESC_HXX +#endif // INCLUDED_SW_INC_PAGEDESC_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/doc/docdesc.cxx b/sw/source/core/doc/docdesc.cxx index adab6e4c0f43..c0cae8e809c3 100644 --- a/sw/source/core/doc/docdesc.cxx +++ b/sw/source/core/doc/docdesc.cxx @@ -615,7 +615,9 @@ SwPageDesc* SwDoc::MakePageDesc( const String &rName, const SwPageDesc *pCpy, pNew->GetFirstMaster().SetFmtAttr( SvxFrameDirectionItem(aFrameDirection, RES_FRAMEDIR) ); pNew->GetFirstLeft().SetFmtAttr( SvxFrameDirectionItem(aFrameDirection, RES_FRAMEDIR) ); } - maPageDescs.push_back( pNew ); + + std::pair<SwPageDescs::const_iterator, bool> res = maPageDescs.insert( pNew ); + SAL_WARN_IF(res.second == false, "sw", "MakePageDesc called with existing name" ); if (bBroadcast) BroadcastStyleOperation(rName, SFX_STYLE_FAMILY_PAGE, @@ -630,22 +632,6 @@ SwPageDesc* SwDoc::MakePageDesc( const String &rName, const SwPageDesc *pCpy, return pNew; } -SwPageDesc* SwDoc::FindPageDesc( const String& rName, sal_uInt16* pPos ) const -{ - SwPageDesc* pRet = NULL; - if( pPos ) *pPos = USHRT_MAX; - - for( sal_uInt16 n = 0, nEnd = maPageDescs.size(); n < nEnd; ++n ) - if( maPageDescs[ n ]->GetName() == rName ) - { - pRet = maPageDescs[ n ]; - if( pPos ) - *pPos = n; - break; - } - return pRet; -} - void SwDoc::PrtDataChanged() { // If you change this, also modify InJobSetup in Sw3io if appropriate. @@ -838,9 +824,28 @@ IMPL_LINK( SwDoc, DoUpdateModifiedOLE, Timer *, ) return 0; } -SwPageDesc * SwDoc::GetPageDesc( const String & rName ) +static SwPageDesc* lcl_FindPageDesc( SwPageDescs *maPageDescs, const OUString & rName, sal_uInt16* pPos ) +{ + SwPageDescs::const_iterator it = maPageDescs->find( rName ); + SwPageDesc* res = NULL; + if (it != maPageDescs->end() ) { + res = const_cast <SwPageDesc *>( *it ); + if( pPos ) + *pPos = std::distance( maPageDescs->begin(), it ); + } + else if( pPos ) + *pPos = USHRT_MAX; + return res; +} + +SwPageDesc* SwDoc::FindPageDesc( const OUString & rName, sal_uInt16* pPos ) +{ + return lcl_FindPageDesc( &maPageDescs, rName, pPos ); +} + +SwPageDesc* SwDoc::FindPageDesc( const OUString & rName, sal_uInt16* pPos ) const { - return FindPageDesc(rName); + return lcl_FindPageDesc( const_cast <SwPageDescs *>( &maPageDescs ), rName, pPos ); } void SwDoc::DelPageDesc( const String & rName, bool bBroadcast ) diff --git a/sw/source/core/doc/docnew.cxx b/sw/source/core/doc/docnew.cxx index be193e5dd394..6fee0c3f2587 100644 --- a/sw/source/core/doc/docnew.cxx +++ b/sw/source/core/doc/docnew.cxx @@ -588,9 +588,7 @@ SwDoc::~SwDoc() // Destroy these only after destroying the FmtIndices, because the content // of headers/footers has to be deleted as well. If in the headers/footers // there are still Flys registered at that point, we have a problem. - BOOST_FOREACH(SwPageDesc *pPageDesc, maPageDescs) - delete pPageDesc; - maPageDescs.clear(); + maPageDescs.DeleteAndDestroyAll(); // Delete content selections. // Don't wait for the SwNodes dtor to destroy them; so that Formats @@ -858,9 +856,9 @@ void SwDoc::ClearDoc() if (FindPageDesc(pDummyPgDsc->GetName(), &nDummyPgDsc)) maPageDescs.erase(maPageDescs.begin() + nDummyPgDsc); - BOOST_FOREACH(SwPageDesc *pPageDesc, maPageDescs) - delete pPageDesc; - maPageDescs.clear(); + // remove the dummy pagedec from the array and delete all the old ones + maPageDescs.erase( pDummyPgDsc ); + maPageDescs.DeleteAndDestroyAll(); // Delete for Collections // So that we get rid of the dependencies @@ -897,12 +895,12 @@ void SwDoc::ClearDoc() GetPageDescFromPool( RES_POOLPAGE_STANDARD ); pFirstNd->ChgFmtColl( GetTxtCollFromPool( RES_POOLCOLL_STANDARD )); - nDummyPgDsc = maPageDescs.size(); - maPageDescs.push_back( pDummyPgDsc ); + std::pair<SwPageDescs::const_iterator, bool> res = maPageDescs.insert( pDummyPgDsc ); + SAL_WARN_IF(res.second == false, "sw", "ClearDoc: inserted already existing PageDesc" ); // set the layout back to the new standard pagedesc pFirstNd->ResetAllAttr(); // delete now the dummy pagedesc - DelPageDesc( nDummyPgDsc ); + DelPageDesc( std::distance( maPageDescs.begin(), res.first) ); } void SwDoc::SetPreViewPrtData( const SwPagePreViewPrtData* pNew ) diff --git a/sw/source/core/doc/poolfmt.cxx b/sw/source/core/doc/poolfmt.cxx index 50dd2df7688a..01e6ee74aea8 100644 --- a/sw/source/core/doc/poolfmt.cxx +++ b/sw/source/core/doc/poolfmt.cxx @@ -2263,7 +2263,7 @@ bool SwDoc::IsPoolPageDescUsed( sal_uInt16 nId ) const { OSL_ENSURE( RES_POOLPAGE_BEGIN <= nId && nId < RES_POOLPAGE_END, "Wrong AutoFormat Id" ); - SwPageDesc *pNewPgDsc = 0; + const SwPageDesc *pNewPgDsc = 0; bool bFnd = false; for( sal_uInt16 n = 0; !bFnd && n < maPageDescs.size(); ++n ) { diff --git a/sw/source/core/layout/pagedesc.cxx b/sw/source/core/layout/pagedesc.cxx index e6cda4a45ef6..7f46874c736d 100644 --- a/sw/source/core/layout/pagedesc.cxx +++ b/sw/source/core/layout/pagedesc.cxx @@ -58,7 +58,8 @@ SwPageDesc::SwPageDesc( const OUString& rName, SwFrmFmt *pFmt, SwDoc *pDc ) : eUse( (UseOnPage)(nsUseOnPage::PD_ALL | nsUseOnPage::PD_HEADERSHARE | nsUseOnPage::PD_FOOTERSHARE | nsUseOnPage::PD_FIRSTSHARE ) ), bLandscape( sal_False ), bHidden( sal_False ), - aFtnInfo() + aFtnInfo(), + list ( 0 ) { } @@ -77,7 +78,8 @@ SwPageDesc::SwPageDesc( const SwPageDesc &rCpy ) : eUse( rCpy.ReadUseOn() ), bLandscape( rCpy.GetLandscape() ), bHidden( rCpy.IsHidden() ), - aFtnInfo( rCpy.GetFtnInfo() ) + aFtnInfo( rCpy.GetFtnInfo() ), + list ( 0 ) { } @@ -106,6 +108,34 @@ SwPageDesc::~SwPageDesc() { } + + +void SwPageDesc::SetName( const OUString& rNewName ) +{ + SwPageDescs *_list = list; + SwPageDescs::const_iterator it; + bool move_entry = false; + + if (list) { + if( list->end() != list->find( rNewName )) + return; + // Optimize by implemeting move in o3tl::sorted_vector + it = list->find( this ); + SAL_WARN_IF( list->end() == it, "sw", "SwPageDesc not found in expected list" ); + // We don't move the first entry + move_entry = (it != list->begin()); + if (move_entry) + // Clears list + list->erase( it ); + } + + aDescName = rNewName; + + if (_list && move_entry) + // Sets list + _list->insert( this ); +} + /************************************************************************* |* |* SwPageDesc::Mirror() @@ -115,8 +145,6 @@ SwPageDesc::~SwPageDesc() |* |*************************************************************************/ - - void SwPageDesc::Mirror() { //Only the margins are mirrored, all other values are just copied. @@ -392,8 +420,6 @@ void SwPageDesc::ChgFirstShare( sal_Bool bNew ) |* |*************************************************************************/ - - SwPageFtnInfo::SwPageFtnInfo() : nMaxHeight( 0 ), nLineWidth(10), @@ -508,7 +534,7 @@ SwPageDescExt::operator SwPageDesc() const { SwPageDesc aResult(aPageDesc); - SwPageDesc * pPageDesc = pDoc->GetPageDesc(sFollow); + SwPageDesc * pPageDesc = pDoc->FindPageDesc(sFollow); if ( 0 != pPageDesc ) aResult.SetFollow(pPageDesc); @@ -518,8 +544,83 @@ SwPageDescExt::operator SwPageDesc() const SwPageDescs::~SwPageDescs() { - for(const_iterator it = begin(); it != end(); ++it) + DeleteAndDestroyAll(); +} + +void SwPageDescs::DeleteAndDestroyAll() +{ + for( const_iterator it = begin(); it != end(); ++it ) delete *it; + clear(); +} + +std::pair<SwPageDescs::const_iterator,bool> SwPageDescs::insert( const value_type& x ) +{ + const_iterator const ret = find( x ); + if (ret == end()) { + SwPageDescsBase::push_back( x ); + SAL_WARN_IF(x->list == 0, "sw", "Inserting already assigned item"); + x->list = this; + return std::make_pair(end() - 1 , true); + } + return std::make_pair(ret, false); +} + +SwPageDescs::size_type SwPageDescs::erase( const value_type& x ) +{ + const_iterator const ret = find( x ); + if (ret != end()) { + SwPageDescsBase::erase( begin_nonconst() + (ret - begin()) ); + x->list = 0; + return 1; + } + return 0; +} + +void SwPageDescs::erase( size_type index ) +{ + erase( begin_nonconst() + index ); +} + +void SwPageDescs::erase( const_iterator const& position ) +{ + (*position)->list = 0; + SwPageDescsBase::erase( begin_nonconst() + (position - begin()) ); +} + +struct spd_oustring_compare : public std::unary_function<SwPageDesc*, bool> +{ + spd_oustring_compare(const OUString &_baseline) : baseline(_baseline) {} + bool operator() (SwPageDesc* const &arg) + { return (baseline.compareTo( arg->GetName() ) == 0); } + const OUString baseline; +}; + +struct spd_item_compare : public std::unary_function<SwPageDesc*, bool> +{ + spd_item_compare(const SwPageDesc* _baseline) : baseline(_baseline) {} + bool operator() (SwPageDesc* const &arg) + { return (baseline->GetName().compareTo( arg->GetName() ) == 0); } + const SwPageDesc* baseline; +}; + +SwPageDescs::const_iterator SwPageDescs::find( const OUString &name ) const +{ + const_iterator const it = std::find_if( + begin(), end(), spd_oustring_compare( name ) ); + return it; +} + +SwPageDescs::const_iterator SwPageDescs::find( const value_type& x ) const +{ + const_iterator const it = std::find_if( + begin(), end(), spd_item_compare( x ) ); + return it; +} + +bool SwPageDescs::Contains( const SwPageDescs::value_type& x ) const +{ + return (x->list == this); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |