+
+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
#endif
#include "array.h"
+#include "math_iter.h"
+#include "math_inset.h"
// Is this still needed? (Lgb)
static inline
: 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()
{
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();
///
void last(int l);
+ ///
+ void swap(MathedArray &);
+
#if 0
///
void insert(iterator pos, const_iterator beg, const_iterator end);
}
+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) {
} 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()) {
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: