From 01080c9eda85c248c4d08fe231db4af3d99812d0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Fri, 9 Aug 2002 10:22:35 +0000 Subject: [PATCH] more cosmetics git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4919 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/math_arrayinset.h | 2 + src/mathed/math_atom.h | 1 - src/mathed/math_autocorrect.C | 2 +- src/mathed/math_cursor.C | 2 +- src/mathed/math_data.C | 16 ++++---- src/mathed/math_extern.C | 74 ++++++++++++++-------------------- src/mathed/math_inset.h | 59 ++++++++++++++------------- src/mathed/math_macro.h | 2 +- src/mathed/math_nestinset.C | 6 +-- src/mathed/math_nestinset.h | 2 +- src/mathed/math_symbolinset.C | 4 +- src/mathed/math_symbolinset.h | 2 +- src/mathed/math_unknowninset.C | 4 +- src/mathed/math_unknowninset.h | 2 +- 14 files changed, 83 insertions(+), 95 deletions(-) diff --git a/src/mathed/math_arrayinset.h b/src/mathed/math_arrayinset.h index 64c7d6f169..5d77b5a2cb 100644 --- a/src/mathed/math_arrayinset.h +++ b/src/mathed/math_arrayinset.h @@ -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; diff --git a/src/mathed/math_atom.h b/src/mathed/math_atom.h index 3434921f7e..33b9d61824 100644 --- a/src/mathed/math_atom.h +++ b/src/mathed/math_atom.h @@ -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_; } diff --git a/src/mathed/math_autocorrect.C b/src/mathed/math_autocorrect.C index 1ae1f149af..02e35619e8 100644 --- a/src/mathed/math_autocorrect.C +++ b/src/mathed/math_autocorrect.C @@ -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 diff --git a/src/mathed/math_cursor.C b/src/mathed/math_cursor.C index e08b1d4d3e..315c6758c2 100644 --- a/src/mathed/math_cursor.C +++ b/src/mathed/math_cursor.C @@ -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; diff --git a/src/mathed/math_data.C b/src/mathed/math_data.C index 8ee1a3418e..bf977f648d 100644 --- a/src/mathed/math_data.C +++ b/src/mathed/math_data.C @@ -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; diff --git a/src/mathed/math_extern.C b/src/mathed/math_extern.C index da2e448a4b..2daae01adc 100644 --- a/src/mathed/math_extern.C +++ b/src/mathed/math_extern.C @@ -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; + MathArray const & arr = ar[i]->asDelimInset()->cell(0); + if (arr.size() != 1) continue; - MathInset const * arr = singleItem(del->cell(0)); - if (!arr || !arr->asGridInset()) + if (!arr.front()->asGridInset()) continue; - *it = MathAtom(new MathMatrixInset(*(arr->asGridInset()))); + 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)); diff --git a/src/mathed/math_inset.h b/src/mathed/math_inset.h index 407112360b..065ad8db5a 100644 --- a/src/mathed/math_inset.h +++ b/src/mathed/math_inset.h @@ -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? diff --git a/src/mathed/math_macro.h b/src/mathed/math_macro.h index f36350bca7..8ecd606b9c 100644 --- a/src/mathed/math_macro.h +++ b/src/mathed/math_macro.h @@ -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; diff --git a/src/mathed/math_nestinset.C b/src/mathed/math_nestinset.C index fc3ea5d7a5..cfe3a1eb04 100644 --- a/src/mathed/math_nestinset.C +++ b/src/mathed/math_nestinset.C @@ -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; } diff --git a/src/mathed/math_nestinset.h b/src/mathed/math_nestinset.h index cf9d4057a0..b61c018c55 100644 --- a/src/mathed/math_nestinset.h +++ b/src/mathed/math_nestinset.h @@ -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? diff --git a/src/mathed/math_symbolinset.C b/src/mathed/math_symbolinset.C index 597dec9ee2..69d6f3c593 100644 --- a/src/mathed/math_symbolinset.C +++ b/src/mathed/math_symbolinset.C @@ -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(); } diff --git a/src/mathed/math_symbolinset.h b/src/mathed/math_symbolinset.h index c79533e936..0c99bbaad2 100644 --- a/src/mathed/math_symbolinset.h +++ b/src/mathed/math_symbolinset.h @@ -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; diff --git a/src/mathed/math_unknowninset.C b/src/mathed/math_unknowninset.C index ebc37b4c22..c54562514a 100644 --- a/src/mathed/math_unknowninset.C +++ b/src/mathed/math_unknowninset.C @@ -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_; } diff --git a/src/mathed/math_unknowninset.h b/src/mathed/math_unknowninset.h index 2d7a1cbf02..1e6c2d6822 100644 --- a/src/mathed/math_unknowninset.h +++ b/src/mathed/math_unknowninset.h @@ -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; -- 2.39.2