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 MathInset * p = bf_[pos]->clone();
43 //lyxerr << "cloning: '" << bf_[pos] << " to " << p << "'\n";
49 bool MathArray::next(int & pos) const
51 if (pos >= size() - 1)
59 int MathArray::last() const
65 void MathArray::substitute(MathMacro const & m)
68 for (int pos = 0; pos < size(); ++pos)
69 bf_[pos]->substitute(tmp, m);
74 MathArray & MathArray::operator=(MathArray const & array)
82 MathInset * MathArray::nextInset(int pos)
84 return (pos == size()) ? 0 : bf_[pos];
88 MathInset const * MathArray::nextInset(int pos) const
90 return (pos == size()) ? 0 : bf_[pos];
94 unsigned char MathArray::getChar(int pos) const
96 return (pos == size()) ? 0 : (bf_[pos]->getChar());
101 string MathArray::getString(int & pos) const
107 MathTextCodes const fcode = getCode(pos);
111 } while (pos < size() && !isInset(pos) && getCode(pos) == fcode);
118 MathTextCodes MathArray::getCode(int pos) const
120 return pos < size() ? (bf_[pos]->code()) : LM_TC_MIN;
124 void MathArray::setCode(int pos, MathTextCodes t)
130 void MathArray::insert(int pos, MathInset * p)
132 bf_.insert(bf_.begin() + pos, p);
136 void MathArray::insert(int pos, unsigned char b, MathTextCodes t)
138 bf_.insert(bf_.begin() + pos, new MathCharInset(b, t));
142 void MathArray::insert(int pos, MathArray const & array)
144 bf_.insert(bf_.begin() + pos, array.bf_.begin(), array.bf_.end());
145 deep_copy(pos, pos + array.size());
149 void MathArray::push_back(MathInset * p)
155 void MathArray::push_back(unsigned char b, MathTextCodes c)
157 insert(size(), b, c);
161 void MathArray::push_back(MathArray const & array)
163 insert(size(), array);
167 void MathArray::clear()
173 void MathArray::swap(MathArray & array)
180 bool MathArray::empty() const
186 int MathArray::size() const
192 void MathArray::erase()
198 void MathArray::erase(int pos)
201 bf_.erase(bf_.begin() + pos);
205 void MathArray::erase(int pos1, int pos2)
207 for (int pos = pos1; pos < pos2; ++pos)
208 delete nextInset(pos);
209 bf_.erase(bf_.begin() + pos1, bf_.begin() + pos2);
213 MathInset * MathArray::back() const
215 return size() ? bf_.back() : 0;
219 void MathArray::dump2(ostream & os) const
221 for (buffer_type::const_iterator it = bf_.begin(); it != bf_.end(); ++it)
226 void MathArray::dump(ostream & os) const
228 for (int pos = 0; pos < size(); ++pos)
229 os << "<" << nextInset(pos) << ">";
233 std::ostream & operator<<(std::ostream & os, MathArray const & ar)
240 void MathArray::write(ostream & os, bool fragile) const
242 for (int pos = 0; pos < size(); ++pos)
243 nextInset(pos)->write(os, fragile);
247 void MathArray::writeNormal(ostream & os) const
258 void MathArray::validate(LaTeXFeatures & features) const
260 for (int pos = 0; pos < size(); ++pos)
261 nextInset(pos)->validate(features);
265 void MathArray::pop_back()
268 lyxerr << "pop_back from empty array!\n";