]> git.lyx.org Git - lyx.git/blob - src/iterators.h
more cursor dispatch
[lyx.git] / src / iterators.h
1 // -*- C++ -*-
2 /* \file iterators.h
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author unknown
7  * \author Lars Gullik Bjønnes
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef ITERATORS_H
13 #define ITERATORS_H
14
15 #include "ParagraphList_fwd.h"
16 #include "InsetList.h"
17
18 #include "support/types.h"
19
20 #include <boost/optional.hpp>
21
22 #include <vector>
23
24 class LyXText;
25 class InsetBase;
26 class Cursor;
27 class Buffer;
28 class PosIterator;
29
30
31 class ParPosition {
32 public:
33         ///
34         ParPosition(ParagraphList::iterator p, ParagraphList const & pl);
35         ///
36         ParagraphList::iterator pit;
37         ///
38         ParagraphList const * plist;
39         ///
40         boost::optional<InsetList::iterator> it;
41         ///
42         boost::optional<int> index;
43 };
44
45
46 class ParIterator  : public std::iterator<
47         std::forward_iterator_tag,
48         ParagraphList::value_type> {
49 public:
50         ///
51         ParIterator(ParagraphList::iterator pit, ParagraphList const & pl);
52         ///
53         ~ParIterator();
54         ///
55         ParIterator(ParIterator const &);
56         ///
57         ParIterator(PosIterator const &);
58         ///
59         void operator=(ParIterator const &);
60         ///
61         ParIterator & operator++();
62         ///
63         Paragraph & operator*() const;
64         ///
65         ParagraphList::iterator operator->() const;
66         /// This gives us the top-most parent paragraph
67         ParagraphList::iterator outerPar() const;
68         ///
69         ParagraphList::iterator pit() const;
70         ///
71         ParagraphList & plist() const;
72         /// returns 'innermost' LyXText
73         LyXText * text(Buffer &) const;
74         /// returns innermost inset
75         InsetBase * inset() const;
76         /// returns index of cell in innermost inset
77         int index() const;
78         ///
79         size_t size() const;
80
81         typedef std::vector<ParPosition> PosHolder;
82         PosHolder const & positions() const
83         {
84                 return positions_;
85         }
86 private:
87         PosHolder positions_;
88 };
89
90 ///
91 bool operator==(ParIterator const & iter1, ParIterator const & iter2);
92
93 ///
94 bool operator!=(ParIterator const & iter1, ParIterator const & iter2);
95
96
97 class ParConstIterator : public std::iterator<
98         std::forward_iterator_tag,
99         ParagraphList::value_type> {
100 public:
101         ///
102         ParConstIterator(ParagraphList::iterator pit, ParagraphList const & pl);
103         ///
104         ~ParConstIterator();
105         ///
106         ParConstIterator(ParConstIterator const &);
107         ///
108         ParConstIterator & operator++();
109         ///
110         ParagraphList::const_iterator pit() const;
111         ///
112         Paragraph const & operator*() const;
113         ///
114         ParagraphList::const_iterator operator->() const;
115         ///
116         ParagraphList const & plist() const;
117
118         /// depth of nesting
119         size_t size() const;
120         typedef std::vector<ParPosition> PosHolder;
121         PosHolder const & positions() const
122         {
123                 return positions_;
124         }
125 private:
126         PosHolder positions_;
127 };
128
129 bool operator==(ParConstIterator const & iter1,
130                 ParConstIterator const & iter2);
131
132 bool operator!=(ParConstIterator const & iter1,
133                 ParConstIterator const & iter2);
134
135 #endif