Line data Source code
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 :
29 0 : BreakPointList::BreakPointList()
30 0 : {}
31 :
32 0 : BreakPointList::BreakPointList(BreakPointList const & rList)
33 : {
34 0 : for (size_t i = 0; i < rList.size(); ++i)
35 0 : maBreakPoints.push_back( new BreakPoint(*rList.at( i ) ) );
36 0 : }
37 :
38 0 : BreakPointList::~BreakPointList()
39 : {
40 0 : reset();
41 0 : }
42 :
43 0 : void BreakPointList::reset()
44 : {
45 0 : for ( size_t i = 0, n = maBreakPoints.size(); i < n; ++i )
46 0 : delete maBreakPoints[ i ];
47 0 : maBreakPoints.clear();
48 0 : }
49 :
50 0 : void BreakPointList::transfer(BreakPointList & rList)
51 : {
52 0 : reset();
53 0 : for (size_t i = 0; i < rList.size(); ++i)
54 0 : maBreakPoints.push_back( rList.at( i ) );
55 0 : rList.clear();
56 0 : }
57 :
58 0 : void BreakPointList::InsertSorted(BreakPoint* pNewBrk)
59 : {
60 0 : for ( ::std::vector< BreakPoint* >::iterator i = maBreakPoints.begin(); i < maBreakPoints.end(); ++i )
61 : {
62 0 : if ( pNewBrk->nLine <= (*i)->nLine )
63 : {
64 : DBG_ASSERT( ( (*i)->nLine != pNewBrk->nLine ) || pNewBrk->bTemp, "BreakPoint existiert schon!" );
65 0 : maBreakPoints.insert( i, pNewBrk );
66 0 : return;
67 : }
68 : }
69 : // no insert position found => LIST_APPEND
70 0 : maBreakPoints.push_back( pNewBrk );
71 : }
72 :
73 0 : void BreakPointList::SetBreakPointsInBasic(SbModule* pModule)
74 : {
75 0 : pModule->ClearAllBP();
76 :
77 0 : for ( size_t i = 0, n = maBreakPoints.size(); i < n; ++i )
78 : {
79 0 : BreakPoint* pBrk = maBreakPoints[ i ];
80 0 : if ( pBrk->bEnabled )
81 0 : pModule->SetBP( (sal_uInt16)pBrk->nLine );
82 : }
83 0 : }
84 :
85 0 : BreakPoint* BreakPointList::FindBreakPoint(size_t nLine)
86 : {
87 0 : for ( size_t i = 0, n = maBreakPoints.size(); i < n; ++i )
88 : {
89 0 : BreakPoint* pBrk = maBreakPoints[ i ];
90 0 : if ( pBrk->nLine == nLine )
91 0 : return pBrk;
92 : }
93 0 : return NULL;
94 : }
95 :
96 0 : void BreakPointList::AdjustBreakPoints(size_t nLine, bool bInserted)
97 : {
98 0 : for ( size_t i = 0; i < maBreakPoints.size(); )
99 : {
100 0 : BreakPoint* pBrk = maBreakPoints[ i ];
101 0 : bool bDelBrk = false;
102 0 : if ( pBrk->nLine == nLine )
103 : {
104 0 : if ( bInserted )
105 0 : pBrk->nLine++;
106 : else
107 0 : bDelBrk = true;
108 : }
109 0 : else if ( pBrk->nLine > nLine )
110 : {
111 0 : if ( bInserted )
112 0 : pBrk->nLine++;
113 : else
114 0 : pBrk->nLine--;
115 : }
116 :
117 0 : if ( bDelBrk )
118 : {
119 0 : delete remove( pBrk );
120 : }
121 : else
122 : {
123 0 : ++i;
124 : }
125 : }
126 0 : }
127 :
128 0 : void BreakPointList::ResetHitCount()
129 : {
130 0 : for ( size_t i = 0, n = maBreakPoints.size(); i < n; ++i )
131 : {
132 0 : BreakPoint* pBrk = maBreakPoints[ i ];
133 0 : pBrk->nHitCount = 0;
134 : }
135 0 : }
136 :
137 0 : BreakPoint* BreakPointList::remove(BreakPoint* ptr)
138 : {
139 0 : for ( ::std::vector< BreakPoint* >::iterator i = maBreakPoints.begin(); i < maBreakPoints.end(); ++i )
140 : {
141 0 : if ( ptr == *i )
142 : {
143 0 : maBreakPoints.erase( i );
144 0 : return ptr;
145 : }
146 : }
147 0 : return NULL;
148 : }
149 :
150 0 : size_t BreakPointList::size() const
151 : {
152 0 : return maBreakPoints.size();
153 : }
154 :
155 0 : BreakPoint* BreakPointList::at(size_t i)
156 : {
157 0 : return i < maBreakPoints.size() ? maBreakPoints[ i ] : NULL;
158 : }
159 :
160 0 : const BreakPoint* BreakPointList::at(size_t i) const
161 : {
162 0 : return i < maBreakPoints.size() ? maBreakPoints[ i ] : NULL;
163 : }
164 :
165 0 : void BreakPointList::clear()
166 : {
167 0 : maBreakPoints.clear();
168 0 : }
169 :
170 : } // namespace basctl
171 :
172 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|