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-17 13:18:10 +00:00
|
|
|
#include "math_charinset.h"
|
2001-09-11 10:58:17 +00:00
|
|
|
#include "math_scriptinset.h"
|
2001-11-05 17:08:45 +00:00
|
|
|
#include "math_stringinset.h"
|
2001-11-08 12:06:56 +00:00
|
|
|
#include "math_mathmlstream.h"
|
2001-11-08 12:15:12 +00:00
|
|
|
#include "math_support.h"
|
2001-04-24 16:13:38 +00:00
|
|
|
#include "debug.h"
|
2001-02-12 08:55:14 +00:00
|
|
|
#include "array.h"
|
2001-10-12 12:02:49 +00:00
|
|
|
#include "support/LAssert.h"
|
2001-02-12 08:55:14 +00:00
|
|
|
|
2001-11-07 08:51:35 +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-09-14 14:05:57 +00:00
|
|
|
MathArray::MathArray(MathArray const & array, size_type from, size_type to)
|
2001-08-09 08:53:16 +00:00
|
|
|
: bf_(array.begin() + from, array.begin() + to)
|
2001-09-11 10:58:17 +00:00
|
|
|
{}
|
2001-07-16 15:53:25 +00:00
|
|
|
|
2001-02-19 18:29:10 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
void MathArray::substitute(MathMacro const & m)
|
|
|
|
{
|
2001-08-09 08:53:16 +00:00
|
|
|
for (iterator it = begin(); it != end(); ++it)
|
2001-10-12 12:02:49 +00:00
|
|
|
it->nucleus()->substitute(m);
|
2001-04-24 16:13:38 +00:00
|
|
|
}
|
|
|
|
|
2001-02-19 14:16:57 +00:00
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
MathScriptInset const * MathArray::asScript(const_iterator it) const
|
2001-02-19 14:16:57 +00:00
|
|
|
{
|
2001-10-12 12:02:49 +00:00
|
|
|
if (it->nucleus()->asScriptInset())
|
|
|
|
return 0;
|
|
|
|
const_iterator jt = it + 1;
|
|
|
|
if (jt == end())
|
|
|
|
return 0;
|
2001-11-07 08:51:35 +00:00
|
|
|
if (!jt->nucleus())
|
|
|
|
return 0;
|
2001-10-12 12:02:49 +00:00
|
|
|
return jt->nucleus()->asScriptInset();
|
2001-02-19 14:16:57 +00:00
|
|
|
}
|
|
|
|
|
2001-05-08 10:50:09 +00:00
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
MathAtom & MathArray::at(size_type pos)
|
2001-04-27 12:35:55 +00:00
|
|
|
{
|
2001-10-12 12:02:49 +00:00
|
|
|
lyx::Assert(pos < size());
|
|
|
|
return bf_[pos];
|
2001-07-12 07:18:29 +00:00
|
|
|
}
|
|
|
|
|
2001-07-24 11:39:38 +00:00
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
MathAtom const & MathArray::at(size_type pos) const
|
2001-02-14 17:50:58 +00:00
|
|
|
{
|
2001-10-12 12:02:49 +00:00
|
|
|
lyx::Assert(pos < size());
|
|
|
|
return bf_[pos];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathArray::insert(size_type pos, MathAtom const & t)
|
|
|
|
{
|
|
|
|
bf_.insert(begin() + pos, t);
|
2001-02-14 17:50:58 +00:00
|
|
|
}
|
|
|
|
|
2001-07-24 11:39:38 +00:00
|
|
|
|
2001-09-14 14:05:57 +00:00
|
|
|
void MathArray::insert(size_type pos, MathArray const & array)
|
2001-02-14 17:50:58 +00:00
|
|
|
{
|
2001-08-09 08:53:16 +00:00
|
|
|
bf_.insert(begin() + pos, array.begin(), array.end());
|
2001-02-14 17:50:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-10 13:20:51 +00:00
|
|
|
void MathArray::push_back(MathAtom const & t)
|
|
|
|
{
|
|
|
|
bf_.push_back(t);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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-10-19 15:20:22 +00:00
|
|
|
|
2001-02-12 08:55:14 +00:00
|
|
|
|
2001-09-14 14:05:57 +00:00
|
|
|
MathArray::size_type 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-09-14 14:05:57 +00:00
|
|
|
void MathArray::erase(size_type 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-09-14 14:05:57 +00:00
|
|
|
void MathArray::erase(size_type pos1, size_type pos2)
|
2001-02-12 08:55:14 +00:00
|
|
|
{
|
2001-08-09 08:53:16 +00:00
|
|
|
bf_.erase(begin() + pos1, begin() + pos2);
|
2001-02-12 08:55:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-09-11 10:58:17 +00:00
|
|
|
MathAtom & MathArray::back()
|
2001-02-17 18:52:53 +00:00
|
|
|
{
|
2001-09-11 10:58:17 +00:00
|
|
|
return bf_.back();
|
2001-02-17 18:52:53 +00:00
|
|
|
}
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2001-11-08 12:06:56 +00:00
|
|
|
void MathArray::dump2() const
|
2001-02-12 08:55:14 +00:00
|
|
|
{
|
2001-11-08 12:06:56 +00:00
|
|
|
NormalStream ns(lyxerr);
|
2001-08-09 08:53:16 +00:00
|
|
|
for (const_iterator it = begin(); it != end(); ++it)
|
2001-11-08 12:06:56 +00:00
|
|
|
ns << it->nucleus() << ' ';
|
2001-02-12 08:55:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-08 12:06:56 +00:00
|
|
|
void MathArray::dump() const
|
2001-02-12 08:55:14 +00:00
|
|
|
{
|
2001-11-08 12:06:56 +00:00
|
|
|
NormalStream ns(lyxerr);
|
2001-08-09 08:53:16 +00:00
|
|
|
for (const_iterator it = begin(); it != end(); ++it)
|
2001-11-08 12:06:56 +00:00
|
|
|
ns << "<" << it->nucleus() << ">";
|
2001-02-12 08:55:14 +00:00
|
|
|
}
|
2001-02-28 17:21:16 +00:00
|
|
|
|
2001-09-11 10:58:17 +00:00
|
|
|
|
2001-08-17 13:18:10 +00:00
|
|
|
// returns sequence of char with same code starting at it up to end
|
|
|
|
// it might be less, though...
|
|
|
|
string charSequence(MathArray::const_iterator it, MathArray::const_iterator end)
|
|
|
|
{
|
|
|
|
string s;
|
2001-09-11 10:58:17 +00:00
|
|
|
MathCharInset const * p = it->nucleus()->asCharInset();
|
2001-08-17 13:18:10 +00:00
|
|
|
if (!p)
|
|
|
|
return s;
|
|
|
|
|
2001-09-11 10:58:17 +00:00
|
|
|
for (MathTextCodes c = p->code(); it != end; ++it) {
|
2001-10-10 13:20:51 +00:00
|
|
|
if (!it->nucleus())
|
|
|
|
break;
|
2001-09-11 10:58:17 +00:00
|
|
|
p = it->nucleus()->asCharInset();
|
2001-10-12 12:02:49 +00:00
|
|
|
if (!p || p->code() != c)
|
2001-09-11 10:58:17 +00:00
|
|
|
break;
|
2001-08-17 13:18:10 +00:00
|
|
|
s += p->getChar();
|
|
|
|
}
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2001-02-28 17:21:16 +00:00
|
|
|
|
2001-11-05 17:08:45 +00:00
|
|
|
MathArray MathArray::glueChars() const
|
|
|
|
{
|
|
|
|
MathArray ar;
|
|
|
|
const_iterator it = begin();
|
|
|
|
while (it != end()) {
|
|
|
|
if (it->nucleus() && it->nucleus()->asCharInset()) {
|
|
|
|
string s = charSequence(it, end());
|
|
|
|
MathTextCodes c = it->nucleus()->asCharInset()->code();
|
|
|
|
ar.push_back(MathAtom(new MathStringInset(s, c)));
|
|
|
|
it += s.size();
|
|
|
|
} else {
|
|
|
|
ar.push_back(*it);
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ar;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-07 17:30:26 +00:00
|
|
|
bool needAsterisk(MathAtom const &, MathAtom const &)
|
2001-11-05 17:08:45 +00:00
|
|
|
{
|
2001-11-07 08:51:35 +00:00
|
|
|
return false;
|
2001-11-05 17:08:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-07 08:51:35 +00:00
|
|
|
MathArray MathArray::guessAsterisks() const
|
2001-02-28 17:21:16 +00:00
|
|
|
{
|
2001-11-07 08:51:35 +00:00
|
|
|
if (size() <= 1)
|
|
|
|
return *this;
|
|
|
|
MathArray ar;
|
|
|
|
ar.push_back(*begin());
|
|
|
|
for (const_iterator it = begin(), jt = begin()+1 ; jt != end(); ++it, ++jt) {
|
|
|
|
if (needAsterisk(*it, *jt))
|
|
|
|
ar.push_back(MathAtom(new MathCharInset('*')));
|
|
|
|
ar.push_back(*it);
|
|
|
|
}
|
|
|
|
ar.push_back(*end());
|
|
|
|
return ar;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathArray::write(MathWriteInfo & wi) const
|
|
|
|
{
|
|
|
|
MathArray ar = glueChars();
|
|
|
|
for (const_iterator it = ar.begin(); it != ar.end(); ++it) {
|
|
|
|
MathInset const * p = it->nucleus();
|
|
|
|
if (MathScriptInset const * q = ar.asScript(it)) {
|
2001-10-19 11:25:48 +00:00
|
|
|
q->write(p, wi);
|
2001-10-12 12:02:49 +00:00
|
|
|
++it;
|
2001-08-17 13:18:10 +00:00
|
|
|
} else {
|
2001-10-19 11:25:48 +00:00
|
|
|
p->write(wi);
|
2001-08-17 13:18:10 +00:00
|
|
|
}
|
|
|
|
}
|
2001-02-28 17:21:16 +00:00
|
|
|
}
|
|
|
|
|
2001-05-08 10:50:09 +00:00
|
|
|
|
2001-11-08 12:06:56 +00:00
|
|
|
void MathArray::writeNormal(NormalStream & os) const
|
2001-04-24 16:13:38 +00:00
|
|
|
{
|
2001-11-07 08:51:35 +00:00
|
|
|
MathArray ar = glueChars();
|
|
|
|
for (const_iterator it = ar.begin(); it != ar.end(); ++it) {
|
|
|
|
MathInset const * p = it->nucleus();
|
|
|
|
if (MathScriptInset const * q = ar.asScript(it)) {
|
2001-10-24 16:10:38 +00:00
|
|
|
q->writeNormal(p, os);
|
|
|
|
++it;
|
2001-11-07 08:51:35 +00:00
|
|
|
} else
|
2001-10-24 16:10:38 +00:00
|
|
|
p->writeNormal(os);
|
|
|
|
}
|
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-11-07 17:30:26 +00:00
|
|
|
void MathArray::octavize(OctaveStream & os) const
|
2001-11-07 08:51:35 +00:00
|
|
|
{
|
|
|
|
MathArray ar = glueChars();
|
|
|
|
for (const_iterator it = ar.begin(); it != ar.end(); ++it) {
|
|
|
|
MathInset const * p = it->nucleus();
|
|
|
|
if (MathScriptInset const * q = ar.asScript(it)) {
|
2001-11-07 17:30:26 +00:00
|
|
|
q->octavize(p, os);
|
2001-11-07 08:51:35 +00:00
|
|
|
++it;
|
|
|
|
} else
|
2001-11-07 17:30:26 +00:00
|
|
|
p->octavize(os);
|
2001-11-07 08:51:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-07 17:30:26 +00:00
|
|
|
void MathArray::maplize(MapleStream & os) const
|
2001-11-07 08:51:35 +00:00
|
|
|
{
|
|
|
|
MathArray ar = glueChars();
|
|
|
|
for (const_iterator it = ar.begin(); it != ar.end(); ++it) {
|
|
|
|
MathInset const * p = it->nucleus();
|
|
|
|
if (MathScriptInset const * q = ar.asScript(it)) {
|
2001-11-07 17:30:26 +00:00
|
|
|
q->maplize(p, os);
|
2001-11-07 08:51:35 +00:00
|
|
|
++it;
|
|
|
|
} else
|
2001-11-07 17:30:26 +00:00
|
|
|
p->maplize(os);
|
2001-11-07 08:51:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-07 17:30:26 +00:00
|
|
|
void MathArray::mathmlize(MathMLStream & os) const
|
2001-11-07 08:51:35 +00:00
|
|
|
{
|
|
|
|
MathArray ar = glueChars();
|
2001-11-07 18:15:24 +00:00
|
|
|
if (ar.size() == 0)
|
|
|
|
os << "<mrow/>";
|
|
|
|
else if (ar.size() == 1)
|
|
|
|
os << ar.begin()->nucleus();
|
|
|
|
else {
|
2001-11-08 12:06:56 +00:00
|
|
|
os << MTag("mrow");
|
2001-11-07 18:15:24 +00:00
|
|
|
for (const_iterator it = ar.begin(); it != ar.end(); ++it) {
|
|
|
|
MathInset const * p = it->nucleus();
|
|
|
|
if (MathScriptInset const * q = ar.asScript(it)) {
|
|
|
|
q->mathmlize(p, os);
|
|
|
|
++it;
|
|
|
|
} else
|
|
|
|
p->mathmlize(os);
|
|
|
|
}
|
2001-11-08 12:06:56 +00:00
|
|
|
os << ETag("mrow");
|
2001-11-07 08:51:35 +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-09 08:53:16 +00:00
|
|
|
for (const_iterator it = begin(); it != end(); ++it)
|
2001-11-07 08:51:35 +00:00
|
|
|
if (it->nucleus())
|
|
|
|
it->nucleus()->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;
|
|
|
|
}
|
|
|
|
bf_.pop_back();
|
2001-07-26 06:46:50 +00:00
|
|
|
}
|
|
|
|
|
2001-08-09 08:53:16 +00:00
|
|
|
|
|
|
|
MathArray::const_iterator MathArray::begin() const
|
|
|
|
{
|
|
|
|
return bf_.begin();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathArray::const_iterator MathArray::end() const
|
|
|
|
{
|
|
|
|
return bf_.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathArray::iterator MathArray::begin()
|
|
|
|
{
|
|
|
|
return bf_.begin();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathArray::iterator MathArray::end()
|
|
|
|
{
|
|
|
|
return bf_.end();
|
|
|
|
}
|
2001-11-07 08:51:35 +00:00
|
|
|
|
|
|
|
|
2001-11-07 10:21:51 +00:00
|
|
|
bool MathArray::isMatrix() const
|
|
|
|
{
|
|
|
|
return size() == 1 && begin()->nucleus() && begin()->nucleus()->isMatrix();
|
|
|
|
}
|
|
|
|
|
|
|
|
|