File: c2bCiterHistory.cpp

package info (click to toggle)
cb2bib 1.4.9-4
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 3,500 kB
  • ctags: 2,613
  • sloc: cpp: 26,112; sh: 481; makefile: 17
file content (60 lines) | stat: -rw-r--r-- 1,884 bytes parent folder | download
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
/***************************************************************************
 *   Copyright (C) 2004-2012 by Pere Constans
 *   constans@molspaces.com
 *   cb2Bib version 1.4.9. Licensed under the GNU GPL version 3.
 *   See the LICENSE file that comes with this distribution.
 ***************************************************************************/
#include "c2bCiterHistory.h"


static const int _maximum_history_states(35);


c2bCiterHistory::c2bCiterHistory()
{
    _last_citation_format = c2bCiter::AJYT;
    _index.resize(_maximum_history_states);
    _states.resize(_maximum_history_states);
    clear();
}


void c2bCiterHistory::clear()
{
    _last_citation = 0;
    _last_keyword = 0;
    _last_selection_citation = 0;
    _last_nonkeyword_state = c2bCiter::State();
    _last_nonselected_state = c2bCiter::State();
    _cstate = -1;
    _nstates = -1;
    for (int i = 0; i < _maximum_history_states; ++i)
        _index[i] = i;
}

void c2bCiterHistory::saveCurrentState(const c2bCiter::Format format, const c2bCiter::Filter filter, const int iindex, const int vindex,
                                       const QString fstring)
{
    if (_cstate != -1)
        _nstates = _cstate - 1;
    _cstate = -1;
    const c2bCiter::State s(format, filter, vindex, fstring);
    if (_nstates > -1 && s == _states[_index[_nstates]])
        return;
    if (++_nstates >= _maximum_history_states)
    {
        // Move, e.g., 0 1 2 3 4 to 1 2 3 4 0
        const int oldest(_index[0]);
        for (int i = 0; i < _maximum_history_states - 1; ++i)
            _index[i] = _index[i+1];
        _index[--_nstates] = oldest;
    }
    _states[_index[_nstates]] = s;
    if (format != c2bCiter::K)
    {
        _last_nonkeyword_state = s;
        if (filter != c2bCiter::Selected)
            _last_nonselected_state = s;
    }
    saveCurrentItemIndex(format, filter, iindex);
}