2001-02-12 08:55:14 +00:00
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "array.h"
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int MathedArray::empty() const
|
|
|
|
{
|
|
|
|
return (last_ == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int MathedArray::last() const
|
|
|
|
{
|
|
|
|
return last_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathedArray::last(int l)
|
|
|
|
{
|
|
|
|
last_ = l;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int MathedArray::maxsize() const
|
|
|
|
{
|
2001-02-12 11:25:44 +00:00
|
|
|
return static_cast<int>(bf_.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathedArray::need_size(int needed)
|
|
|
|
{
|
|
|
|
if (needed >= maxsize())
|
|
|
|
resize(needed);
|
2001-02-12 08:55:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathedArray::resize(int newsize)
|
|
|
|
{
|
|
|
|
if (newsize < ARRAY_MIN_SIZE)
|
|
|
|
newsize = ARRAY_MIN_SIZE;
|
|
|
|
newsize += ARRAY_STEP - (newsize % ARRAY_STEP);
|
|
|
|
bf_.resize(newsize);
|
|
|
|
if (last_ >= newsize) last_ = newsize - 1;
|
|
|
|
bf_[last_] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathedArray::MathedArray(int size)
|
|
|
|
{
|
2001-02-12 11:25:44 +00:00
|
|
|
int newsize = (size < ARRAY_MIN_SIZE) ? ARRAY_MIN_SIZE : size;
|
|
|
|
bf_.resize(newsize);
|
2001-02-12 08:55:14 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathedArray::mergeF(MathedArray * a, int p, int dx)
|
|
|
|
{
|
|
|
|
my_memcpy(&bf_[p], &a->bf_[0], dx);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathedArray::raw_pointer_copy(MathedInset ** p, int pos) const
|
|
|
|
{
|
|
|
|
my_memcpy(p, &bf_[pos], sizeof(MathedInset*));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathedArray::raw_pointer_insert(void * p, int pos, int len)
|
|
|
|
{
|
|
|
|
my_memcpy(&bf_[pos], &p, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathedArray::insert(int pos, byte c)
|
|
|
|
{
|
|
|
|
if (pos < 0) pos = last_;
|
2001-02-12 11:25:44 +00:00
|
|
|
|
|
|
|
// I think this should be replaced by need_size(pos). Note that the
|
|
|
|
// current code looks troublesome if pos > maxsize() + ARRAY_STEP.
|
|
|
|
if (pos >= maxsize())
|
|
|
|
resize(maxsize() + ARRAY_STEP);
|
2001-02-12 08:55:14 +00:00
|
|
|
bf_[pos] = c;
|
|
|
|
if (pos >= last_)
|
|
|
|
last_ = pos + 1;
|
|
|
|
}
|