Kaydet (Commit) 537cda44 authored tarafından Takeshi Abe's avatar Takeshi Abe Kaydeden (comit) David Tardon

fdo#75757: remove inheritance to std::vector

... by boost::ptr_vector.
Originally TextCharAttribList::Clear() was never called with false,
so this drops the argument.

Change-Id: I0306cd787dd38de0960af38afe9c08a910195b26
Reviewed-on: https://gerrit.libreoffice.org/10549Tested-by: 's avatarLibreOffice gerrit bot <gerrit@libreoffice.org>
Reviewed-by: 's avatarDavid Tardon <dtardon@redhat.com>
Tested-by: 's avatarDavid Tardon <dtardon@redhat.com>
üst ce4e7a83
...@@ -171,7 +171,7 @@ public: ...@@ -171,7 +171,7 @@ public:
inline bool IsIn( sal_uInt16 nIndex ); inline bool IsIn( sal_uInt16 nIndex );
inline bool IsInside( sal_uInt16 nIndex ); inline bool IsInside( sal_uInt16 nIndex );
inline bool IsEmpty(); inline bool IsEmpty() const;
}; };
...@@ -217,7 +217,7 @@ inline bool TextCharAttrib::IsInside( sal_uInt16 nIndex ) ...@@ -217,7 +217,7 @@ inline bool TextCharAttrib::IsInside( sal_uInt16 nIndex )
return ( ( mnStart < nIndex ) && ( mnEnd > nIndex ) ); return ( ( mnStart < nIndex ) && ( mnEnd > nIndex ) );
} }
inline bool TextCharAttrib::IsEmpty() inline bool TextCharAttrib::IsEmpty() const
{ {
return mnStart == mnEnd; return mnStart == mnEnd;
} }
......
...@@ -19,11 +19,12 @@ ...@@ -19,11 +19,12 @@
#include <textdoc.hxx> #include <textdoc.hxx>
#include <stdlib.h> #include <stdlib.h>
#include <boost/mem_fn.hpp>
// compare function called by QuickSort // compare function called by QuickSort
static bool CompareStart( const TextCharAttrib* pFirst, const TextCharAttrib* pSecond ) static bool CompareStart( const TextCharAttrib& pFirst, const TextCharAttrib& pSecond )
{ {
return pFirst->GetStart() < pSecond->GetStart(); return pFirst.GetStart() < pSecond.GetStart();
} }
TextCharAttrib::TextCharAttrib( const TextAttrib& rAttr, sal_uInt16 nStart, sal_uInt16 nEnd ) TextCharAttrib::TextCharAttrib( const TextAttrib& rAttr, sal_uInt16 nStart, sal_uInt16 nEnd )
...@@ -55,12 +56,9 @@ TextCharAttribList::~TextCharAttribList() ...@@ -55,12 +56,9 @@ TextCharAttribList::~TextCharAttribList()
// PTRARR_DEL // PTRARR_DEL
} }
void TextCharAttribList::Clear( bool bDestroyAttribs ) void TextCharAttribList::Clear()
{ {
if ( bDestroyAttribs ) maAttribs.clear();
for(iterator it = begin(); it != end(); ++it)
delete *it;
TextCharAttribs::clear();
} }
void TextCharAttribList::InsertAttrib( TextCharAttrib* pAttrib ) void TextCharAttribList::InsertAttrib( TextCharAttrib* pAttrib )
...@@ -68,67 +66,57 @@ void TextCharAttribList::InsertAttrib( TextCharAttrib* pAttrib ) ...@@ -68,67 +66,57 @@ void TextCharAttribList::InsertAttrib( TextCharAttrib* pAttrib )
if ( pAttrib->IsEmpty() ) if ( pAttrib->IsEmpty() )
mbHasEmptyAttribs = true; mbHasEmptyAttribs = true;
const sal_uInt16 nCount = size();
const sal_uInt16 nStart = pAttrib->GetStart(); // maybe better for Comp.Opt. const sal_uInt16 nStart = pAttrib->GetStart(); // maybe better for Comp.Opt.
bool bInserted = false; bool bInserted = false;
for ( sal_uInt16 x = 0; x < nCount; x++ ) for (TextCharAttribs::iterator it = maAttribs.begin(); it != maAttribs.end(); ++it)
{ {
TextCharAttrib* pCurAttrib = GetAttrib( x ); if ( it->GetStart() > nStart )
if ( pCurAttrib->GetStart() > nStart )
{ {
insert( begin() + x, pAttrib ); maAttribs.insert( it, pAttrib );
bInserted = true; bInserted = true;
break; break;
} }
} }
if ( !bInserted ) if ( !bInserted )
push_back( pAttrib ); maAttribs.push_back( pAttrib );
} }
void TextCharAttribList::ResortAttribs() void TextCharAttribList::ResortAttribs()
{ {
if ( !empty() ) maAttribs.sort(CompareStart);
std::sort( begin(), end(), CompareStart );
} }
TextCharAttrib* TextCharAttribList::FindAttrib( sal_uInt16 nWhich, sal_uInt16 nPos ) TextCharAttrib* TextCharAttribList::FindAttrib( sal_uInt16 nWhich, sal_uInt16 nPos )
{ {
// backwards; if one ends there and the next starts there for (TextCharAttribs::reverse_iterator it = maAttribs.rbegin(); it != maAttribs.rend(); ++it)
// ==> the starting one counts
for ( sal_uInt16 nAttr = size(); nAttr; )
{ {
TextCharAttrib* pAttr = GetAttrib( --nAttr ); if ( it->GetEnd() < nPos )
if ( pAttr->GetEnd() < nPos )
return 0; return 0;
if ( ( pAttr->Which() == nWhich ) && pAttr->IsIn(nPos) ) if ( ( it->Which() == nWhich ) && it->IsIn(nPos) )
return pAttr; return &*it;
} }
return NULL; return NULL;
} }
TextCharAttrib* TextCharAttribList::FindNextAttrib( sal_uInt16 nWhich, sal_uInt16 nFromPos, sal_uInt16 nMaxPos ) const const TextCharAttrib* TextCharAttribList::FindNextAttrib( sal_uInt16 nWhich, sal_uInt16 nFromPos, sal_uInt16 nMaxPos ) const
{ {
DBG_ASSERT( nWhich, "FindNextAttrib: Which?" ); DBG_ASSERT( nWhich, "FindNextAttrib: Which?" );
const sal_uInt16 nAttribs = size(); for (TextCharAttribs::const_iterator it = maAttribs.begin(); it != maAttribs.end(); ++it)
for ( sal_uInt16 nAttr = 0; nAttr < nAttribs; nAttr++ )
{ {
TextCharAttrib* pAttr = GetAttrib( nAttr ); if ( ( it->GetStart() >= nFromPos ) &&
if ( ( pAttr->GetStart() >= nFromPos ) && ( it->GetEnd() <= nMaxPos ) &&
( pAttr->GetEnd() <= nMaxPos ) && ( it->Which() == nWhich ) )
( pAttr->Which() == nWhich ) ) return &*it;
return pAttr;
} }
return NULL; return NULL;
} }
bool TextCharAttribList::HasAttrib( sal_uInt16 nWhich ) const bool TextCharAttribList::HasAttrib( sal_uInt16 nWhich ) const
{ {
for ( sal_uInt16 nAttr = size(); nAttr; ) for (TextCharAttribs::const_reverse_iterator it = maAttribs.rbegin(); it != maAttribs.rend(); ++it)
{ {
const TextCharAttrib* pAttr = GetAttrib( --nAttr ); if ( it->Which() == nWhich )
if ( pAttr->Which() == nWhich )
return true; return true;
} }
return false; return false;
...@@ -136,16 +124,12 @@ bool TextCharAttribList::HasAttrib( sal_uInt16 nWhich ) const ...@@ -136,16 +124,12 @@ bool TextCharAttribList::HasAttrib( sal_uInt16 nWhich ) const
bool TextCharAttribList::HasBoundingAttrib( sal_uInt16 nBound ) bool TextCharAttribList::HasBoundingAttrib( sal_uInt16 nBound )
{ {
// backwards; if one ends there and the next starts there for (TextCharAttribs::reverse_iterator it = maAttribs.rbegin(); it != maAttribs.rend(); ++it)
// ==> the starting one counts
for ( sal_uInt16 nAttr = size(); nAttr; )
{ {
TextCharAttrib* pAttr = GetAttrib( --nAttr ); if ( it->GetEnd() < nBound )
if ( pAttr->GetEnd() < nBound )
return false; return false;
if ( ( pAttr->GetStart() == nBound ) || ( pAttr->GetEnd() == nBound ) ) if ( ( it->GetStart() == nBound ) || ( it->GetEnd() == nBound ) )
return true; return true;
} }
return false; return false;
...@@ -156,31 +140,20 @@ TextCharAttrib* TextCharAttribList::FindEmptyAttrib( sal_uInt16 nWhich, sal_uInt ...@@ -156,31 +140,20 @@ TextCharAttrib* TextCharAttribList::FindEmptyAttrib( sal_uInt16 nWhich, sal_uInt
if ( !mbHasEmptyAttribs ) if ( !mbHasEmptyAttribs )
return 0; return 0;
const sal_uInt16 nAttribs = size(); for (TextCharAttribs::iterator it = maAttribs.begin(); it != maAttribs.end(); ++it)
for ( sal_uInt16 nAttr = 0; nAttr < nAttribs; nAttr++ )
{ {
TextCharAttrib* pAttr = GetAttrib( nAttr ); if ( it->GetStart() > nPos )
if ( pAttr->GetStart() > nPos )
return 0; return 0;
if ( ( pAttr->GetStart() == nPos ) && ( pAttr->GetEnd() == nPos ) && ( pAttr->Which() == nWhich ) ) if ( ( it->GetStart() == nPos ) && ( it->GetEnd() == nPos ) && ( it->Which() == nWhich ) )
return pAttr; return &*it;
} }
return 0; return 0;
} }
void TextCharAttribList::DeleteEmptyAttribs() void TextCharAttribList::DeleteEmptyAttribs()
{ {
for ( sal_uInt16 nAttr = 0; nAttr < size(); nAttr++ ) maAttribs.erase_if(boost::mem_fn(&TextCharAttrib::IsEmpty));
{
TextCharAttrib* pAttr = GetAttrib( nAttr );
if ( pAttr->IsEmpty() )
{
erase( begin() + nAttr );
delete pAttr;
nAttr--;
}
}
mbHasEmptyAttribs = false; mbHasEmptyAttribs = false;
} }
...@@ -399,9 +372,9 @@ void TextNode::Append( const TextNode& rNode ) ...@@ -399,9 +372,9 @@ void TextNode::Append( const TextNode& rNode )
const sal_uInt16 nAttribs = rNode.GetCharAttribs().Count(); const sal_uInt16 nAttribs = rNode.GetCharAttribs().Count();
for ( sal_uInt16 nAttr = 0; nAttr < nAttribs; nAttr++ ) for ( sal_uInt16 nAttr = 0; nAttr < nAttribs; nAttr++ )
{ {
TextCharAttrib* pAttrib = rNode.GetCharAttribs().GetAttrib( nAttr ); const TextCharAttrib& rAttrib = rNode.GetCharAttrib( nAttr );
bool bMelted = false; bool bMelted = false;
if ( pAttrib->GetStart() == 0 ) if ( rAttrib.GetStart() == 0 )
{ {
// potentially merge attributes // potentially merge attributes
sal_uInt16 nTmpAttribs = maCharAttribs.Count(); sal_uInt16 nTmpAttribs = maCharAttribs.Count();
...@@ -411,11 +384,11 @@ void TextNode::Append( const TextNode& rNode ) ...@@ -411,11 +384,11 @@ void TextNode::Append( const TextNode& rNode )
if ( pTmpAttrib->GetEnd() == nOldLen ) if ( pTmpAttrib->GetEnd() == nOldLen )
{ {
if ( ( pTmpAttrib->Which() == pAttrib->Which() ) && if ( ( pTmpAttrib->Which() == rAttrib.Which() ) &&
( pTmpAttrib->GetAttr() == pAttrib->GetAttr() ) ) ( pTmpAttrib->GetAttr() == rAttrib.GetAttr() ) )
{ {
pTmpAttrib->GetEnd() = pTmpAttrib->GetEnd() =
pTmpAttrib->GetEnd() + pAttrib->GetLen(); pTmpAttrib->GetEnd() + rAttrib.GetLen();
bMelted = true; bMelted = true;
break; // there can be only one of this type at this position break; // there can be only one of this type at this position
} }
...@@ -425,7 +398,7 @@ void TextNode::Append( const TextNode& rNode ) ...@@ -425,7 +398,7 @@ void TextNode::Append( const TextNode& rNode )
if ( !bMelted ) if ( !bMelted )
{ {
TextCharAttrib* pNewAttrib = new TextCharAttrib( *pAttrib ); TextCharAttrib* pNewAttrib = new TextCharAttrib( rAttrib );
pNewAttrib->GetStart() = pNewAttrib->GetStart() + nOldLen; pNewAttrib->GetStart() = pNewAttrib->GetStart() + nOldLen;
pNewAttrib->GetEnd() = pNewAttrib->GetEnd() + nOldLen; pNewAttrib->GetEnd() = pNewAttrib->GetEnd() + nOldLen;
maCharAttribs.InsertAttrib( pNewAttrib ); maCharAttribs.InsertAttrib( pNewAttrib );
......
...@@ -23,33 +23,26 @@ ...@@ -23,33 +23,26 @@
#include <rtl/ustring.hxx> #include <rtl/ustring.hxx>
#include <vcl/textdata.hxx> #include <vcl/textdata.hxx>
#include <vcl/txtattr.hxx> #include <vcl/txtattr.hxx>
#include <vector> #include <boost/noncopyable.hpp>
#include <boost/ptr_container/ptr_vector.hpp>
class TextCharAttribs : public std::vector<TextCharAttrib*> { class TextCharAttribList : boost::noncopyable
public:
~TextCharAttribs()
{
for( iterator it = begin(); it != end(); ++it )
delete *it;
}
};
class TextCharAttribList : private TextCharAttribs
{ {
private: private:
typedef boost::ptr_vector<TextCharAttrib> TextCharAttribs;
TextCharAttribs maAttribs;
bool mbHasEmptyAttribs; bool mbHasEmptyAttribs;
TextCharAttribList( const TextCharAttribList& ) : TextCharAttribs() {}
public: public:
TextCharAttribList(); TextCharAttribList();
~TextCharAttribList(); ~TextCharAttribList();
void Clear( bool bDestroyAttribs ); void Clear();
sal_uInt16 Count() const { return TextCharAttribs::size(); } sal_uInt16 Count() const { return maAttribs.size(); }
TextCharAttrib* GetAttrib( sal_uInt16 n ) const { return TextCharAttribs::operator[]( n ); } const TextCharAttrib& GetAttrib( sal_uInt16 n ) const { return maAttribs[n]; }
void RemoveAttrib( sal_uInt16 n ) { TextCharAttribs::erase( begin() + n ); } TextCharAttrib* GetAttrib( sal_uInt16 n ) { return &maAttribs[n]; }
void RemoveAttrib( sal_uInt16 n ) { maAttribs.release( maAttribs.begin() + n ).release(); }
void InsertAttrib( TextCharAttrib* pAttrib ); void InsertAttrib( TextCharAttrib* pAttrib );
...@@ -60,7 +53,7 @@ public: ...@@ -60,7 +53,7 @@ public:
bool& HasEmptyAttribs() { return mbHasEmptyAttribs; } bool& HasEmptyAttribs() { return mbHasEmptyAttribs; }
TextCharAttrib* FindAttrib( sal_uInt16 nWhich, sal_uInt16 nPos ); TextCharAttrib* FindAttrib( sal_uInt16 nWhich, sal_uInt16 nPos );
TextCharAttrib* FindNextAttrib( sal_uInt16 nWhich, sal_uInt16 nFromPos, sal_uInt16 nMaxPos = 0xFFFF ) const; const TextCharAttrib* FindNextAttrib( sal_uInt16 nWhich, sal_uInt16 nFromPos, sal_uInt16 nMaxPos = 0xFFFF ) const;
TextCharAttrib* FindEmptyAttrib( sal_uInt16 nWhich, sal_uInt16 nPos ); TextCharAttrib* FindEmptyAttrib( sal_uInt16 nWhich, sal_uInt16 nPos );
bool HasAttrib( sal_uInt16 nWhich ) const; bool HasAttrib( sal_uInt16 nWhich ) const;
bool HasBoundingAttrib( sal_uInt16 nBound ); bool HasBoundingAttrib( sal_uInt16 nBound );
...@@ -82,6 +75,7 @@ public: ...@@ -82,6 +75,7 @@ public:
const OUString& GetText() const { return maText; } const OUString& GetText() const { return maText; }
const TextCharAttrib& GetCharAttrib(sal_uInt16 nPos) const { return maCharAttribs.GetAttrib(nPos); }
const TextCharAttribList& GetCharAttribs() const { return maCharAttribs; } const TextCharAttribList& GetCharAttribs() const { return maCharAttribs; }
TextCharAttribList& GetCharAttribs() { return maCharAttribs; } TextCharAttribList& GetCharAttribs() { return maCharAttribs; }
......
...@@ -2590,7 +2590,7 @@ bool TextEngine::Write( SvStream& rOutput, const TextSelection* pSel, bool bHTML ...@@ -2590,7 +2590,7 @@ bool TextEngine::Write( SvStream& rOutput, const TextSelection* pSel, bool bHTML
sal_uInt16 nTmpEnd = nEndPos; sal_uInt16 nTmpEnd = nEndPos;
do do
{ {
TextCharAttrib* pAttr = pNode->GetCharAttribs().FindNextAttrib( TEXTATTR_HYPERLINK, nTmpStart, nEndPos ); const TextCharAttrib* pAttr = pNode->GetCharAttribs().FindNextAttrib( TEXTATTR_HYPERLINK, nTmpStart, nEndPos );
nTmpEnd = pAttr ? pAttr->GetStart() : nEndPos; nTmpEnd = pAttr ? pAttr->GetStart() : nEndPos;
// Text before Attribute // Text before Attribute
...@@ -2635,7 +2635,7 @@ void TextEngine::RemoveAttribs( sal_uLong nPara, bool bIdleFormatAndUpdate ) ...@@ -2635,7 +2635,7 @@ void TextEngine::RemoveAttribs( sal_uLong nPara, bool bIdleFormatAndUpdate )
TextNode* pNode = mpDoc->GetNodes().GetObject( nPara ); TextNode* pNode = mpDoc->GetNodes().GetObject( nPara );
if ( pNode->GetCharAttribs().Count() ) if ( pNode->GetCharAttribs().Count() )
{ {
pNode->GetCharAttribs().Clear( true ); pNode->GetCharAttribs().Clear();
TEParaPortion* pTEParaPortion = mpTEParaPortions->GetObject( nPara ); TEParaPortion* pTEParaPortion = mpTEParaPortions->GetObject( nPara );
pTEParaPortion->MarkSelectionInvalid( 0, pNode->GetText().getLength() ); pTEParaPortion->MarkSelectionInvalid( 0, pNode->GetText().getLength() );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment