Bump version to 24.04.3.4
[LibreOffice.git] / basctl / source / basicide / breakpoint.cxx
blob0d0347ace228711e83c1b24120ec43e3993ad817
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( rList.at( i ) );
38 BreakPointList::~BreakPointList()
42 void BreakPointList::reset()
44 maBreakPoints.clear();
47 void BreakPointList::transfer(BreakPointList & rList)
49 maBreakPoints = std::move(rList.maBreakPoints);
52 void BreakPointList::InsertSorted(BreakPoint aNewBrk)
54 auto it = std::find_if(maBreakPoints.begin(), maBreakPoints.end(),
55 [&aNewBrk](const BreakPoint& rBreakPoint) { return aNewBrk.nLine <= rBreakPoint.nLine; });
56 if (it != maBreakPoints.end())
58 DBG_ASSERT( it->nLine != aNewBrk.nLine, "BreakPoint exists already!" );
59 maBreakPoints.insert( it, aNewBrk );
60 return;
62 // no insert position found => LIST_APPEND
63 maBreakPoints.push_back( aNewBrk );
66 void BreakPointList::SetBreakPointsInBasic(SbModule* pModule)
68 pModule->ClearAllBP();
70 for (const BreakPoint& rBrk : maBreakPoints)
72 if ( rBrk.bEnabled )
73 pModule->SetBP( rBrk.nLine );
77 BreakPoint* BreakPointList::FindBreakPoint(sal_uInt16 nLine)
79 for (BreakPoint& rBrk : maBreakPoints)
81 if ( rBrk.nLine == nLine )
82 return &rBrk;
84 return nullptr;
87 void BreakPointList::AdjustBreakPoints(sal_uInt16 nLine, bool bInserted)
89 for ( size_t i = 0; i < maBreakPoints.size(); )
91 BreakPoint& rBrk = maBreakPoints[ i ];
92 bool bDelBrk = false;
93 if ( rBrk.nLine == nLine )
95 if ( bInserted )
96 rBrk.nLine++;
97 else
98 bDelBrk = true;
100 else if ( rBrk.nLine > nLine )
102 if ( bInserted )
103 rBrk.nLine++;
104 else
105 rBrk.nLine--;
108 if ( bDelBrk )
110 maBreakPoints.erase(maBreakPoints.begin() + i);
112 else
114 ++i;
119 void BreakPointList::ResetHitCount()
121 for (BreakPoint& rBrk : maBreakPoints)
123 rBrk.nHitCount = 0;
127 void BreakPointList::remove(const BreakPoint* ptr)
129 auto i = std::find_if(maBreakPoints.begin(), maBreakPoints.end(),
130 [&ptr](const BreakPoint& rBreakPoint) { return ptr == &rBreakPoint; });
131 if (i != maBreakPoints.end())
132 maBreakPoints.erase( i );
133 return;
136 void BreakPointList::remove(size_t idx)
138 maBreakPoints.erase( maBreakPoints.begin() + idx );
141 size_t BreakPointList::size() const
143 return maBreakPoints.size();
146 BreakPoint& BreakPointList::at(size_t i)
148 return maBreakPoints[ i ];
151 const BreakPoint& BreakPointList::at(size_t i) const
153 return maBreakPoints[ i ];
156 } // namespace basctl
158 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */