small cleanup read ChangeLog

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1663 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Lars Gullik Bjønnes 2001-03-05 10:18:36 +00:00
parent 078e4c896c
commit d96f7c829c
6 changed files with 80 additions and 61 deletions

View File

@ -1,5 +1,19 @@
2001-03-01 Lars Gullik Bjønnes <larsbj@trylle.birdstep.com>
* math_macrotemplate.C (update): use MathMacro::getArg, and
receive a const reference.
(getMacroPar): add an Assert
* math_macrotemplate.h: make MathMacro a friend, make update take
a const reference.
* math_macro.[hC]: get rid of getRowSt, remove MacroArgumentBase
and store a MathMacroArgument in the vector
* math_macro.C: changes because of the above.
(getArg): new method
* math_parser.C (mathed_parse): plug potential leak
* math_iter.h: add comment on virtual destructor
* math_iter.C (Delete): make c const

View File

@ -48,9 +48,19 @@ MathMacro::MathMacro(boost::shared_ptr<MathMacroTemplate> const & t)
: MathParInset(LM_ST_TEXT, "", LM_OT_MACRO),
tmplate_(t)
{
nargs_ = tmplate_->getNoArgs();
//nargs_ = tmplate_->getNoArgs();
int const n = tmplate_->getNoArgs();
tcode_ = tmplate_->getTCode();
args_.resize(nargs_);
for (int i = 0; i < n; ++i) {
args_.push_back(MathMacroArgument(t->args_[i]));
}
//for (int i = 0; i < nargs_; ++i) {
// MathMacroArgument * ma = new MathMacroArgument(*t->args_[i]);
// args_.push_back(boost::shared_ptr<MathMacroArgument>(ma));
//}
idx_ = 0;
SetName(tmplate_->GetName());
}
@ -64,8 +74,8 @@ MathedInset * MathMacro::Clone()
void MathMacro::Metrics()
{
if (nargs_ > 0)
tmplate_->update(this);
if (args_.size() > 0)
tmplate_->update(*this);
tmplate_->SetStyle(size());
tmplate_->Metrics();
width = tmplate_->Width();
@ -86,7 +96,7 @@ void MathMacro::draw(Painter & pain, int x, int y)
bool MathMacro::setArgumentIdx(int i)
{
if (i >= 0 && i < nargs_) {
if (i >= 0 && i < args_.size()) {
idx_ = i;
return true;
} else
@ -102,19 +112,19 @@ int MathMacro::getArgumentIdx() const
int MathMacro::getMaxArgumentIdx() const
{
return nargs_ - 1;
return args_.size() - 1;
}
MathedArray & MathMacro::GetData()
{
return args_[idx_].array;
return args_[idx_].GetData();
}
MathedArray const & MathMacro::GetData() const
{
return args_[idx_].array;
return args_[idx_].GetData();
}
@ -126,19 +136,14 @@ int MathMacro::GetColumns() const
void MathMacro::GetXY(int & x, int & y) const
{
#if 0
x = args_[idx_].x_;
y = args_[idx_].y_;
#else
const_cast<MathMacro*>(this)->Metrics();
tmplate_->GetMacroXY(idx_, x, y);
#endif
}
bool MathMacro::Permit(short f) const
{
return (nargs_ > 0) ?
return (args_.size() > 0) ?
tmplate_->getMacroPar(idx_)->Permit(f) :
MathParInset::Permit(f);
}
@ -153,13 +158,7 @@ void MathMacro::SetFocus(int x, int y)
void MathMacro::setData(MathedArray const & a)
{
args_[idx_].array = a;
}
MathedRowSt * MathMacro::getRowSt() const
{
return args_[idx_].row;
args_[idx_].setData(a);
}
@ -173,16 +172,29 @@ void MathMacro::Write(ostream & os, bool fragile)
{
os << '\\' << name;
if (nargs_ > 0) {
int const n = args_.size();
if (n > 0) {
os << '{';
for (int i = 0; i < nargs_; ++i) {
array = args_[i].array;
for (int i = 0; i < n; ++i) {
array = args_[i].GetData();
MathParInset::Write(os, fragile);
if (i < nargs_ - 1)
if (i < n - 1)
os << "}{";
}
os << '}';
} else
os << ' ';
}
MathMacroArgument const & MathMacro::getArg(int i) const
{
return args_[i];
}
//boost::shared_ptr<MathMacroArgument> MathMacro::getArg(int i)
//{
// return args_[i];
//}

View File

@ -25,6 +25,7 @@
#include <boost/smart_ptr.hpp>
#include "math_parinset.h"
#include "math_macroarg.h"
class MathMacroTemplate;
@ -63,32 +64,24 @@ public:
///
MathedArray const & GetData() const;
///
MathedRowSt * getRowSt() const;
///
void setData(MathedArray const &);
///
MathedTextCodes getTCode() const;
///
bool Permit(short) const;
///
MathMacroArgument const & getArg(int i) const;
//boost::shared_ptr<MathMacroArgument> getArg(int i);
private:
///
boost::shared_ptr<MathMacroTemplate> tmplate_;
///
struct MacroArgumentBase {
///
MathedRowSt * row;
///
MathedArray array;
///
MacroArgumentBase()
: row(0)
{}
};
std::vector<MacroArgumentBase> args_;
//std::vector<boost::shared_ptr<MathMacroArgument> > args_;
std::vector<MathMacroArgument> args_;
///
int idx_;
///
int nargs_;
//int nargs_;
///
MathedTextCodes tcode_;
};

View File

@ -23,6 +23,10 @@ MathMacroTemplate::MathMacroTemplate(string const & nm, int na):
for (int i = 0; i < nargs_; ++i) {
args_.push_back(MathMacroArgument(i + 1));
}
//for (int i = 0; i < nargs_; ++i) {
// MathMacroArgument * ma = new MathMacroArgument(i + 1);
// args_.push_back(boost::shared_ptr<MathMacroArgument>(ma));
//}
} else {
tcode_ = LM_TC_INSET;
// Here is nargs != args_.size()
@ -86,7 +90,6 @@ void MathMacroTemplate::draw(Painter & pain, int x, int y)
MathParInset::draw(pain, x, y);
xo(x2);
yo(y2);
for (int i = 0; i < nargs_; ++i) {
args_[i].setExpand(expnd);
}
@ -107,24 +110,17 @@ void MathMacroTemplate::Metrics()
}
}
MathParInset::Metrics();
for (int i = 0; i < nargs_; ++i) {
args_[i].setExpand(expnd);
}
}
void MathMacroTemplate::update(MathMacro * macro)
void MathMacroTemplate::update(MathMacro const & macro)
{
Assert(macro);
int const idx = macro->getArgumentIdx();
for (int i = 0; i < nargs_; ++i) {
macro->setArgumentIdx(i);
args_[i].setData(macro->GetData());
MathedRowSt * row = macro->getRowSt();
args_[i].setRowSt(row);
}
macro->setArgumentIdx(idx);
args_[i] = macro.getArg(i);
}
}
@ -139,7 +135,8 @@ void MathMacroTemplate::WriteDef(ostream & os, bool fragile)
for (int i = 0; i < nargs_; ++i) {
args_[i].setExpand(false);
}
}
Write(os, fragile);
os << "}\n";
}
@ -153,10 +150,12 @@ void MathMacroTemplate::GetMacroXY(int i, int & x, int & y) const
MathParInset * MathMacroTemplate::getMacroPar(int i) const
{
if (i >= 0 && i < nargs_)
return const_cast<MathParInset *>
if (i >= 0 && i < nargs_) {
MathParInset * p = const_cast<MathParInset *>
(static_cast<MathParInset const *>(&args_[i]));
else
Assert(p);
return p;
} else
return 0;
}

