1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20 #include "breakpoint.hxx"
21
22 #include <basic/sbmod.hxx>
23 #include <tools/debug.hxx>
24
25
26 namespace basctl
27 {
28
BreakPointList()29 BreakPointList::BreakPointList()
30 {}
31
BreakPointList(BreakPointList const & rList)32 BreakPointList::BreakPointList(BreakPointList const & rList)
33 {
34 for (size_t i = 0; i < rList.size(); ++i)
35 maBreakPoints.push_back( rList.at( i ) );
36 }
37
~BreakPointList()38 BreakPointList::~BreakPointList()
39 {
40 }
41
reset()42 void BreakPointList::reset()
43 {
44 maBreakPoints.clear();
45 }
46
transfer(BreakPointList & rList)47 void BreakPointList::transfer(BreakPointList & rList)
48 {
49 maBreakPoints = std::move(rList.maBreakPoints);
50 }
51
InsertSorted(BreakPoint aNewBrk)52 void BreakPointList::InsertSorted(BreakPoint aNewBrk)
53 {
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())
57 {
58 DBG_ASSERT( it->nLine != aNewBrk.nLine, "BreakPoint exists already!" );
59 maBreakPoints.insert( it, aNewBrk );
60 return;
61 }
62 // no insert position found => LIST_APPEND
63 maBreakPoints.push_back( aNewBrk );
64 }
65
SetBreakPointsInBasic(SbModule * pModule)66 void BreakPointList::SetBreakPointsInBasic(SbModule* pModule)
67 {
68 pModule->ClearAllBP();
69
70 for (const BreakPoint& rBrk : maBreakPoints)
71 {
72 if ( rBrk.bEnabled )
73 pModule->SetBP( rBrk.nLine );
74 }
75 }
76
FindBreakPoint(sal_uInt16 nLine)77 BreakPoint* BreakPointList::FindBreakPoint(sal_uInt16 nLine)
78 {
79 for (BreakPoint& rBrk : maBreakPoints)
80 {
81 if ( rBrk.nLine == nLine )
82 return &rBrk;
83 }
84 return nullptr;
85 }
86
AdjustBreakPoints(sal_uInt16 nLine,bool bInserted)87 void BreakPointList::AdjustBreakPoints(sal_uInt16 nLine, bool bInserted)
88 {
89 for ( size_t i = 0; i < maBreakPoints.size(); )
90 {
91 BreakPoint& rBrk = maBreakPoints[ i ];
92 bool bDelBrk = false;
93 if ( rBrk.nLine == nLine )
94 {
95 if ( bInserted )
96 rBrk.nLine++;
97 else
98 bDelBrk = true;
99 }
100 else if ( rBrk.nLine > nLine )
101 {
102 if ( bInserted )
103 rBrk.nLine++;
104 else
105 rBrk.nLine--;
106 }
107
108 if ( bDelBrk )
109 {
110 maBreakPoints.erase(maBreakPoints.begin() + i);
111 }
112 else
113 {
114 ++i;
115 }
116 }
117 }
118
ResetHitCount()119 void BreakPointList::ResetHitCount()
120 {
121 for (BreakPoint& rBrk : maBreakPoints)
122 {
123 rBrk.nHitCount = 0;
124 }
125 }
126
remove(const BreakPoint * ptr)127 void BreakPointList::remove(const BreakPoint* ptr)
128 {
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;
134 }
135
remove(size_t idx)136 void BreakPointList::remove(size_t idx)
137 {
138 maBreakPoints.erase( maBreakPoints.begin() + idx );
139 }
140
size() const141 size_t BreakPointList::size() const
142 {
143 return maBreakPoints.size();
144 }
145
at(size_t i)146 BreakPoint& BreakPointList::at(size_t i)
147 {
148 return maBreakPoints[ i ];
149 }
150
at(size_t i) const151 const BreakPoint& BreakPointList::at(size_t i) const
152 {
153 return maBreakPoints[ i ];
154 }
155
156 } // namespace basctl
157
158 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
159