From 02ec9422d0498334c1ec601e54d7f25bab7e2a81 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Fri, 14 Sep 2001 14:05:57 +0000 Subject: [PATCH] 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 --- src/mathed/array.C | 26 ++++++++++---------------- src/mathed/array.h | 21 ++++++++++----------- src/mathed/math_inset.h | 3 +++ src/mathed/math_nestinset.C | 5 +++-- src/mathed/xarray.C | 18 +++++++++--------- src/mathed/xarray.h | 9 ++++++--- 6 files changed, 41 insertions(+), 41 deletions(-) diff --git a/src/mathed/array.C b/src/mathed/array.C index 2815e24b4e..cdf974e615 100644 --- a/src/mathed/array.C +++ b/src/mathed/array.C @@ -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); } diff --git a/src/mathed/array.h b/src/mathed/array.h index 939310945d..1112176647 100644 --- a/src/mathed/array.h +++ b/src/mathed/array.h @@ -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; /// diff --git a/src/mathed/math_inset.h b/src/mathed/math_inset.h index ed6c4c9591..f408a186e3 100644 --- a/src/mathed/math_inset.h +++ b/src/mathed/math_inset.h @@ -43,6 +43,9 @@ class MathScriptInset; class MathInset { public: + /// + typedef MathArray::size_type size_type; + /// MathInset(); /// the virtual base destructor diff --git a/src/mathed/math_nestinset.C b/src/mathed/math_nestinset.C index 3d1de5e64e..aae1db633d 100644 --- a/src/mathed/math_nestinset.C +++ b/src/mathed/math_nestinset.C @@ -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; } diff --git a/src/mathed/xarray.C b/src/mathed/xarray.C index 1a31caee9f..6842bb0051 100644 --- a/src/mathed/xarray.C +++ b/src/mathed/xarray.C @@ -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; diff --git a/src/mathed/xarray.h b/src/mathed/xarray.h index 0dc4ddcee9..5df0ea5b80 100644 --- a/src/mathed/xarray.h +++ b/src/mathed/xarray.h @@ -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_; } -- 2.39.5