use 'size_type' at least for container-like stuff

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2761 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2001-09-14 14:05:57 +00:00
parent 72cc3e1f65
commit 02ec9422d0
6 changed files with 41 additions and 41 deletions

View File

@ -17,17 +17,11 @@ MathArray::MathArray()
{}
MathArray::MathArray(MathArray const & array, int from, int to)
MathArray::MathArray(MathArray const & array, size_type from, size_type to)
: bf_(array.begin() + from, array.begin() + to)
{}
int MathArray::last() const
{
return size() - 1;
}
void MathArray::substitute(MathMacro const & m)
{
for (iterator it = begin(); it != end(); ++it)
@ -35,19 +29,19 @@ void MathArray::substitute(MathMacro const & m)
}
MathAtom * MathArray::at(int pos)
MathAtom * MathArray::at(size_type pos)
{
return (0 <= pos && pos < size()) ? &bf_[pos] : 0;
return pos < size() ? &bf_[pos] : 0;
}
MathAtom const * MathArray::at(int pos) const
MathAtom const * MathArray::at(size_type pos) const
{
return (0 <= pos && pos < size()) ? &bf_[pos] : 0;
return pos < size() ? &bf_[pos] : 0;
}
void MathArray::insert(int pos, MathInset * p)
void MathArray::insert(size_type pos, MathInset * p)
{
//cerr << "\n 1: "; p->write(cerr, true); cerr << p << "\n";
// inserting here invalidates the pointer!
@ -56,7 +50,7 @@ void MathArray::insert(int pos, MathInset * p)
}
void MathArray::insert(int pos, MathArray const & array)
void MathArray::insert(size_type pos, MathArray const & array)
{
bf_.insert(begin() + pos, array.begin(), array.end());
}
@ -93,7 +87,7 @@ bool MathArray::empty() const
}
int MathArray::size() const
MathArray::size_type MathArray::size() const
{
return bf_.size();
}
@ -105,14 +99,14 @@ void MathArray::erase()
}
void MathArray::erase(int pos)
void MathArray::erase(size_type pos)
{
if (pos < size())
erase(pos, pos + 1);
}
void MathArray::erase(int pos1, int pos2)
void MathArray::erase(size_type pos1, size_type pos2)
{
bf_.erase(begin() + pos1, begin() + pos2);
}

View File

@ -45,15 +45,17 @@ public:
typedef buffer_type::const_iterator const_iterator;
///
typedef buffer_type::iterator iterator;
///
typedef buffer_type::size_type size_type;
public:
///
MathArray();
///
MathArray(MathArray const &, int from, int to);
MathArray(MathArray const &, size_type from, size_type to);
///
int size() const;
size_type size() const;
///
bool empty() const;
///
@ -62,19 +64,16 @@ public:
void swap(MathArray &);
///
void insert(int pos, MathInset * inset);
void insert(size_type pos, MathInset * inset);
///
void insert(int pos, MathArray const &);
void insert(size_type pos, MathArray const &);
///
void erase(int pos1, int pos2);
void erase(size_type pos1, size_type pos2);
///
void erase(int pos);
void erase(size_type pos);
///
void erase();
///
int last() const;
///
void push_back(MathInset * inset);
@ -93,9 +92,9 @@ public:
void substitute(MathMacro const &);
///
MathAtom * at(int pos);
MathAtom * at(size_type pos);
///
MathAtom const * at(int pos) const;
MathAtom const * at(size_type pos) const;
///
void write(std::ostream &, bool) const;
///

View File

@ -43,6 +43,9 @@ class MathScriptInset;
class MathInset {
public:
///
typedef MathArray::size_type size_type;
///
MathInset();
/// the virtual base destructor

View File

@ -128,10 +128,11 @@ bool MathNestInset::idxHome(int & /* idx */, int & pos) const
bool MathNestInset::idxEnd(int & idx, int & pos) const
{
if (pos == cell(idx).size())
int n = cell(idx).size();
if (pos == n)
return false;
pos = cell(idx).size();
pos = n;
return true;
}

View File

@ -29,7 +29,7 @@ void MathXArray::metrics(MathStyles st) const
width_ = 0;
//lyxerr << "MathXArray::metrics(): '" << data_ << "'\n";
for (int pos = 0; pos < data_.size(); ++pos) {
for (size_type pos = 0; pos < data_.size(); ++pos) {
MathAtom const * p = data_.at(pos);
p->metrics(st);
ascent_ = std::max(ascent_, p->ascent());
@ -51,7 +51,7 @@ void MathXArray::draw(Painter & pain, int x, int y) const
return;
}
for (int pos = 0; pos < data_.size(); ++pos) {
for (size_type pos = 0; pos < data_.size(); ++pos) {
MathAtom const * p = data_.at(pos);
p->draw(pain, x, y);
x += p->width();
@ -59,21 +59,21 @@ void MathXArray::draw(Painter & pain, int x, int y) const
}
int MathXArray::pos2x(int targetpos) const
int MathXArray::pos2x(size_type targetpos) const
{
int x = 0;
targetpos = std::min(targetpos, data_.size());
for (int pos = 0; pos < targetpos; ++pos)
for (size_type pos = 0; pos < targetpos; ++pos)
x += width(pos);
return x;
}
int MathXArray::x2pos(int targetx) const
MathArray::size_type MathXArray::x2pos(int targetx) const
{
int pos = 0;
int lastx = 0;
int currx = 0;
size_type pos = 0;
int lastx = 0;
int currx = 0;
for ( ; currx < targetx && pos < data_.size(); ++pos) {
lastx = currx;
currx += width(pos);
@ -84,7 +84,7 @@ int MathXArray::x2pos(int targetx) const
}
int MathXArray::width(int pos) const
int MathXArray::width(size_type pos) const
{
MathAtom const * t = data_.at(pos);
return t ? t->width() : 0;

View File

@ -16,6 +16,9 @@ class Painter;
class MathXArray
{
public:
///
typedef MathArray::size_type size_type;
///
MathXArray();
///
@ -28,11 +31,11 @@ public:
///
int yo() const { return yo_; }
///
int pos2x(int pos) const;
int pos2x(size_type pos) const;
///
int x2pos(int pos) const;
size_type x2pos(int pos) const;
///
int width(int pos) const;
int width(size_type pos) const;
///
int ascent() const { return ascent_; }