5 #include "math_inset.h"
6 #include "math_charinset.h"
7 #include "math_scriptinset.h"
10 #include "mathed/support.h"
11 #include "support/LAssert.h"
17 MathArray::MathArray()
21 MathArray::MathArray(MathArray const & array, size_type from, size_type to)
22 : bf_(array.begin() + from, array.begin() + to)
26 void MathArray::substitute(MathMacro const & m)
28 for (iterator it = begin(); it != end(); ++it)
29 it->nucleus()->substitute(m);
33 MathScriptInset const * MathArray::asScript(const_iterator it) const
35 if (it->nucleus()->asScriptInset())
37 const_iterator jt = it + 1;
40 return jt->nucleus()->asScriptInset();
44 MathAtom & MathArray::at(size_type pos)
46 lyx::Assert(pos < size());
51 MathAtom const & MathArray::at(size_type pos) const
53 lyx::Assert(pos < size());
58 void MathArray::insert(size_type pos, MathAtom const & t)
60 bf_.insert(begin() + pos, t);
64 void MathArray::insert(size_type pos, MathArray const & array)
66 bf_.insert(begin() + pos, array.begin(), array.end());
70 void MathArray::push_back(MathAtom const & t)
76 void MathArray::push_back(MathArray const & array)
78 insert(size(), array);
82 void MathArray::clear()
88 void MathArray::swap(MathArray & array)
95 bool MathArray::empty() const
101 MathArray::size_type MathArray::size() const
107 void MathArray::erase()
113 void MathArray::erase(size_type pos)
120 void MathArray::erase(size_type pos1, size_type pos2)
122 bf_.erase(begin() + pos1, begin() + pos2);
126 MathAtom & MathArray::back()
132 void MathArray::dump2(ostream & os) const
134 for (const_iterator it = begin(); it != end(); ++it)
135 os << it->nucleus() << ' ';
139 void MathArray::dump(ostream & os) const
141 for (const_iterator it = begin(); it != end(); ++it)
142 os << "<" << it->nucleus() << ">";
146 std::ostream & operator<<(std::ostream & os, MathArray const & ar)
153 // returns sequence of char with same code starting at it up to end
154 // it might be less, though...
155 string charSequence(MathArray::const_iterator it, MathArray::const_iterator end)
158 MathCharInset const * p = it->nucleus()->asCharInset();
162 for (MathTextCodes c = p->code(); it != end; ++it) {
165 p = it->nucleus()->asCharInset();
166 if (!p || p->code() != c)
174 void MathArray::write(ostream & os, bool fragile) const
176 for (const_iterator it = begin(); it != end(); ++it) {
177 MathInset * p = it->nucleus();
182 if (p->asCharInset()) {
183 MathCharInset const * c = p->asCharInset();
184 // special handling for character sequences with the same code
185 string s = charSequence(it, end());
192 if (MathScriptInset const * q = asScript(it)) {
193 q->write(p, os, fragile);
196 p->write(os, fragile);
202 void MathArray::writeNormal(ostream & os) const
213 void MathArray::validate(LaTeXFeatures & features) const
215 for (const_iterator it = begin(); it != end(); ++it)
216 it->nucleus()->validate(features);
220 void MathArray::pop_back()
223 lyxerr << "pop_back from empty array!\n";
230 MathArray::const_iterator MathArray::begin() const
236 MathArray::const_iterator MathArray::end() const
242 MathArray::iterator MathArray::begin()
248 MathArray::iterator MathArray::end()