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-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 "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-09-11 10:58:17 +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-09-11 15:46:51 +00:00
|
|
|
it->substitute(m);
|
2001-04-24 16:13:38 +00:00
|
|
|
}
|
|
|
|
|
2001-02-19 14:16:57 +00:00
|
|
|
|
2001-09-14 14:05:57 +00:00
|
|
|
MathAtom * MathArray::at(size_type pos)
|
2001-02-19 14:16:57 +00:00
|
|
|
{
|
2001-09-14 14:05:57 +00:00
|
|
|
return pos < size() ? &bf_[pos] : 0;
|
2001-02-19 14:16:57 +00:00
|
|
|
}
|
|
|
|
|
2001-05-08 10:50:09 +00:00
|
|
|
|
2001-09-14 14:05:57 +00:00
|
|
|
MathAtom const * MathArray::at(size_type pos) const
|
2001-04-27 12:35:55 +00:00
|
|
|
{
|
2001-09-14 14:05:57 +00:00
|
|
|
return pos < size() ? &bf_[pos] : 0;
|
2001-07-12 07:18:29 +00:00
|
|
|
}
|
|
|
|
|
2001-07-24 11:39:38 +00:00
|
|
|
|
2001-09-14 14:05:57 +00:00
|
|
|
void MathArray::insert(size_type pos, MathInset * p)
|
2001-02-14 17:50:58 +00:00
|
|
|
{
|
2001-09-11 10:58:17 +00:00
|
|
|
//cerr << "\n 1: "; p->write(cerr, true); cerr << p << "\n";
|
2001-09-11 12:46:58 +00:00
|
|
|
// inserting here invalidates the pointer!
|
2001-09-11 10:58:17 +00:00
|
|
|
bf_.insert(begin() + pos, MathAtom(p));
|
|
|
|
//cerr << "\n 2: "; p->write(cerr, true); cerr << p << "\n";
|
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(MathInset * p)
|
|
|
|
{
|
2001-10-10 13:20:51 +00:00
|
|
|
bf_.push_back(MathAtom(p));
|
2001-02-14 17:50:58 +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-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
|
|
|
|
|
|
|
void MathArray::dump2(ostream & os) const
|
2001-02-12 08:55:14 +00:00
|
|
|
{
|
2001-08-09 08:53:16 +00:00
|
|
|
for (const_iterator it = begin(); it != 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-09 08:53:16 +00:00
|
|
|
for (const_iterator it = begin(); it != end(); ++it)
|
|
|
|
os << "<" << *it << ">";
|
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-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();
|
|
|
|
if (!p || it->up() || it->down() || p->code() != c)
|
|
|
|
break;
|
2001-08-17 13:18:10 +00:00
|
|
|
s += p->getChar();
|
|
|
|
}
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
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-09-11 10:58:17 +00:00
|
|
|
for (const_iterator it = begin(); it != end(); ++it) {
|
2001-10-10 13:20:51 +00:00
|
|
|
if (it->nucleus() && it->nucleus()->asCharInset()
|
|
|
|
&& !it->up() && !it->down())
|
|
|
|
{
|
|
|
|
MathCharInset const * p = it->nucleus()->asCharInset();
|
2001-08-17 13:18:10 +00:00
|
|
|
// special handling for character sequences with the same code
|
|
|
|
string s = charSequence(it, end());
|
|
|
|
p->writeHeader(os);
|
|
|
|
os << s;
|
|
|
|
p->writeTrailer(os);
|
2001-09-11 10:58:17 +00:00
|
|
|
it += s.size() - 1;
|
2001-08-17 13:18:10 +00:00
|
|
|
} else {
|
2001-09-11 10:58:17 +00:00
|
|
|
it->write(os, fragile);
|
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-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-09 08:53:16 +00:00
|
|
|
for (const_iterator it = begin(); it != end(); ++it)
|
2001-09-11 10:58:17 +00:00
|
|
|
it->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();
|
|
|
|
}
|