Kaydet (Commit) 43377e09 authored tarafından Michael Stahl's avatar Michael Stahl

fix some problems in previous STL conversion:

- use o3tl::find_partialorder_ptrequals to allow multiple hints on same
  position
- GetPos must not dereference its argument
- unused IsEquals

Change-Id: I274203be96ff90d1e9a46bab17fd00355514a4fa
üst 4623c603
......@@ -75,13 +75,15 @@ struct CompareSwpHtStart
{
bool operator()(SwTxtAttr* const lhs, SwTxtAttr* const rhs) const;
};
class SwpHtStart : public o3tl::sorted_vector<SwTxtAttr*, CompareSwpHtStart> {};
class SwpHtStart : public o3tl::sorted_vector<SwTxtAttr*, CompareSwpHtStart,
o3tl::find_partialorder_ptrequals<SwTxtAttr*, CompareSwpHtStart> > {};
struct CompareSwpHtEnd
{
bool operator()(SwTxtAttr* const lhs, SwTxtAttr* const rhs) const;
};
class SwpHtEnd : public o3tl::sorted_vector<SwTxtAttr*, CompareSwpHtEnd> {};
class SwpHtEnd : public o3tl::sorted_vector<SwTxtAttr*, CompareSwpHtEnd,
o3tl::find_partialorder_ptrequals<SwTxtAttr*, CompareSwpHtEnd> > {};
// Class SwpHintsArr
......@@ -212,7 +214,8 @@ SvStream &operator<<(SvStream &aS, const SwpHints &rHints); //$ ostream
inline sal_uInt16 SwpHintsArray::GetStartOf( const SwTxtAttr *pHt ) const
{
SwpHtStart::const_iterator it = m_HintStarts.find( (SwTxtAttr*)pHt );
SwpHtStart::const_iterator const it =
m_HintStarts.find(const_cast<SwTxtAttr*>(pHt));
if ( it == m_HintStarts.end() )
{
return USHRT_MAX;
......
......@@ -38,15 +38,6 @@
inline void DumpHints(const SwpHtStart &, const SwpHtEnd &) { }
/*************************************************************************
* inline IsEqual()
*************************************************************************/
static bool IsEqual( const SwTxtAttr &rHt1, const SwTxtAttr &rHt2 )
{
return &rHt1 == &rHt2;
}
/*************************************************************************
* IsLessStart()
*************************************************************************/
......@@ -140,13 +131,15 @@ void SwpHintsArray::Insert( const SwTxtAttr *pHt )
{
Resort();
#if OSL_DEBUG_LEVEL > 0
OSL_ENSURE(m_HintStarts.find( (SwTxtAttr*)pHt ) == m_HintStarts.end(),
OSL_ENSURE(
m_HintStarts.find(const_cast<SwTxtAttr*>(pHt)) == m_HintStarts.end(),
"Insert: hint already in HtStart");
OSL_ENSURE(m_HintEnds.find( (SwTxtAttr*)pHt ) == m_HintEnds.end(),
OSL_ENSURE(
m_HintEnds.find(const_cast<SwTxtAttr*>(pHt)) == m_HintEnds.end(),
"Insert: hint already in HtEnd");
#endif
m_HintStarts.insert( (SwTxtAttr*)pHt );
m_HintEnds.insert( (SwTxtAttr*)pHt );
m_HintStarts.insert( const_cast<SwTxtAttr*>(pHt) );
m_HintEnds .insert( const_cast<SwTxtAttr*>(pHt) );
}
void SwpHintsArray::DeleteAtPos( const sal_uInt16 nPos )
......@@ -157,15 +150,23 @@ void SwpHintsArray::DeleteAtPos( const sal_uInt16 nPos )
Resort();
m_HintEnds.erase( pHt );
bool const done = m_HintEnds.erase(pHt);
assert(done);
}
sal_uInt16 SwpHintsArray::GetPos( const SwTxtAttr *pHt ) const
{
SwpHtStart::const_iterator it = m_HintStarts.find( (SwTxtAttr*)pHt );
if( it == m_HintStarts.end() )
return USHRT_MAX;
return it - m_HintStarts.begin();
// DO NOT use find() here!
// if called from SwTxtNode::InsertItem, pHt has already been deleted,
// so it cannot be dereferenced
for (size_t i = 0; i < m_HintStarts.size(); ++i)
{
if (m_HintStarts[i] == pHt)
{
return i;
}
}
return USHRT_MAX;
}
#ifdef DBG_UTIL
......@@ -234,13 +235,13 @@ bool SwpHintsArray::Check() const
// --- Ueberkreuzungen ---
// 5) gleiche Pointer in beiden Arrays
if( m_HintStarts.find( (SwTxtAttr*)pHt ) == m_HintStarts.end() )
if (m_HintStarts.find(const_cast<SwTxtAttr*>(pHt)) == m_HintStarts.end())
nIdx = STRING_LEN;
CHECK_ERR( STRING_LEN != nIdx, "HintsCheck: no GetStartOf" );
// 6) gleiche Pointer in beiden Arrays
if( m_HintEnds.find( (SwTxtAttr*)pHt ) == m_HintEnds.end() )
if (m_HintEnds.find(const_cast<SwTxtAttr*>(pHt)) == m_HintEnds.end())
nIdx = STRING_LEN;
CHECK_ERR( STRING_LEN != nIdx, "HintsCheck: no GetEndOf" );
......
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