From: André Pönitz Date: Thu, 8 Aug 2002 16:08:11 +0000 (+0000) Subject: a bit more const correctness X-Git-Tag: 1.6.10~18637 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=73b1ac43f4abe9f6e5eb15471c79c82c0897865f;p=features.git a bit more const correctness git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4905 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/mathed/formula.C b/src/mathed/formula.C index d471a76ff6..441767e649 100644 --- a/src/mathed/formula.C +++ b/src/mathed/formula.C @@ -396,13 +396,19 @@ bool InsetFormula::display() const } -MathHullInset * InsetFormula::hull() const +MathHullInset const * InsetFormula::hull() const { lyx::Assert(par_->asHullInset()); return par_->asHullInset(); } +MathHullInset * InsetFormula::hull() +{ + lyx::Assert(par_->asHullInset()); + return par_->asHullInset(); +} + Inset::Code InsetFormula::lyxCode() const { return Inset::MATH_CODE; diff --git a/src/mathed/formula.h b/src/mathed/formula.h index 1b1d66834a..f5ccf5bec7 100644 --- a/src/mathed/formula.h +++ b/src/mathed/formula.h @@ -94,7 +94,9 @@ private: /// available in AMS only? bool ams() const; /// access to hull - MathHullInset * hull() const; + MathHullInset const * hull() const; + /// access to hull + MathHullInset * hull(); /// void handleExtern(string const & arg); diff --git a/src/mathed/math_atom.h b/src/mathed/math_atom.h index 04cf2a391d..4a7d1c1a51 100644 --- a/src/mathed/math_atom.h +++ b/src/mathed/math_atom.h @@ -50,7 +50,8 @@ public: /// change inset under the hood void reset(MathInset * p); /// access to the inset (checked with gprof) - MathInset * nucleus() const { return nucleus_; } + MathInset const * nucleus() const { return nucleus_; } + MathInset * nucleus() { return nucleus_; } /// access to the inset MathInset * operator->() const { return nucleus_; } diff --git a/src/mathed/math_charinset.C b/src/mathed/math_charinset.C index 6ec00b0582..b44ad7111f 100644 --- a/src/mathed/math_charinset.C +++ b/src/mathed/math_charinset.C @@ -135,7 +135,7 @@ bool MathCharInset::isRelOp() const } -bool MathCharInset::match(MathInset * p) const +bool MathCharInset::match(MathInset const * p) const { MathCharInset const * q = p->asCharInset(); return q && char_ == q->char_; diff --git a/src/mathed/math_charinset.h b/src/mathed/math_charinset.h index 22664138f6..a25e892878 100644 --- a/src/mathed/math_charinset.h +++ b/src/mathed/math_charinset.h @@ -39,7 +39,7 @@ public: /// bool isRelOp() const; /// - bool match(MathInset *) const; + bool match(MathInset const *) const; private: /// the character diff --git a/src/mathed/math_cursor.C b/src/mathed/math_cursor.C index cc011e6359..5874875f85 100644 --- a/src/mathed/math_cursor.C +++ b/src/mathed/math_cursor.C @@ -587,7 +587,7 @@ bool MathCursor::toggleLimits() void MathCursor::macroModeClose() { - MathUnknownInset * p = inMacroMode(); + MathUnknownInset const * p = inMacroMode(); if (!p) return; p->finalize(); @@ -688,7 +688,6 @@ void MathCursor::selGet(MathArray & ar) } - void MathCursor::drawSelection(MathPainterInfo & pi) const { if (!selection_) @@ -702,7 +701,10 @@ void MathCursor::drawSelection(MathPainterInfo & pi) const void MathCursor::handleNest(MathAtom const & at) { - at->cell(0) = grabAndEraseSelection().glue(); +#ifdef WITH_WARNINGS +#warning temporarily disabled + //at->cell(0) = grabAndEraseSelection().glue(); +#endif insert(at); pushRight(prevAtom()); } @@ -750,11 +752,11 @@ MathCursor::pos_type & MathCursor::pos() } -MathUnknownInset * MathCursor::inMacroMode() const +MathUnknownInset const * MathCursor::inMacroMode() const { if (!hasPrevAtom()) return 0; - MathUnknownInset * p = prevAtom()->asUnknownInset(); + MathUnknownInset const * p = prevAtom()->asUnknownInset(); return (p && !p->final()) ? p : 0; } diff --git a/src/mathed/math_cursor.h b/src/mathed/math_cursor.h index b16b55102d..b529de2347 100644 --- a/src/mathed/math_cursor.h +++ b/src/mathed/math_cursor.h @@ -134,7 +134,7 @@ public: /// interpret name a name of a macro void macroModeClose(); /// are we currently typing the name of a macro? - MathUnknownInset * inMacroMode() const; + MathUnknownInset const * inMacroMode() const; /// are we currently typing '#1' or '#2' or...? bool inMacroArgMode() const; /// are we in math mode (1), text mode (-1) or unsure? diff --git a/src/mathed/math_data.C b/src/mathed/math_data.C index 12de1e2582..b99772041e 100644 --- a/src/mathed/math_data.C +++ b/src/mathed/math_data.C @@ -154,8 +154,11 @@ void MathArray::replace(ReplaceData & rep) } } - for (const_iterator it = begin(); it != end(); ++it) - it->nucleus()->replace(rep); +#ifdef WITH_WARNINGS +#warning temporarily disabled + // for (const_iterator it = begin(); it != end(); ++it) + // it->nucleus()->replace(rep); +#endif } diff --git a/src/mathed/math_extern.C b/src/mathed/math_extern.C index 921e59fce4..b5d83a09ca 100644 --- a/src/mathed/math_extern.C +++ b/src/mathed/math_extern.C @@ -44,7 +44,7 @@ ostream & operator<<(ostream & os, MathArray const & ar) // define a function for tests -typedef bool TestItemFunc(MathInset *); +typedef bool TestItemFunc(MathInset const *); // define a function for replacing subexpressions typedef MathInset * ReplaceArgumentFunc(const MathArray & ar); @@ -132,14 +132,14 @@ void extractStrings(MathArray & ar) if (!ar[i]->asCharInset()) continue; string s = charSequence(ar.begin() + i, ar.end()); - ar[i].reset(new MathStringInset(s)); + ar[i] = MathAtom(new MathStringInset(s)); ar.erase(i + 1, i + s.size()); } //lyxerr << "\nStrings to: " << ar << "\n"; } -MathInset * singleItem(MathArray & ar) +MathInset const * singleItem(MathArray const & ar) { return ar.size() == 1 ? ar.begin()->nucleus() : 0; } @@ -153,7 +153,7 @@ void extractMatrices(MathArray & ar) MathDelimInset * del = (*it)->asDelimInset(); if (!del) continue; - MathInset * arr = singleItem(del->cell(0)); + MathInset const * arr = singleItem(del->cell(0)); if (!arr || !arr->asGridInset()) continue; *it = MathAtom(new MathMatrixInset(*(arr->asGridInset()))); @@ -171,7 +171,7 @@ void extractMatrices(MathArray & ar) // convert this inset somehow to a string -bool extractString(MathInset * p, string & str) +bool extractString(MathInset const * p, string & str) { if (!p) return false; @@ -204,7 +204,7 @@ bool extractNumber(MathArray const & ar, double & d) } -bool testString(MathInset * p, const string & str) +bool testString(MathInset const * p, const string & str) { string s; return extractString(p, s) && str == s; @@ -257,7 +257,7 @@ void replaceNested( // replace the original stuff by the new inset ar.erase(it + 1, jt + 1); - (*it).reset(p); + *it = MathAtom(p); } } @@ -319,7 +319,7 @@ void extractExps(MathArray & ar) continue; // create a proper exp-inset as replacement - *it = new MathExFuncInset("exp", sup->cell(1)); + *it = MathAtom(new MathExFuncInset("exp", sup->cell(1))); ar.erase(it + 1); } //lyxerr << "\nExps to: " << ar << "\n"; @@ -338,7 +338,7 @@ void extractDets(MathArray & ar) continue; if (!del->isAbs()) continue; - *it = new MathExFuncInset("det", del->cell(0)); + *it = MathAtom(new MathExFuncInset("det", del->cell(0))); } //lyxerr << "\ndet to: " << ar << "\n"; } @@ -379,7 +379,7 @@ void extractNumbers(MathArray & ar) string s = digitSequence(ar.begin() + i, ar.end()); - ar[i].reset(new MathNumberInset(s)); + ar[i] = MathAtom(new MathNumberInset(s)); ar.erase(i + 1, i + s.size()); } //lyxerr << "\nNumbers to: " << ar << "\n"; @@ -391,13 +391,13 @@ void extractNumbers(MathArray & ar) // search deliminiters // -bool testOpenParan(MathInset * p) +bool testOpenParan(MathInset const * p) { return testString(p, "("); } -bool testCloseParan(MathInset * p) +bool testCloseParan(MathInset const * p) { return testString(p, ")"); } @@ -470,7 +470,7 @@ void extractFunctions(MathArray & ar) MathArray::iterator st = extractArgument(p->cell(0), jt, ar.end()); // replace the function name by a real function inset - (*it).reset(p); + *it = MathAtom(p); // remove the source of the argument from the array ar.erase(it + 1, st); @@ -486,19 +486,19 @@ void extractFunctions(MathArray & ar) // search integrals // -bool testSymbol(MathInset * p, string const & name) +bool testSymbol(MathInset const * p, string const & name) { return p->asSymbolInset() && p->asSymbolInset()->name() == name; } -bool testIntSymbol(MathInset * p) +bool testIntSymbol(MathInset const * p) { return testSymbol(p, "int"); } -bool testIntegral(MathInset * p) +bool testIntegral(MathInset const * p) { return testIntSymbol(p) || @@ -509,7 +509,7 @@ bool testIntegral(MathInset * p) -bool testIntDiff(MathInset * p) +bool testIntDiff(MathInset const * p) { return testString(p, "d"); } @@ -554,7 +554,7 @@ void extractIntegrals(MathArray & ar) // remove used parts ar.erase(it + 1, tt); - (*it).reset(p); + *it = MathAtom(p); } //lyxerr << "\nIntegrals to: " << ar << "\n"; } @@ -571,13 +571,13 @@ bool testEqualSign(MathAtom const & at) } -bool testSumSymbol(MathInset * p) +bool testSumSymbol(MathInset const * p) { return testSymbol(p, "sum"); } -bool testSum(MathInset * p) +bool testSum(MathInset const * p) { return testSumSymbol(p) || @@ -633,7 +633,7 @@ void extractSums(MathArray & ar) // cleanup ar.erase(it + 1, tt); - (*it).reset(p); + *it = MathAtom(p); } //lyxerr << "\nSums to: " << ar << "\n"; } @@ -656,9 +656,9 @@ bool testDiffArray(MathArray const & ar) } -bool testDiffFrac(MathInset * p) +bool testDiffFrac(MathInset const * p) { - MathFracInset * f = p->asFracInset(); + MathFracInset const * f = p->asFracInset(); return f && testDiffArray(f->cell(0)) && testDiffArray(f->cell(1)); } @@ -743,7 +743,7 @@ void extractDiff(MathArray & ar) // cleanup ar.erase(it + 1, jt); - (*it).reset(diff); + *it = MathAtom(diff); } //lyxerr << "\nDiffs to: " << ar << "\n"; } @@ -798,12 +798,11 @@ void extractLims(MathArray & ar) MathArray f; MathArray::iterator tt = extractArgument(f, it + 2, ar.end()); - // create a proper inset as replacement - MathLimInset * p = new MathLimInset(f, x, x0); - // cleanup ar.erase(it + 1, tt); - (*it).reset(p); + + // create a proper inset as replacement + *it = MathAtom(new MathLimInset(f, x, x0)); } //lyxerr << "\nLimits to: " << ar << "\n"; } diff --git a/src/mathed/math_fracinset.C b/src/mathed/math_fracinset.C index 49aea91824..1ad3d22225 100644 --- a/src/mathed/math_fracinset.C +++ b/src/mathed/math_fracinset.C @@ -29,6 +29,12 @@ MathFracInset * MathFracInset::asFracInset() } +MathFracInset const * MathFracInset::asFracInset() const +{ + return atop_ ? 0 : this; +} + + void MathFracInset::metrics(MathMetricsInfo & mi) const { MathFracChanger dummy(mi.base); diff --git a/src/mathed/math_fracinset.h b/src/mathed/math_fracinset.h index 0fc668b914..45197d5981 100644 --- a/src/mathed/math_fracinset.h +++ b/src/mathed/math_fracinset.h @@ -25,8 +25,10 @@ public: void metricsT(TextMetricsInfo const & mi) const; /// void drawT(TextPainter &, int x, int y) const; - /// + /// identifies FracInsets MathFracInset * asFracInset(); + /// identifies FracInsets + MathFracInset const * asFracInset() const; /// string name() const; diff --git a/src/mathed/math_gridinset.h b/src/mathed/math_gridinset.h index 481544a582..0f8bfb68d8 100644 --- a/src/mathed/math_gridinset.h +++ b/src/mathed/math_gridinset.h @@ -125,7 +125,9 @@ public: /// CellInfo & cellinfo(idx_type idx) { return cellinfo_[idx]; } /// identifies GridInset - virtual MathGridInset * asGridInset() { return this; } + MathGridInset * asGridInset() { return this; } + /// identifies GridInset + MathGridInset const * asGridInset() const { return this; } /// col_type ncols() const; diff --git a/src/mathed/math_hullinset.C b/src/mathed/math_hullinset.C index 2635382916..a988bbe237 100644 --- a/src/mathed/math_hullinset.C +++ b/src/mathed/math_hullinset.C @@ -516,9 +516,8 @@ void MathHullInset::mutate(string const & newtype) setType("eqnarray"); mutate(newtype); } else if (newtype == "multline" || newtype == "gather") { - setType("multline"); + setType(newtype); numbered(0, false); - mutate(newtype); } else { MathGridInset::addCol(1); // split it "nicely" diff --git a/src/mathed/math_inset.h b/src/mathed/math_inset.h index 7b2de3d821..d092e19645 100644 --- a/src/mathed/math_inset.h +++ b/src/mathed/math_inset.h @@ -195,17 +195,21 @@ public: 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 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 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; } @@ -236,11 +240,11 @@ 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 { return false; } + virtual bool match(MathInset const *) const { return false; } /// replace things by other things virtual void replace(ReplaceData &) {} /// do we contain a given subsequence? - virtual bool contains(MathArray const &) { return false; } + virtual bool contains(MathArray const &) const { return false; } /// access to the lock (only nest array have one) virtual bool lock() const { return false; } /// access to the lock (only nest array have one) diff --git a/src/mathed/math_iterator.C b/src/mathed/math_iterator.C index 087c5f27d5..8b70f3d523 100644 --- a/src/mathed/math_iterator.C +++ b/src/mathed/math_iterator.C @@ -74,7 +74,7 @@ void MathIterator::goEnd() void MathIterator::operator++() { MathCursorPos & top = back(); - MathArray const & ar = top.par_->cell(top.idx_); + MathArray & ar = top.par_->cell(top.idx_); // move into the current inset if possible // it is impossible for pos() == size()! diff --git a/src/mathed/math_macro.h b/src/mathed/math_macro.h index 9a944f5fc5..f36350bca7 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 { return false; } + bool match(MathInset const *) const { return false; } /// void maplize(MapleStream &) const; diff --git a/src/mathed/math_nestinset.C b/src/mathed/math_nestinset.C index d0708b0be6..fc3ea5d7a5 100644 --- a/src/mathed/math_nestinset.C +++ b/src/mathed/math_nestinset.C @@ -228,7 +228,7 @@ void MathNestInset::validate(LaTeXFeatures & features) const } -bool MathNestInset::match(MathInset * p) const +bool MathNestInset::match(MathInset const * p) const { if (nargs() != p->nargs()) return false; @@ -246,7 +246,7 @@ void MathNestInset::replace(ReplaceData & rep) } -bool MathNestInset::contains(MathArray const & ar) +bool MathNestInset::contains(MathArray const & ar) const { for (idx_type i = 0; i < nargs(); ++i) if (cell(i).contains(ar)) diff --git a/src/mathed/math_nestinset.h b/src/mathed/math_nestinset.h index 3ca195bab9..cf9d4057a0 100644 --- a/src/mathed/math_nestinset.h +++ b/src/mathed/math_nestinset.h @@ -38,6 +38,8 @@ public: void substitute(MathMacro const & macro); /// identifies NestInsets MathNestInset * asNestInset() { return this; } + /// identifies NestInsets + MathNestInset const * asNestInset() const { return this; } /// get cursor position void getPos(idx_type idx, pos_type pos, int & x, int & y) const; @@ -81,11 +83,11 @@ public: void validate(LaTeXFeatures & features) const; /// match in all cells - bool match(MathInset *) const; + bool match(MathInset const *) const; /// replace in all cells void replace(ReplaceData &); /// do we contain a given pattern? - bool contains(MathArray const &); + bool contains(MathArray const &) const; /// glue everything to a single cell MathArray glue() const; diff --git a/src/mathed/math_symbolinset.C b/src/mathed/math_symbolinset.C index 245b5c9b80..597dec9ee2 100644 --- a/src/mathed/math_symbolinset.C +++ b/src/mathed/math_symbolinset.C @@ -140,7 +140,7 @@ char const * MathMLtype(string const & s) } -bool MathSymbolInset::match(MathInset * p) const +bool MathSymbolInset::match(MathInset const * p) const { MathSymbolInset const * q = p->asSymbolInset(); return q && name() == q->name(); diff --git a/src/mathed/math_symbolinset.h b/src/mathed/math_symbolinset.h index 7316332726..c79533e936 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; + bool match(MathInset 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 fac5abeb22..5bebcf321d 100644 --- a/src/mathed/math_unknowninset.C +++ b/src/mathed/math_unknowninset.C @@ -27,13 +27,13 @@ string MathUnknownInset::name() const } -void MathUnknownInset::setName(string const & name) +void MathUnknownInset::setName(string const & name) const { name_ = name; } -bool MathUnknownInset::match(MathInset * p) const +bool MathUnknownInset::match(MathInset const * p) const { MathUnknownInset const * q = p->asUnknownInset(); return q && name_ == q->name_; @@ -61,7 +61,7 @@ void MathUnknownInset::draw(MathPainterInfo & pi, int x, int y) const } -void MathUnknownInset::finalize() +void MathUnknownInset::finalize() const { final_ = true; } diff --git a/src/mathed/math_unknowninset.h b/src/mathed/math_unknowninset.h index 8ecc8064a6..1b65a80d53 100644 --- a/src/mathed/math_unknowninset.h +++ b/src/mathed/math_unknowninset.h @@ -23,7 +23,7 @@ public: /// void draw(MathPainterInfo & pi, int x, int y) const; /// - void setName(string const & name); + void setName(string const & name) const; /// string name() const; /// identifies UnknownInsets @@ -31,7 +31,7 @@ public: /// identifies UnknownInsets MathUnknownInset * asUnknownInset() { return this; } /// - bool match(MathInset * p) const; + bool match(MathInset const * p) const; /// void normalize(NormalStream &) const; @@ -44,14 +44,14 @@ public: /// void octavize(OctaveStream &) const; /// - void finalize(); + void finalize() const; /// bool final() const; private: /// - string name_; + mutable string name_; /// are we finished creating the name? - bool final_; + mutable bool final_; /// bool black_; };