Version 6.1.4.1, tag libreoffice-6.1.4.1
[LibreOffice.git] / basctl / source / basicide / breakpoint.cxx
blobabb47b1f1afaf9844f1ecdb15ed4784461794758
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "breakpoint.hxx"
22 #include <basic/sbmod.hxx>
23 #include <tools/debug.hxx>
26 namespace basctl
29 BreakPointList::BreakPointList()
32 BreakPointList::BreakPointList(BreakPointList const & rList)
34 for (size_t i = 0; i < rList.size(); ++i)
35 maBreakPoints.push_back( new BreakPoint(*rList.at( i ) ) );
38 BreakPointList::~BreakPointList()
40 reset();
43 void BreakPointList::reset()
45 for (BreakPoint* pBreakPoint : maBreakPoints)
46 delete pBreakPoint;
47 maBreakPoints.clear();
50 void BreakPointList::transfer(BreakPointList & rList)
52 maBreakPoints.swap(rList.maBreakPoints);
53 rList.reset();
56 void BreakPointList::InsertSorted(BreakPoint* pNewBrk)
58 for ( std::vector< BreakPoint* >::iterator i = maBreakPoints.begin(); i != maBreakPoints.end(); ++i )
60 if ( pNewBrk->nLine <= (*i)->nLine )
62 DBG_ASSERT( (*i)->nLine != pNewBrk->nLine, "BreakPoint exists already!" );
63 maBreakPoints.insert( i, pNewBrk );
64 return;
67 // no insert position found => LIST_APPEND
68 maBreakPoints.push_back( pNewBrk );
71 void BreakPointList::SetBreakPointsInBasic(SbModule* pModule)
73 pModule->ClearAllBP();
75 for (BreakPoint* pBrk : maBreakPoints)
77 if ( pBrk->bEnabled )
78 pModule->SetBP( static_cast<sal_uInt16>(pBrk->nLine) );
82 BreakPoint* BreakPointList::FindBreakPoint(size_t nLine)
84 for (BreakPoint* pBrk : maBreakPoints)
86 if ( pBrk->nLine == nLine )
87 return pBrk;
89 return nullptr;
92 void BreakPointList::AdjustBreakPoints(size_t nLine, bool bInserted)
94 for ( size_t i = 0; i < maBreakPoints.size(); )
96 BreakPoint* pBrk = maBreakPoints[ i ];
97 bool bDelBrk = false;
98 if ( pBrk->nLine == nLine )
100 if ( bInserted )
101 pBrk->nLine++;
102 else
103 bDelBrk = true;
105 else if ( pBrk->nLine > nLine )
107 if ( bInserted )
108 pBrk->nLine++;
109 else
110 pBrk->nLine--;
113 if ( bDelBrk )
115 delete remove( pBrk );
117 else
119 ++i;
124 void BreakPointList::ResetHitCount()
126 for (BreakPoint* pBrk : maBreakPoints)
128 pBrk->nHitCount = 0;
132 BreakPoint* BreakPointList::remove(BreakPoint* ptr)
134 for ( std::vector< BreakPoint* >::iterator i = maBreakPoints.begin(); i != maBreakPoints.end(); ++i )
136 if ( ptr == *i )
138 maBreakPoints.erase( i );
139 return ptr;
142 return nullptr;
145 size_t BreakPointList::size() const
147 return maBreakPoints.size();
150 BreakPoint* BreakPointList::at(size_t i)
152 return i < maBreakPoints.size() ? maBreakPoints[ i ] : nullptr;
155 const BreakPoint* BreakPointList::at(size_t i) const
157 return i < maBreakPoints.size() ? maBreakPoints[ i ] : nullptr;
160 } // namespace basctl
162 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */