a bit more const correctness

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4905 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2002-08-08 16:08:11 +00:00
parent fe5cc4b241
commit 73b1ac43f4
22 changed files with 91 additions and 63 deletions

View File

@ -396,13 +396,19 @@ bool InsetFormula::display() const
} }
MathHullInset * InsetFormula::hull() const MathHullInset const * InsetFormula::hull() const
{ {
lyx::Assert(par_->asHullInset()); lyx::Assert(par_->asHullInset());
return par_->asHullInset(); return par_->asHullInset();
} }
MathHullInset * InsetFormula::hull()
{
lyx::Assert(par_->asHullInset());
return par_->asHullInset();
}
Inset::Code InsetFormula::lyxCode() const Inset::Code InsetFormula::lyxCode() const
{ {
return Inset::MATH_CODE; return Inset::MATH_CODE;

View File

@ -94,7 +94,9 @@ private:
/// available in AMS only? /// available in AMS only?
bool ams() const; bool ams() const;
/// access to hull /// access to hull
MathHullInset * hull() const; MathHullInset const * hull() const;
/// access to hull
MathHullInset * hull();
/// ///
void handleExtern(string const & arg); void handleExtern(string const & arg);

View File

@ -50,7 +50,8 @@ public:
/// change inset under the hood /// change inset under the hood
void reset(MathInset * p); void reset(MathInset * p);
/// access to the inset (checked with gprof) /// 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 /// access to the inset
MathInset * operator->() const { return nucleus_; } MathInset * operator->() const { return nucleus_; }

View File

@ -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(); MathCharInset const * q = p->asCharInset();
return q && char_ == q->char_; return q && char_ == q->char_;

View File

@ -39,7 +39,7 @@ public:
/// ///
bool isRelOp() const; bool isRelOp() const;
/// ///
bool match(MathInset *) const; bool match(MathInset const *) const;
private: private:
/// the character /// the character

View File

@ -587,7 +587,7 @@ bool MathCursor::toggleLimits()
void MathCursor::macroModeClose() void MathCursor::macroModeClose()
{ {
MathUnknownInset * p = inMacroMode(); MathUnknownInset const * p = inMacroMode();
if (!p) if (!p)
return; return;
p->finalize(); p->finalize();
@ -688,7 +688,6 @@ void MathCursor::selGet(MathArray & ar)
} }
void MathCursor::drawSelection(MathPainterInfo & pi) const void MathCursor::drawSelection(MathPainterInfo & pi) const
{ {
if (!selection_) if (!selection_)
@ -702,7 +701,10 @@ void MathCursor::drawSelection(MathPainterInfo & pi) const
void MathCursor::handleNest(MathAtom const & at) 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); insert(at);
pushRight(prevAtom()); pushRight(prevAtom());
} }
@ -750,11 +752,11 @@ MathCursor::pos_type & MathCursor::pos()
} }
MathUnknownInset * MathCursor::inMacroMode() const MathUnknownInset const * MathCursor::inMacroMode() const
{ {
if (!hasPrevAtom()) if (!hasPrevAtom())
return 0; return 0;
MathUnknownInset * p = prevAtom()->asUnknownInset(); MathUnknownInset const * p = prevAtom()->asUnknownInset();
return (p && !p->final()) ? p : 0; return (p && !p->final()) ? p : 0;
} }

View File

@ -134,7 +134,7 @@ public:
/// interpret name a name of a macro /// interpret name a name of a macro
void macroModeClose(); void macroModeClose();
/// are we currently typing the name of a macro? /// are we currently typing the name of a macro?
MathUnknownInset * inMacroMode() const; MathUnknownInset const * inMacroMode() const;
/// are we currently typing '#1' or '#2' or...? /// are we currently typing '#1' or '#2' or...?
bool inMacroArgMode() const; bool inMacroArgMode() const;
/// are we in math mode (1), text mode (-1) or unsure? /// are we in math mode (1), text mode (-1) or unsure?

