5 #include "math_inset.h"
6 #include "math_charinset.h"
9 #include "math_scriptinset.h"
10 #include "mathed/support.h"
15 MathArray::MathArray()
19 MathArray::~MathArray()
25 MathArray::MathArray(MathArray const & array)
32 MathArray::MathArray(MathArray const & array, int from, int to)
33 : bf_(array.bf_.begin() + from, array.bf_.begin() + to)
39 void MathArray::deep_copy(int pos1, int pos2)
41 for (int pos = pos1; pos < pos2; ++pos)
42 bf_[pos] = bf_[pos]->clone();
46 bool MathArray::next(int & pos) const
48 if (pos >= size() - 1)
56 bool MathArray::prev(int & pos) const
66 bool MathArray::last(int & pos) const
73 void MathArray::substitute(MathMacro const & m)
76 for (int pos = 0; pos < size(); ++pos)
77 bf_[pos]->substitute(tmp, m);
82 MathArray & MathArray::operator=(MathArray const & array)
90 MathInset * MathArray::nextInset(int pos) const
92 return (pos == size()) ? 0 : bf_[pos];
96 MathInset * MathArray::prevInset(int pos) const
98 return (pos == 0) ? 0 : bf_[pos - 1];
102 unsigned char MathArray::getChar(int pos) const
104 return (pos == size()) ? 0 : (bf_[pos]->getChar());
109 string MathArray::getString(int & pos) const
115 MathTextCodes const fcode = getCode(pos);
119 } while (pos < size() && !isInset(pos) && getCode(pos) == fcode);
126 MathTextCodes MathArray::getCode(int pos) const
128 return pos < size() ? (bf_[pos]->code()) : LM_TC_MIN;
132 void MathArray::setCode(int pos, MathTextCodes t)
138 void MathArray::insert(int pos, MathInset * p)
140 bf_.insert(bf_.begin() + pos, p);
144 void MathArray::insert(int pos, unsigned char b, MathTextCodes t)
146 bf_.insert(bf_.begin() + pos, new MathCharInset(b, t));
150 void MathArray::insert(int pos, MathArray const & array)
152 bf_.insert(bf_.begin() + pos, array.bf_.begin(), array.bf_.end());
153 deep_copy(pos, pos + array.size());
157 void MathArray::push_back(MathInset * p)
163 void MathArray::push_back(unsigned char b, MathTextCodes c)
165 insert(size(), b, c);
169 void MathArray::push_back(MathArray const & array)
171 insert(size(), array);
175 void MathArray::clear()
181 void MathArray::swap(MathArray & array)
188 bool MathArray::empty() const
194 int MathArray::size() const
200 void MathArray::erase()
206 void MathArray::erase(int pos)
209 bf_.erase(bf_.begin() + pos);
213 void MathArray::erase(int pos1, int pos2)
215 for (int pos = pos1; pos < pos2; ++pos)
216 delete nextInset(pos);
217 bf_.erase(bf_.begin() + pos1, bf_.begin() + pos2);
221 MathInset * MathArray::back() const
223 return prevInset(size());
227 void MathArray::dump2(ostream & os) const
229 for (buffer_type::const_iterator it = bf_.begin(); it != bf_.end(); ++it)
230 os << int(*it) << ' ';
235 void MathArray::dump(ostream & os) const
237 for (int pos = 0; pos < size(); ++pos)
238 os << "<" << nextInset(pos) << ">";
242 std::ostream & operator<<(std::ostream & os, MathArray const & ar)
249 void MathArray::write(ostream & os, bool fragile) const
251 for (int pos = 0; pos < size(); ++pos)
252 nextInset(pos)->write(os, fragile);
256 void MathArray::writeNormal(ostream & os) const
267 void MathArray::validate(LaTeXFeatures & features) const
269 for (int pos = 0; pos < size(); ++pos)
270 nextInset(pos)->validate(features);
274 void MathArray::pop_back()