+2001-03-15 André Pönitz <poenitz@htwm.de>
+ * math_rowst.h: Finally remove MathedRowSt
+
+ * math_parser.C:
+ math_xiter.C: changed accordingly
+
2001-03-12 André Pönitz <poenitz@htwm.de>
2001-03-12 André Pönitz <poenitz@htwm.de>
- * math_rowst.h: replace MathedRowSt with MathedRowSt,
+ * math_rowst.h: replace MathedRowSt with MathedRowStruct,
more robust MathedRowSt::[gs]etTab (to get rid of the constructor arg)
2001-03-10 André Pönitz <poenitz@htwm.de>
more robust MathedRowSt::[gs]etTab (to get rid of the constructor arg)
2001-03-10 André Pönitz <poenitz@htwm.de>
}
MathedXIter * Item(int idx) {
}
MathedXIter * Item(int idx) {
- return (idx + 1 <= i) ? &item[i - idx - 1] : 0;
+ if (idx + 1 > i)
+ cerr << "Wrong index: " << idx << " i: " << i << endl;
+ return &item[i - idx - 1];
+byte MathedIter::at(int p) const
+{
+ return (*array)[p];
+}
+
+byte & MathedIter::at(int p)
+{
+ return (*array)[p];
+}
int MathedIter::Empty() const
{
int MathedIter::Empty() const
{
void MathedIter::Reset()
{
void MathedIter::Reset()
{
- if (array->last() > 0 && MathIsFont((*array)[0])) {
- fcode((*array)[0]);
+ if (array->last() > 0 && MathIsFont(at(0))) {
+ fcode(at(0));
pos = 1;
} else {
fcode(-1);
pos = 1;
} else {
fcode(-1);
byte MathedIter::GetChar() const
{
if (IsFont()) {
byte MathedIter::GetChar() const
{
if (IsFont()) {
}
string const MathedIter::GetString() const
{
if (IsFont()) {
}
string const MathedIter::GetString() const
{
if (IsFont()) {
- fcode((*array)[++pos]);
- for (; (*array)[pos] >= ' ' && pos < array->last(); ++pos)
- s += (*array)[pos];
+ for (; at(pos) >= ' ' && pos < array->last(); ++pos)
+ s += at(pos);
return p;
} else {
lyxerr << "Math Error: This is not an inset["
return p;
} else {
lyxerr << "Math Error: This is not an inset["
- << (*array)[pos] << "]" << endl;
+ << at(pos) << "]" << endl;
- if ((*array)[pos] < ' ') {
fcode(-1);
if (IsTab())
++col;
fcode(-1);
if (IsTab())
++col;
- fcode((*array)[pos++]);
bool MathedIter::goNextCode(MathedTextCodes code)
{
while (Next()) {
bool MathedIter::goNextCode(MathedTextCodes code)
{
while (Next()) {
- if ((*array)[pos] == code)
// Address 0x47b857 is 1 byte before start of malloc'd block at
// 0x47b858 of 16 bytes.
// Address 0x47b857 is 1 byte before start of malloc'd block at
// 0x47b858 of 16 bytes.
- if (c == ' ' && ((*array)[pos] == ' ' || (*array)[pos - 1] == ' '))
+ if (c == ' ' && (at(pos) == ' ' || at(pos - 1) == ' '))
- if (IsFont() && (*array)[pos] == t) {
+ if (IsFont() && at(pos) == t) {
fcode(t);
++pos;
} else {
fcode(t);
++pos;
} else {
- if (t != fcode() && pos > 0 && MathIsFont((*array)[pos - 1])) {
+ if (t != fcode() && pos > 0 && MathIsFont(at(pos - 1))) {
- for (; k >= 0 && (*array)[k] >= ' '; --k)
+ for (; k >= 0 && at(k) >= ' '; --k)
- fcode( (k >= 0 && MathIsFont((*array)[k])) ? (*array)[k] : -1 );
+ fcode( (k >= 0 && MathIsFont(at(k))) ? at(k) : -1 );
- short const f = ((*array)[pos] < ' ') ? 0 : fcode();
+ short const f = (at(pos) < ' ') ? 0 : fcode();
int shift = (t == fcode()) ? 1 : ((f) ? 3 : 2);
if (t == LM_TC_TAB || t == LM_TC_CR) {
int shift = (t == fcode()) ? 1 : ((f) ? 3 : 2);
if (t == LM_TC_TAB || t == LM_TC_CR) {
else {
array->need_size(array->last() + shift);
array->last(array->last() + shift);
else {
array->need_size(array->last() + shift);
array->last(array->last() + shift);
- (*array)[array->last()] = '\0';
+ at(array->last()) = '\0';
}
if (t != fcode()) {
if (f)
}
if (t != fcode()) {
if (f)
- (*array)[pos + shift - 1] = fcode();
+ at(pos + shift - 1) = fcode();
fcode(t);
} else
fcode(0);
}
fcode(t);
} else
fcode(0);
}
if (pos < array->last()) {
bool fg = false;
if (pos < array->last()) {
bool fg = false;
- if ((*array)[pos] >= ' ') {
- if (pos> 0 && MathIsFont((*array)[pos - 1]))
+ if (at(pos) >= ' ') {
+ if (pos> 0 && MathIsFont(at(pos - 1)))
array->move(pos, shift);
if (fg)
array->move(pos, shift);
if (fg)
- (*array)[pos + shift - 1] = fcode();
+ at(pos + shift - 1) = fcode();
array->last(array->last() + shift);
}
array->last(array->last() + shift);
}
- (*array)[array->last()] = '\0';
+ at(array->last()) = '\0';
return;
short f = fcode();
return;
short f = fcode();
- if (pos > 0 && (*array)[pos] >= ' ' && MathIsFont((*array)[pos - 1]))
+ if (pos > 0 && at(pos) >= ' ' && MathIsFont(at(pos - 1)))
- if (MathIsFont((*array)[pos2 - 1]))
+ if (MathIsFont(at(pos2 - 1)))
- if ((*array)[pos2] >= ' ') {
for (int p = pos2; p > 0; --p) {
for (int p = pos2; p > 0; --p) {
- if (MathIsFont((*array)[p])) {
- f = (*array)[p];
+ if (MathIsFont(at(p))) {
+ f = at(p);
}
array->move(pos2, pos - pos2);
}
array->move(pos2, pos - pos2);
array->raw_pointer_insert(p, pos + 1);
pos += SizeInset;
array->raw_pointer_insert(p, pos + 1);
pos += SizeInset;
- (*array)[pos - 1] = type;
- (*array)[array->last()] = '\0';
+ at(pos - 1) = type;
+ at(array->last()) = '\0';
byte const c = GetChar();
if (c >= ' ') {
byte const c = GetChar();
if (c >= ' ') {
- if (MathIsFont((*array)[pos - 1]) && (*array)[pos + 1] < ' ') {
+ if (MathIsFont(at(pos - 1)) && at(pos + 1) < ' ') {
shift = 2;
pos--;
int i = pos - 1;
shift = 2;
pos--;
int i = pos - 1;
- for (; i > 0 && !MathIsFont((*array)[i]); --i)
+ for (; i > 0 && !MathIsFont(at(i)); --i)
- if (i > 0 && MathIsFont((*array)[i]))
- fcode((*array)[i]);
+ if (i > 0 && MathIsFont(at(i)))
+ fcode(at(i));
} else
shift = 1;
} else {
} else
shift = 1;
} else {
- if (MathIsInset((*array)[pos]))
+ if (MathIsInset(at(pos)))
shift = sizeof(char*) + 2;
else if (c == LM_TC_TAB || c == LM_TC_CR) {
++shift;
shift = sizeof(char*) + 2;
else if (c == LM_TC_TAB || c == LM_TC_CR) {
++shift;
bool MathedIter::IsInset() const
{
bool MathedIter::IsInset() const
{
- return MathIsInset((*array)[pos]);
+ return MathIsInset(at(pos));
}
bool MathedIter::IsActive() const
{
}
bool MathedIter::IsActive() const
{
- return MathIsActive((*array)[pos]);
+ return MathIsActive(at(pos));
}
bool MathedIter::IsFont() const
{
}
bool MathedIter::IsFont() const
{
- return MathIsFont((*array)[pos]);
+ return MathIsFont(at(pos));
}
bool MathedIter::IsScript() const
{
}
bool MathedIter::IsScript() const
{
- return MathIsScript((*array)[pos]);
+ return MathIsScript(at(pos));
}
bool MathedIter::IsTab() const
{
}
bool MathedIter::IsTab() const
{
- return ((*array)[pos] == LM_TC_TAB);
+ return (at(pos) == LM_TC_TAB);
}
bool MathedIter::IsCR() const
{
}
bool MathedIter::IsCR() const
{
- return ((*array)[pos] == LM_TC_CR);
+ return (at(pos) == LM_TC_CR);
pos = 0;
row = 0;
col = 0;
pos = 0;
row = 0;
col = 0;
- fcode( (array && IsFont()) ? (*array)[0] : 0 );
+ fcode( (array && IsFont()) ? at(0) : 0 );
void setNumCols(int n) { ncols = n; }
///
MathedArray * GetData() const;
void setNumCols(int n) { ncols = n; }
///
MathedArray * GetData() const;
+ ///
+ byte & at(int pos);
+ ///
+ byte at(int pos) const;
protected:
///
void split(int);
protected:
///
void split(int);
{
flag = 15;
if (n > 0) {
{
flag = 15;
if (n > 0) {
- row_.data_ = new MathedRowSt(nc_ + 1);
MathedXIter it(this);
for (int j = 1; j < n; ++j)
it.addRow();
MathedXIter it(this);
for (int j = 1; j < n; ++j)
it.addRow();
it.insert('T', LM_TC_TAB);
}
} else if (n < 0) {
it.insert('T', LM_TC_TAB);
}
} else if (n < 0) {
- row_.data_ = new MathedRowSt(nc_ + 1);
+ MathedXIter it(this);
+ it.addRow();
void MathMatrixInset::Metrics()
{
void MathMatrixInset::Metrics()
{
- //if (row_.empty()) {
-#warning This leaks row_.data but goes away soon
- // lyxerr << " MIDA ";
- MathedXIter it(this);
- it.GoBegin();
- if (!it.crow_) {
- it.crow_.st_ = new MathedRowSt(it.ncols + 1); // this leaks
- }
- MathedRowSt * mrow = it.crow_.st_;
- while (it.OK()) {
- if (it.IsCR()) {
- if (it.col >= it.ncols)
- it.ncols = it.col + 1;
- MathedRowSt * r = new MathedRowSt(it.ncols + 1); // this leaks
- it.crow_.st_->next_ = r;
- it.crow_.st_ = r;
- }
- it.Next();
- }
- row_.data_ = mrow;
- //}
+ // Adjust row structure
+ MathedXIter it(this);
+ it.GoBegin();
+ int nrows = 1;
+ while (it.OK()) {
+ if (it.IsCR()) {
+ ++nrows;
+ if (it.col >= it.ncols)
+ it.ncols = it.col + 1;
+ }
+ it.Next();
+ }
+ row_.data_.resize(nrows);
// Clean the arrays
for (MathedRowContainer::iterator it = row_.begin(); it; ++it)
// Clean the arrays
for (MathedRowContainer::iterator it = row_.begin(); it; ++it)
case LM_TK_NEWLINE:
if (mt && (flags & FLAG_END)) {
if (mt->Permit(LMPF_ALLOW_CR)) {
case LM_TK_NEWLINE:
if (mt && (flags & FLAG_END)) {
if (mt->Permit(LMPF_ALLOW_CR)) {
- mt->getRowSt().insert_after(crow, MathedRowSt(mt->GetColumns() + 1));
+ mt->getRowSt().insert(crow);
++crow;
data.insert('K', LM_TC_CR);
} else
++crow;
data.insert('K', LM_TC_CR);
} else
typedef std::vector<int> Widths;
///
typedef std::vector<int> Widths;
///
- explicit
- MathedRowStruct(int n)
- : asc_(0), desc_(0), y_(0), widths_(n + 1, 0),
- numbered_(true)
+ MathedRowStruct()
+ : asc_(0), desc_(0), y_(0), numbered_(true)
{}
///
string const & getLabel() const;
{}
///
string const & getLabel() const;
-class MathedRowContainer;
-
-class MathedRowSt : public MathedRowStruct {
-public:
- ///
- explicit MathedRowSt(int n)
- : MathedRowStruct(n), next_(0)
- {}
- explicit MathedRowSt(MathedRowStruct const & t)
- : MathedRowStruct(t), next_(0)
- {}
-//private:
- ///
- MathedRowSt * next_;
- ///
- friend class MathedRowContainer;
-};
-
-
// The idea is to change this MathedRowContainer to mimic the behaviour
// of std::list<MathedRowStruct> in several small steps. In the end it
// could be replaced by such a list and MathedRowSt can go as well.
// The idea is to change this MathedRowContainer to mimic the behaviour
// of std::list<MathedRowStruct> in several small steps. In the end it
// could be replaced by such a list and MathedRowSt can go as well.
///
struct iterator {
///
///
struct iterator {
///
- iterator() : st_(0) {}
- ///
- explicit iterator(MathedRowSt * st) : st_(st) {}
+ iterator() : st_(0), pos_(0) {}
- explicit iterator(MathedRowContainer * m) : st_(m->data_) {}
- /// "better" conversion to bool
- operator void *() const { return st_; }
+ explicit iterator(MathedRowContainer * m) : st_(m), pos_(0) {}
+ /// "better" conversion to bool, static_cast doens't help?
+ operator void *() const
+ { return (void *)(st_ && pos_ < st_->data_.size()); }
- MathedRowStruct & operator*() { Assert(st_); return *st_; }
+ MathedRowStruct & operator*() { Assert(st_); return st_->data_[pos_]; }
- MathedRowStruct * operator->() { return st_; }
+ MathedRowStruct * operator->() { return &st_->data_[pos_]; }
- MathedRowStruct const * operator->() const { return st_; }
+ MathedRowStruct const * operator->() const { return &st_->data_[pos_]; }
- void operator++() { Assert(st_); st_ = st_->next_; }
+ void operator++() { Assert(st_); ++pos_; }
- bool is_last() const { Assert(st_); return st_->next_ == 0; }
+ bool is_last() const { Assert(st_); return pos_ == st_->data_.size() - 1; }
- bool operator==(const iterator & it) const { return st_ == it.st_; }
+ bool operator==(const iterator & it) const
+ { return st_ == it.st_ && pos_ == it.pos_; }
+ MathedRowContainer * st_;
+ ///
+ unsigned int pos_;
- ///
- MathedRowContainer() : data_(0) {}
-
- ///
- MathedRowContainer(MathedRowContainer const & c) : data_(0) {
- if (!c.empty()) {
- MathedRowSt * ro = 0;
- MathedRowSt * mrow = c.data_;
-
- while (mrow) {
- MathedRowSt * r = new MathedRowSt(*mrow);
- if (!ro)
- data_ = r;
- else
- ro->next_ = r;
- mrow = mrow->next_;
- ro = r;
- }
- }
- }
-
-
- ~MathedRowContainer() {
- MathedRowSt * r = data_;
- while (r) {
- MathedRowSt * q = r->next_;
- delete r;
- r = q;
- }
- }
-
///
iterator begin() { return iterator(this); }
///
///
iterator begin() { return iterator(this); }
///
- bool empty() const { return data_ == 0; }
+ bool empty() const { return data_.size() == 0; }
/// insert 'item' before 'iterator'
/// insert 'item' before 'iterator'
- void insert(iterator const & it, MathedRowStruct const & item) {
- MathedRowSt * r = new MathedRowSt(item);
- if (data_ == it.st_)
- data_ = r;
- else {
- MathedRowSt * pos = data_;
- if (pos->next_ == it.st_)
- pos->next_ = r;
- }
- r->next_ = it.st_;
+ void insert(iterator const & it) {
+ Assert(it.st_ == this);
+ data_.insert(data_.begin() + it.pos_, MathedRowStruct());
- /// insert 'item' after 'iterator'
- void insert_after(iterator & it, MathedRowStruct const & item) {
- MathedRowSt * r = new MathedRowSt(item);
- if (it) {
- r->next_ = it.st_->next_;
- it.st_->next_ = r;
- } else {
- it.st_ = r;
- r->next_ = 0;
- }
- }
-
void erase(iterator & it) {
void erase(iterator & it) {
- Assert(it.st_);
- MathedRowSt * r = it.st_->next_;
- if (r) {
- it.st_->next_ = r->next_;
- delete r;
- }
+ Assert(it.st_ == this);
+ data_.erase(data_.begin() + it.pos_);
+ std::vector<MathedRowStruct> data_;
private:
// currently unimplemented just to make sure it's not used
private:
// currently unimplemented just to make sure it's not used
while (pos < pos2 && OK()) {
if (IsCR()) {
if (p_ && p_->Permit(LMPF_ALLOW_CR)) {
while (pos < pos2 && OK()) {
if (IsCR()) {
if (p_ && p_->Permit(LMPF_ALLOW_CR)) {
- container().insert_after(crow_, MathedRowSt(ncols + 1));
+ container().insert(crow_);
++crow_;
} else {
Delete();
++crow_;
} else {
Delete();
}
// Create new item for the structure
}
// Create new item for the structure
- container().insert_after(crow_, MathedRowSt(ncols + 1));
+ container().insert(crow_);
// Fill missed tabs in current row
while (col < ncols - 1)
insert('T', LM_TC_TAB);
// Fill missed tabs in current row
while (col < ncols - 1)
insert('T', LM_TC_TAB);