1 /*
2 * Copyright (C) 2011 Nicolas Bonnefon and other contributors
3 *
4 * This file is part of glogg.
5 *
6 * glogg is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * glogg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with glogg. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "marks.h"
21
22 #include "log.h"
23 #include "utils.h"
24
25 // This file implements the list of marks for a file.
26 // It is implemented as a QList which is kept in order when inserting,
27 // it is simpler than something fancy like a heap, and insertion are
28 // not done very often anyway. Oh and we need to iterate through the
29 // list, disqualifying a straight heap.
30
Marks()31 Marks::Marks() : marks_()
32 {
33 }
34
addMark(qint64 line,QChar mark)35 void Marks::addMark( qint64 line, QChar mark )
36 {
37 // Look for the index immediately before
38 int index;
39 if ( ! lookupLineNumber< QList<Mark> >( marks_, line, &index ) )
40 {
41 // If a mark is not already set for this line
42 LOG(logDEBUG) << "Inserting mark at line " << line
43 << " (index " << index << ")";
44 marks_.insert( index, Mark( line ) );
45 }
46 else
47 {
48 LOG(logERROR) << "Trying to add an existing mark at line " << line;
49 }
50
51 // 'mark' is not used yet
52 mark = mark;
53 }
54
getMark(QChar mark) const55 qint64 Marks::getMark( QChar mark ) const
56 {
57 // 'mark' is not used yet
58 mark = mark;
59
60 return 0;
61 }
62
isLineMarked(qint64 line) const63 bool Marks::isLineMarked( qint64 line ) const
64 {
65 int index;
66 return lookupLineNumber< QList<Mark> >( marks_, line, &index );
67 }
68
deleteMark(QChar mark)69 void Marks::deleteMark( QChar mark )
70 {
71 // 'mark' is not used yet
72 mark = mark;
73 }
74
deleteMark(qint64 line)75 void Marks::deleteMark( qint64 line )
76 {
77 int index;
78
79 if ( lookupLineNumber< QList<Mark> >( marks_, line, &index ) )
80 {
81 marks_.removeAt( index );
82 }
83 }
84
clear()85 void Marks::clear()
86 {
87 marks_.clear();
88 }
89