mathed59.diff

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1773 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Lars Gullik Bjønnes 2001-03-15 15:07:17 +00:00
parent 31b38676de
commit a18d4a692a
5 changed files with 236 additions and 134 deletions

View File

@ -1,24 +1,35 @@
2001-03-15 André Pönitz <poenitz@htwm.de>
* math_parser.C: read '\nonumber' again (was broken)
* math_rowst.C: new file
2001-03-15 Angus Leeming <a.leeming@ic.ac.uk> 2001-03-15 Angus Leeming <a.leeming@ic.ac.uk>
* math_cursor.C: added using directive. * math_cursor.C: added using directive.
2001-03-15 André Pönitz <poenitz@htwm.de> 2001-03-15 André Pönitz <poenitz@htwm.de>
* math_rowst.h: Finally remove MathedRowSt * math_rowst.h: Finally remove MathedRowSt
* math_parser.C: * math_parser.C:
math_xiter.C: changed accordingly 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 MathedRowStruct, * math_rowst.h: replace MathedRowSt with MathedRowStruct,
more robust MathedRowSt::[gs]etTab (to get rid of the constructor arg) more robust MathedRowSt::[gs]etTab (to get rid of the constructor arg)
2001-03-10 André Pönitz <poenitz@htwm.de> 2001-03-10 André Pönitz <poenitz@htwm.de>
* math_xiter.[Ch]: * math_xiter.[Ch]:
math_matrixinset.C: move adjustVerticalSt to the only place where math_matrixinset.C: move adjustVerticalSt to the only place where
it is used. Fix a small bug where the cached row structure and the it is used. Fix a small bug where the cached row structure and the
actual data get out of sync after the deletion of whole rows actual data get out of sync after the deletion of whole rows
2001-03-09 André Pönitz <poenitz@htwm.de> 2001-03-09 André Pönitz <poenitz@htwm.de>
* math_cursor.C: use std::vector<> in MathStackXIter * math_cursor.C: use std::vector<> in MathStackXIter
change selstk from a pointer to the "real thing" change selstk from a pointer to the "real thing"
@ -29,6 +40,7 @@
* math_parser.C: use MathedRowContainer::insert_after * math_parser.C: use MathedRowContainer::insert_after
2001-03-08 André Pönitz <poenitz@htwm.de> 2001-03-08 André Pönitz <poenitz@htwm.de>
* math_rowst.h: give MathedRowContainer an 'insert' method. * math_rowst.h: give MathedRowContainer an 'insert' method.
* math_xiter.C: new 'container()' method to encapsulated access to * math_xiter.C: new 'container()' method to encapsulated access to
@ -41,6 +53,7 @@
automatically created by the compiler are ok now. automatically created by the compiler are ok now.
2001-03-06 André Pönitz <poenitz@htwm.de> 2001-03-06 André Pönitz <poenitz@htwm.de>
* array.[Ch]: factor out deep_copy, * array.[Ch]: factor out deep_copy,
remove third argument from raw_pointer_insert remove third argument from raw_pointer_insert
@ -53,6 +66,7 @@
several files: corresponding changes several files: corresponding changes
2001-03-04 André Pönitz <poenitz@htwm.de> 2001-03-04 André Pönitz <poenitz@htwm.de>
* math_macrotemplate.[Ch]: * math_macrotemplate.[Ch]:
math_macro.C: move update() functionality to the macro math_macro.C: move update() functionality to the macro

View File

@ -60,6 +60,7 @@ libmathed_la_SOURCES = \
math_parser.h \ math_parser.h \
math_root.C \ math_root.C \
math_root.h \ math_root.h \
math_rowst.C \
math_rowst.h \ math_rowst.h \
math_spaceinset.C \ math_spaceinset.C \
math_spaceinset.h \ math_spaceinset.h \

View File

