summaryrefslogtreecommitdiff
path: root/basctl/source/basicide/breakpoint.cxx
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2018-05-17 15:31:21 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2018-05-28 08:45:44 +0200
commit4b5699bff586dd923123fbfd949c9bf03e491ed7 (patch)
tree336ec76d3b1026291d46e79de6605236cfc85595 /basctl/source/basicide/breakpoint.cxx
parent0f30c9a1ef185a76c353349f497e576cfce0cd13 (diff)
loplugin:useuniqueptr in BreakPointList
and simplify the surrounding code Change-Id: Ie4b24008a1c7d30d43ba562d14ddc14d1a4569b6 Reviewed-on: https://gerrit.libreoffice.org/54845 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'basctl/source/basicide/breakpoint.cxx')
-rw-r--r--basctl/source/basicide/breakpoint.cxx77
1 files changed, 39 insertions, 38 deletions
diff --git a/basctl/source/basicide/breakpoint.cxx b/basctl/source/basicide/breakpoint.cxx
index abb47b1f1afa..cc396f666b69 100644
--- a/basctl/source/basicide/breakpoint.cxx
+++ b/basctl/source/basicide/breakpoint.cxx
@@ -32,87 +32,83 @@ BreakPointList::BreakPointList()
BreakPointList::BreakPointList(BreakPointList const & rList)
{
for (size_t i = 0; i < rList.size(); ++i)
- maBreakPoints.push_back( new BreakPoint(*rList.at( i ) ) );
+ maBreakPoints.push_back( BreakPoint(rList.at( i )) );
}
BreakPointList::~BreakPointList()
{
- reset();
}
void BreakPointList::reset()
{
- for (BreakPoint* pBreakPoint : maBreakPoints)
- delete pBreakPoint;
maBreakPoints.clear();
}
void BreakPointList::transfer(BreakPointList & rList)
{
- maBreakPoints.swap(rList.maBreakPoints);
- rList.reset();
+ maBreakPoints = std::move(rList.maBreakPoints);
}
-void BreakPointList::InsertSorted(BreakPoint* pNewBrk)
+void BreakPointList::InsertSorted(BreakPoint aNewBrk)
{
- for ( std::vector< BreakPoint* >::iterator i = maBreakPoints.begin(); i != maBreakPoints.end(); ++i )
+ for ( auto it = maBreakPoints.begin(); it != maBreakPoints.end(); ++it )
{
- if ( pNewBrk->nLine <= (*i)->nLine )
+ if ( aNewBrk.nLine <= it->nLine )
{
- DBG_ASSERT( (*i)->nLine != pNewBrk->nLine, "BreakPoint exists already!" );
- maBreakPoints.insert( i, pNewBrk );
+ DBG_ASSERT( it->nLine != aNewBrk.nLine, "BreakPoint exists already!" );
+ maBreakPoints.insert( it, aNewBrk );
return;
}
}
// no insert position found => LIST_APPEND
- maBreakPoints.push_back( pNewBrk );
+ maBreakPoints.push_back( aNewBrk );
}
void BreakPointList::SetBreakPointsInBasic(SbModule* pModule)
{
pModule->ClearAllBP();
- for (BreakPoint* pBrk : maBreakPoints)
+ for (BreakPoint& rBrk : maBreakPoints)
{
- if ( pBrk->bEnabled )
- pModule->SetBP( static_cast<sal_uInt16>(pBrk->nLine) );
+ if ( rBrk.bEnabled )
+ pModule->SetBP( rBrk.nLine );
}
}
-BreakPoint* BreakPointList::FindBreakPoint(size_t nLine)
+BreakPoint* BreakPointList::FindBreakPoint(sal_uInt16 nLine)
{
- for (BreakPoint* pBrk : maBreakPoints)
+ for (BreakPoint& rBrk : maBreakPoints)
{
- if ( pBrk->nLine == nLine )
- return pBrk;
+ if ( rBrk.nLine == nLine )
+ return &rBrk;
}
return nullptr;
}
-void BreakPointList::AdjustBreakPoints(size_t nLine, bool bInserted)
+void BreakPointList::AdjustBreakPoints(sal_uInt16 nLine, bool bInserted)
{
for ( size_t i = 0; i < maBreakPoints.size(); )
{
- BreakPoint* pBrk = maBreakPoints[ i ];
+ BreakPoint& rBrk = maBreakPoints[ i ];
bool bDelBrk = false;
- if ( pBrk->nLine == nLine )
+ if ( rBrk.nLine == nLine )
{
if ( bInserted )
- pBrk->nLine++;
+ rBrk.nLine++;
else
bDelBrk = true;
}
- else if ( pBrk->nLine > nLine )
+ else if ( rBrk.nLine > nLine )
{
if ( bInserted )
- pBrk->nLine++;
+ rBrk.nLine++;
else
- pBrk->nLine--;
+ rBrk.nLine--;
}
if ( bDelBrk )
{
- delete remove( pBrk );
+ maBreakPoints.erase(maBreakPoints.begin() + i);
}
else
{
@@ -123,23 +119,28 @@ void BreakPointList::AdjustBreakPoints(size_t nLine, bool bInserted)
void BreakPointList::ResetHitCount()
{
- for (BreakPoint* pBrk : maBreakPoints)
+ for (BreakPoint& rBrk : maBreakPoints)
{
- pBrk->nHitCount = 0;
+ rBrk.nHitCount = 0;
}
}
-BreakPoint* BreakPointList::remove(BreakPoint* ptr)
+void BreakPointList::remove(BreakPoint* ptr)
{
- for ( std::vector< BreakPoint* >::iterator i = maBreakPoints.begin(); i != maBreakPoints.end(); ++i )
+ for ( auto i = maBreakPoints.begin(); i != maBreakPoints.end(); ++i )
{
- if ( ptr == *i )
+ if ( ptr == &(*i) )
{
maBreakPoints.erase( i );
- return ptr;
+ return;
}
}
- return nullptr;
+ return;
+}
+
+void BreakPointList::remove(size_t idx)
+{
+ maBreakPoints.erase( maBreakPoints.begin() + idx );
}
size_t BreakPointList::size() const
@@ -147,14 +148,14 @@ size_t BreakPointList::size() const
return maBreakPoints.size();
}
-BreakPoint* BreakPointList::at(size_t i)
+BreakPoint& BreakPointList::at(size_t i)
{
- return i < maBreakPoints.size() ? maBreakPoints[ i ] : nullptr;
+ return maBreakPoints[ i ];
}
-const BreakPoint* BreakPointList::at(size_t i) const
+const BreakPoint& BreakPointList::at(size_t i) const
{
- return i < maBreakPoints.size() ? maBreakPoints[ i ] : nullptr;
+ return maBreakPoints[ i ];
}
} // namespace basctl