5 #include "math_inset.h"
6 #include "math_charinset.h"
7 #include "math_scriptinset.h"
10 #include "mathed/support.h"
16 MathArray::MathArray()
20 MathArray::MathArray(MathArray const & array, int from, int to)
21 : bf_(array.begin() + from, array.begin() + to)
25 int MathArray::last() const
31 void MathArray::substitute(MathMacro const & m)
34 for (iterator it = begin(); it != end(); ++it)
35 it->substitute(tmp, m);
40 MathAtom * MathArray::at(int pos)
42 return (0 <= pos && pos < size()) ? &bf_[pos] : 0;
46 MathAtom const * MathArray::at(int pos) const
48 return (0 <= pos && pos < size()) ? &bf_[pos] : 0;
52 void MathArray::insert(int pos, MathInset * p)
54 //cerr << "\n 1: "; p->write(cerr, true); cerr << p << "\n";
55 // inserting here invalidates the pointer!
56 bf_.insert(begin() + pos, MathAtom(p));
57 //cerr << "\n 2: "; p->write(cerr, true); cerr << p << "\n";
61 void MathArray::insert(int pos, MathArray const & array)
63 bf_.insert(begin() + pos, array.begin(), array.end());
67 void MathArray::push_back(MathInset * p)
73 void MathArray::push_back(MathArray const & array)
75 insert(size(), array);
79 void MathArray::clear()
85 void MathArray::swap(MathArray & array)
92 bool MathArray::empty() const
98 int MathArray::size() const
104 void MathArray::erase()
110 void MathArray::erase(int pos)
117 void MathArray::erase(int pos1, int pos2)
119 bf_.erase(begin() + pos1, begin() + pos2);
123 MathAtom & MathArray::back()
129 void MathArray::dump2(ostream & os) const
131 for (const_iterator it = begin(); it != end(); ++it)
136 void MathArray::dump(ostream & os) const
138 for (const_iterator it = begin(); it != end(); ++it)
139 os << "<" << *it << ">";
143 std::ostream & operator<<(std::ostream & os, MathArray const & ar)
150 // returns sequence of char with same code starting at it up to end
151 // it might be less, though...
152 string charSequence(MathArray::const_iterator it, MathArray::const_iterator end)
155 MathCharInset const * p = it->nucleus()->asCharInset();
159 for (MathTextCodes c = p->code(); it != end; ++it) {
160 p = it->nucleus()->asCharInset();
161 if (!p || it->up() || it->down() || p->code() != c)
169 void MathArray::write(ostream & os, bool fragile) const
171 for (const_iterator it = begin(); it != end(); ++it) {
172 MathCharInset const * p = it->nucleus()->asCharInset();
173 if (p && !it->up() && !it->down()) {
174 // special handling for character sequences with the same code
175 string s = charSequence(it, end());
181 it->write(os, fragile);
187 void MathArray::writeNormal(ostream & os) const
198 void MathArray::validate(LaTeXFeatures & features) const
200 for (const_iterator it = begin(); it != end(); ++it)
201 it->validate(features);
205 void MathArray::pop_back()
208 lyxerr << "pop_back from empty array!\n";
215 MathArray::const_iterator MathArray::begin() const
221 MathArray::const_iterator MathArray::end() const
227 MathArray::iterator MathArray::begin()
233 MathArray::iterator MathArray::end()