mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-14 09:32:20 +00:00
ef87c26b55
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@5602 a592a061-630c-0410-9148-cb99ea01b6c8
120 lines
2.0 KiB
C++
120 lines
2.0 KiB
C++
// -*- C++ -*-
|
|
|
|
#ifndef ITERATORS_H
|
|
#define ITERATORS_H
|
|
|
|
#include <stack>
|
|
|
|
#include "paragraph.h"
|
|
|
|
class ParPosition {
|
|
public:
|
|
ParPosition(Paragraph * p)
|
|
: par(p), it(p->insetlist.begin()), index(-1) {}
|
|
///
|
|
Paragraph * par;
|
|
///
|
|
InsetList::iterator it;
|
|
///
|
|
int index;
|
|
};
|
|
|
|
|
|
inline
|
|
bool operator==(ParPosition const & pos1, ParPosition const & pos2) {
|
|
return pos1.par == pos2.par &&
|
|
pos1.it == pos2.it &&
|
|
pos1.index == pos2.index;
|
|
}
|
|
|
|
inline
|
|
bool operator!=(ParPosition const & pos1, ParPosition const & pos2) {
|
|
return !(pos1 == pos2);
|
|
}
|
|
|
|
|
|
class ParIterator {
|
|
public:
|
|
///
|
|
typedef std::stack<ParPosition> PosHolder;
|
|
///
|
|
ParIterator() {}
|
|
///
|
|
ParIterator(Paragraph * par) {
|
|
positions.push(ParPosition(par));
|
|
}
|
|
///
|
|
ParIterator & operator++();
|
|
///
|
|
Paragraph * operator*() {
|
|
return positions.top().par;
|
|
}
|
|
///
|
|
PosHolder::size_type size() const
|
|
{ return positions.size(); }
|
|
///
|
|
friend
|
|
bool operator==(ParIterator const & iter1, ParIterator const & iter2);
|
|
private:
|
|
///
|
|
PosHolder positions;
|
|
};
|
|
|
|
|
|
///
|
|
inline
|
|
bool operator==(ParIterator const & iter1, ParIterator const & iter2) {
|
|
return iter1.positions == iter2.positions;
|
|
}
|
|
|
|
|
|
///
|
|
inline
|
|
bool operator!=(ParIterator const & iter1, ParIterator const & iter2) {
|
|
return !(iter1 == iter2);
|
|
}
|
|
|
|
|
|
class ParConstIterator {
|
|
public:
|
|
///
|
|
typedef std::stack<ParPosition> PosHolder;
|
|
///
|
|
ParConstIterator() {}
|
|
///
|
|
ParConstIterator(Paragraph * par) {
|
|
positions.push(ParPosition(par));
|
|
}
|
|
///
|
|
ParConstIterator & operator++();
|
|
///
|
|
Paragraph const * operator*() {
|
|
return positions.top().par;
|
|
}
|
|
///
|
|
PosHolder::size_type size() const
|
|
{ return positions.size(); }
|
|
///
|
|
friend
|
|
bool operator==(ParConstIterator const & iter1,
|
|
ParConstIterator const & iter2);
|
|
private:
|
|
///
|
|
PosHolder positions;
|
|
};
|
|
|
|
|
|
///
|
|
inline
|
|
bool operator==(ParConstIterator const & iter1, ParConstIterator const & iter2) {
|
|
return iter1.positions == iter2.positions;
|
|
}
|
|
|
|
///
|
|
inline
|
|
bool operator!=(ParConstIterator const & iter1, ParConstIterator const & iter2) {
|
|
return !(iter1 == iter2);
|
|
}
|
|
|
|
#endif
|