]> git.lyx.org Git - lyx.git/blob - src/PosIterator.h
a PosIterator-based ParIterator ctor and 1 user
[lyx.git] / src / PosIterator.h
1 // -*- C++ -*-
2 /* \file PosIterator.h
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Alfredo Braunstein
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #ifndef POSITERATOR_H
12 #define POSITERATOR_H
13
14 #include "ParagraphList_fwd.h"
15
16 #include "iterators.h"
17
18 #include "support/types.h"
19
20 #include <stack>
21
22
23 class BufferView;
24
25 struct PosIteratorItem 
26 {
27         PosIteratorItem(ParagraphList * pl,
28                         ParagraphList::iterator pit,
29                         lyx::pos_type pos,
30                         int index = 0)
31                 : pl(pl), pit(pit), pos(pos), index(index) {};
32         ParagraphList * pl;
33         ParagraphList::iterator pit;
34         lyx::pos_type pos;
35         int index;
36 };
37
38
39 class PosIterator
40 {
41 public:
42         PosIterator(BufferView & bv);
43         PosIterator(ParIterator & par, lyx::pos_type pos);
44         PosIterator(ParagraphList * pl, ParagraphList::iterator pit,
45                     lyx::pos_type pos);
46         PosIterator(ParIterator const & parit, lyx::pos_type p);
47         PosIterator & operator++();
48         PosIterator & operator--();
49         friend bool operator==(PosIterator const &, PosIterator const &);
50
51         ParagraphList::iterator pit() const { return stack_.top().pit; }
52         lyx::pos_type pos() const { return stack_.top().pos; }
53         bool at_end() const;
54         friend PosIterator ParIterator::asPosIterator(lyx::pos_type) const;
55         friend ParIterator::ParIterator(PosIterator const &);
56         
57 private:
58         PosIterator() {};
59         std::stack<PosIteratorItem> stack_;
60 };
61
62 bool operator!=(PosIterator const &, PosIterator const &);
63 bool operator==(PosIterator const &, PosIterator const &);
64
65 int distance(PosIterator const &, PosIterator const &);
66 void advance(PosIterator &, int);
67
68 #endif
69