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