@ -424,9 +424,6 @@ void mathed_parse(MathedArray & array, unsigned flags = 0,
int acc_brace = 0; int acc_brace = 0;
int acc_braces[8]; int acc_braces[8];
MathParInset * mt = (mtx) ? *mtx : 0; MathParInset * mt = (mtx) ? *mtx : 0;
MathedRowContainer::iterator crow;
if (mt)
crow = mt->getRowSt().begin();
++plevel; ++plevel;
MathedIter data(&array); MathedIter data(&array);
@ -604,8 +601,7 @@ void mathed_parse(MathedArray & array, unsigned flags = 0,
case LM_TK_NEWLINE: case LM_TK_NEWLINE:
if (mt && (flags & FLAG_END)) { if (mt && (flags & FLAG_END)) {
if (mt->Permit(LMPF_ALLOW_CR)) { if (mt->Permit(LMPF_ALLOW_CR)) {
mt->getRowSt().insert(crow); mt->getRowSt().push_back();
++crow;
data.insert('K', LM_TC_CR); data.insert('K', LM_TC_CR);
} else } else
mathPrintError("Unexpected newline"); mathPrintError("Unexpected newline");
@ -757,8 +753,11 @@ void mathed_parse(MathedArray & array, unsigned flags = 0,
break; break;
case LM_TK_NONUM: case LM_TK_NONUM:
if (crow) if (mt) {
crow->setNumbered(false); if (!mt->getRowSt().size())
mt->getRowSt().push_back();
mt->getRowSt().back().setNumbered(false);
}
break; break;
case LM_TK_PMOD: case LM_TK_PMOD:
@ -869,7 +868,6 @@ void mathed_parse(MathedArray & array, unsigned flags = 0,
} }
mt->SetStyle(size); mt->SetStyle(size);
mt->SetType(mathed_env); mt->SetType(mathed_env);
crow = mt->getRowSt().begin();
} }
lyxerr[Debug::MATHED] << "MATH BEGIN[" << mathed_env << "]" << endl; lyxerr[Debug::MATHED] << "MATH BEGIN[" << mathed_env << "]" << endl;
@ -914,8 +912,10 @@ void mathed_parse(MathedArray & array, unsigned flags = 0,
panic = true; panic = true;
break; break;
} }
if (crow) { if (mt) {
crow->setLabel(yytext.data()); if (!mt->getRowSt().size())
mt->getRowSt().push_back();
mt->getRowSt().back().setLabel(yytext.data());
} else { } else {
mathed_label = yytext.data(); mathed_label = yytext.data();
} }

176
src/mathed/math_rowst.C Normal file
View File

@ -0,0 +1,176 @@
#include "math_rowst.h"
#include "support/LAssert.h"
//
// MathedRowContainer
//
MathedRowStruct::MathedRowStruct()
: asc_(0), desc_(0), y_(0), numbered_(true)
{}
string const & MathedRowStruct::getLabel() const
{
return label_;
}
bool MathedRowStruct::isNumbered() const
{
return numbered_;
}
int MathedRowStruct::getBaseline() const
{
return y_;
}
void MathedRowStruct::setBaseline(int b)
{
y_ = b;
}
int MathedRowStruct::ascent() const
{
return asc_;
}
int MathedRowStruct::descent() const
{
return desc_;
}
void MathedRowStruct::ascent(int a)
{
asc_ = a;
}
void MathedRowStruct::descent(int d)
{
desc_ = d;
}
int MathedRowStruct::getTab(unsigned int i) const
{
return i < widths_.size() ? widths_[i] : 0;
}
void MathedRowStruct::setLabel(string const & l)
{
label_ = l;
}
void MathedRowStruct::setNumbered(bool nf)
{
numbered_ = nf;
}
void MathedRowStruct::setTab(unsigned int i, int t)
{
if (i >= widths_.size())
widths_.resize(i + 2);
widths_[i] = t;
}
//
// MathedRowContainer
//
MathedRowContainer::iterator MathedRowContainer::begin()
{
return iterator(this);
}
bool MathedRowContainer::empty() const
{
return data_.size() == 0;
}
void MathedRowContainer::insert(iterator const & it)
{
Assert(it.st_ == this);
data_.insert(data_.begin() + it.pos_, MathedRowStruct());
}
void MathedRowContainer::erase(iterator & it)
{
Assert(it.st_ == this);
data_.erase(data_.begin() + it.pos_);
}
MathedRowStruct & MathedRowContainer::back()
{
Assert(data_.size());
return data_.back();
}
void MathedRowContainer::push_back()
{
data_.push_back(MathedRowStruct());
}
MathedRowContainer::size_type MathedRowContainer::size() const
{
return data_.size();
}
//
// MathedRowContainer::iterator
//
MathedRowContainer::iterator::iterator()
: st_(0), pos_(0)
{}
MathedRowContainer::iterator::iterator(MathedRowContainer * m)
: st_(m), pos_(0)
{}
MathedRowContainer::iterator::operator void *() const
{
return (void *)(st_ && pos_ < st_->size());
}
MathedRowStruct & MathedRowContainer::iterator::operator*()
{
Assert(st_);
return st_->data_[pos_];
}
MathedRowStruct * MathedRowContainer::iterator::operator->()
{
Assert(st_);
return &st_->data_[pos_];
}
MathedRowStruct const * MathedRowContainer::iterator::operator->() const
{
Assert(st_);
return &st_->data_[pos_];
}
void MathedRowContainer::iterator::operator++()
{
Assert(st_);
++pos_;
}
bool MathedRowContainer::iterator::is_last() const
{
Assert(st_);
return pos_ == st_->size() - 1;
}
bool MathedRowContainer::iterator::operator==(const iterator & it) const
{
return st_ == it.st_ && pos_ == it.pos_;
}

View File

@ -2,8 +2,8 @@
#ifndef MATH_ROWST_H #ifndef MATH_ROWST_H
#define MATH_ROWST_H #define MATH_ROWST_H
#include <vector>
#include "support/LAssert.h" #include "support/LAssert.h"
#include <vector>
/** The physical structure of a row and aditional information is stored here. /** The physical structure of a row and aditional information is stored here.
It allows to manage the extra info independently of the paragraph data. It allows to manage the extra info independently of the paragraph data.
@ -17,9 +17,7 @@ public:
typedef std::vector<int> Widths; typedef std::vector<int> Widths;
/// ///
MathedRowStruct() MathedRowStruct();
: asc_(0), desc_(0), y_(0), numbered_(true)
{}
/// ///
string const & getLabel() const; string const & getLabel() const;
/// ///
@ -62,34 +60,32 @@ protected:
}; };
class MathedRowContainer {
// The idea is to change this MathedRowContainer to mimic the behaviour private:
// 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. typedef std::vector<MathedRowStruct> data_type;
///
struct MathedRowContainer { typedef data_type::size_type size_type;
/// ///
struct iterator { struct iterator {
/// ///
iterator() : st_(0), pos_(0) {} iterator();
/// ///
explicit iterator(MathedRowContainer * m) : st_(m), pos_(0) {} explicit iterator(MathedRowContainer * m);
/// "better" conversion to bool, static_cast doens't help? /// "better" conversion to bool
operator void *() const operator void *() const;
{ return (void *)(st_ && pos_ < st_->data_.size()); }
/// ///
MathedRowStruct & operator*() { Assert(st_); return st_->data_[pos_]; } MathedRowStruct & operator*();
/// ///
MathedRowStruct * operator->() { return &st_->data_[pos_]; } MathedRowStruct * operator->();
/// ///
MathedRowStruct const * operator->() const { return &st_->data_[pos_]; } MathedRowStruct const * operator->() const;
/// ///
void operator++() { Assert(st_); ++pos_; } void operator++();
/// ///
bool is_last() const { Assert(st_); return pos_ == st_->data_.size() - 1; } bool is_last() const;
/// ///
bool operator==(const iterator & it) const bool operator==(const iterator & it) const;
{ return st_ == it.st_ && pos_ == it.pos_; }
//private: //private:
MathedRowContainer * st_; MathedRowContainer * st_;
@ -97,23 +93,24 @@ struct MathedRowContainer {
unsigned int pos_; unsigned int pos_;
}; };
public:
///
iterator begin();
/// ///
iterator begin() { return iterator(this); } bool empty() const;
/// insert item before 'it'
void insert(iterator const & it);
/// erase item pointed to by 'it'
void erase(iterator & it);
/// access to last row
MathedRowStruct & back();
/// append empty element
void push_back();
/// ///
bool empty() const { return data_.size() == 0; } size_type size() const;
/// insert 'item' before 'iterator' //private:
void insert(iterator const & it) {
Assert(it.st_ == this);
data_.insert(data_.begin() + it.pos_, MathedRowStruct());
}
/// insert 'item' before 'iterator'
void erase(iterator & it) {
Assert(it.st_ == this);
data_.erase(data_.begin() + it.pos_);
}
/// ///
std::vector<MathedRowStruct> data_; std::vector<MathedRowStruct> data_;
@ -122,90 +119,4 @@ private:
void operator=(MathedRowContainer const &); // unimplemented void operator=(MathedRowContainer const &); // unimplemented
}; };
inline
string const & MathedRowStruct::getLabel() const
{
return label_;
}
inline
bool MathedRowStruct::isNumbered() const
{
return numbered_;
}
inline
int MathedRowStruct::getBaseline() const
{
return y_;
}
inline
void MathedRowStruct::setBaseline(int b)
{
y_ = b;
}
inline
int MathedRowStruct::ascent() const
{
return asc_;
}
inline
int MathedRowStruct::descent() const
{
return desc_;
}
inline
void MathedRowStruct::ascent(int a)
{
asc_ = a;
}
inline
void MathedRowStruct::descent(int d)
{
desc_ = d;
}
inline
int MathedRowStruct::getTab(unsigned int i) const
{
return i < widths_.size() ? widths_[i] : 0;
}
inline
void MathedRowStruct::setLabel(string const & l)
{
label_ = l;
}
inline
void MathedRowStruct::setNumbered(bool nf)
{
numbered_ = nf;
}
inline
void MathedRowStruct::setTab(unsigned int i, int t)
{
if (i >= widths_.size())
widths_.resize(i + 2);
widths_[i] = t;
}
#endif #endif