lyx_mirror/src/iterators.C

87 lines
2.2 KiB
C++
Raw Normal View History

#include <config.h>
#include "iterators.h"
ParIterator & ParIterator::operator++()
{
while (!positions.empty()) {
ParPosition & p = positions.top();
// Does the current inset contain more "cells" ?
if (p.index >= 0) {
++p.index;
ParagraphList * plist = p.it.getInset()->getParagraphs(p.index);
if (plist && !plist->empty()) {
positions.push(ParPosition(&plist->front()));
return *this;
}
++p.it;
} else
// The following line is needed because the value of
// p.it may be invalid if inset was added/removed to
// the paragraph pointed by the iterator
p.it = p.par->insetlist.begin();
// Try to find the next inset that contains paragraphs
InsetList::iterator end = p.par->insetlist.end();
for (; p.it != end; ++p.it) {
ParagraphList * plist = p.it.getInset()->getParagraphs(0);
if (plist && !plist->empty()) {
p.index = 0;
positions.push(ParPosition(&plist->front()));
return *this;
}
}
// Try to go to the next paragarph
if (p.par->next()) {
p = ParPosition(p.par->next());
return *this;
}
positions.pop();
}
return *this;
}
ParConstIterator & ParConstIterator::operator++()
{
while (!positions.empty()) {
ParPosition & p = positions.top();
// Does the current inset contain more "cells" ?
if (p.index >= 0) {
++p.index;
ParagraphList * plist = p.it.getInset()->getParagraphs(p.index);
if (plist && !plist->empty()) {
positions.push(ParPosition(&plist->front()));
return *this;
}
++p.it;
} else
// The following line is needed because the value of
// p.it may be invalid if inset was added/removed to
// the paragraph pointed by the iterator
p.it = p.par->insetlist.begin();
// Try to find the next inset that contains paragraphs
InsetList::iterator end = p.par->insetlist.end();
for (; p.it != end; ++p.it) {
ParagraphList * plist = p.it.getInset()->getParagraphs(0);
if (plist && !plist->empty()) {
p.index = 0;
positions.push(ParPosition(&plist->front()));
return *this;
}
}
// Try to go to the next paragarph
if (p.par->next()) {
p = ParPosition(p.par->next());
return *this;
}
positions.pop();
}
return *this;
}