View File

@ -154,8 +154,11 @@ void MathArray::replace(ReplaceData & rep)
} }
} }
for (const_iterator it = begin(); it != end(); ++it) #ifdef WITH_WARNINGS
it->nucleus()->replace(rep); #warning temporarily disabled
// for (const_iterator it = begin(); it != end(); ++it)
// it->nucleus()->replace(rep);
#endif
} }

View File

@ -44,7 +44,7 @@ ostream & operator<<(ostream & os, MathArray const & ar)
// define a function for tests // define a function for tests
typedef bool TestItemFunc(MathInset *); typedef bool TestItemFunc(MathInset const *);
// define a function for replacing subexpressions // define a function for replacing subexpressions
typedef MathInset * ReplaceArgumentFunc(const MathArray & ar); typedef MathInset * ReplaceArgumentFunc(const MathArray & ar);
@ -132,14 +132,14 @@ void extractStrings(MathArray & ar)
if (!ar[i]->asCharInset()) if (!ar[i]->asCharInset())
continue; continue;
string s = charSequence(ar.begin() + i, ar.end()); 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()); ar.erase(i + 1, i + s.size());
} }
//lyxerr << "\nStrings to: " << ar << "\n"; //lyxerr << "\nStrings to: " << ar << "\n";
} }
MathInset * singleItem(MathArray & ar) MathInset const * singleItem(MathArray const & ar)
{ {
return ar.size() == 1 ? ar.begin()->nucleus() : 0; return ar.size() == 1 ? ar.begin()->nucleus() : 0;
} }
@ -153,7 +153,7 @@ void extractMatrices(MathArray & ar)
MathDelimInset * del = (*it)->asDelimInset(); MathDelimInset * del = (*it)->asDelimInset();
if (!del) if (!del)
continue; continue;
MathInset * arr = singleItem(del->cell(0)); MathInset const * arr = singleItem(del->cell(0));
if (!arr || !arr->asGridInset()) if (!arr || !arr->asGridInset())
continue; continue;
*it = MathAtom(new MathMatrixInset(*(arr->asGridInset()))); *it = MathAtom(new MathMatrixInset(*(arr->asGridInset())));
@ -171,7 +171,7 @@ void extractMatrices(MathArray & ar)
// convert this inset somehow to a string // convert this inset somehow to a string
bool extractString(MathInset * p, string & str) bool extractString(MathInset const * p, string & str)
{ {
if (!p) if (!p)
return false; 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; string s;
return extractString(p, s) && str == s; return extractString(p, s) && str == s;
@ -257,7 +257,7 @@ void replaceNested(
// 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).reset(p); *it = MathAtom(p);
} }
} }
@ -319,7 +319,7 @@ void extractExps(MathArray & ar)
continue; continue;
// create a proper exp-inset as replacement // 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); ar.erase(it + 1);
} }
//lyxerr << "\nExps to: " << ar << "\n"; //lyxerr << "\nExps to: " << ar << "\n";
@ -338,7 +338,7 @@ void extractDets(MathArray & ar)
continue; continue;
if (!del->isAbs()) if (!del->isAbs())
continue; continue;
*it = new MathExFuncInset("det", del->cell(0)); *it = MathAtom(new MathExFuncInset("det", del->cell(0)));
} }
//lyxerr << "\ndet to: " << ar << "\n"; //lyxerr << "\ndet to: " << ar << "\n";
} }
@ -379,7 +379,7 @@ void extractNumbers(MathArray & ar)
string s = digitSequence(ar.begin() + i, ar.end()); 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()); ar.erase(i + 1, i + s.size());
} }
//lyxerr << "\nNumbers to: " << ar << "\n"; //lyxerr << "\nNumbers to: " << ar << "\n";
@ -391,13 +391,13 @@ void extractNumbers(MathArray & ar)
// search deliminiters // search deliminiters
// //
bool testOpenParan(MathInset * p) bool testOpenParan(MathInset const * p)
{ {
return testString(p, "("); return testString(p, "(");
} }
bool testCloseParan(MathInset * p) bool testCloseParan(MathInset const * p)
{ {
return testString(p, ")"); return testString(p, ")");
} }
@ -470,7 +470,7 @@ void extractFunctions(MathArray & ar)
MathArray::iterator st = extractArgument(p->cell(0), jt, ar.end()); MathArray::iterator st = extractArgument(p->cell(0), jt, ar.end());
// replace the function name by a real function inset // replace the function name by a real function inset
(*it).reset(p); *it = MathAtom(p);
// remove the source of the argument from the array // remove the source of the argument from the array
ar.erase(it + 1, st); ar.erase(it + 1, st);
@ -486,19 +486,19 @@ void extractFunctions(MathArray & ar)
// search integrals // search integrals
// //
bool testSymbol(MathInset * p, string const & name) bool testSymbol(MathInset const * p, string const & name)
{ {
return p->asSymbolInset() && p->asSymbolInset()->name() == name; return p->asSymbolInset() && p->asSymbolInset()->name() == name;
} }
bool testIntSymbol(MathInset * p) bool testIntSymbol(MathInset const * p)
{ {
return testSymbol(p, "int"); return testSymbol(p, "int");
} }
bool testIntegral(MathInset * p) bool testIntegral(MathInset const * p)
{ {
return return
testIntSymbol(p) || testIntSymbol(p) ||
@ -509,7 +509,7 @@ bool testIntegral(MathInset * p)
bool testIntDiff(MathInset * p) bool testIntDiff(MathInset const * p)
{ {
return testString(p, "d"); return testString(p, "d");
} }
@ -554,7 +554,7 @@ void extractIntegrals(MathArray & ar)
// remove used parts // remove used parts
ar.erase(it + 1, tt); ar.erase(it + 1, tt);
(*it).reset(p); *it = MathAtom(p);
} }
//lyxerr << "\nIntegrals to: " << ar << "\n"; //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"); return testSymbol(p, "sum");
} }
bool testSum(MathInset * p) bool testSum(MathInset const * p)
{ {
return return
testSumSymbol(p) || testSumSymbol(p) ||
@ -633,7 +633,7 @@ void extractSums(MathArray & ar)
// cleanup // cleanup
ar.erase(it + 1, tt); ar.erase(it + 1, tt);
(*it).reset(p); *it = MathAtom(p);
} }
//lyxerr << "\nSums to: " << ar << "\n"; //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)); return f && testDiffArray(f->cell(0)) && testDiffArray(f->cell(1));
} }
@ -743,7 +743,7 @@ void extractDiff(MathArray & ar)
// cleanup // cleanup
ar.erase(it + 1, jt); ar.erase(it + 1, jt);
(*it).reset(diff); *it = MathAtom(diff);
} }
//lyxerr << "\nDiffs to: " << ar << "\n"; //lyxerr << "\nDiffs to: " << ar << "\n";
} }
@ -798,12 +798,11 @@ void extractLims(MathArray & ar)
MathArray f; MathArray f;
MathArray::iterator tt = extractArgument(f, it + 2, ar.end()); MathArray::iterator tt = extractArgument(f, it + 2, ar.end());
// create a proper inset as replacement
MathLimInset * p = new MathLimInset(f, x, x0);
// cleanup // cleanup
ar.erase(it + 1, tt); 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"; //lyxerr << "\nLimits to: " << ar << "\n";
} }

