]> git.lyx.org Git - features.git/commitdiff
mathed28.diff
authorLars Gullik Bjønnes <larsbj@gullik.org>
Mon, 19 Feb 2001 14:16:57 +0000 (14:16 +0000)
committerLars Gullik Bjønnes <larsbj@gullik.org>
Mon, 19 Feb 2001 14:16:57 +0000 (14:16 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1534 a592a061-630c-0410-9148-cb99ea01b6c8

src/mathed/ChangeLog
src/mathed/array.C
src/mathed/array.h
src/mathed/math_iter.C
src/mathed/math_iter.h

index ba1fe6514e4db2f80a6868bd7e2ca0a22e8e97a5..7d29a422e29378461a0831d02a56dc3c1c147c80 100644 (file)
@@ -1,3 +1,10 @@
+
+2001-02-14  André Pönitz  <poenitz@htwm.de>
+
+       * array.[Ch]: "deep" copy constructor and assignment operator for MathArray
+
+       * math_iter.[Ch]: seperate Copy() from Copy(int, int)
+
 2001-02-14  André Pönitz  <poenitz@htwm.de>
 
        * array.[Ch]: remove constructor and  enums ARRAY_MIN_SIZE and ARRAY_STEP
index 4d42317fd75de97d67c6b06862136ec1aa638fdf..661fee1ae8d729f8b97ebb5c5a21e6614460e7e4 100644 (file)
@@ -6,6 +6,8 @@
 #endif
 
 #include "array.h"
+#include "math_iter.h"
+#include "math_inset.h"
 
 // Is this still needed? (Lgb)
 static inline
@@ -22,6 +24,65 @@ MathedArray::MathedArray()
        : bf_(1, 0), last_(0)
 {}
 
+MathedArray::~MathedArray()
+{
+       // deep destruction
+       // let's leak for a while... 
+/*
+       MathedIter it;
+       it.SetData(this);
+       while (it.OK()) {
+               if (it.IsInset()) {
+                       MathedInset * inset = it.GetInset();
+                       delete inset;
+               }
+               it.Next();
+       }
+*/
+}
+
+
+MathedArray::MathedArray(MathedArray const & array)
+{
+       // this "implementation" is obviously wrong: MathedIter should be
+       // implemented by MathedArray (not the other way round) but I think
+       // getting the _interface_ of MathedArray right is more important right
+       // now (Andre')
+
+       // shallow copy
+       bf_   = array.bf_;
+       last_ = array.last_;
+
+       // deep copy
+       // we'll not yet get exeption safety
+       MathedIter it;
+       it.SetData(this);
+       while (it.OK()) {
+               if (it.IsInset()) {
+                       MathedInset * inset = it.GetInset();
+                       inset = inset->Clone();
+                       raw_pointer_insert(inset, it.getPos() + 1, sizeof(inset));
+               }
+               it.Next();
+       }
+}
+
+
+MathedArray & MathedArray::operator=(MathedArray const & array)
+{
+       MathedArray tmp(array);
+       swap(tmp);
+       return *this;
+}
+
+void MathedArray::swap(MathedArray & array)
+{
+       if (this != &array) {
+               bf_.swap(array.bf_);
+               std::swap(last_, array.last_);
+       }
+}
+
 
 MathedArray::iterator MathedArray::begin() 
 {
index c9cff48a7137d594f492dbe3ad2ce0ff3d17aeda..16cba293b9cc1d117e675e8c9b2d2b119a35d68c 100644 (file)
@@ -39,14 +39,20 @@ class MathedInset;
 class MathedArray  {
 public:
        ///
-       typedef std::vector<byte>         buffer_type;
-       typedef byte                      value_type;
-       typedef buffer_type::size_type    size_type;
-       typedef buffer_type::iterator iterator;
+       typedef std::vector<byte>           buffer_type;
+       typedef byte                        value_type;
+       typedef buffer_type::size_type      size_type;
+       typedef buffer_type::iterator       iterator;
        typedef buffer_type::const_iterator const_iterator;
        
        ///
        MathedArray();
+       ///
+       MathedArray(MathedArray const &);
+       ///
+       MathedArray & operator=(MathedArray const &);
+       ///
+       ~MathedArray();
 
        ///
        iterator begin();
@@ -65,6 +71,9 @@ public:
        ///
        void last(int l);
 
+       ///
+       void swap(MathedArray &);
+
 #if 0
        ///
        void insert(iterator pos, const_iterator beg, const_iterator end);
index 2f5dfcb8420471c9f546f16103427cd671d6894d..4a467a4b579c1b5fac871f85d4f51feab7f87198 100644 (file)
@@ -381,6 +381,21 @@ bool MathedIter::Delete()
 }
 
 
+MathedArray * MathedIter::Copy()
+{
+#if 0
+       return Copy(0, 10000);
+#else
+       if (!array) {
+       //      lyxerr << "Math error: Attempting to copy a void array." << endl;
+               return 0;
+       }
+
+       return new MathedArray(*array);
+#endif
+}
+
+
 MathedArray * MathedIter::Copy(int pos1, int pos2)
 {
        if (!array) {
@@ -424,6 +439,10 @@ MathedArray * MathedIter::Copy(int pos1, int pos2)
        } else
                a = new MathedArray(*array);
 
+       // this should be unnecessary and leak in some (most?) cases since
+       // a = new MathedArray(*array);  makes already a deep copy...
+       // I guess it'll go soon... (Andre')
+
        SetData(a);
        while (OK()) {
                if (IsInset()) {
index a16de18776dccba0f457e09bc4392c37e01780b2..db8487ef7057d88d69552577a8085de923c04177 100644 (file)
@@ -112,8 +112,10 @@ public:
        void SetData(MathedArray * a);
        ///
        MathedArray * GetData() const;
+       /// Copy every object 
+       MathedArray * Copy();
        /// Copy every object from position p1 to p2
-       MathedArray * Copy(int p1 = 0, int p2 = 10000);
+       MathedArray * Copy(int p1, int p2);
        /// Delete every object from position p1 to p2
        void Clear();
 protected: