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(MathAtom const & t)
65 void MathArray::push_back(MathInset * p)
67 bf_.push_back(MathAtom(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 MathArray::size_type MathArray::size() const
102 void MathArray::erase()
108 void MathArray::erase(size_type pos)
115 void MathArray::erase(size_type pos1, size_type 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) {
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 if (it->nucleus() && it->nucleus()->asCharInset()
173 && !it->up() && !it->down())
175 MathCharInset const * p = it->nucleus()->asCharInset();
176 // special handling for character sequences with the same code
177 string s = charSequence(it, end());
183 it->write(os, fragile);
189 void MathArray::writeNormal(ostream & os) const
200 void MathArray::validate(LaTeXFeatures & features) const
202 for (const_iterator it = begin(); it != end(); ++it)
203 it->validate(features);
207 void MathArray::pop_back()
210 lyxerr << "pop_back from empty array!\n";
217 MathArray::const_iterator MathArray::begin() const
223 MathArray::const_iterator MathArray::end() const
229 MathArray::iterator MathArray::begin()
235 MathArray::iterator MathArray::end()