]> git.lyx.org Git - features.git/blob - src/PosIterator.h
19449c1c0be6278e59c8c4747d34ca2091894fb7
[features.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 <vector>
21
22
23 class BufferView;
24
25 struct PosIteratorItem {
26         PosIteratorItem(ParagraphList * pl,
27                         ParagraphList::iterator pit,
28                         lyx::pos_type pos,
29                         int index = 0)
30                 : pl(pl), pit(pit), pos(pos), index(index) {};
31         ParagraphList * pl;
32         ParagraphList::iterator pit;
33         lyx::pos_type pos;
34         int index;
35 };
36
37
38 class PosIterator {
39 public:
40         PosIterator(BufferView & bv);
41         PosIterator(ParIterator & par, lyx::pos_type pos);
42         PosIterator(ParagraphList * pl, ParagraphList::iterator pit,
43                     lyx::pos_type pos);
44         PosIterator(ParIterator const & parit, lyx::pos_type p);
45         PosIterator & operator++();
46         PosIterator & operator--();
47         friend bool operator==(PosIterator const &, PosIterator const &);
48
49         ParagraphList::iterator pit() const { return stack_.back().pit; }
50         lyx::pos_type pos() const { return stack_.back().pos; }
51         bool at_end() const;
52         InsetBase * inset() const;
53         friend PosIterator ParIterator::asPosIterator(lyx::pos_type) const;
54         friend ParIterator::ParIterator(PosIterator const &);
55         
56 private:
57         PosIterator() {};
58         //this is conceptually a stack, but we need random access sometimes
59         std::vector<PosIteratorItem> stack_;
60 };
61
62
63 bool operator!=(PosIterator const &, PosIterator const &);
64 bool operator==(PosIterator const &, PosIterator const &);
65
66 int distance(PosIterator const &, PosIterator const &);
67 void advance(PosIterator &, int);
68
69 #endif
70