#include <boost/assert.hpp>
-MathIterator::MathIterator()
-{}
-
-
-MathIterator::MathIterator(MathInset * p)
-{
- push(p);
-}
-
-
-
MathArray const & MathIterator::cell() const
{
CursorSlice const & top = back();
}
-
-void MathIterator::push(MathInset * p)
-{
- //lyxerr << "push: " << p << endl;
- push_back(CursorSlice(p));
-}
-
-
-void MathIterator::pop()
-{
- //lyxerr << "pop: " << endl;
- BOOST_ASSERT(size());
- pop_back();
-}
-
-
-void MathIterator::goEnd()
-{
- CursorSlice & top = back();
- top.idx_ = top.asMathInset()->nargs() - 1;
- top.pos_ = cell().size();
-}
-
-
void MathIterator::operator++()
{
CursorSlice & top = back();
if (top.pos_ != ar.size())
n = (ar.begin() + top.pos_)->nucleus();
if (n && n->isActive()) {
- push(n);
+ push_back(CursorSlice(n));
return;
}
// otherwise leave array, move on one back
// this might yield pos() == size(), but that's a ok.
- pop();
+ pop_back();
// it certainly invalidates top
++back().pos_;
}
-bool MathIterator::normal() const
-{
- return back().pos_ < cell().size();
-}
-
-
-void MathIterator::shrink(size_type i)
-{
- if (i < size())
- erase(begin() + i, end());
-}
-
-
bool operator==(MathIterator const & it, MathIterator const & jt)
{
return MathIterator::base_type(it) == MathIterator::base_type(jt);
MathIterator ibegin(MathInset * p)
{
- return MathIterator(p);
+ MathIterator it;
+ it.push_back(CursorSlice(p));
+ return it;
}
MathIterator iend(MathInset * p)
{
- MathIterator it(p);
- it.goEnd();
+ MathIterator it;
+ it.push_back(CursorSlice(p));
+ return it;
+ CursorSlice & top = it.back();
+ top.idx_ = top.asMathInset()->nargs() - 1;
+ top.pos_ = it.cell().size();
return it;
}
friend bool operator!=(MathIterator const &, MathIterator const &);
friend bool operator==(MathIterator const &, MathIterator const &);
- /// default constructor
- MathIterator();
- /// start with given inset
- explicit MathIterator(MathInset * p);
/// move on one step
void operator++();
- /// helper for iend
- void goEnd();
/// read access to top most item
MathArray const & cell() const;
- /// is this a non-end position
- bool normal() const;
- /// shrinks to at most i levels
- void shrink(size_type i);
-
-private:
- /// own level down
- void push(MathInset *);
- /// own level up
- void pop();
};
///