-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtclFindResultDoc.cpp
More file actions
234 lines (211 loc) · 7.7 KB
/
Copy pathtclFindResultDoc.cpp
File metadata and controls
234 lines (211 loc) · 7.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
/* -------------------------------------
This file is part of AnalysePlugin for NotePad++
Copyright (c) 2022 Matthias H. mattesh(at)gmx.net
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
------------------------------------- */
/**
* implementation of tclFindResultDoc
*/
//#include "stdafx.h"
#include "tclFindResultDoc.h"
#include <algorithm>
#include "tclResult.h"
#include <assert.h>
#define MDBG_COMP "FRDoc:"
#include "myDebug.h"
/**
* insert the line into the result window if not already in.
* @return the resultwindow line number; (-1 is error case and should never come)
*/
tiLine tclFindResultDoc::insertPosInfo(tPatId patternId, tiLine foundLine, tclPosInfo pos) {
// check line in
mLines[foundLine].posInfos()[patternId].insert(pos);
insertResLine(foundLine);
return getLineNoAtRes(foundLine);
}
/** function creates an empty line if not available before */
std::string& tclFindResultDoc::refLineText(tiLine foundLine) {
return mLines[foundLine].text();
}
bool tclFindResultDoc::getLineAvail(tiLine foundLine) const {
tlmLinePosInfo::const_iterator it = mLines.find(foundLine);
if(it!=mLines.end()) {
return it->second.valid();
}
return false;
}
/** function creates an empty line if not available before */
const std::string& tclFindResultDoc::getLineText(tiLine foundLine) {
tlmLinePosInfo::const_iterator it = mLines.find(foundLine);
if(it!=mLines.end()) {
return it->second.text();
} else {
return mDefLineInfo.second.text();
}
}
/** setLineText returns true in case that line was added or updated */
bool tclFindResultDoc::setLineText(tiLine foundLine, const std::string& text) {
tlmLinePosInfo::iterator it = mLines.find(foundLine);
bool bNew;
if(it != mLines.end()) {
bNew = !it->second.valid();
it->second.first = tclResultLine(text);
} else {
bNew = true;
mLines[foundLine].first = tclResultLine(text);
insertResLine(foundLine);
}
return bNew;
}
void tclFindResultDoc::reserve(unsigned count) {
mReslines.reserve(count);
}
void tclFindResultDoc::clear() {
mLines.clear();
mReslines.clear();
}
tiLine tclFindResultDoc::size() const {
return (tiLine)mLines.size();
}
void tclFindResultDoc::erase(tiLine foundLine){
removeResLine(foundLine);
mLines.erase(foundLine);
}
void tclFindResultDoc::moveResult(tPatId oldPattId, tPatId newPattId)
{
DBG2("moveResult(old, new) %f %f", oldPattId, newPattId);
// iterate over all lines and change old in new id
tlmLinePosInfo::iterator it = mLines.begin();
for(;it != mLines.end(); ++it) {
tlmIdxPosInfo& posInfos = it->second.posInfos();
tlmIdxPosInfo::iterator iOld = posInfos.find(oldPattId);
if(iOld != posInfos.end()) {
// old pattern found in this line -> move
posInfos[newPattId] = iOld->second;
posInfos.erase(iOld);
}
}
}
/** make sure function is not called with resultWinLine >= size() */
const tlpLinePosInfo& tclFindResultDoc::getLineAtRes(tiLine resultWinLine) const {
if(resultWinLine >= size()) {
if (resultWinLine == size() && resultWinLine > 0) {
// special case click in CR from last line
--resultWinLine;
} else {
assert(resultWinLine == 0 || resultWinLine < size()); // index out of range
return mDefLineInfo;
}
}
tiLine foundLine = mReslines[resultWinLine];
tlmLinePosInfo::const_iterator it = mLines.lower_bound(foundLine);
if((it!= mLines.end())&&(it->first==foundLine)) {
return *it;
} else {
assert((it!= mLines.end())&&(it->first==foundLine)); // index out of range
return mDefLineInfo;
}
}
/** function returns empty line (default CTOR) if not available before */
const tclLinePosInfo& tclFindResultDoc::getLineAtMain(tiLine foundLine) const {
tlmLinePosInfo::const_iterator it = mLines.lower_bound(foundLine);
if((it!= mLines.end())&&(it->first==foundLine)) {
return it->second;
} else {
assert((it!= mLines.end())&&(it->first==foundLine)); // index out of range
return mDefLineInfo.second;
}
}
tiLine tclFindResultDoc::getNextLineNoAtMain(tiLine iFirstLineInView) const {
tlmLinePosInfo::const_iterator it = mLines.lower_bound(iFirstLineInView);
if (it != mLines.end()) {
return it->first;
}
else {
return (tiLine)-1;
}
}
/** function returns true if available */
bool tclFindResultDoc::getLineAtMainAvail(tiLine foundLine) const {
tlmLinePosInfo::const_iterator it = mLines.lower_bound(foundLine);
if((it!= mLines.end())&&(it->first==foundLine)) {
return true;
} else {
return false;
}
}
/** function returns newly inserted element if not available before */
tclLinePosInfo& tclFindResultDoc::refLineAtMain(tiLine foundLine) {
return mLines[foundLine];
}
tiLine tclFindResultDoc::getLineNoAtRes(tiLine foundLine) const {
//tlmLinePosInfo::const_iterator it = mLines.find(foundLine);
// inform window to redraw the given line array
tiLine i=-1;
//// go the shorteset way to the end and count the lines before or after
tlvLine::const_iterator first = mReslines.begin();
tlvLine::const_iterator last, it;
if ( (tiLine)mReslines.size() > foundLine ) {
last = mReslines.begin() + foundLine;
} else {
last = mReslines.end();
}
it = std::lower_bound(first, last, foundLine);
if((it != mReslines.end())&&(*it == foundLine)) {
i = (tiLine)(it - first);
} else {assert(0); }
return i;
}
/** make sure function is not called with resultWinLine >= size() */
tiLine tclFindResultDoc::getLineNoAtMain(tiLine resultWinLine) const {
if(resultWinLine >= size() ) {
assert(resultWinLine <= size()); // index out of range but 0 should be not be an error as it is reset scintilla
return -1;
}
return mReslines.at(resultWinLine);
}
void tclFindResultDoc::insertResLine(tiLine foundLine) {
// from resline == foundline we start searching for the real place
// foundline cannot be bigger as resline
tlvLine::iterator first = mReslines.begin(),
last, it;
if ( (tiLine)mReslines.size() > foundLine) {
last = mReslines.begin() + foundLine;
} else {
last = mReslines.end();
}
it = std::lower_bound(first, last, foundLine);
if(it == mReslines.end()) {
mReslines.insert(it, foundLine);
} else if(*it > foundLine) {
mReslines.insert(it, foundLine);
}
}
void tclFindResultDoc::removeResLine(tiLine foundLine) {
// from resline == foundline we start searching for the real place
// foundline cannot be bigger as resline
tlvLine::iterator first = mReslines.begin(),
last, it;
if ( (tiLine)mReslines.size() > foundLine) {
last = mReslines.begin() + foundLine;
} else {
last = mReslines.end();
}
it = std::lower_bound(first, last, foundLine);
if(it == mReslines.end()) {
assert(0); // line allready removed!
} else if(*it == foundLine) {
mReslines.erase(it);
} else if(*it > foundLine) {
assert(0); // line allready removed!
}
}