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)
33 for (iterator it = begin(); it != end(); ++it)
38 MathAtom * MathArray::at(int pos)
40 return (0 <= pos && pos < size()) ? &bf_[pos] : 0;
44 MathAtom const * MathArray::at(int pos) const
46 return (0 <= pos && pos < size()) ? &bf_[pos] : 0;
50 void MathArray::insert(int pos, MathInset * p)
52 //cerr << "\n 1: "; p->write(cerr, true); cerr << p << "\n";
53 // inserting here invalidates the pointer!
54 bf_.insert(begin() + pos, MathAtom(p));
55 //cerr << "\n 2: "; p->write(cerr, true); cerr << p << "\n";
59 void MathArray::insert(int pos, MathArray const & array)
61 bf_.insert(begin() + pos, array.begin(), array.end());
65 void MathArray::push_back(MathInset * p)
71 void MathArray::push_back(MathArray const & array)
73 insert(size(), array);
77 void MathArray::clear()
83 void MathArray::swap(MathArray & array)
90 bool MathArray::empty() const
96 int MathArray::size() const
102 void MathArray::erase()
108 void MathArray::erase(int pos)
115 void MathArray::erase(int pos1, int pos2)
117 bf_.erase(begin() + pos1, begin() + pos2);
121 MathAtom & MathArray::back()
127 void MathArray::dump2(ostream & os) const
129 for (const_iterator it = begin(); it != end(); ++it)
134 void MathArray::dump(ostream & os) const
136 for (const_iterator it = begin(); it != end(); ++it)
137 os << "<" << *it << ">";
141 std::ostream & operator<<(std::ostream & os, MathArray const & ar)
148 // returns sequence of char with same code starting at it up to end
149 // it might be less, though...
150 string charSequence(MathArray::const_iterator it, MathArray::const_iterator end)
153 MathCharInset const * p = it->nucleus()->asCharInset();
157 for (MathTextCodes c = p->code(); it != end; ++it) {
158 p = it->nucleus()->asCharInset();
159 if (!p || it->up() || it->down() || p->code() != c)
167 void MathArray::write(ostream & os, bool fragile) const
169 for (const_iterator it = begin(); it != end(); ++it) {
170 MathCharInset const * p = it->nucleus()->asCharInset();
171 if (p && !it->up() && !it->down()) {
172 // special handling for character sequences with the same code
173 string s = charSequence(it, end());
179 it->write(os, fragile);
185 void MathArray::writeNormal(ostream & os) const
196 void MathArray::validate(LaTeXFeatures & features) const
198 for (const_iterator it = begin(); it != end(); ++it)
199 it->validate(features);
203 void MathArray::pop_back()
206 lyxerr << "pop_back from empty array!\n";
213 MathArray::const_iterator MathArray::begin() const
219 MathArray::const_iterator MathArray::end() const
225 MathArray::iterator MathArray::begin()
231 MathArray::iterator MathArray::end()