]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/array.C
small cleanup, doxygen, formatting changes
[lyx.git] / src / mathed / array.C
index 6c7b9a5c42ce3dc97afc542611603728c0afc7c1..245b801a2f0f99f75a0cd678dbf3eca396aff7b4 100644 (file)
@@ -6,8 +6,6 @@
 #endif
 
 #include "array.h"
-#include "math_defs.h"
-
 
 // Is this still needed? (Lgb)
 static inline
@@ -20,6 +18,38 @@ void * my_memcpy(void * ps_in, void const * pt_in, size_t n)
 }
 
 
+MathedArray::MathedArray(int size)
+       : last_(0)
+{
+       int const newsize = (size < ARRAY_MIN_SIZE) ? ARRAY_MIN_SIZE : size;
+       bf_.resize(newsize);
+}
+
+
+MathedArray::iterator MathedArray::begin() 
+{
+       return bf_.begin();
+}
+
+
+MathedArray::iterator MathedArray::end() 
+{
+       return bf_.end();
+}
+
+
+MathedArray::const_iterator MathedArray::begin() const
+{
+       return bf_.begin();
+}
+
+
+MathedArray::const_iterator MathedArray::end() const
+{
+       return bf_.end();
+}
+
+
 int MathedArray::empty() const
 {
        return (last_ == 0);
@@ -38,9 +68,10 @@ void MathedArray::last(int l)
 }
 
 
-int MathedArray::maxsize() const
+void MathedArray::need_size(int needed)
 {
-       return maxsize_;
+       if (needed >= static_cast<int>(bf_.size()))
+               resize(needed);
 }
 
 
@@ -50,26 +81,16 @@ void MathedArray::resize(int newsize)
                newsize = ARRAY_MIN_SIZE;
        newsize += ARRAY_STEP - (newsize % ARRAY_STEP);
        bf_.resize(newsize);
-       if (last_ >= newsize) last_ = newsize - 1;
-       maxsize_ = newsize;
+       if (last_ >= newsize)
+               last_ = newsize - 1;
        bf_[last_] = 0;
 }
 
 
-MathedArray::MathedArray(int size) 
-{
-       maxsize_ = (size < ARRAY_MIN_SIZE) ? ARRAY_MIN_SIZE : size;
-       bf_.resize(maxsize_);
-       last_ = 0;
-}
-
-
 void MathedArray::move(int p, int shift)
 {
        if (p <= last_) {
-               if (last_ + shift >= maxsize_) { 
-                   resize(last_ + shift);
-               }
+               need_size(last_ + shift);
                memmove(&bf_[p + shift], &bf_[p], last_ - p);
                last_ += shift;
                bf_[last_] = 0;
@@ -77,10 +98,20 @@ void MathedArray::move(int p, int shift)
 }
 
 
+#if 0
+void MathedArray::insert(MathedArray::iterator pos,
+                        MathedArray::const_iterator beg,
+                        MathedArray::const_iterator end)
+{
+       bf_.insert(pos, beg, end);
+       last_ = bf_.size() - 1;
+}
+#else
 void MathedArray::mergeF(MathedArray * a, int p, int dx)
 {
        my_memcpy(&bf_[p], &a->bf_[0], dx);
 }
+#endif
 
 
 void MathedArray::raw_pointer_copy(MathedInset ** p, int pos) const
@@ -98,7 +129,7 @@ void MathedArray::raw_pointer_insert(void * p, int pos, int len)
 void MathedArray::strange_copy(MathedArray * dest, int dpos,
                                int spos, int len)
 {
-       my_memcpy(&dest[dpos], &bf_[spos], len);
+       my_memcpy(&dest->bf_[dpos], &bf_[spos], len);
 }
 
 
@@ -112,14 +143,3 @@ byte & MathedArray::operator[](int i)
 {
        return bf_[i];
 }
-
-
-void MathedArray::insert(int pos, byte c)
-{
-       if (pos < 0) pos = last_;
-       if (pos >= maxsize_) 
-               resize(maxsize_ + ARRAY_STEP);
-       bf_[pos] = c;
-       if (pos >= last_)
-               last_ = pos + 1;
-}