]> git.lyx.org Git - features.git/commitdiff
use 'size_type' at least for container-like stuff
authorAndré Pönitz <poenitz@gmx.net>
Fri, 14 Sep 2001 14:05:57 +0000 (14:05 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Fri, 14 Sep 2001 14:05:57 +0000 (14:05 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2761 a592a061-630c-0410-9148-cb99ea01b6c8

src/mathed/array.C
src/mathed/array.h
src/mathed/math_inset.h
src/mathed/math_nestinset.C
src/mathed/xarray.C
src/mathed/xarray.h

index 2815e24b4e53e9b964d25c4828b3e7de677955c3..cdf974e615889e990e7a862f4d770d72a1b02c92 100644 (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);
 }
index 939310945da4a1b04b1a8a364c70c103190e67e1..11121766476bf6f8f71322f8a3d1c03cb63053f2 100644 (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;
        ///
index ed6c4c95917d09a0174b8dc23794c00343504ce3..f408a186e38c48c50f1e092a2369a44341c5a111 100644 (file)
@@ -43,6 +43,9 @@ class MathScriptInset;
 
 class MathInset {
 public: 
+       ///
+       typedef MathArray::size_type     size_type;
+
        ///
        MathInset();
        /// the virtual base destructor
index 3d1de5e64eda6427c324cef853ba2af916ae013e..aae1db633ddefaf81154da6a0e61a6cd91aa6f53 100644 (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;
 }
 
index 1a31caee9f13e93a55b62b91357318fa19939675..6842bb005192661d153efd2333ae3412fccbb19e 100644 (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;
index 0dc4ddcee95f6a7d4326e1d39337234d05d89d80..5df0ea5b809cfc5eba4febbc3251659e40b1d4b6 100644 (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_; }