View File

@ -5,6 +5,7 @@
#include <vector>
#include <boost/utility.hpp>
//#include <boost/smart_ptr.hpp>
#include "math_parinset.h"
#include "math_macroarg.h"
@ -20,6 +21,8 @@ class MathMacro;
*/
class MathMacroTemplate : public MathParInset, public noncopyable {
public:
friend class MathMacro;
/// A template constructor needs all the data
explicit
MathMacroTemplate(string const &, int na);
@ -45,13 +48,14 @@ public:
void setEditMode(bool);
/// Replace the appropriate arguments with a specific macro's data
void update(MathMacro * m);
void update(MathMacro const & m);
private:
/// Are we in edit mode or not?
bool edit_;
///
MathedTextCodes tcode_;
///
//std::vector<boost::shared_ptr<MathMacroArgument> > args_;
std::vector<MathMacroArgument> args_;
///
int nargs_;

View File

@ -763,16 +763,13 @@ void mathed_parse(MathedArray & array, unsigned flags = 0,
case LM_TK_PMOD:
case LM_TK_FUNC:
{
#warning This must leak. (Lgb)
// if (accent) this must leak... (Lgb)
MathedInset * bg = new MathFuncInset(yylval.l->name);
if (accent) {
data.insert(t, LM_TC_CONST);
} else
} else {
MathedInset * bg = new MathFuncInset(yylval.l->name);
data.insertInset(bg, LM_TC_INSET);
}
break;
}
case LM_TK_FUNCLIM:
data.insertInset(new MathFuncInset(yylval.l->name, LM_OT_FUNCLIM),