]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/array.C
mathed58.diff
[lyx.git] / src / mathed / array.C
index eba96ab49546616a7ac21e63d35352959502626b..bc5b02596d7fb8a7704f6c016ce97a8cbc988018 100644 (file)
@@ -9,7 +9,11 @@
 #include "math_iter.h"
 #include "math_inset.h"
 
-// Is this still needed? (Lgb)
+#include "support/LOstream.h"
+
+using std::ostream;
+using std::endl;
+
 static inline
 void * my_memcpy(void * ps_in, void const * pt_in, size_t n)
 {
@@ -55,13 +59,17 @@ MathedArray::MathedArray(MathedArray const & array)
        last_ = array.last_;
 
        // deep copy
-       // we'll not yet get exeption safety
+       deep_copy();
+}
+
+void MathedArray::deep_copy()
+{
        MathedIter it(this);
        while (it.OK()) {
                if (it.IsInset()) {
                        MathedInset * inset = it.GetInset();
                        inset = inset->Clone();
-                       raw_pointer_insert(inset, it.getPos() + 1, sizeof(inset));
+                       raw_pointer_insert(inset, it.getPos() + 1);
                }
                it.Next();
        }
@@ -195,18 +203,8 @@ void MathedArray::shrink(int pos1, int pos2)
        a.last(dx);
        a[dx] = '\0';
 
-       MathedIter it(&a);
-       it.Reset();
-
-       while (it.OK()) {
-               if (it.IsInset()) {
-                       MathedInset * inset = it.GetInset();
-                       inset = inset->Clone();
-                       a.raw_pointer_insert(inset, it.getPos() + 1, sizeof(inset));
-               }
-               it.Next();
-       }
        swap(a);
+       deep_copy();
 }
 
 
@@ -256,9 +254,9 @@ MathedInset * MathedArray::getInset(int pos)
 }
 
 #else
-void MathedArray::raw_pointer_insert(void * p, int pos, int len)
+void MathedArray::raw_pointer_insert(void * p, int pos)
 {
-       my_memcpy(&bf_[pos], &p, len);
+       my_memcpy(&bf_[pos], &p, sizeof(p));
 }
 #endif
 
@@ -280,3 +278,16 @@ byte & MathedArray::operator[](int i)
 {
        return bf_[i];
 }
+
+
+void MathedArray::dump(ostream & os) const
+{
+       buffer_type::const_iterator cit = bf_.begin();
+       buffer_type::const_iterator end = bf_.end();
+       for (; cit != end; ++cit) {
+               os << (*cit);
+       }
+       os << endl;
+}
+
+