2001-02-12 08:55:14 +00:00
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
2001-07-13 09:54:32 +00:00
|
|
|
#include "math_inset.h"
|
2001-08-03 17:10:22 +00:00
|
|
|
#include "math_charinset.h"
|
2001-04-24 16:13:38 +00:00
|
|
|
#include "debug.h"
|
2001-02-12 08:55:14 +00:00
|
|
|
#include "array.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
#include "math_scriptinset.h"
|
|
|
|
#include "mathed/support.h"
|
2001-02-12 08:55:14 +00:00
|
|
|
|
2001-06-27 15:57:57 +00:00
|
|
|
using std::ostream;
|
|
|
|
using std::endl;
|
2001-06-01 10:53:24 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
MathArray::MathArray()
|
|
|
|
{}
|
2001-06-01 10:53:24 +00:00
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
MathArray::~MathArray()
|
2001-02-12 08:55:14 +00:00
|
|
|
{
|
2001-08-01 09:18:21 +00:00
|
|
|
erase();
|
2001-02-12 08:55:14 +00:00
|
|
|
}
|
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
MathArray::MathArray(MathArray const & array)
|
|
|
|
: bf_(array.bf_)
|
|
|
|
{
|
2001-08-01 09:18:21 +00:00
|
|
|
deep_copy(0, size());
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
2001-02-14 17:50:58 +00:00
|
|
|
|
2001-08-01 09:18:21 +00:00
|
|
|
|
2001-07-16 15:53:25 +00:00
|
|
|
MathArray::MathArray(MathArray const & array, int from, int to)
|
|
|
|
: bf_(array.bf_.begin() + from, array.bf_.begin() + to)
|
|
|
|
{
|
2001-08-01 09:18:21 +00:00
|
|
|
deep_copy(0, size());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathArray::deep_copy(int pos1, int pos2)
|
|
|
|
{
|
2001-08-06 17:20:26 +00:00
|
|
|
for (int pos = pos1; pos < pos2; ++pos) {
|
|
|
|
MathInset * p = bf_[pos]->clone();
|
|
|
|
//lyxerr << "cloning: '" << bf_[pos] << " to " << p << "'\n";
|
|
|
|
bf_[pos] = p;
|
|
|
|
}
|
2001-07-16 15:53:25 +00:00
|
|
|
}
|
|
|
|
|
2001-02-19 18:29:10 +00:00
|
|
|
|
2001-08-06 17:20:26 +00:00
|
|
|
int MathArray::last() const
|
2001-02-19 14:16:57 +00:00
|
|
|
{
|
2001-08-06 17:20:26 +00:00
|
|
|
return size() - 1;
|
2001-02-19 14:16:57 +00:00
|
|
|
}
|
|
|
|
|
2001-05-08 10:50:09 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
void MathArray::substitute(MathMacro const & m)
|
|
|
|
{
|
|
|
|
MathArray tmp;
|
2001-08-03 17:10:22 +00:00
|
|
|
for (int pos = 0; pos < size(); ++pos)
|
|
|
|
bf_[pos]->substitute(tmp, m);
|
2001-06-25 00:06:33 +00:00
|
|
|
swap(tmp);
|
2001-04-24 16:13:38 +00:00
|
|
|
}
|
|
|
|
|
2001-02-19 14:16:57 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
MathArray & MathArray::operator=(MathArray const & array)
|
2001-02-19 14:16:57 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
MathArray tmp(array);
|
2001-02-19 14:16:57 +00:00
|
|
|
swap(tmp);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2001-05-08 10:50:09 +00:00
|
|
|
|
2001-08-06 17:20:26 +00:00
|
|
|
MathInset * MathArray::nextInset(int pos)
|
2001-04-27 12:35:55 +00:00
|
|
|
{
|
2001-08-03 17:10:22 +00:00
|
|
|
return (pos == size()) ? 0 : bf_[pos];
|
2001-04-27 12:35:55 +00:00
|
|
|
}
|
|
|
|
|
2001-08-01 09:18:21 +00:00
|
|
|
|
2001-08-06 17:20:26 +00:00
|
|
|
MathInset const * MathArray::nextInset(int pos) const
|
2001-07-12 07:18:29 +00:00
|
|
|
{
|
2001-08-06 17:20:26 +00:00
|
|
|
return (pos == size()) ? 0 : bf_[pos];
|
2001-07-12 07:18:29 +00:00
|
|
|
}
|
|
|
|
|
2001-07-24 11:39:38 +00:00
|
|
|
|
2001-07-26 09:01:36 +00:00
|
|
|
unsigned char MathArray::getChar(int pos) const
|
2001-04-27 12:35:55 +00:00
|
|
|
{
|
2001-08-03 17:10:22 +00:00
|
|
|
return (pos == size()) ? 0 : (bf_[pos]->getChar());
|
2001-04-27 12:35:55 +00:00
|
|
|
}
|
|
|
|
|
2001-07-24 11:39:38 +00:00
|
|
|
|
2001-07-26 09:01:36 +00:00
|
|
|
MathTextCodes MathArray::getCode(int pos) const
|
2001-02-20 13:16:07 +00:00
|
|
|
{
|
2001-08-03 17:10:22 +00:00
|
|
|
return pos < size() ? (bf_[pos]->code()) : LM_TC_MIN;
|
2001-02-20 13:16:07 +00:00
|
|
|
}
|
|
|
|
|
2001-07-24 11:39:38 +00:00
|
|
|
|
2001-07-03 07:56:55 +00:00
|
|
|
void MathArray::setCode(int pos, MathTextCodes t)
|
|
|
|
{
|
2001-08-03 17:10:22 +00:00
|
|
|
bf_[pos]->code(t);
|
2001-07-03 07:56:55 +00:00
|
|
|
}
|
|
|
|
|
2001-07-24 11:39:38 +00:00
|
|
|
|
2001-07-24 16:10:17 +00:00
|
|
|
void MathArray::insert(int pos, MathInset * p)
|
2001-02-14 17:50:58 +00:00
|
|
|
{
|
2001-08-03 17:10:22 +00:00
|
|
|
bf_.insert(bf_.begin() + pos, p);
|
2001-02-14 17:50:58 +00:00
|
|
|
}
|
|
|
|
|
2001-07-24 11:39:38 +00:00
|
|
|
|
2001-07-13 11:32:22 +00:00
|
|
|
void MathArray::insert(int pos, unsigned char b, MathTextCodes t)
|
2001-02-14 17:50:58 +00:00
|
|
|
{
|
2001-08-03 17:10:22 +00:00
|
|
|
bf_.insert(bf_.begin() + pos, new MathCharInset(b, t));
|
2001-02-14 17:50:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
void MathArray::insert(int pos, MathArray const & array)
|
2001-02-14 17:50:58 +00:00
|
|
|
{
|
2001-07-03 15:04:59 +00:00
|
|
|
bf_.insert(bf_.begin() + pos, array.bf_.begin(), array.bf_.end());
|
2001-08-01 09:18:21 +00:00
|
|
|
deep_copy(pos, pos + array.size());
|
2001-02-14 17:50:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
void MathArray::push_back(MathInset * p)
|
|
|
|
{
|
|
|
|
insert(size(), p);
|
2001-02-14 17:50:58 +00:00
|
|
|
}
|
|
|
|
|
2001-07-24 11:39:38 +00:00
|
|
|
|
2001-07-13 11:32:22 +00:00
|
|
|
void MathArray::push_back(unsigned char b, MathTextCodes c)
|
2001-02-12 08:55:14 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
insert(size(), b, c);
|
2001-02-12 08:55:14 +00:00
|
|
|
}
|
|
|
|
|
2001-07-24 11:39:38 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
void MathArray::push_back(MathArray const & array)
|
2001-02-12 08:55:14 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
insert(size(), array);
|
2001-02-12 08:55:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
void MathArray::clear()
|
2001-02-12 11:25:44 +00:00
|
|
|
{
|
2001-08-01 09:18:21 +00:00
|
|
|
erase();
|
2001-02-12 08:55:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
void MathArray::swap(MathArray & array)
|
2001-02-12 08:55:14 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
if (this != &array)
|
|
|
|
bf_.swap(array.bf_);
|
2001-02-12 08:55:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
bool MathArray::empty() const
|
2001-02-12 08:55:14 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
return bf_.empty();
|
2001-02-12 08:55:14 +00:00
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2001-02-12 08:55:14 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
int MathArray::size() const
|
2001-02-20 13:16:07 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
return bf_.size();
|
2001-02-20 13:16:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-16 15:53:25 +00:00
|
|
|
void MathArray::erase()
|
|
|
|
{
|
|
|
|
erase(0, size());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
void MathArray::erase(int pos)
|
2001-02-14 17:50:58 +00:00
|
|
|
{
|
2001-08-03 17:10:22 +00:00
|
|
|
if (pos < size())
|
2001-08-07 12:02:21 +00:00
|
|
|
erase(pos, pos + 1);
|
2001-02-14 17:50:58 +00:00
|
|
|
}
|
2001-02-12 08:55:14 +00:00
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
void MathArray::erase(int pos1, int pos2)
|
2001-02-12 08:55:14 +00:00
|
|
|
{
|
2001-08-03 17:10:22 +00:00
|
|
|
for (int pos = pos1; pos < pos2; ++pos)
|
2001-08-07 12:02:21 +00:00
|
|
|
delete bf_[pos];
|
2001-06-25 00:06:33 +00:00
|
|
|
bf_.erase(bf_.begin() + pos1, bf_.begin() + pos2);
|
2001-02-12 08:55:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-03 17:10:22 +00:00
|
|
|
MathInset * MathArray::back() const
|
2001-02-17 18:52:53 +00:00
|
|
|
{
|
2001-08-06 17:20:26 +00:00
|
|
|
return size() ? bf_.back() : 0;
|
2001-02-17 18:52:53 +00:00
|
|
|
}
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
|
|
void MathArray::dump2(ostream & os) const
|
2001-02-12 08:55:14 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
for (buffer_type::const_iterator it = bf_.begin(); it != bf_.end(); ++it)
|
2001-08-06 17:20:26 +00:00
|
|
|
os << *it << ' ';
|
2001-02-12 08:55:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
void MathArray::dump(ostream & os) const
|
2001-02-12 08:55:14 +00:00
|
|
|
{
|
2001-08-03 17:10:22 +00:00
|
|
|
for (int pos = 0; pos < size(); ++pos)
|
|
|
|
os << "<" << nextInset(pos) << ">";
|
2001-02-12 08:55:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
std::ostream & operator<<(std::ostream & os, MathArray const & ar)
|
2001-02-12 08:55:14 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
ar.dump2(os);
|
|
|
|
return os;
|
2001-02-12 08:55:14 +00:00
|
|
|
}
|
2001-02-28 17:21:16 +00:00
|
|
|
|
|
|
|
|
2001-07-26 06:56:43 +00:00
|
|
|
void MathArray::write(ostream & os, bool fragile) const
|
2001-02-28 17:21:16 +00:00
|
|
|
{
|
2001-08-03 17:10:22 +00:00
|
|
|
for (int pos = 0; pos < size(); ++pos)
|
|
|
|
nextInset(pos)->write(os, fragile);
|
2001-02-28 17:21:16 +00:00
|
|
|
}
|
|
|
|
|
2001-05-08 10:50:09 +00:00
|
|
|
|
2001-07-26 06:56:43 +00:00
|
|
|
void MathArray::writeNormal(ostream & os) const
|
2001-04-24 16:13:38 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
if (empty()) {
|
|
|
|
os << "[par] ";
|
|
|
|
return;
|
2001-04-24 16:13:38 +00:00
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2001-07-26 06:56:43 +00:00
|
|
|
write(os, true);
|
2001-04-24 16:13:38 +00:00
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2001-07-13 14:54:56 +00:00
|
|
|
|
2001-07-26 06:56:43 +00:00
|
|
|
void MathArray::validate(LaTeXFeatures & features) const
|
2001-07-13 14:54:56 +00:00
|
|
|
{
|
2001-08-03 17:10:22 +00:00
|
|
|
for (int pos = 0; pos < size(); ++pos)
|
|
|
|
nextInset(pos)->validate(features);
|
2001-07-13 14:54:56 +00:00
|
|
|
}
|
|
|
|
|
2001-07-26 06:46:50 +00:00
|
|
|
|
|
|
|
void MathArray::pop_back()
|
|
|
|
{
|
2001-08-06 17:20:26 +00:00
|
|
|
if (!size()) {
|
|
|
|
lyxerr << "pop_back from empty array!\n";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
delete back();
|
|
|
|
bf_.pop_back();
|
2001-07-26 06:46:50 +00:00
|
|
|
}
|
|
|
|
|