#include <config.h>
-#include "debug.h"
#include "math_iterator.h"
+#include "debug.h"
+#include "support/LAssert.h"
-MathIterator::MathIterator()
-{}
+//MathIterator::MathIterator()
+//{}
MathIterator::MathIterator(MathInset * p)
}
-MathIterator::MathIterator(MathCursor::cursor_type const & c)
- : cursor_(c)
-{}
+//MathIterator::MathIterator(MathCursor::cursor_type const & c)
+// : cursor_(c)
+//{}
MathCursorPos const & MathIterator::position() const
{
+ lyx::Assert(cursor_.size());
return cursor_.back();
}
MathCursorPos & MathIterator::position()
{
+ lyx::Assert(cursor_.size());
return cursor_.back();
}
}
-MathInset * MathIterator::par() const
+MathInset const * MathIterator::par() const
+{
+ return position().par_;
+}
+
+
+MathInset * MathIterator::par()
{
- return cursor_.size() ? cursor_.back().par_ : 0;
+ return position().par_;
}
MathXArray const & MathIterator::xcell() const
{
- if (!par())
- lyxerr << "MathIterator::xcell: no cell\n";
return par()->xcell(position().idx_);
}
+MathArray const & MathIterator::cell() const
+{
+ return par()->xcell(position().idx_).data_;
+}
+
+
MathInset * MathIterator::nextInset() const
{
if (position().pos_ == xcell().data_.size())
void MathIterator::pop()
{
//lyxerr << "pop: " << endl;
+ lyx::Assert(cursor_.size());
cursor_.pop_back();
}
}
+void MathIterator::goEnd()
+{
+ position().idx_ = par()->nargs() - 1;
+ position().pos_ = xcell().data_.size();
+}
+
+
void MathIterator::operator++()
{
// move into the current inset if possible
return;
}
- // otherwise leave array, move on one cell
+ // otherwise leave array, move on one position
// this might yield pos() == size(), but that's a ok.
pop();
++position().pos_;
}
+void MathIterator::jump(MathInset::difference_type i)
+{
+ position().pos_ += i;
+ //lyx::Assert(position().pos_ >= 0);
+ lyx::Assert(position().pos_ <= cell().size());
+}
+
bool operator==(MathIterator const & it, MathIterator const & jt)
{
return it.cursor() != jt.cursor();
}
+
+MathIterator ibegin(MathInset * p)
+{
+ return MathIterator(p);
+}
+
+
+MathIterator iend(MathInset * p)
+{
+ MathIterator it(p);
+ it.goEnd();
+ return it;
+}