summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakeshi Abe <tabe@fixedpoint.jp>2014-07-26 02:40:00 +0900
committerDavid Tardon <dtardon@redhat.com>2014-07-27 08:12:18 +0000
commit537cda44576730525e30fd1ace2fcf8800cad2bb (patch)
treeacccbaecd37285806ba2c35cb0aae28333f084bb
parentce4e7a830d5350848d3c83b872f916a7b1691266 (diff)
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/10549 Tested-by: LibreOffice gerrit bot <gerrit@libreoffice.org> Reviewed-by: David Tardon <dtardon@redhat.com> Tested-by: David Tardon <dtardon@redhat.com>
-rw-r--r--include/vcl/txtattr.hxx4
-rw-r--r--vcl/source/edit/textdoc.cxx99
-rw-r--r--vcl/source/edit/textdoc.hxx30
-rw-r--r--vcl/source/edit/texteng.cxx4
4 files changed, 52 insertions, 85 deletions
diff --git a/include/vcl/txtattr.hxx b/include/vcl/txtattr.hxx
index d0075187f480..98a679c79c6f 100644
--- a/include/vcl/txtattr.hxx
+++ b/include/vcl/txtattr.hxx
@@ -171,7 +171,7 @@ public:
inline bool IsIn( 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 )
return ( ( mnStart < nIndex ) && ( mnEnd > nIndex ) );
}
-inline bool TextCharAttrib::IsEmpty()
+inline bool TextCharAttrib::IsEmpty() const
{
return mnStart == mnEnd;
}
diff --git a/vcl/source/edit/textdoc.cxx b/vcl/source/edit/textdoc.cxx
index e96dacde26fb..01a06f22e7a0 100644
--- a/vcl/source/edit/textdoc.cxx
+++ b/vcl/source/edit/textdoc.cxx
@@ -19,11 +19,12 @@
#include <textdoc.hxx>
#include <stdlib.h>
+#include <boost/mem_fn.hpp>
// 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 )
@@ -55,12 +56,9 @@ TextCharAttribList::~TextCharAttribList()
// PTRARR_DEL
}
-void TextCharAttribList::Clear( bool bDestroyAttribs )
+void TextCharAttribList::Clear()
{
- if ( bDestroyAttribs )
- for(iterator it = begin(); it != end(); ++it)
- delete *it;
- TextCharAttribs::clear();
+ maAttribs.clear();
}
void TextCharAttribList::InsertAttrib( TextCharAttrib* pAttrib )
@@ -68,67 +66,57 @@ void TextCharAttribList::InsertAttrib( TextCharAttrib* pAttrib )
if ( pAttrib->IsEmpty() )
mbHasEmptyAttribs = true;
- const sal_uInt16 nCount = size();
const sal_uInt16 nStart = pAttrib->GetStart(); // maybe better for Comp.Opt.
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 ( pCurAttrib->GetStart() > nStart )
+ if ( it->GetStart() > nStart )
{
- insert( begin() + x, pAttrib );
+ maAttribs.insert( it, pAttrib );
bInserted = true;
break;
}
}
if ( !bInserted )
- push_back( pAttrib );
+ maAttribs.push_back( pAttrib );
}
void TextCharAttribList::ResortAttribs()
{
- if ( !empty() )
- std::sort( begin(), end(), CompareStart );
+ maAttribs.sort(CompareStart);
}
TextCharAttrib* TextCharAttribList::FindAttrib( sal_uInt16 nWhich, sal_uInt16 nPos )
{
- // backwards; if one ends there and the next starts there
- // ==> the starting one counts
- for ( sal_uInt16 nAttr = size(); nAttr; )
+ for (TextCharAttribs::reverse_iterator it = maAttribs.rbegin(); it != maAttribs.rend(); ++it)
{
- TextCharAttrib* pAttr = GetAttrib( --nAttr );
-
- if ( pAttr->GetEnd() < nPos )
+ if ( it->GetEnd() < nPos )
return 0;
- if ( ( pAttr->Which() == nWhich ) && pAttr->IsIn(nPos) )
- return pAttr;
+ if ( ( it->Which() == nWhich ) && it->IsIn(nPos) )
+ return &*it;
}
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?" );
- const sal_uInt16 nAttribs = size();
- for ( sal_uInt16 nAttr = 0; nAttr < nAttribs; nAttr++ )
+ for (TextCharAttribs::const_iterator it = maAttribs.begin(); it != maAttribs.end(); ++it)
{
- TextCharAttrib* pAttr = GetAttrib( nAttr );
- if ( ( pAttr->GetStart() >= nFromPos ) &&
- ( pAttr->GetEnd() <= nMaxPos ) &&
- ( pAttr->Which() == nWhich ) )
- return pAttr;
+ if ( ( it->GetStart() >= nFromPos ) &&
+ ( it->GetEnd() <= nMaxPos ) &&
+ ( it->Which() == nWhich ) )
+ return &*it;
}
return NULL;
}
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 ( pAttr->Which() == nWhich )
+ if ( it->Which() == nWhich )
return true;
}
return false;
@@ -136,16 +124,12 @@ bool TextCharAttribList::HasAttrib( sal_uInt16 nWhich ) const
bool TextCharAttribList::HasBoundingAttrib( sal_uInt16 nBound )
{
- // backwards; if one ends there and the next starts there
- // ==> the starting one counts
- for ( sal_uInt16 nAttr = size(); nAttr; )
+ for (TextCharAttribs::reverse_iterator it = maAttribs.rbegin(); it != maAttribs.rend(); ++it)
{
- TextCharAttrib* pAttr = GetAttrib( --nAttr );
-
- if ( pAttr->GetEnd() < nBound )
+ if ( it->GetEnd() < nBound )
return false;
- if ( ( pAttr->GetStart() == nBound ) || ( pAttr->GetEnd() == nBound ) )
+ if ( ( it->GetStart() == nBound ) || ( it->GetEnd() == nBound ) )
return true;
}
return false;
@@ -156,31 +140,20 @@ TextCharAttrib* TextCharAttribList::FindEmptyAttrib( sal_uInt16 nWhich, sal_uInt
if ( !mbHasEmptyAttribs )
return 0;
- const sal_uInt16 nAttribs = size();
- for ( sal_uInt16 nAttr = 0; nAttr < nAttribs; nAttr++ )
+ for (TextCharAttribs::iterator it = maAttribs.begin(); it != maAttribs.end(); ++it)
{
- TextCharAttrib* pAttr = GetAttrib( nAttr );
- if ( pAttr->GetStart() > nPos )
+ if ( it->GetStart() > nPos )
return 0;
- if ( ( pAttr->GetStart() == nPos ) && ( pAttr->GetEnd() == nPos ) && ( pAttr->Which() == nWhich ) )
- return pAttr;
+ if ( ( it->GetStart() == nPos ) && ( it->GetEnd() == nPos ) && ( it->Which() == nWhich ) )
+ return &*it;
}
return 0;
}
void TextCharAttribList::DeleteEmptyAttribs()
{
- for ( sal_uInt16 nAttr = 0; nAttr < size(); nAttr++ )
- {
- TextCharAttrib* pAttr = GetAttrib( nAttr );
- if ( pAttr->IsEmpty() )
- {
- erase( begin() + nAttr );
- delete pAttr;
- nAttr--;
- }
- }
+ maAttribs.erase_if(boost::mem_fn(&TextCharAttrib::IsEmpty));
mbHasEmptyAttribs = false;
}
@@ -399,9 +372,9 @@ void TextNode::Append( const TextNode& rNode )
const sal_uInt16 nAttribs = rNode.GetCharAttribs().Count();
for ( sal_uInt16 nAttr = 0; nAttr < nAttribs; nAttr++ )
{
- TextCharAttrib* pAttrib = rNode.GetCharAttribs().GetAttrib( nAttr );
+ const TextCharAttrib& rAttrib = rNode.GetCharAttrib( nAttr );
bool bMelted = false;
- if ( pAttrib->GetStart() == 0 )
+ if ( rAttrib.GetStart() == 0 )
{
// potentially merge attributes
sal_uInt16 nTmpAttribs = maCharAttribs.Count();
@@ -411,11 +384,11 @@ void TextNode::Append( const TextNode& rNode )
if ( pTmpAttrib->GetEnd() == nOldLen )
{
- if ( ( pTmpAttrib->Which() == pAttrib->Which() ) &&
- ( pTmpAttrib->GetAttr() == pAttrib->GetAttr() ) )
+ if ( ( pTmpAttrib->Which() == rAttrib.Which() ) &&
+ ( pTmpAttrib->GetAttr() == rAttrib.GetAttr() ) )
{
pTmpAttrib->GetEnd() =
- pTmpAttrib->GetEnd() + pAttrib->GetLen();
+ pTmpAttrib->GetEnd() + rAttrib.GetLen();
bMelted = true;
break; // there can be only one of this type at this position
}
@@ -425,7 +398,7 @@ void TextNode::Append( const TextNode& rNode )
if ( !bMelted )
{
- TextCharAttrib* pNewAttrib = new TextCharAttrib( *pAttrib );
+ TextCharAttrib* pNewAttrib = new TextCharAttrib( rAttrib );
pNewAttrib->GetStart() = pNewAttrib->GetStart() + nOldLen;
pNewAttrib->GetEnd() = pNewAttrib->GetEnd() + nOldLen;
maCharAttribs.InsertAttrib( pNewAttrib );
diff --git a/vcl/source/edit/textdoc.hxx b/vcl/source/edit/textdoc.hxx
index 1f42c3a0f7c8..739de18040c6 100644
--- a/vcl/source/edit/textdoc.hxx
+++ b/vcl/source/edit/textdoc.hxx
@@ -23,33 +23,26 @@
#include <rtl/ustring.hxx>
#include <vcl/textdata.hxx>
#include <vcl/txtattr.hxx>
-#include <vector>
+#include <boost/noncopyable.hpp>
+#include <boost/ptr_container/ptr_vector.hpp>
-class TextCharAttribs : public std::vector<TextCharAttrib*> {
-public:
- ~TextCharAttribs()
- {
- for( iterator it = begin(); it != end(); ++it )
- delete *it;
- }
-};
-
-class TextCharAttribList : private TextCharAttribs
+class TextCharAttribList : boost::noncopyable
{
private:
+ typedef boost::ptr_vector<TextCharAttrib> TextCharAttribs;
+ TextCharAttribs maAttribs;
bool mbHasEmptyAttribs;
- TextCharAttribList( const TextCharAttribList& ) : TextCharAttribs() {}
-
public:
TextCharAttribList();
~TextCharAttribList();
- void Clear( bool bDestroyAttribs );
- sal_uInt16 Count() const { return TextCharAttribs::size(); }
+ void Clear();
+ sal_uInt16 Count() const { return maAttribs.size(); }
- TextCharAttrib* GetAttrib( sal_uInt16 n ) const { return TextCharAttribs::operator[]( n ); }
- void RemoveAttrib( sal_uInt16 n ) { TextCharAttribs::erase( begin() + n ); }
+ const TextCharAttrib& GetAttrib( sal_uInt16 n ) const { return maAttribs[n]; }
+ TextCharAttrib* GetAttrib( sal_uInt16 n ) { return &maAttribs[n]; }
+ void RemoveAttrib( sal_uInt16 n ) { maAttribs.release( maAttribs.begin() + n ).release(); }
void InsertAttrib( TextCharAttrib* pAttrib );
@@ -60,7 +53,7 @@ public:
bool& HasEmptyAttribs() { return mbHasEmptyAttribs; }
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 );
bool HasAttrib( sal_uInt16 nWhich ) const;
bool HasBoundingAttrib( sal_uInt16 nBound );
@@ -82,6 +75,7 @@ public:
const OUString& GetText() const { return maText; }
+ const TextCharAttrib& GetCharAttrib(sal_uInt16 nPos) const { return maCharAttribs.GetAttrib(nPos); }
const TextCharAttribList& GetCharAttribs() const { return maCharAttribs; }
TextCharAttribList& GetCharAttribs() { return maCharAttribs; }
diff --git a/vcl/source/edit/texteng.cxx b/vcl/source/edit/texteng.cxx
index c020ef0aded1..42ef8efcdc0d 100644
--- a/vcl/source/edit/texteng.cxx
+++ b/vcl/source/edit/texteng.cxx
@@ -2590,7 +2590,7 @@ bool TextEngine::Write( SvStream& rOutput, const TextSelection* pSel, bool bHTML
sal_uInt16 nTmpEnd = nEndPos;
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;
// Text before Attribute
@@ -2635,7 +2635,7 @@ void TextEngine::RemoveAttribs( sal_uLong nPara, bool bIdleFormatAndUpdate )
TextNode* pNode = mpDoc->GetNodes().GetObject( nPara );
if ( pNode->GetCharAttribs().Count() )
{
- pNode->GetCharAttribs().Clear( true );
+ pNode->GetCharAttribs().Clear();
TEParaPortion* pTEParaPortion = mpTEParaPortions->GetObject( nPara );
pTEParaPortion->MarkSelectionInvalid( 0, pNode->GetText().getLength() );