]> git.lyx.org Git - lyx.git/blob - src/iterators.C
Alfredo's second patch
[lyx.git] / src / iterators.C
1 #include <config.h>
2
3 #include "iterators.h"
4
5 ParIterator & ParIterator::operator++()
6 {
7         while (!positions.empty()) {
8                 ParPosition & p = positions.top();
9
10                 // Does the current inset contain more "cells" ?
11                 if (p.index >= 0) {
12                         ++p.index;
13                         Paragraph * par = p.it.getInset()->getFirstParagraph(p.index);
14                         if (par) {
15                                 positions.push(ParPosition(par));
16                                 return *this;
17                         }
18                         ++p.it;
19                 } else
20                         // The following line is needed because the value of
21                         // p.it may be invalid if inset was added/removed to
22                         // the paragraph pointed by the iterator
23                         p.it = p.par->insetlist.begin();
24
25                 // Try to find the next inset that contains paragraphs
26                 InsetList::iterator end = p.par->insetlist.end();
27                 for (; p.it != end; ++p.it) {
28                         Paragraph * par = p.it.getInset()->getFirstParagraph(0);
29                         if (par) {
30                                 p.index = 0;
31                                 positions.push(ParPosition(par));
32                                 return *this;
33                         }
34                 }
35                 // Try to go to the next paragarph
36                 if (p.par->next()) {
37                         p = ParPosition(p.par->next());
38                         return *this;
39                 }
40
41                 positions.pop();
42         }
43         return *this;
44 }
45
46
47 ParConstIterator & ParConstIterator::operator++()
48 {
49         while (!positions.empty()) {
50                 ParPosition & p = positions.top();
51
52                 // Does the current inset contain more "cells" ?
53                 if (p.index >= 0) {
54                         ++p.index;
55                         Paragraph * par = p.it.getInset()->getFirstParagraph(p.index);
56                         if (par) {
57                                 positions.push(ParPosition(par));
58                                 return *this;
59                         }
60                         ++p.it;
61                 } else
62                         // The following line is needed because the value of
63                         // p.it may be invalid if inset was added/removed to
64                         // the paragraph pointed by the iterator
65                         p.it = p.par->insetlist.begin();
66
67                 // Try to find the next inset that contains paragraphs
68                 InsetList::iterator end = p.par->insetlist.end();
69                 for (; p.it != end; ++p.it) {
70                         Paragraph * par = p.it.getInset()->getFirstParagraph(0);
71                         if (par) {
72                                 p.index = 0;
73                                 positions.push(ParPosition(par));
74                                 return *this;
75                         }
76                 }
77                 // Try to go to the next paragarph
78                 if (p.par->next()) {
79                         p = ParPosition(p.par->next());
80                         return *this;
81                 }
82
83                 positions.pop();
84         }
85         return *this;
86 }