mathed28.diff

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1534 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Lars Gullik Bjønnes 2001-02-19 14:16:57 +00:00
parent f0c75a909e
commit 1dd613bb03
5 changed files with 103 additions and 5 deletions

View 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

View 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()
{

View 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);

View 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()) {

View 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: