From 1dd613bb03935714b44d8c94b9e51add0a9549e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Gullik=20Bj=C3=B8nnes?= Date: Mon, 19 Feb 2001 14:16:57 +0000 Subject: [PATCH] mathed28.diff git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1534 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/ChangeLog | 7 +++++ src/mathed/array.C | 61 ++++++++++++++++++++++++++++++++++++++++++ src/mathed/array.h | 17 +++++++++--- src/mathed/math_iter.C | 19 +++++++++++++ src/mathed/math_iter.h | 4 ++- 5 files changed, 103 insertions(+), 5 deletions(-) diff --git a/src/mathed/ChangeLog b/src/mathed/ChangeLog index ba1fe6514e..7d29a422e2 100644 --- a/src/mathed/ChangeLog +++ b/src/mathed/ChangeLog @@ -1,3 +1,10 @@ + +2001-02-14 André Pönitz + + * 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 * array.[Ch]: remove constructor and enums ARRAY_MIN_SIZE and ARRAY_STEP diff --git a/src/mathed/array.C b/src/mathed/array.C index 4d42317fd7..661fee1ae8 100644 --- a/src/mathed/array.C +++ b/src/mathed/array.C @@ -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() { diff --git a/src/mathed/array.h b/src/mathed/array.h index c9cff48a71..16cba293b9 100644 --- a/src/mathed/array.h +++ b/src/mathed/array.h @@ -39,14 +39,20 @@ class MathedInset; class MathedArray { public: /// - typedef std::vector buffer_type; - typedef byte value_type; - typedef buffer_type::size_type size_type; - typedef buffer_type::iterator iterator; + typedef std::vector 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); diff --git a/src/mathed/math_iter.C b/src/mathed/math_iter.C index 2f5dfcb842..4a467a4b57 100644 --- a/src/mathed/math_iter.C +++ b/src/mathed/math_iter.C @@ -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()) { diff --git a/src/mathed/math_iter.h b/src/mathed/math_iter.h index a16de18776..db8487ef70 100644 --- a/src/mathed/math_iter.h +++ b/src/mathed/math_iter.h @@ -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: