]> git.lyx.org Git - features.git/blob - src/ParIterator.cpp
There was a bit too much copying of dociterators gpoing on leading to an
[features.git] / src / ParIterator.cpp
1 /* \file ParIterator.cpp
2  * This file is part of LyX, the document processor.
3  * Licence details can be found in the file COPYING.
4  *
5  * \author unknown
6  * \author Lars Gullik Bjønnes
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "ParIterator.h"
14
15 #include "Paragraph.h"
16 #include "Text.h"
17
18 #include "insets/Inset.h"
19
20
21 namespace lyx {
22
23 ///
24 /// ParIterator
25 ///
26
27 ParIterator::ParIterator(DocIterator const & cur)
28         : DocIterator(cur)
29 {}
30
31
32 ParIterator par_iterator_begin(Inset & inset)
33 {
34         return ParIterator(doc_iterator_begin(inset));
35 }
36
37
38 ParIterator par_iterator_end(Inset & inset)
39 {
40         return ParIterator(doc_iterator_end(inset));
41 }
42
43
44 ParIterator::ParIterator(ParIterator const & pi)
45         : DocIterator(DocIterator(pi))
46 {}
47
48
49 ParIterator & ParIterator::operator++()
50 {
51         forwardPar();
52         return *this;
53 }
54
55
56 ParIterator ParIterator::operator++(int)
57 {
58         ParIterator tmp(*this);
59         forwardPar();
60         return tmp;
61 }
62
63
64 #if 0
65 // Unused member functions. Also having this makes ParIterator not be
66 // an forward iterator anymore. So unless we change that, this function
67 // should not be compiled/used. (Lgb)
68 ParIterator & ParIterator::operator--()
69 {
70         // FIXME: look here
71 //      DocIterator::backwardPar();
72         return *this;
73 }
74 #endif
75
76
77 Paragraph & ParIterator::operator*() const
78 {
79         return const_cast<Paragraph&>(text()->getPar(pit()));
80 }
81
82
83 pit_type ParIterator::pit() const
84 {
85         return DocIterator::pit();
86 }
87
88
89 Paragraph * ParIterator::operator->() const
90 {
91         return const_cast<Paragraph*>(&text()->getPar(pit()));
92 }
93
94
95 pit_type ParIterator::outerPar() const
96 {
97         return bottom().pit();
98 }
99
100
101 ParagraphList & ParIterator::plist() const
102 {
103         return const_cast<ParagraphList&>(text()->paragraphs());
104 }
105
106
107 DocIterator makeDocIterator(ParIterator const & par, pos_type pos)
108 {
109         DocIterator dit(par);
110         dit.pos() = pos;
111         return dit;
112 }
113
114
115
116 ///
117 /// ParConstIterator
118 ///
119
120
121 ParConstIterator::ParConstIterator(DocIterator const & dit)
122         : DocIterator(dit)
123 {}
124
125
126 ParConstIterator::ParConstIterator(ParConstIterator const & pi)
127         : DocIterator(DocIterator(pi))
128 {}
129
130
131 ParConstIterator & ParConstIterator::operator++()
132 {
133         DocIterator::forwardPar();
134         return *this;
135 }
136
137
138 Paragraph const & ParConstIterator::operator*() const
139 {
140         return text()->getPar(pit());
141 }
142
143
144 Paragraph const * ParConstIterator::operator->() const
145 {
146         return &text()->getPar(pit());
147 }
148
149
150 ParagraphList const & ParConstIterator::plist() const
151 {
152         return text()->paragraphs();
153 }
154
155 #if 0
156 bool operator==(ParConstIterator const & iter1, ParConstIterator const & iter2)
157 {
158         // FIXME: this makes two full copies!
159         return DocIterator(iter1) == DocIterator(iter2);
160 }
161
162
163 bool operator!=(ParConstIterator const & iter1, ParConstIterator const & iter2)
164 {
165         return !(iter1 == iter2);
166 }
167 #endif
168
169
170 // FIXME: const correctness!
171
172 ParConstIterator par_const_iterator_begin(Inset const & inset)
173 {
174         return ParConstIterator(doc_iterator_begin(const_cast<Inset &>(inset)));
175 }
176
177
178 ParConstIterator par_const_iterator_end(Inset const & inset)
179 {
180         return ParConstIterator(doc_iterator_end(const_cast<Inset &>(inset)));
181 }
182
183
184 } // namespace lyx