]> git.lyx.org Git - lyx.git/blob - src/iterators.h
unpimplify ParIterator, move some functions around, remove some friends.
[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 BufferView;
29 class PosIterator;
30
31
32 class ParPosition {
33 public:
34         ///
35         ParPosition(ParagraphList::iterator p, ParagraphList const & pl);
36         ///
37         ParagraphList::iterator pit;
38         ///
39         ParagraphList const * plist;
40         ///
41         boost::optional<InsetList::iterator> it;
42         ///
43         boost::optional<int> index;
44 };
45
46
47 class ParIterator  : public std::iterator<
48         std::forward_iterator_tag,
49         ParagraphList::value_type> {
50 public:
51         ///
52         ParIterator(ParagraphList::iterator pit, ParagraphList const & pl);
53         ///
54         ~ParIterator();
55         ///
56         ParIterator(ParIterator const &);
57         ///
58         ParIterator(PosIterator const &);
59         ///
60         void operator=(ParIterator const &);
61         ///
62         ParIterator & operator++();
63         ///
64         Paragraph & operator*() const;
65         ///
66         ParagraphList::iterator operator->() const;
67         /// This gives us the top-most parent paragraph
68         ParagraphList::iterator outerPar() const;
69         ///
70         ParagraphList::iterator pit() const;
71         ///
72         ParagraphList & plist() const;
73         /// returns 'innermost' LyXText
74         LyXText * text(Buffer &) const;
75         /// returns innermost inset
76         InsetBase * inset() const;
77         /// returns index of cell in innermost inset
78         int index() const;
79         ///
80         size_t size() const;
81         ///
82         void lockPath(BufferView *) const;
83
84         typedef std::vector<ParPosition> PosHolder;
85         PosHolder const & positions() const
86         {
87                 return positions_;
88         }
89 private:
90         PosHolder positions_;
91 };
92
93 ///
94 bool operator==(ParIterator const & iter1, ParIterator const & iter2);
95
96 ///
97 bool operator!=(ParIterator const & iter1, ParIterator const & iter2);
98
99
100 class ParConstIterator : public std::iterator<
101         std::forward_iterator_tag,
102         ParagraphList::value_type> {
103 public:
104         ///
105         ParConstIterator(ParagraphList::iterator pit, ParagraphList const & pl);
106         ///
107         ~ParConstIterator();
108         ///
109         ParConstIterator(ParConstIterator const &);
110         ///
111         ParConstIterator & operator++();
112         ///
113         ParagraphList::const_iterator pit() const;
114         ///
115         Paragraph const & operator*() const;
116         ///
117         ParagraphList::const_iterator operator->() const;
118         ///
119         ParagraphList const & plist() const;
120
121         /// depth of nesting
122         size_t size() const;
123         typedef std::vector<ParPosition> PosHolder;
124         PosHolder const & positions() const
125         {
126                 return positions_;
127         }
128 private:
129         PosHolder positions_;
130 };
131
132 bool operator==(ParConstIterator const & iter1,
133                 ParConstIterator const & iter2);
134
135 bool operator!=(ParConstIterator const & iter1,
136                 ParConstIterator const & iter2);
137
138 #endif