]> git.lyx.org Git - lyx.git/blob - src/PosIterator.h
Compile fix gcc 2.95 + stlport
[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 <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 : public std::iterator<
39         std::bidirectional_iterator_tag,
40         ParagraphList::value_type> {
41 public:
42         // Creates a singular.
43         PosIterator() {};
44
45         PosIterator(BufferView & bv);
46         PosIterator(ParagraphList * pl, ParagraphList::iterator pit,
47                     lyx::pos_type pos);
48         PosIterator(ParIterator const & par, lyx::pos_type pos);
49         PosIterator & operator++();
50         PosIterator & operator--();
51         friend bool operator==(PosIterator const &, PosIterator const &);
52
53         ParagraphList::iterator pit() const { return stack_.back().pit; }
54         lyx::pos_type pos() const { return stack_.back().pos; }
55         bool at_end() const;
56         InsetBase * inset() const;
57         friend ParIterator::ParIterator(PosIterator const &);
58 private:
59         void setFrom(ParIterator const & par, lyx::pos_type pos);
60         // This is conceptually a stack,
61         // but we need random access sometimes.
62         std::vector<PosIteratorItem> stack_;
63 };
64
65
66 bool operator==(PosIterator const &, PosIterator const &);
67
68
69 inline
70 bool operator!=(PosIterator const & lhs, PosIterator const & rhs)
71 {
72         return !(lhs == rhs);
73 }
74
75 #endif