From 63d8977f9fb0618d36dc8e0ee2f8068b1af92fe6 Mon Sep 17 00:00:00 2001 From: Michaël Lefèvre Date: Sat, 15 Nov 2014 11:41:49 +0100 Subject: fdo#75757 remove inheritance from std::vector MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For TextDoc, also removing ToolsList Change-Id: Id818f61f562317ce106414937253f1748a33315a Reviewed-on: https://gerrit.libreoffice.org/12454 Reviewed-by: Caolán McNamara Tested-by: Caolán McNamara --- vcl/source/edit/textdoc.cxx | 80 ++++++++++++++++++++------------------------- 1 file changed, 36 insertions(+), 44 deletions(-) (limited to 'vcl/source/edit/textdoc.cxx') diff --git a/vcl/source/edit/textdoc.cxx b/vcl/source/edit/textdoc.cxx index 560284ccb1d6..324d81b5f519 100644 --- a/vcl/source/edit/textdoc.cxx +++ b/vcl/source/edit/textdoc.cxx @@ -407,38 +407,33 @@ void TextNode::Append( const TextNode& rNode ) } } +bool TextNode::operator==(TextNode const& other) const +{ + return maText == other.maText && &maCharAttribs == &other.maCharAttribs; +} + + + TextDoc::TextDoc() { mnLeftMargin = 0; }; -TextDoc::~TextDoc() -{ - DestroyTextNodes(); -} - void TextDoc::Clear() { - DestroyTextNodes(); -} - -void TextDoc::DestroyTextNodes() -{ - for ( sal_uLong nNode = 0; nNode < maTextNodes.Count(); nNode++ ) - delete maTextNodes.GetObject( nNode ); maTextNodes.clear(); } OUString TextDoc::GetText( const sal_Unicode* pSep ) const { - sal_uLong nNodes = maTextNodes.Count(); + sal_uLong nNodes = maTextNodes.size(); OUString aASCIIText; sal_uLong nLastNode = nNodes-1; for ( sal_uLong nNode = 0; nNode < nNodes; nNode++ ) { - TextNode* pNode = maTextNodes.GetObject( nNode ); - OUString aTmp( pNode->GetText() ); + const TextNode& pNode = maTextNodes[ nNode ]; + OUString aTmp( pNode.GetText() ); aASCIIText += aTmp; if ( pSep && ( nNode != nLastNode ) ) aASCIIText += pSep; @@ -451,9 +446,8 @@ OUString TextDoc::GetText( sal_uLong nPara ) const { OUString aText; - TextNode* pNode = ( nPara < maTextNodes.Count() ) ? maTextNodes.GetObject( nPara ) : 0; - if ( pNode ) - aText = pNode->GetText(); + if ( nPara < maTextNodes.size() ) + aText = maTextNodes[ nPara ].GetText(); return aText; } @@ -461,7 +455,7 @@ OUString TextDoc::GetText( sal_uLong nPara ) const sal_uLong TextDoc::GetTextLen( const sal_Unicode* pSep, const TextSelection* pSel ) const { sal_uLong nLen = 0; - sal_uLong nNodes = maTextNodes.Count(); + sal_uLong nNodes = maTextNodes.size(); if ( nNodes ) { sal_uLong nStartNode = 0; @@ -474,10 +468,10 @@ sal_uLong TextDoc::GetTextLen( const sal_Unicode* pSep, const TextSelection* pSe for ( sal_uLong nNode = nStartNode; nNode <= nEndNode; nNode++ ) { - TextNode* pNode = maTextNodes.GetObject( nNode ); + const TextNode& pNode = maTextNodes[ nNode ]; sal_uInt16 nS = 0; - sal_Int32 nE = pNode->GetText().getLength(); + sal_Int32 nE = pNode.GetText().getLength(); if ( pSel && ( nNode == pSel->GetStart().GetPara() ) ) nS = pSel->GetStart().GetIndex(); if ( pSel && ( nNode == pSel->GetEnd().GetPara() ) ) @@ -495,11 +489,11 @@ sal_uLong TextDoc::GetTextLen( const sal_Unicode* pSep, const TextSelection* pSe TextPaM TextDoc::InsertText( const TextPaM& rPaM, sal_Unicode c ) { - DBG_ASSERT( c != 0x0A, "TextDoc::InsertText: Zeilentrenner in Absatz nicht erlaubt!" ); - DBG_ASSERT( c != 0x0D, "TextDoc::InsertText: Zeilentrenner in Absatz nicht erlaubt!" ); + DBG_ASSERT( c != 0x0A, "TextDoc::InsertText: Newline not allowed in paragraph!" ); + DBG_ASSERT( c != 0x0D, "TextDoc::InsertText: Newline not allowed in paragraph!" ); - TextNode* pNode = maTextNodes.GetObject( rPaM.GetPara() ); - pNode->InsertText( rPaM.GetIndex(), c ); + TextNode& pNode = maTextNodes[ rPaM.GetPara() ]; + pNode.InsertText( rPaM.GetIndex(), c ); TextPaM aPaM( rPaM.GetPara(), rPaM.GetIndex()+1 ); return aPaM; @@ -507,11 +501,11 @@ TextPaM TextDoc::InsertText( const TextPaM& rPaM, sal_Unicode c ) TextPaM TextDoc::InsertText( const TextPaM& rPaM, const OUString& rStr ) { - DBG_ASSERT( rStr.indexOf( 0x0A ) == -1, "TextDoc::InsertText: Zeilentrenner in Absatz nicht erlaubt!" ); - DBG_ASSERT( rStr.indexOf( 0x0D ) == -1, "TextDoc::InsertText: Zeilentrenner in Absatz nicht erlaubt!" ); + DBG_ASSERT( rStr.indexOf( 0x0A ) == -1, "TextDoc::InsertText: Newline not allowed in paragraph!" ); + DBG_ASSERT( rStr.indexOf( 0x0D ) == -1, "TextDoc::InsertText: Newline not allowed in paragraph!" ); - TextNode* pNode = maTextNodes.GetObject( rPaM.GetPara() ); - pNode->InsertText( rPaM.GetIndex(), rStr ); + TextNode& pNode = maTextNodes[ rPaM.GetPara() ]; + pNode.InsertText( rPaM.GetIndex(), rStr ); TextPaM aPaM( rPaM.GetPara(), rPaM.GetIndex()+rStr.getLength() ); return aPaM; @@ -519,47 +513,45 @@ TextPaM TextDoc::InsertText( const TextPaM& rPaM, const OUString& rStr ) TextPaM TextDoc::InsertParaBreak( const TextPaM& rPaM, bool bKeepEndingAttribs ) { - TextNode* pNode = maTextNodes.GetObject( rPaM.GetPara() ); - TextNode* pNew = pNode->Split( rPaM.GetIndex(), bKeepEndingAttribs ); + TextNode& pNode = maTextNodes[ rPaM.GetPara() ]; + TextNode* pNew = pNode.Split( rPaM.GetIndex(), bKeepEndingAttribs ); - maTextNodes.Insert( pNew, rPaM.GetPara()+1 ); + maTextNodes.insert( maTextNodes.begin()+rPaM.GetPara()+1, pNew ); TextPaM aPaM( rPaM.GetPara()+1, 0 ); return aPaM; } -TextPaM TextDoc::ConnectParagraphs( TextNode* pLeft, TextNode* pRight ) +TextPaM TextDoc::ConnectParagraphs( TextNode& pLeft, const TextNode& pRight ) { - sal_Int32 nPrevLen = pLeft->GetText().getLength(); - pLeft->Append( *pRight ); + sal_Int32 nPrevLen = pLeft.GetText().getLength(); + pLeft.Append( pRight ); // the paragraph on the right vanishes - sal_uLong nRight = maTextNodes.GetPos( pRight ); - maTextNodes.Remove( nRight ); - delete pRight; + RemoveNode( ::std::find( maTextNodes.cbegin(), maTextNodes.cend(), pRight ) - maTextNodes.cbegin() ); - sal_uLong nLeft = maTextNodes.GetPos( pLeft ); + sal_uLong nLeft = std::find( maTextNodes.begin(), maTextNodes.end(), pLeft ) - maTextNodes.begin(); TextPaM aPaM( nLeft, nPrevLen ); return aPaM; } TextPaM TextDoc::RemoveChars( const TextPaM& rPaM, sal_uInt16 nChars ) { - TextNode* pNode = maTextNodes.GetObject( rPaM.GetPara() ); - pNode->RemoveText( rPaM.GetIndex(), nChars ); + TextNode& pNode = maTextNodes[ rPaM.GetPara() ]; + pNode.RemoveText( rPaM.GetIndex(), nChars ); return rPaM; } bool TextDoc::IsValidPaM( const TextPaM& rPaM ) { - if ( rPaM.GetPara() >= maTextNodes.Count() ) + if ( rPaM.GetPara() >= maTextNodes.size() ) { OSL_FAIL( "PaM: Para out of range" ); return false; } - TextNode * pNode = maTextNodes.GetObject( rPaM.GetPara() ); - if ( rPaM.GetIndex() > pNode->GetText().getLength() ) + TextNode& pNode = maTextNodes[ rPaM.GetPara() ]; + if ( rPaM.GetIndex() > pNode.GetText().getLength() ) { OSL_FAIL( "PaM: Index out of range" ); return false; -- cgit v1.2.3