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, size_type from, size_type to)
21 : bf_(array.begin() + from, array.begin() + to)
25 void MathArray::substitute(MathMacro const & m)
27 for (iterator it = begin(); it != end(); ++it)
32 MathAtom * MathArray::at(size_type pos)
34 return pos < size() ? &bf_[pos] : 0;
38 MathAtom const * MathArray::at(size_type pos) const
40 return pos < size() ? &bf_[pos] : 0;
44 void MathArray::insert(size_type pos, MathInset * p)
46 //cerr << "\n 1: "; p->write(cerr, true); cerr << p << "\n";
47 // inserting here invalidates the pointer!
48 bf_.insert(begin() + pos, MathAtom(p));
49 //cerr << "\n 2: "; p->write(cerr, true); cerr << p << "\n";
53 void MathArray::insert(size_type pos, MathArray const & array)
55 bf_.insert(begin() + pos, array.begin(), array.end());
59 void MathArray::push_back(MathInset * p)
65 void MathArray::push_back(MathArray const & array)
67 insert(size(), array);
71 void MathArray::clear()
77 void MathArray::swap(MathArray & array)
84 bool MathArray::empty() const
90 MathArray::size_type MathArray::size() const
96 void MathArray::erase()
102 void MathArray::erase(size_type pos)
109 void MathArray::erase(size_type pos1, size_type pos2)
111 bf_.erase(begin() + pos1, begin() + pos2);
115 MathAtom & MathArray::back()
121 void MathArray::dump2(ostream & os) const
123 for (const_iterator it = begin(); it != end(); ++it)
128 void MathArray::dump(ostream & os) const
130 for (const_iterator it = begin(); it != end(); ++it)
131 os << "<" << *it << ">";
135 std::ostream & operator<<(std::ostream & os, MathArray const & ar)
142 // returns sequence of char with same code starting at it up to end
143 // it might be less, though...
144 string charSequence(MathArray::const_iterator it, MathArray::const_iterator end)
147 MathCharInset const * p = it->nucleus()->asCharInset();
151 for (MathTextCodes c = p->code(); it != end; ++it) {
152 p = it->nucleus()->asCharInset();
153 if (!p || it->up() || it->down() || p->code() != c)
161 void MathArray::write(ostream & os, bool fragile) const
163 for (const_iterator it = begin(); it != end(); ++it) {
164 MathCharInset const * p = it->nucleus()->asCharInset();
165 if (p && !it->up() && !it->down()) {
166 // special handling for character sequences with the same code
167 string s = charSequence(it, end());
173 it->write(os, fragile);
179 void MathArray::writeNormal(ostream & os) const
190 void MathArray::validate(LaTeXFeatures & features) const
192 for (const_iterator it = begin(); it != end(); ++it)
193 it->validate(features);
197 void MathArray::pop_back()
200 lyxerr << "pop_back from empty array!\n";
207 MathArray::const_iterator MathArray::begin() const
213 MathArray::const_iterator MathArray::end() const
219 MathArray::iterator MathArray::begin()
225 MathArray::iterator MathArray::end()