more const correctness

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4914 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2002-08-09 07:01:17 +00:00
parent 30a10564b1
commit b54bf51387
11 changed files with 107 additions and 84 deletions

View File

@ -406,7 +406,7 @@ MathHullInset const * InsetFormula::hull() const
MathHullInset * InsetFormula::hull()
{
lyx::Assert(par_->asHullInset());
return par_->asHullInset();
return par_.nucleus()->asHullInset();
}
Inset::Code InsetFormula::lyxCode() const
@ -463,7 +463,7 @@ string InsetFormula::hullType() const
void InsetFormula::mutate(string const & type)
{
par()->mutate(type);
par_.nucleus()->mutate(type);
}

View File

@ -27,6 +27,8 @@ public:
void draw(MathPainterInfo & pain, int x, int y) const;
///
MathAMSArrayInset * asAMSArrayInset() { return this; }
///
MathAMSArrayInset const * asAMSArrayInset() const { return this; }
///
void write(WriteStream & os) const;

View File

@ -49,7 +49,7 @@ public:
MathInset const * nucleus() const { return nucleus_; }
MathInset * nucleus() { return nucleus_; }
/// access to the inset
MathInset * operator->() const { return nucleus_; }
MathInset const * operator->() const { return nucleus_; }
private:
///

View File

