more cosmetics

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4919 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2002-08-09 10:22:35 +00:00
parent 9e27f631a7
commit 01080c9eda
14 changed files with 83 additions and 95 deletions

View File

@ -26,6 +26,8 @@ public:
void metrics(MathMetricsInfo & st) const; void metrics(MathMetricsInfo & st) const;
/// ///
MathArrayInset * asArrayInset() { return this; } MathArrayInset * asArrayInset() { return this; }
///
MathArrayInset const * asArrayInset() const { return this; }
/// ///
void write(WriteStream & os) const; void write(WriteStream & os) const;

View File

@ -46,7 +46,6 @@ public:
/// assignment invokes nucleus_->clone() /// assignment invokes nucleus_->clone()
void operator=(MathAtom const &); void operator=(MathAtom const &);
/// access to the inset (checked with gprof) /// access to the inset (checked with gprof)
MathInset const * nucleus() const { return nucleus_; }
MathInset * nucleus() { return nucleus_; } MathInset * nucleus() { return nucleus_; }
/// access to the inset /// access to the inset
MathInset const * operator->() const { return nucleus_; } MathInset const * operator->() const { return nucleus_; }

View File

@ -73,7 +73,7 @@ bool Correction::correct(MathAtom & at, char c) const
// << "trying to correct ar: " << at << " from: '" << from1_ << "'" << endl; // << "trying to correct ar: " << at << " from: '" << from1_ << "'" << endl;
if (from2_ != c) if (from2_ != c)
return false; return false;
if (!at->match(from1_.nucleus())) if (!at->match(from1_))
return false; return false;
lyxerr[Debug::MATHED] lyxerr[Debug::MATHED]
<< "match found! subst in " << at << "match found! subst in " << at

View File

@ -174,7 +174,7 @@ bool MathCursor::openable(MathAtom const & t, bool sel) const
// we can't move into anything new during selection // we can't move into anything new during selection
if (depth() == Anchor_.size()) if (depth() == Anchor_.size())
return false; return false;
if (t.nucleus() != Anchor_[depth()].par_) if (t.operator->() != Anchor_[depth()].par_)
return false; return false;
} }
return true; return true;

View File

@ -136,7 +136,7 @@ bool MathArray::matchpart(MathArray const & ar, pos_type pos) const
return false; return false;
const_iterator it = begin() + pos; const_iterator it = begin() + pos;
for (const_iterator jt = ar.begin(); jt != ar.end(); ++jt, ++it) for (const_iterator jt = ar.begin(); jt != ar.end(); ++jt, ++it)
if (!(*jt)->match(it->nucleus())) if (!(*jt)->match(*it))
return false; return false;
return true; return true;
} }
@ -165,7 +165,7 @@ bool MathArray::find1(MathArray const & ar, size_type pos) const
{ {
//lyxerr << "finding '" << ar << "' in '" << *this << "'\n"; //lyxerr << "finding '" << ar << "' in '" << *this << "'\n";
for (size_type i = 0, n = ar.size(); i < n; ++i) for (size_type i = 0, n = ar.size(); i < n; ++i)
if (!operator[](pos + i)->match(ar[i].nucleus())) if (!operator[](pos + i)->match(ar[i]))
return false; return false;
return true; return true;
} }
@ -194,7 +194,7 @@ bool MathArray::contains(MathArray const & ar) const
if (find(ar) != size()) if (find(ar) != size())
return true; return true;
for (const_iterator it = begin(); it != end(); ++it) for (const_iterator it = begin(); it != end(); ++it)
if (it->nucleus()->contains(ar)) if ((*it)->contains(ar))
return true; return true;
return false; return false;
} }
@ -300,10 +300,9 @@ int MathArray::pos2x(size_type pos1, size_type pos2, int glue) const
size_type target = min(pos2, size()); size_type target = min(pos2, size());
for (size_type i = pos1; i < target; ++i) { for (size_type i = pos1; i < target; ++i) {
const_iterator it = begin() + i; const_iterator it = begin() + i;
MathInset const * p = it->nucleus(); if ((*it)->getChar() == ' ')
if (p->getChar() == ' ')
x += glue; x += glue;
x += p->width(); x += (*it)->width();
} }
return x; return x;
} }
@ -323,10 +322,9 @@ MathArray::size_type MathArray::x2pos(size_type startpos, int targetx,
int currx = 0; int currx = 0;
for (; currx < targetx && it < end(); ++it) { for (; currx < targetx && it < end(); ++it) {
lastx = currx; lastx = currx;
MathInset const * p = it->nucleus(); if ((*it)->getChar() == ' ')
if (p->getChar() == ' ')
currx += glue; currx += glue;
currx += p->width(); currx += (*it)->width();
} }
if (abs(lastx - targetx) < abs(currx - targetx) && it != begin() + startpos) if (abs(lastx - targetx) < abs(currx - targetx) && it != begin() + startpos)
--it; --it;

View File

@ -47,7 +47,7 @@ ostream & operator<<(ostream & os, MathArray const & ar)
typedef bool TestItemFunc(MathAtom const &); typedef bool TestItemFunc(MathAtom const &);
// define a function for replacing subexpressions // define a function for replacing subexpressions
typedef MathInset * ReplaceArgumentFunc(const MathArray & ar); typedef MathAtom ReplaceArgumentFunc(const MathArray & ar);
@ -139,32 +139,26 @@ void extractStrings(MathArray & ar)
} }
MathInset const * singleItem(MathArray const & ar)
{
return ar.size() == 1 ? ar.begin()->nucleus() : 0;
}
void extractMatrices(MathArray & ar) void extractMatrices(MathArray & ar)
{ {
//lyxerr << "\nMatrices from: " << ar << "\n"; //lyxerr << "\nMatrices from: " << ar << "\n";
// first pass for explicitly delimited stuff // first pass for explicitly delimited stuff
for (MathArray::iterator it = ar.begin(); it != ar.end(); ++it) { for (MathArray::size_type i = 0; i < ar.size(); ++i) {
MathDelimInset const * del = (*it)->asDelimInset(); if (!ar[i]->asDelimInset())
if (!del)
continue; continue;
MathInset const * arr = singleItem(del->cell(0)); MathArray const & arr = ar[i]->asDelimInset()->cell(0);
if (!arr || !arr->asGridInset()) if (arr.size() != 1)
continue; continue;
*it = MathAtom(new MathMatrixInset(*(arr->asGridInset()))); if (!arr.front()->asGridInset())
continue;
ar[i] = MathAtom(new MathMatrixInset(*(arr.front()->asGridInset())));
} }
// second pass for AMS "pmatrix" etc // second pass for AMS "pmatrix" etc
for (MathArray::iterator it = ar.begin(); it != ar.end(); ++it) { for (MathArray::size_type i = 0; i < ar.size(); ++i) {
MathAMSArrayInset const * ams = (*it)->asAMSArrayInset(); if (ar[i]->asAMSArrayInset())
if (!ams)
continue; continue;
*it = MathAtom(new MathMatrixInset(*ams)); ar[i] = MathAtom(new MathMatrixInset(*(ar[i]->asGridInset())));
} }
//lyxerr << "\nMatrices to: " << ar << "\n"; //lyxerr << "\nMatrices to: " << ar << "\n";
} }
@ -241,21 +235,20 @@ void replaceNested(
// to modify the array. // to modify the array.
for (MathArray::size_type i = 0; i < ar.size(); ++i) { for (MathArray::size_type i = 0; i < ar.size(); ++i) {
// check whether this is the begin of the sequence // check whether this is the begin of the sequence
MathArray::iterator it = ar.begin() + i; if (!testOpen(ar[i]))
if (!testOpen(*it))
continue; continue;
// search end of sequence // search end of sequence
MathArray::iterator it = ar.begin() + i;
MathArray::iterator jt = endNestSearch(it, ar.end(), testOpen, testClose); MathArray::iterator jt = endNestSearch(it, ar.end(), testOpen, testClose);
if (jt == ar.end()) if (jt == ar.end())
continue; continue;
// create a proper inset as replacement
MathInset * p = replaceArg(MathArray(it + 1, jt));
// replace the original stuff by the new inset // replace the original stuff by the new inset
ar.erase(it + 1, jt + 1); ar.erase(it + 1, jt + 1);
*it = MathAtom(p);
// create a proper inset as replacement
ar[i] = replaceArg(MathArray(it + 1, jt));
} }
} }
@ -270,20 +263,19 @@ void splitScripts(MathArray & ar)
{ {
//lyxerr << "\nScripts from: " << ar << "\n"; //lyxerr << "\nScripts from: " << ar << "\n";
for (MathArray::size_type i = 0; i < ar.size(); ++i) { for (MathArray::size_type i = 0; i < ar.size(); ++i) {
MathArray::iterator it = ar.begin() + i;
// is this script inset? // is this script inset?
MathScriptInset * p = (*it).nucleus()->asScriptInset(); if (!ar[i]->asScriptInset())
if (!p)
continue; continue;
// no problem if we don't have both... // no problem if we don't have both...
if (!p->hasUp() || !p->hasDown()) if (!ar[i]->asScriptInset()->hasUp())
continue;
if (!ar[i]->asScriptInset()->hasDown())
continue; continue;
// create extra script inset and move superscript over // create extra script inset and move superscript over
MathScriptInset * q = new MathScriptInset; MathScriptInset * p = ar[i].nucleus()->asScriptInset();
q->ensure(true); MathScriptInset * q = new MathScriptInset(true);
std::swap(q->up(), p->up()); std::swap(q->up(), p->up());
p->removeScript(true); p->removeScript(true);
@ -302,23 +294,19 @@ void splitScripts(MathArray & ar)
void extractExps(MathArray & ar) void extractExps(MathArray & ar)
{ {
//lyxerr << "\nExps from: " << ar << "\n"; //lyxerr << "\nExps from: " << ar << "\n";
for (MathArray::size_type i = 0; i + 1 < ar.size(); ++i) { for (MathArray::size_type i = 0; i + 1 < ar.size(); ++i) {
MathArray::iterator it = ar.begin() + i;
// is this 'e'? // is this 'e'?
MathCharInset const * p = (*it)->asCharInset(); if (ar[i]->getChar() != 'e')
if (!p || p->getChar() != 'e')
continue; continue;
// we need an exponent but no subscript // we need an exponent but no subscript
MathScriptInset const * sup = (*(it + 1))->asScriptInset(); MathScriptInset const * sup = ar[i + 1]->asScriptInset();
if (!sup || sup->hasDown()) if (!sup || sup->hasDown())
continue; continue;
// create a proper exp-inset as replacement // create a proper exp-inset as replacement
*it = MathAtom(new MathExFuncInset("exp", sup->cell(1))); ar[i] = MathAtom(new MathExFuncInset("exp", sup->cell(1)));
ar.erase(it + 1); ar.erase(i + 1);
} }
//lyxerr << "\nExps to: " << ar << "\n"; //lyxerr << "\nExps to: " << ar << "\n";
} }
@ -401,9 +389,9 @@ bool testCloseParan(MathAtom const & at)
} }
MathInset * replaceDelims(const MathArray & ar) MathAtom replaceDelims(const MathArray & ar)
{ {
return new MathDelimInset("(", ")", ar); return MathAtom(new MathDelimInset("(", ")", ar));
} }
@ -598,14 +586,14 @@ void extractSums(MathArray & ar)
MathArray::iterator it = ar.begin() + i; MathArray::iterator it = ar.begin() + i;
// is this a sum name? // is this a sum name?
if (!testSum(*it)) if (!testSum(ar[i]))
continue; continue;
// create a proper inset as replacement // create a proper inset as replacement
MathExIntInset * p = new MathExIntInset("sum"); MathExIntInset * p = new MathExIntInset("sum");
// collect lower bound and summation index // collect lower bound and summation index
MathScriptInset const * sub = (*it)->asScriptInset(); MathScriptInset const * sub = ar[i]->asScriptInset();
if (sub && sub->hasDown()) { if (sub && sub->hasDown()) {
// try to figure out the summation index from the subscript // try to figure out the summation index from the subscript
MathArray const & ar = sub->down(); MathArray const & ar = sub->down();
@ -1028,7 +1016,7 @@ namespace {
// parse output as matrix or single number // parse output as matrix or single number
MathAtom at(new MathArrayInset("array", out)); MathAtom at(new MathArrayInset("array", out));
MathArrayInset const * mat = at.nucleus()->asArrayInset(); MathArrayInset const * mat = at->asArrayInset();
MathArray res; MathArray res;
if (mat->ncols() == 1 && mat->nrows() == 1) if (mat->ncols() == 1 && mat->nrows() == 1)
res.append(mat->cell(0)); res.append(mat->cell(0));

View File

@ -189,34 +189,35 @@ public:
virtual void getPos(idx_type idx, pos_type pos, int & x, int & y) const; virtual void getPos(idx_type idx, pos_type pos, int & x, int & y) const;
/// identifies certain types of insets /// identifies certain types of insets
virtual MathAMSArrayInset * asAMSArrayInset() { return 0; } virtual MathAMSArrayInset * asAMSArrayInset() { return 0; }
virtual MathAMSArrayInset const* asAMSArrayInset() const{ return 0; } virtual MathAMSArrayInset const * asAMSArrayInset() const { return 0; }
virtual MathArrayInset * asArrayInset() { return 0; } virtual MathArrayInset * asArrayInset() { return 0; }
virtual MathCharInset const * asCharInset() const { return 0; } virtual MathArrayInset const * asArrayInset() const { return 0; }
virtual MathDelimInset * asDelimInset() { return 0; } virtual MathCharInset const * asCharInset() const { return 0; }
virtual MathDelimInset const * asDelimInset() const { return 0; } virtual MathDelimInset * asDelimInset() { return 0; }
virtual MathFracInset * asFracInset() { return 0; } virtual MathDelimInset const * asDelimInset() const { return 0; }
virtual MathFracInset const * asFracInset() const { return 0; } virtual MathFracInset * asFracInset() { return 0; }
virtual MathGridInset * asGridInset() { return 0; } virtual MathFracInset const * asFracInset() const { return 0; }
virtual MathGridInset const * asGridInset() const { return 0; } virtual MathGridInset * asGridInset() { return 0; }
virtual MathHullInset * asHullInset() { return 0; } virtual MathGridInset const * asGridInset() const { return 0; }
virtual MathHullInset const * asHullInset() const { return 0; } virtual MathHullInset * asHullInset() { return 0; }
virtual MathMacroTemplate * asMacroTemplate() { return 0; } virtual MathHullInset const * asHullInset() const { return 0; }
virtual MathMacroTemplate const* asMacroTemplate() const{ return 0; } virtual MathMacroTemplate * asMacroTemplate() { return 0; }
virtual MathMatrixInset const * asMatrixInset() const { return 0; } virtual MathMacroTemplate const * asMacroTemplate() const { return 0; }
virtual MathNestInset * asNestInset() { return 0; } virtual MathMatrixInset const * asMatrixInset() const { return 0; }
virtual MathNestInset const * asNestInset() const { return 0; } virtual MathNestInset * asNestInset() { return 0; }
virtual MathParboxInset * asParboxInset() { return 0; } virtual MathNestInset const * asNestInset() const { return 0; }
virtual MathScriptInset * asScriptInset() { return 0; } virtual MathParboxInset * asParboxInset() { return 0; }
virtual MathScriptInset const * asScriptInset() const { return 0; } virtual MathScriptInset * asScriptInset() { return 0; }
virtual MathSpaceInset * asSpaceInset() { return 0; } virtual MathScriptInset const * asScriptInset() const { return 0; }
virtual MathSpaceInset const * asSpaceInset() const { return 0; } virtual MathSpaceInset * asSpaceInset() { return 0; }
virtual MathStringInset * asStringInset() { return 0; } virtual MathSpaceInset const * asSpaceInset() const { return 0; }
virtual MathStringInset const * asStringInset() const { return 0; } virtual MathStringInset * asStringInset() { return 0; }
virtual MathSymbolInset const * asSymbolInset() const { return 0; } virtual MathStringInset const * asStringInset() const { return 0; }
virtual MathUnknownInset * asUnknownInset() { return 0; } virtual MathSymbolInset const * asSymbolInset() const { return 0; }
virtual MathUnknownInset const * asUnknownInset() const { return 0; } virtual MathUnknownInset * asUnknownInset() { return 0; }
virtual InsetRef * asInsetRef() { return 0; } virtual MathUnknownInset const * asUnknownInset() const { return 0; }
virtual InsetRef * asInsetRef() { return 0; }
/// identifies things that can get scripts /// identifies things that can get scripts
virtual bool isScriptable() const { return false; } virtual bool isScriptable() const { return false; }
@ -243,7 +244,7 @@ public:
/// char char code if possible /// char char code if possible
virtual void handleFont(string const &) {} virtual void handleFont(string const &) {}
/// is this inset equal to a given other inset? /// is this inset equal to a given other inset?
virtual bool match(MathInset const *) const { return false; } virtual bool match(MathAtom const &) const { return false; }
/// replace things by other things /// replace things by other things
virtual void replace(ReplaceData &) {} virtual void replace(ReplaceData &) {}
/// do we contain a given subsequence? /// do we contain a given subsequence?

View File

@ -60,7 +60,7 @@ public:
/// ///
bool isMacro() const { return true; } bool isMacro() const { return true; }
/// ///
bool match(MathInset const *) const { return false; } bool match(MathAtom const &) const { return false; }
/// ///
void maplize(MapleStream &) const; void maplize(MapleStream &) const;

View File

@ -228,12 +228,12 @@ void MathNestInset::validate(LaTeXFeatures & features) const
} }
bool MathNestInset::match(MathInset const * p) const bool MathNestInset::match(MathAtom const & at) const
{ {
if (nargs() != p->nargs()) if (nargs() != at->nargs())
return false; return false;
for (idx_type i = 0; i < nargs(); ++i) for (idx_type i = 0; i < nargs(); ++i)
if (!cell(i).match(p->cell(i))) if (!cell(i).match(at->cell(i)))
return false; return false;
return true; return true;
} }

View File

@ -83,7 +83,7 @@ public:
void validate(LaTeXFeatures & features) const; void validate(LaTeXFeatures & features) const;
/// match in all cells /// match in all cells
bool match(MathInset const *) const; bool match(MathAtom const &) const;
/// replace in all cells /// replace in all cells
void replace(ReplaceData &); void replace(ReplaceData &);
/// do we contain a given pattern? /// do we contain a given pattern?

View File

@ -140,9 +140,9 @@ char const * MathMLtype(string const & s)
} }
bool MathSymbolInset::match(MathInset const * p) const bool MathSymbolInset::match(MathAtom const & at) const
{ {
MathSymbolInset const * q = p->asSymbolInset(); MathSymbolInset const * q = at->asSymbolInset();
return q && name() == q->name(); return q && name() == q->name();
} }

View File

@ -34,7 +34,7 @@ public:
/// the LaTeX name of the symbol (without the backslash) /// the LaTeX name of the symbol (without the backslash)
string name() const; string name() const;
/// ///
bool match(MathInset const *) const; bool match(MathAtom const &) const;
/// request "external features" /// request "external features"
void validate(LaTeXFeatures & features) const; void validate(LaTeXFeatures & features) const;

View File

@ -33,9 +33,9 @@ void MathUnknownInset::setName(string const & name)
} }
bool MathUnknownInset::match(MathInset const * p) const bool MathUnknownInset::match(MathAtom const & at) const
{ {
MathUnknownInset const * q = p->asUnknownInset(); MathUnknownInset const * q = at->asUnknownInset();
return q && name_ == q->name_; return q && name_ == q->name_;
} }

View File

@ -31,7 +31,7 @@ public:
/// identifies UnknownInsets /// identifies UnknownInsets
MathUnknownInset * asUnknownInset() { return this; } MathUnknownInset * asUnknownInset() { return this; }
/// ///
bool match(MathInset const * p) const; bool match(MathAtom const & at) const;
/// ///
void normalize(NormalStream &) const; void normalize(NormalStream &) const;