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