@ -574,11 +574,9 @@ bool MathCursor::down(bool sel)
bool MathCursor::toggleLimits()
{
if (!hasNextAtom())
return false;
MathScriptInset * t = nextAtom()->asScriptInset();
if (!t)
if (!hasNextAtom() || !nextAtom()->asScriptInset())
return false;
MathScriptInset * t = nextAtom().nucleus()->asScriptInset();
int old = t->limits();
t->limits(old < 0 ? 1 : -1);
return old != t->limits();
@ -587,9 +585,9 @@ bool MathCursor::toggleLimits()
void MathCursor::macroModeClose()
{
MathUnknownInset const * p = inMacroMode();
if (!p)
if (!inMacroMode())
return;
MathUnknownInset * p = activeMacro();
p->finalize();
string s = p->name();
--pos();
@ -601,7 +599,7 @@ void MathCursor::macroModeClose()
string MathCursor::macroName() const
{
return inMacroMode() ? inMacroMode()->name() : string();
return inMacroMode() ? activeMacro()->name() : string();
}
@ -752,12 +750,24 @@ MathCursor::pos_type & MathCursor::pos()
}
MathUnknownInset const * MathCursor::inMacroMode() const
bool MathCursor::inMacroMode() const
{
if (!hasPrevAtom())
return 0;
return false;
MathUnknownInset const * p = prevAtom()->asUnknownInset();
return (p && !p->final()) ? p : 0;
return p && !p->final();
}
MathUnknownInset * MathCursor::activeMacro()
{
return inMacroMode() ? prevAtom().nucleus()->asUnknownInset() : 0;
}
MathUnknownInset const * MathCursor::activeMacro() const
{
return inMacroMode() ? prevAtom()->asUnknownInset() : 0;
}
@ -859,7 +869,7 @@ void MathCursor::normalize()
// remove empty scripts if possible
if (1) {
for (pos_type i = 0; i < size(); ++i) {
MathScriptInset * p = array()[i]->asScriptInset();
MathScriptInset * p = array()[i].nucleus()->asScriptInset();
if (p) {
p->removeEmptyScripts();
//if (p->empty())
@ -1064,7 +1074,8 @@ bool MathCursor::goUpDown(bool up)
// Be warned: The 'logic' implemented in this function is highly fragile.
// A distance of one pixel or a '<' vs '<=' _really_ matters.
// So fiddle around with it only if you know what you are doing!
int xo, yo;
int xo = 0;
int yo = 0;
getPos(xo, yo);
// check if we had something else in mind, if not, this is the future goal
@ -1076,7 +1087,7 @@ bool MathCursor::goUpDown(bool up)
// try neigbouring script insets
// try left
if (hasPrevAtom()) {
MathScriptInset * p = prevAtom()->asScriptInset();
MathScriptInset const * p = prevAtom()->asScriptInset();
if (p && p->has(up)) {
--pos();
push(nextAtom());
@ -1089,7 +1100,7 @@ bool MathCursor::goUpDown(bool up)
// try right
if (hasNextAtom()) {
MathScriptInset * p = nextAtom()->asScriptInset();
MathScriptInset const * p = nextAtom()->asScriptInset();
if (p && p->has(up)) {
push(nextAtom());
idx() = up;
@ -1249,7 +1260,7 @@ bool MathCursor::interpret(string const & s)
if (name == "over" || name == "choose" || name == "atop") {
MathAtom t(createMathInset(name));
t->asNestInset()->cell(0) = array();
t.nucleus()->asNestInset()->cell(0) = array();
array().clear();
pos() = 0;
niceInsert(t);
@ -1290,7 +1301,7 @@ bool MathCursor::script(bool up)
idx() = up;
pos() = 0;
} else if (hasPrevAtom() && prevAtom()->asScriptInset()) {
prevAtom()->asScriptInset()->ensure(up);
prevAtom().nucleus()->asScriptInset()->ensure(up);
pushRight(prevAtom());
idx() = up;
pos() = size();
@ -1302,7 +1313,7 @@ bool MathCursor::script(bool up)
pos() = 0;
} else {
plainInsert(MathAtom(new MathScriptInset(up)));
prevAtom()->asScriptInset()->ensure(up);
prevAtom().nucleus()->asScriptInset()->ensure(up);
pushRight(prevAtom());
idx() = up;
pos() = 0;
@ -1321,7 +1332,7 @@ bool MathCursor::interpret(char c)
--pos();
plainErase();
int n = c - '0';
MathMacroTemplate * p = formula()->par()->asMacroTemplate();
MathMacroTemplate const * p = formula()->par()->asMacroTemplate();
if (p && 1 <= n && n <= p->numargs())
insert(MathAtom(new MathMacroArgument(c - '0')));
else {
@ -1343,7 +1354,7 @@ bool MathCursor::interpret(char c)
}
if (isalpha(c)) {
inMacroMode()->setName(inMacroMode()->name() + c);
activeMacro()->setName(activeMacro()->name() + c);
return true;
}
@ -1407,7 +1418,7 @@ bool MathCursor::interpret(char c)
return true;
}
if (hasPrevAtom() && prevAtom()->asSpaceInset()) {
prevAtom()->asSpaceInset()->incSpace();
prevAtom().nucleus()->asSpaceInset()->incSpace();
return true;
}
if (popRight())
@ -1490,10 +1501,10 @@ void MathCursor::insetToggle()
{
if (hasNextAtom()) {
// toggle previous inset ...
nextAtom()->lock(!nextAtom()->lock());
nextAtom().nucleus()->lock(!nextAtom()->lock());
} else if (popLeft() && hasNextAtom()) {
// ... or enclosing inset if we are in the last inset position
nextAtom()->lock(!nextAtom()->lock());
nextAtom().nucleus()->lock(!nextAtom()->lock());
posRight();
}
}
@ -1697,10 +1708,10 @@ int MathCursor::dispatch(string const & cmd)
// try to dispatch to adajcent items if they are not editable
// actually, this should only happen for mouse clicks...
if (hasNextAtom() && !openable(nextAtom(), false))
if (int res = nextAtom()->dispatch(cmd, 0, 0))
if (int res = nextAtom().nucleus()->dispatch(cmd, 0, 0))
return res;
if (hasPrevAtom() && !openable(prevAtom(), false))
if (int res = prevAtom()->dispatch(cmd, 0, 0))
if (int res = prevAtom().nucleus()->dispatch(cmd, 0, 0))
return res;
for (int i = Cursor_.size() - 1; i >= 0; --i) {

View File

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

View File

@ -150,7 +150,7 @@ 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 * del = (*it)->asDelimInset();
MathDelimInset const * del = (*it)->asDelimInset();
if (!del)
continue;
MathInset const * arr = singleItem(del->cell(0));
@ -161,7 +161,7 @@ void extractMatrices(MathArray & ar)
// second pass for AMS "pmatrix" etc
for (MathArray::iterator it = ar.begin(); it != ar.end(); ++it) {
MathAMSArrayInset * ams = (*it)->asAMSArrayInset();
MathAMSArrayInset const * ams = (*it)->asAMSArrayInset();
if (!ams)
continue;
*it = MathAtom(new MathMatrixInset(*ams));
@ -273,7 +273,7 @@ void splitScripts(MathArray & ar)
MathArray::iterator it = ar.begin() + i;
// is this script inset?
MathScriptInset * p = (*it)->asScriptInset();
MathScriptInset * p = (*it).nucleus()->asScriptInset();
if (!p)
continue;
@ -312,7 +312,7 @@ void extractExps(MathArray & ar)
continue;
// we need an exponent but no subscript
MathScriptInset * sup = (*(it + 1))->asScriptInset();
MathScriptInset const * sup = (*(it + 1))->asScriptInset();
if (!sup || sup->hasDown())
continue;
@ -331,7 +331,7 @@ void extractDets(MathArray & ar)
{
//lyxerr << "\ndet from: " << ar << "\n";
for (MathArray::iterator it = ar.begin(); it != ar.end(); ++it) {
MathDelimInset * del = (*it)->asDelimInset();
MathDelimInset const * del = (*it)->asDelimInset();
if (!del)
continue;
if (!del->isAbs())
@ -450,7 +450,7 @@ void extractFunctions(MathArray & ar)
continue;
// guess so, if this is followed by
// a DelimInset with a single item in the cell
MathDelimInset * del = (*jt)->asDelimInset();
MathDelimInset const * del = (*jt)->asDelimInset();
if (!del || del->cell(0).size() != 1)
continue;
// fall trough into main branch
@ -605,11 +605,11 @@ void extractSums(MathArray & ar)
MathExIntInset * p = new MathExIntInset("sum");
// collect lower bound and summation index
MathScriptInset * sub = (*it)->asScriptInset();
MathScriptInset const * sub = (*it)->asScriptInset();
if (sub && sub->hasDown()) {
// try to figure out the summation index from the subscript
MathArray & ar = sub->down();
MathArray::iterator xt =
MathArray const & ar = sub->down();
MathArray::const_iterator xt =
find_if(ar.begin(), ar.end(), &testEqualSign);
if (xt != ar.end()) {
// we found a '=', use everything in front of that as index,
@ -673,7 +673,7 @@ void extractDiff(MathArray & ar)
if (!testDiffFrac(*it))
continue;
MathFracInset * f = (*it)->asFracInset();
MathFracInset const * f = (*it)->asFracInset();
if (!f) {
lyxerr << "should not happen\n";
continue;
@ -685,7 +685,7 @@ void extractDiff(MathArray & ar)
// collect function, let jt point behind last used item
MathArray::iterator jt = it + 1;
//int n = 1;
MathArray & numer = f->cell(0);
MathArray const & numer = f->cell(0);
if (numer.size() > 1 && numer[1]->asScriptInset()) {
// this is something like d^n f(x) / d... or d^n / d...
// FIXME
@ -703,14 +703,15 @@ void extractDiff(MathArray & ar)
}
// collect denominator parts
MathArray & denom = f->cell(1);
for (MathArray::iterator dt = denom.begin(); dt != denom.end();) {
MathArray const & denom = f->cell(1);
for (MathArray::const_iterator dt = denom.begin(); dt != denom.end();) {
// find the next 'd'
MathArray::iterator et = find_if(dt + 1, denom.end(), &testDiffItem);
MathArray::const_iterator et
= find_if(dt + 1, denom.end(), &testDiffItem);
// point before this
MathArray::iterator st = et - 1;
MathScriptInset * script = (*st)->asScriptInset();
MathArray::const_iterator st = et - 1;
MathScriptInset const * script = (*st)->asScriptInset();
if (script && script->hasUp()) {
// things like d.../dx^n
int mult = 1;
@ -763,13 +764,13 @@ void extractLims(MathArray & ar)
continue;
// the next one must be a subscript (without superscript)
MathScriptInset * sub = (*(it + 1))->asScriptInset();
MathScriptInset const * sub = (*(it + 1))->asScriptInset();
if (!sub || !sub->hasDown() || sub->hasUp())
continue;
// and it must contain a -> symbol
MathArray & s = sub->down();
MathArray::iterator st = find_if(s.begin(), s.end(), &testRightArrow);
MathArray const & s = sub->down();
MathArray::const_iterator st = find_if(s.begin(), s.end(), &testRightArrow);
if (st == s.end())
continue;
@ -1033,7 +1034,7 @@ namespace {
res.append(mat->cell(0));
else {
res.push_back(MathAtom(new MathDelimInset("(", ")")));
res.back()->cell(0).push_back(at);
res.back().nucleus()->cell(0).push_back(at);
}
return res;
}

View File

@ -190,6 +190,7 @@ public:
/// 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; }
@ -201,6 +202,7 @@ public:
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; }
@ -208,6 +210,7 @@ public:
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; }

View File

@ -41,6 +41,8 @@ public:
void metrics(MathMetricsInfo & st) const;
/// identifies macro templates
MathMacroTemplate * asMacroTemplate() { return this; }
/// identifies macro templates
MathMacroTemplate const * asMacroTemplate() const { return this; }
private:
///
int numargs_;

View File

@ -508,7 +508,7 @@ bool Parser::parse(MathAtom & at)
lyxerr << "unusual contents found: " << ar << endl;
at = MathAtom(new MathParInset);
if (at->nargs() > 0)
at->cell(0) = ar;
at.nucleus()->cell(0) = ar;
else
lyxerr << "unusual contents found: " << ar << endl;
return true;
@ -529,7 +529,7 @@ void Parser::parse(MathArray & array, unsigned flags, mode_type mode)
void Parser::parse2(MathAtom & at, unsigned flags, mode_type mode,
bool numbered)
{
parse1(*(at->asGridInset()), flags, mode, numbered);
parse1(*(at.nucleus()->asGridInset()), flags, mode, numbered);
}
@ -673,12 +673,12 @@ void Parser::parse1(MathGridInset & grid, unsigned flags,
cell->push_back(MathAtom(new MathScriptInset(up)));
else if (cell->back()->asScriptInset() &&
!cell->back()->asScriptInset()->has(up))
cell->back()->asScriptInset()->ensure(up);
cell->back().nucleus()->asScriptInset()->ensure(up);
else if (cell->back()->asScriptInset())
cell->push_back(MathAtom(new MathScriptInset(up)));
else
cell->back() = MathAtom(new MathScriptInset(cell->back(), up));
MathScriptInset * p = cell->back()->asScriptInset();
MathScriptInset * p = cell->back().nucleus()->asScriptInset();
parse(p->cell(up), FLAG_ITEM, mode);
p->limits(limits);
limits = 0;
@ -704,7 +704,7 @@ void Parser::parse1(MathGridInset & grid, unsigned flags,
else if (t.cs() == "lyxlock") {
if (cell->size())
cell->back()->lock(true);
cell->back().nucleus()->lock(true);
}
else if (t.cs() == "def" || t.cs() == "newcommand") {
@ -871,18 +871,18 @@ void Parser::parse1(MathGridInset & grid, unsigned flags,
parse(ar, FLAG_OPTION, mode);
if (ar.size()) {
cell->push_back(MathAtom(new MathRootInset));
cell->back()->cell(0) = ar;
parse(cell->back()->cell(1), FLAG_ITEM, mode);
cell->back().nucleus()->cell(0) = ar;
parse(cell->back().nucleus()->cell(1), FLAG_ITEM, mode);
} else {
cell->push_back(MathAtom(new MathSqrtInset));
parse(cell->back()->cell(0), FLAG_ITEM, mode);
parse(cell->back().nucleus()->cell(0), FLAG_ITEM, mode);
}
}
else if (t.cs() == "ref") {
cell->push_back(MathAtom(new RefInset));
parse(cell->back()->cell(1), FLAG_OPTION, mode);
parse(cell->back()->cell(0), FLAG_ITEM, mode);
parse(cell->back().nucleus()->cell(1), FLAG_OPTION, mode);
parse(cell->back().nucleus()->cell(0), FLAG_ITEM, mode);
}
else if (t.cs() == "left") {
@ -979,7 +979,7 @@ void Parser::parse1(MathGridInset & grid, unsigned flags,
// lyxerr << "unknow math inset begin '" << name << "'\n";
// create generic environment inset
cell->push_back(MathAtom(new MathEnvInset(name)));
parse(cell->back()->cell(0), FLAG_END, mode);
parse(cell->back().nucleus()->cell(0), FLAG_END, mode);
}
}
@ -1013,11 +1013,11 @@ void Parser::parse1(MathGridInset & grid, unsigned flags,
}
else if (t.cs() == "choose" || t.cs() == "over" || t.cs() == "atop") {
MathAtom p = createMathInset(t.cs());
p->cell(0) = *cell;
MathAtom at = createMathInset(t.cs());
at.nucleus()->cell(0) = *cell;
cell->clear();
parse(p->cell(1), flags, mode);
cell->push_back(p);
parse(at.nucleus()->cell(1), flags, mode);
cell->push_back(at);
return;
}
@ -1055,18 +1055,18 @@ void Parser::parse1(MathGridInset & grid, unsigned flags,
if (l) {
if (l->inset == "font") {
cell->push_back(createMathInset(t.cs()));
parse(cell->back()->cell(0), FLAG_ITEM, asMode(l->extra));
parse(cell->back().nucleus()->cell(0), FLAG_ITEM, asMode(l->extra));
}
else if (l->inset == "oldfont") {
cell->push_back(createMathInset(t.cs()));
parse(cell->back()->cell(0), flags, asMode(l->extra));
parse(cell->back().nucleus()->cell(0), flags, asMode(l->extra));
return;
}
else if (l->inset == "style") {
cell->push_back(createMathInset(t.cs()));
parse(cell->back()->cell(0), flags, mode);
parse(cell->back().nucleus()->cell(0), flags, mode);
return;
}
@ -1076,27 +1076,27 @@ void Parser::parse1(MathGridInset & grid, unsigned flags,
parse(pos, FLAG_OPTION, MathInset::VERBATIM_MODE);
parse(width, FLAG_ITEM, MathInset::VERBATIM_MODE);
cell->push_back(createMathInset(t.cs()));
parse(cell->back()->cell(0), FLAG_ITEM, MathInset::TEXT_MODE);
cell->back()->asParboxInset()->setPosition(asString(pos));
cell->back()->asParboxInset()->setWidth(asString(width));
parse(cell->back().nucleus()->cell(0), FLAG_ITEM, MathInset::TEXT_MODE);
cell->back().nucleus()->asParboxInset()->setPosition(asString(pos));
cell->back().nucleus()->asParboxInset()->setWidth(asString(width));
}
else {
MathAtom p = createMathInset(t.cs());
for (MathInset::idx_type i = 0; i < p->nargs(); ++i)
parse(p->cell(i), FLAG_ITEM, asMode(l->extra));
cell->push_back(p);
MathAtom at = createMathInset(t.cs());
for (MathInset::idx_type i = 0; i < at->nargs(); ++i)
parse(at.nucleus()->cell(i), FLAG_ITEM, asMode(l->extra));
cell->push_back(at);
}
}
else {
MathAtom p = createMathInset(t.cs());
MathAtom at = createMathInset(t.cs());
MathInset::mode_type m = mode;
if (m == MathInset::UNDECIDED_MODE)
m = p->currentMode();
for (MathInset::idx_type i = 0; i < p->nargs(); ++i)
parse(p->cell(i), FLAG_ITEM, m);
cell->push_back(p);
m = at->currentMode();
for (MathInset::idx_type i = 0; i < at->nargs(); ++i)
parse(at.nucleus()->cell(i), FLAG_ITEM, m);
cell->push_back(at);
}
}

View File

@ -27,7 +27,7 @@ string MathUnknownInset::name() const
}
void MathUnknownInset::setName(string const & name) const
void MathUnknownInset::setName(string const & name)
{
name_ = name;
}
@ -61,7 +61,7 @@ void MathUnknownInset::draw(MathPainterInfo & pi, int x, int y) const
}
void MathUnknownInset::finalize() const
void MathUnknownInset::finalize()
{
final_ = true;
}

View File

@ -23,7 +23,7 @@ public:
///
void draw(MathPainterInfo & pi, int x, int y) const;
///
void setName(string const & name) const;
void setName(string const & name);
///
string name() const;
/// identifies UnknownInsets
@ -44,14 +44,14 @@ public:
///
void octavize(OctaveStream &) const;
///
void finalize() const;
void finalize();
///
bool final() const;
private:
///
mutable string name_;
string name_;
/// are we finished creating the name?
mutable bool final_;
bool final_;
///
bool black_;
};