2001-02-12 08:55:14 +00:00
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "array.h"
|
2001-02-19 14:16:57 +00:00
|
|
|
#include "math_iter.h"
|
|
|
|
#include "math_inset.h"
|
2001-02-12 08:55:14 +00:00
|
|
|
|
|
|
|
// Is this still needed? (Lgb)
|
|
|
|
static inline
|
|
|
|
void * my_memcpy(void * ps_in, void const * pt_in, size_t n)
|
|
|
|
{
|
|
|
|
char * ps = static_cast<char *>(ps_in);
|
|
|
|
char const * pt = static_cast<char const *>(pt_in);
|
|
|
|
while (n--) *ps++ = *pt++;
|
|
|
|
return ps_in;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-19 10:18:21 +00:00
|
|
|
MathedArray::MathedArray()
|
2001-02-19 17:33:14 +00:00
|
|
|
: bf_(1, '\0'), last_(0)
|
2001-02-19 10:18:21 +00:00
|
|
|
{}
|
2001-02-14 17:50:58 +00:00
|
|
|
|
2001-02-19 18:29:10 +00:00
|
|
|
|
2001-02-19 14:16:57 +00:00
|
|
|
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
|
2001-02-19 18:29:10 +00:00
|
|
|
MathedIter it(this);
|
2001-02-19 14:16:57 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2001-02-20 13:16:07 +00:00
|
|
|
void MathedArray::clear()
|
|
|
|
{
|
|
|
|
last_ = 0;
|
|
|
|
bf_.resize(1);
|
|
|
|
bf_[0] = 0;
|
|
|
|
}
|
|
|
|
|
2001-02-19 14:16:57 +00:00
|
|
|
void MathedArray::swap(MathedArray & array)
|
|
|
|
{
|
|
|
|
if (this != &array) {
|
|
|
|
bf_.swap(array.bf_);
|
|
|
|
std::swap(last_, array.last_);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-14 17:50:58 +00:00
|
|
|
|
|
|
|
MathedArray::iterator MathedArray::begin()
|
|
|
|
{
|
|
|
|
return bf_.begin();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathedArray::iterator MathedArray::end()
|
|
|
|
{
|
|
|
|
return bf_.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathedArray::const_iterator MathedArray::begin() const
|
|
|
|
{
|
|
|
|
return bf_.begin();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathedArray::const_iterator MathedArray::end() const
|
|
|
|
{
|
|
|
|
return bf_.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-12 08:55:14 +00:00
|
|
|
int MathedArray::empty() const
|
|
|
|
{
|
|
|
|
return (last_ == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int MathedArray::last() const
|
|
|
|
{
|
|
|
|
return last_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathedArray::last(int l)
|
|
|
|
{
|
|
|
|
last_ = l;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-12 11:25:44 +00:00
|
|
|
void MathedArray::need_size(int needed)
|
|
|
|
{
|
2001-02-14 17:50:58 +00:00
|
|
|
if (needed >= static_cast<int>(bf_.size()))
|
2001-02-12 11:25:44 +00:00
|
|
|
resize(needed);
|
2001-02-12 08:55:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathedArray::resize(int newsize)
|
|
|
|
{
|
2001-02-19 10:18:21 +00:00
|
|
|
// still a bit smelly...
|
|
|
|
++newsize;
|
|
|
|
bf_.resize(newsize + 1);
|
2001-02-14 17:50:58 +00:00
|
|
|
if (last_ >= newsize)
|
|
|
|
last_ = newsize - 1;
|
2001-02-12 08:55:14 +00:00
|
|
|
bf_[last_] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathedArray::move(int p, int shift)
|
|
|
|
{
|
|
|
|
if (p <= last_) {
|
2001-02-12 11:25:44 +00:00
|
|
|
need_size(last_ + shift);
|
2001-02-12 08:55:14 +00:00
|
|
|
memmove(&bf_[p + shift], &bf_[p], last_ - p);
|
|
|
|
last_ += shift;
|
|
|
|
bf_[last_] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-20 13:16:07 +00:00
|
|
|
|
|
|
|
void MathedArray::shrink(int pos1, int pos2)
|
|
|
|
{
|
|
|
|
if (pos1 == 0 && pos2 >= last())
|
|
|
|
return;
|
|
|
|
|
|
|
|
short fc = 0;
|
|
|
|
if (pos1 > 0 && bf_[pos1] > ' ') {
|
|
|
|
for (int p = pos1; p >= 0; --p) {
|
|
|
|
if (MathIsFont(bf_[p])) {
|
|
|
|
if (p != pos1 - 1)
|
|
|
|
fc = bf_[p];
|
|
|
|
else
|
|
|
|
--pos1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pos2 > 0 && bf_[pos2] >= ' ' && MathIsFont(bf_[pos2 - 1]))
|
|
|
|
--pos2;
|
|
|
|
|
|
|
|
int dx = pos2 - pos1;
|
|
|
|
MathedArray a;
|
|
|
|
a.resize(dx + 1);
|
|
|
|
strange_copy(&a, (fc) ? 1 : 0, pos1, dx);
|
|
|
|
if (fc) {
|
|
|
|
a[0] = fc;
|
|
|
|
++dx;
|
|
|
|
}
|
|
|
|
a.last(dx);
|
|
|
|
a[dx] = '\0';
|
|
|
|
|
|
|
|
MathedIter it(&a);
|
|
|
|
it.Reset();
|
|
|
|
|
|
|
|
while (it.OK()) {
|
|
|
|
if (it.IsInset()) {
|
|
|
|
MathedInset * inset = it.GetInset();
|
|
|
|
inset = inset->Clone();
|
|
|
|
a.raw_pointer_insert(inset, it.getPos() + 1, sizeof(inset));
|
|
|
|
}
|
|
|
|
it.Next();
|
|
|
|
}
|
|
|
|
swap(a);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-14 17:50:58 +00:00
|
|
|
#if 0
|
|
|
|
void MathedArray::insert(MathedArray::iterator pos,
|
|
|
|
MathedArray::const_iterator beg,
|
|
|
|
MathedArray::const_iterator end)
|
|
|
|
{
|
|
|
|
bf_.insert(pos, beg, end);
|
|
|
|
last_ = bf_.size() - 1;
|
|
|
|
}
|
|
|
|
#else
|
2001-02-20 18:32:18 +00:00
|
|
|
void MathedArray::merge(MathedArray const & a, int p)
|
2001-02-12 08:55:14 +00:00
|
|
|
{
|
2001-02-20 18:32:18 +00:00
|
|
|
my_memcpy(&bf_[p], &a.bf_[0], a.last());
|
2001-02-12 08:55:14 +00:00
|
|
|
}
|
2001-02-14 17:50:58 +00:00
|
|
|
#endif
|
2001-02-12 08:55:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
void MathedArray::raw_pointer_copy(MathedInset ** p, int pos) const
|
|
|
|
{
|
|
|
|
my_memcpy(p, &bf_[pos], sizeof(MathedInset*));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-17 18:52:53 +00:00
|
|
|
#if 0
|
|
|
|
void MathedArray::insertInset(int pos, MathedInset * p, int type)
|
|
|
|
{
|
|
|
|
//bf_.insert(pos, type);
|
|
|
|
InsetTable tmp(pos, p);
|
|
|
|
insetList_.push_back(tmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathedInset * MathedArray::getInset(int pos)
|
|
|
|
{
|
|
|
|
InsetList::const_iterator cit = insetList_.begin();
|
|
|
|
InsetList::const_iterator end = insetList_.end();
|
|
|
|
for (; cit != end; ++cit) {
|
|
|
|
if ((*cit).pos == pos)
|
|
|
|
return (*cit).inset;
|
|
|
|
}
|
|
|
|
// not found
|
|
|
|
return 0;
|
|
|
|
// We would really like to throw an exception instead... (Lgb)
|
|
|
|
// throw inset_not_found();
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
2001-02-12 08:55:14 +00:00
|
|
|
void MathedArray::raw_pointer_insert(void * p, int pos, int len)
|
|
|
|
{
|
|
|
|
my_memcpy(&bf_[pos], &p, len);
|
|
|
|
}
|
2001-02-17 18:52:53 +00:00
|
|
|
#endif
|
2001-02-12 08:55:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
void MathedArray::strange_copy(MathedArray * dest, int dpos,
|
|
|
|
int spos, int len)
|
|
|
|
{
|
2001-02-13 13:28:32 +00:00
|
|
|
my_memcpy(&dest->bf_[dpos], &bf_[spos], len);
|
2001-02-12 08:55:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
byte MathedArray::operator[](int i) const
|
|
|
|
{
|
|
|
|
return bf_[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
byte & MathedArray::operator[](int i)
|
|
|
|
{
|
|
|
|
return bf_[i];
|
|
|
|
}
|