]> git.lyx.org Git - lyx.git/blob - src/ParIterator.cpp
366c709f4c2ded0e8a389561463fadf0d8b9b79a
[lyx.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 ///
108 /// ParConstIterator
109 ///
110
111
112 ParConstIterator::ParConstIterator(DocIterator const & dit)
113         : DocIterator(dit)
114 {}
115
116
117 ParConstIterator::ParConstIterator(ParConstIterator const & pi)
118         : DocIterator(DocIterator(pi))
119 {}
120
121
122 ParConstIterator & ParConstIterator::operator++()
123 {
124         DocIterator::forwardPar();
125         return *this;
126 }
127
128
129 Paragraph const & ParConstIterator::operator*() const
130 {
131         return text()->getPar(pit());
132 }
133
134
135 Paragraph const * ParConstIterator::operator->() const
136 {
137         return &text()->getPar(pit());
138 }
139
140
141 ParagraphList const & ParConstIterator::plist() const
142 {
143         return text()->paragraphs();
144 }
145
146 #if 0
147 bool operator==(ParConstIterator const & iter1, ParConstIterator const & iter2)
148 {
149         // FIXME: this makes two full copies!
150         return DocIterator(iter1) == DocIterator(iter2);
151 }
152
153
154 bool operator!=(ParConstIterator const & iter1, ParConstIterator const & iter2)
155 {
156         return !(iter1 == iter2);
157 }
158 #endif
159
160
161 // FIXME: const correctness!
162
163 ParConstIterator par_const_iterator_begin(Inset const & inset)
164 {
165         return ParConstIterator(doc_iterator_begin(const_cast<Inset &>(inset)));
166 }
167
168
169 ParConstIterator par_const_iterator_end(Inset const & inset)
170 {
171         return ParConstIterator(doc_iterator_end(const_cast<Inset &>(inset)));
172 }
173
174
175 } // namespace lyx