We are crossing unsafe ground: This moves most parts of the "deep copy" from MathedIter to MathArray where it actually belongs. It's far from being nice and clean, but again I'd rather see it applied with this limited scope... Andre' -- André Pönitz ........................................ [EMAIL PROTECTED]
? .ChangeLog.swp ? .array.h.swp ? mathed25.diff ? .array.C.swp ? mathed26.diff Index: ChangeLog =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/ChangeLog,v retrieving revision 1.33 diff -u -p -u -r1.33 ChangeLog --- ChangeLog 2001/02/19 10:18:21 1.33 +++ ChangeLog 2001/02/19 12:14:24 @@ -1,3 +1,10 @@ + +2001-02-14 André Pönitz <[EMAIL PROTECTED]> + + * 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 <[EMAIL PROTECTED]> * array.[Ch]: remove constructor and enums ARRAY_MIN_SIZE and ARRAY_STEP Index: array.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/array.C,v retrieving revision 1.7 diff -u -p -u -r1.7 array.C --- array.C 2001/02/19 10:18:21 1.7 +++ array.C 2001/02/19 12:14:24 @@ -6,6 +6,8 @@ #endif #include "array.h" +#include "math_iter.h" +#include "math_inset.h" // Is this still needed? (Lgb) static inline @@ -21,6 +23,39 @@ void * my_memcpy(void * ps_in, void cons MathedArray::MathedArray() : bf_(1, 0), last_(0) {} + + +MathedArray::MathedArray(MathedArray const & array) +{ + operator=(array); +} + + +MathedArray & MathedArray::operator=(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 + 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(); + } + + return *this; +} MathedArray::iterator MathedArray::begin() Index: array.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/array.h,v retrieving revision 1.16 diff -u -p -u -r1.16 array.h --- array.h 2001/02/19 10:18:21 1.16 +++ array.h 2001/02/19 12:14:24 @@ -39,14 +39,18 @@ 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 &); /// iterator begin(); Index: math_iter.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_iter.C,v retrieving revision 1.35 diff -u -p -u -r1.35 math_iter.C --- math_iter.C 2001/02/19 10:18:21 1.35 +++ math_iter.C 2001/02/19 12:14:25 @@ -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) { @@ -423,6 +438,10 @@ MathedArray * MathedIter::Copy(int pos1, (*a)[dx] = '\0'; } 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()) { Index: math_iter.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_iter.h,v retrieving revision 1.24 diff -u -p -u -r1.24 math_iter.h --- math_iter.h 2001/02/17 18:52:53 1.24 +++ math_iter.h 2001/02/19 12:14:25 @@ -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: