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;
///
MathArrayInset * asArrayInset() { return this; }
///
MathArrayInset const * asArrayInset() const { return this; }
///
void write(WriteStream & os) const;

View File

@ -46,7 +46,6 @@ public:
/// assignment invokes nucleus_->clone()
void operator=(MathAtom const &);
/// access to the inset (checked with gprof)
MathInset const * nucleus() const { return nucleus_; }
MathInset * nucleus() { return nucleus_; }
/// access to the inset
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;
if (from2_ != c)
return false;
if (!at->match(from1_.nucleus()))
if (!at->match(from1_))
return false;
lyxerr[Debug::MATHED]
<< "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
if (depth() == Anchor_.size())
return false;
if (t.nucleus() != Anchor_[depth()].par_)
if (t.operator->() != Anchor_[depth()].par_)
return false;
}
return true;

View File

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

View File

@ -47,7 +47,7 @@ ostream & operator<<(ostream & os, MathArray const & ar)
typedef bool TestItemFunc(MathAtom const &);
// 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)
{
//lyxerr << "\nMatrices from: " << ar << "\n";
// first pass for explicitly delimited stuff
for (MathArray::iterator it = ar.begin(); it != ar.end(); ++it) {
MathDelimInset const * del = (*it)->asDelimInset();
if (!del)
for (MathArray::size_type i = 0; i < ar.size(); ++i) {
if (!ar[i]->asDelimInset())
continue;
MathInset const * arr = singleItem(del->cell(0));
if (!arr || !arr->asGridInset())
MathArray const & arr = ar[i]->asDelimInset()->cell(0);
if (arr.size() != 1)
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
for (MathArray::iterator it = ar.begin(); it != ar.end(); ++it) {
MathAMSArrayInset const * ams = (*it)->asAMSArrayInset();
if (!ams)
for (MathArray::size_type i = 0; i < ar.size(); ++i) {
if (ar[i]->asAMSArrayInset())
continue;
*it = MathAtom(new MathMatrixInset(*ams));
ar[i] = MathAtom(new MathMatrixInset(*(ar[i]->asGridInset())));
}
//lyxerr << "\nMatrices to: " << ar << "\n";
}
@ -241,21 +235,20 @@ void replaceNested(
// to modify the array.
for (MathArray::size_type i = 0; i < ar.size(); ++i) {
// check whether this is the begin of the sequence
MathArray::iterator it = ar.begin() + i;
if (!testOpen(*it))
if (!testOpen(ar[i]))
continue;
// search end of sequence
MathArray::iterator it = ar.begin() + i;
MathArray::iterator jt = endNestSearch(it, ar.end(), testOpen, testClose);
if (jt == ar.end())
continue;
// create a proper inset as replacement
MathInset * p = replaceArg(MathArray(it + 1, jt));
// replace the original stuff by the new inset
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";
for (MathArray::size_type i = 0; i < ar.size(); ++i) {
MathArray::iterator it = ar.begin() + i;
// is this script inset?
MathScriptInset * p = (*it).nucleus()->asScriptInset();
if (!p)
if (!ar[i]->asScriptInset())
continue;
// 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;
// create extra script inset and move superscript over
MathScriptInset * q = new MathScriptInset;
q->ensure(true);
MathScriptInset * p = ar[i].nucleus()->asScriptInset();
MathScriptInset * q = new MathScriptInset(true);
std::swap(q->up(), p->up());
p->removeScript(true);
@ -302,23 +294,19 @@ void splitScripts(MathArray & ar)
void extractExps(MathArray & ar)
{
//lyxerr << "\nExps from: " << ar << "\n";
for (MathArray::size_type i = 0; i + 1 < ar.size(); ++i) {
MathArray::iterator it = ar.begin() + i;
// is this 'e'?
MathCharInset const * p = (*it)->asCharInset();
if (!p || p->getChar() != 'e')
if (ar[i]->getChar() != 'e')
continue;
// we need an exponent but no subscript
MathScriptInset const * sup = (*(it + 1))->asScriptInset();
MathScriptInset const * sup = ar[i + 1]->asScriptInset();
if (!sup || sup->hasDown())
continue;
// create a proper exp-inset as replacement
*it = MathAtom(new MathExFuncInset("exp", sup->cell(1)));
ar.erase(it + 1);
ar[i] = MathAtom(new MathExFuncInset("exp", sup->cell(1)));
ar.erase(i + 1);
}
//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;
// is this a sum name?
if (!testSum(*it))
if (!testSum(ar[i]))
continue;
// create a proper inset as replacement
MathExIntInset * p = new MathExIntInset("sum");
// collect lower bound and summation index
MathScriptInset const * sub = (*it)->asScriptInset();
MathScriptInset const * sub = ar[i]->asScriptInset();
if (sub && sub->hasDown()) {
// try to figure out the summation index from the subscript
MathArray const & ar = sub->down();
@ -1028,7 +1016,7 @@ namespace {
// parse output as matrix or single number
MathAtom at(new MathArrayInset("array", out));
MathArrayInset const * mat = at.nucleus()->asArrayInset();
MathArrayInset const * mat = at->asArrayInset();
MathArray res;
if (mat->ncols() == 1 && mat->nrows() == 1)
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;
/// identifies certain types of insets
virtual MathAMSArrayInset * asAMSArrayInset() { return 0; }
virtual MathAMSArrayInset const* asAMSArrayInset() const{ return 0; }
virtual MathArrayInset * asArrayInset() { return 0; }
virtual MathCharInset const * asCharInset() const { return 0; }
virtual MathDelimInset * asDelimInset() { return 0; }
virtual MathDelimInset const * asDelimInset() const { return 0; }
virtual MathFracInset * asFracInset() { return 0; }
virtual MathFracInset const * asFracInset() const { return 0; }
virtual MathGridInset * asGridInset() { return 0; }
virtual MathGridInset const * asGridInset() const { return 0; }
virtual MathHullInset * asHullInset() { return 0; }
virtual MathHullInset const * asHullInset() const { return 0; }
virtual MathMacroTemplate * asMacroTemplate() { return 0; }
virtual MathMacroTemplate const* asMacroTemplate() const{ return 0; }
virtual MathMatrixInset const * asMatrixInset() const { return 0; }
virtual MathNestInset * asNestInset() { return 0; }
virtual MathNestInset const * asNestInset() const { return 0; }
virtual MathParboxInset * asParboxInset() { return 0; }
virtual MathScriptInset * asScriptInset() { return 0; }
virtual MathScriptInset const * asScriptInset() const { return 0; }
virtual MathSpaceInset * asSpaceInset() { return 0; }
virtual MathSpaceInset const * asSpaceInset() const { return 0; }
virtual MathStringInset * asStringInset() { return 0; }
virtual MathStringInset const * asStringInset() const { return 0; }
virtual MathSymbolInset const * asSymbolInset() const { return 0; }
virtual MathUnknownInset * asUnknownInset() { return 0; }
virtual MathUnknownInset const * asUnknownInset() const { return 0; }
virtual InsetRef * asInsetRef() { return 0; }
virtual MathAMSArrayInset * asAMSArrayInset() { return 0; }
virtual MathAMSArrayInset const * asAMSArrayInset() const { return 0; }
virtual MathArrayInset * asArrayInset() { return 0; }
virtual MathArrayInset const * asArrayInset() const { return 0; }
virtual MathCharInset const * asCharInset() const { return 0; }
virtual MathDelimInset * asDelimInset() { return 0; }
virtual MathDelimInset const * asDelimInset() const { return 0; }
virtual MathFracInset * asFracInset() { return 0; }
virtual MathFracInset const * asFracInset() const { return 0; }
virtual MathGridInset * asGridInset() { return 0; }
virtual MathGridInset const * asGridInset() const { return 0; }
virtual MathHullInset * asHullInset() { return 0; }
virtual MathHullInset const * asHullInset() const { return 0; }
virtual MathMacroTemplate * asMacroTemplate() { return 0; }
virtual MathMacroTemplate const * asMacroTemplate() const { return 0; }
virtual MathMatrixInset const * asMatrixInset() const { return 0; }
virtual MathNestInset * asNestInset() { return 0; }
virtual MathNestInset const * asNestInset() const { return 0; }
virtual MathParboxInset * asParboxInset() { return 0; }
virtual MathScriptInset * asScriptInset() { return 0; }
virtual MathScriptInset const * asScriptInset() const { return 0; }
virtual MathSpaceInset * asSpaceInset() { return 0; }
virtual MathSpaceInset const * asSpaceInset() const { return 0; }
virtual MathStringInset * asStringInset() { return 0; }
virtual MathStringInset const * asStringInset() const { return 0; }
virtual MathSymbolInset const * asSymbolInset() const { return 0; }
virtual MathUnknownInset * asUnknownInset() { return 0; }
virtual MathUnknownInset const * asUnknownInset() const { return 0; }
virtual InsetRef * asInsetRef() { return 0; }
/// identifies things that can get scripts
virtual bool isScriptable() const { return false; }
@ -243,7 +244,7 @@ public:
/// char char code if possible
virtual void handleFont(string const &) {}
/// 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
virtual void replace(ReplaceData &) {}
/// do we contain a given subsequence?

View File

@ -60,7 +60,7 @@ public:
///
bool isMacro() const { return true; }
///
bool match(MathInset const *) const { return false; }
bool match(MathAtom const &) const { return false; }
///
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;
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 true;
}

View File

@ -83,7 +83,7 @@ public:
void validate(LaTeXFeatures & features) const;
/// match in all cells
bool match(MathInset const *) const;
bool match(MathAtom const &) const;
/// replace in all cells
void replace(ReplaceData &);
/// 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();
}

View File

@ -34,7 +34,7 @@ public:
/// the LaTeX name of the symbol (without the backslash)
string name() const;
///
bool match(MathInset const *) const;
bool match(MathAtom const &) const;
/// request "external features"
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_;
}

View File

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