View File

@ -29,6 +29,12 @@ MathFracInset * MathFracInset::asFracInset()
} }
MathFracInset const * MathFracInset::asFracInset() const
{
return atop_ ? 0 : this;
}
void MathFracInset::metrics(MathMetricsInfo & mi) const void MathFracInset::metrics(MathMetricsInfo & mi) const
{ {
MathFracChanger dummy(mi.base); MathFracChanger dummy(mi.base);

View File

@ -25,8 +25,10 @@ public:
void metricsT(TextMetricsInfo const & mi) const; void metricsT(TextMetricsInfo const & mi) const;
/// ///
void drawT(TextPainter &, int x, int y) const; void drawT(TextPainter &, int x, int y) const;
/// /// identifies FracInsets
MathFracInset * asFracInset(); MathFracInset * asFracInset();
/// identifies FracInsets
MathFracInset const * asFracInset() const;
/// ///
string name() const; string name() const;

View File

@ -125,7 +125,9 @@ public:
/// ///
CellInfo & cellinfo(idx_type idx) { return cellinfo_[idx]; } CellInfo & cellinfo(idx_type idx) { return cellinfo_[idx]; }
/// identifies GridInset /// identifies GridInset
virtual MathGridInset * asGridInset() { return this; } MathGridInset * asGridInset() { return this; }
/// identifies GridInset
MathGridInset const * asGridInset() const { return this; }
/// ///
col_type ncols() const; col_type ncols() const;

View File

@ -516,9 +516,8 @@ void MathHullInset::mutate(string const & newtype)
setType("eqnarray"); setType("eqnarray");
mutate(newtype); mutate(newtype);
} else if (newtype == "multline" || newtype == "gather") { } else if (newtype == "multline" || newtype == "gather") {
setType("multline"); setType(newtype);
numbered(0, false); numbered(0, false);
mutate(newtype);
} else { } else {
MathGridInset::addCol(1); MathGridInset::addCol(1);
// split it "nicely" // split it "nicely"

View File

@ -195,17 +195,21 @@ public:
virtual MathDelimInset * asDelimInset() { return 0; } virtual MathDelimInset * asDelimInset() { return 0; }
virtual MathDelimInset const * asDelimInset() const { return 0; } virtual MathDelimInset const * asDelimInset() const { return 0; }
virtual MathFracInset * asFracInset() { return 0; } virtual MathFracInset * asFracInset() { return 0; }
virtual MathFracInset const * asFracInset() const { return 0; }
virtual MathGridInset * asGridInset() { return 0; } virtual MathGridInset * asGridInset() { return 0; }
virtual MathGridInset const * asGridInset() const { return 0; }
virtual MathHullInset * asHullInset() { return 0; } virtual MathHullInset * asHullInset() { return 0; }
virtual MathHullInset const * asHullInset() const { return 0; } virtual MathHullInset const * asHullInset() const { return 0; }
virtual MathMacroTemplate * asMacroTemplate() { return 0; } virtual MathMacroTemplate * asMacroTemplate() { return 0; }
virtual MathMatrixInset const * asMatrixInset() const { return 0; } virtual MathMatrixInset const * asMatrixInset() const { return 0; }
virtual MathNestInset * asNestInset() { return 0; } virtual MathNestInset * asNestInset() { return 0; }
virtual MathNestInset const * asNestInset() const { return 0; }
virtual MathParboxInset * asParboxInset() { return 0; } virtual MathParboxInset * asParboxInset() { return 0; }
virtual MathScriptInset * asScriptInset() { return 0; } virtual MathScriptInset * asScriptInset() { return 0; }
virtual MathScriptInset const * asScriptInset() const { return 0; } virtual MathScriptInset const * asScriptInset() const { return 0; }
virtual MathSpaceInset * asSpaceInset() { return 0; } virtual MathSpaceInset * asSpaceInset() { return 0; }
virtual MathStringInset * asStringInset() { return 0; } virtual MathStringInset * asStringInset() { return 0; }
virtual MathStringInset const * asStringInset() const { return 0; }
virtual MathSymbolInset const * asSymbolInset() const { return 0; } virtual MathSymbolInset const * asSymbolInset() const { return 0; }
virtual MathUnknownInset * asUnknownInset() { return 0; } virtual MathUnknownInset * asUnknownInset() { return 0; }
virtual MathUnknownInset const * asUnknownInset() const { return 0; } virtual MathUnknownInset const * asUnknownInset() const { return 0; }
@ -236,11 +240,11 @@ 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 { return false; } virtual bool match(MathInset 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?
virtual bool contains(MathArray const &) { return false; } virtual bool contains(MathArray const &) const { return false; }
/// access to the lock (only nest array have one) /// access to the lock (only nest array have one)
virtual bool lock() const { return false; } virtual bool lock() const { return false; }
/// access to the lock (only nest array have one) /// access to the lock (only nest array have one)

View File

@ -74,7 +74,7 @@ void MathIterator::goEnd()
void MathIterator::operator++() void MathIterator::operator++()
{ {
MathCursorPos & top = back(); 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 // move into the current inset if possible
// it is impossible for pos() == size()! // it is impossible for pos() == size()!

View File

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

View File

@ -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()) if (nargs() != p->nargs())
return false; 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) for (idx_type i = 0; i < nargs(); ++i)
if (cell(i).contains(ar)) if (cell(i).contains(ar))

View File

@ -38,6 +38,8 @@ public:
void substitute(MathMacro const & macro); void substitute(MathMacro const & macro);
/// identifies NestInsets /// identifies NestInsets
MathNestInset * asNestInset() { return this; } MathNestInset * asNestInset() { return this; }
/// identifies NestInsets
MathNestInset const * asNestInset() const { return this; }
/// get cursor position /// get cursor position
void getPos(idx_type idx, pos_type pos, int & x, int & y) const; void getPos(idx_type idx, pos_type pos, int & x, int & y) const;
@ -81,11 +83,11 @@ public:
void validate(LaTeXFeatures & features) const; void validate(LaTeXFeatures & features) const;
/// match in all cells /// match in all cells
bool match(MathInset *) const; bool match(MathInset 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?
bool contains(MathArray const &); bool contains(MathArray const &) const;
/// glue everything to a single cell /// glue everything to a single cell
MathArray glue() const; MathArray glue() const;

View File

@ -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(); MathSymbolInset const * q = p->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; bool match(MathInset const *) const;
/// request "external features" /// request "external features"
void validate(LaTeXFeatures & features) const; void validate(LaTeXFeatures & features) const;

View File

@ -27,13 +27,13 @@ string MathUnknownInset::name() const
} }
void MathUnknownInset::setName(string const & name) void MathUnknownInset::setName(string const & name) const
{ {
name_ = name; name_ = name;
} }
bool MathUnknownInset::match(MathInset * p) const bool MathUnknownInset::match(MathInset const * p) const
{ {
MathUnknownInset const * q = p->asUnknownInset(); MathUnknownInset const * q = p->asUnknownInset();
return q && name_ == q->name_; 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; final_ = true;
} }

View File

@ -23,7 +23,7 @@ public:
/// ///
void draw(MathPainterInfo & pi, int x, int y) const; void draw(MathPainterInfo & pi, int x, int y) const;
/// ///
void setName(string const & name); void setName(string const & name) const;
/// ///
string name() const; string name() const;
/// identifies UnknownInsets /// identifies UnknownInsets
@ -31,7 +31,7 @@ public:
/// identifies UnknownInsets /// identifies UnknownInsets
MathUnknownInset * asUnknownInset() { return this; } MathUnknownInset * asUnknownInset() { return this; }
/// ///
bool match(MathInset * p) const; bool match(MathInset const * p) const;
/// ///
void normalize(NormalStream &) const; void normalize(NormalStream &) const;
@ -44,14 +44,14 @@ public:
/// ///
void octavize(OctaveStream &) const; void octavize(OctaveStream &) const;
/// ///
void finalize(); void finalize() const;
/// ///
bool final() const; bool final() const;
private: private:
/// ///
string name_; mutable string name_;
/// are we finished creating the name? /// are we finished creating the name?
bool final_; mutable bool final_;
/// ///
bool black_; bool black_;
}; };