5 #include "math_inset.h"
6 #include "math_charinset.h"
7 #include "math_scriptinset.h"
8 #include "math_stringinset.h"
11 #include "mathed/support.h"
12 #include "support/LAssert.h"
18 MathArray::MathArray()
22 MathArray::MathArray(MathArray const & array, size_type from, size_type to)
23 : bf_(array.begin() + from, array.begin() + to)
27 void MathArray::substitute(MathMacro const & m)
29 for (iterator it = begin(); it != end(); ++it)
30 it->nucleus()->substitute(m);
34 MathScriptInset const * MathArray::asScript(const_iterator it) const
36 if (it->nucleus()->asScriptInset())
38 const_iterator jt = it + 1;
41 return jt->nucleus()->asScriptInset();
45 MathAtom & MathArray::at(size_type pos)
47 lyx::Assert(pos < size());
52 MathAtom const & MathArray::at(size_type pos) const
54 lyx::Assert(pos < size());
59 void MathArray::insert(size_type pos, MathAtom const & t)
61 bf_.insert(begin() + pos, t);
65 void MathArray::insert(size_type pos, MathArray const & array)
67 bf_.insert(begin() + pos, array.begin(), array.end());
71 void MathArray::push_back(MathAtom const & t)
77 void MathArray::push_back(MathArray const & array)
79 insert(size(), array);
83 void MathArray::clear()
89 void MathArray::swap(MathArray & array)
96 bool MathArray::empty() const
102 MathArray::size_type MathArray::size() const
108 void MathArray::erase()
114 void MathArray::erase(size_type pos)
121 void MathArray::erase(size_type pos1, size_type pos2)
123 bf_.erase(begin() + pos1, begin() + pos2);
127 MathAtom & MathArray::back()
133 void MathArray::dump2(ostream & os) const
135 for (const_iterator it = begin(); it != end(); ++it)
136 os << it->nucleus() << ' ';
140 void MathArray::dump(ostream & os) const
142 for (const_iterator it = begin(); it != end(); ++it)
143 os << "<" << it->nucleus() << ">";
147 std::ostream & operator<<(std::ostream & os, MathArray const & ar)
154 // returns sequence of char with same code starting at it up to end
155 // it might be less, though...
156 string charSequence(MathArray::const_iterator it, MathArray::const_iterator end)
159 MathCharInset const * p = it->nucleus()->asCharInset();
163 for (MathTextCodes c = p->code(); it != end; ++it) {
166 p = it->nucleus()->asCharInset();
167 if (!p || p->code() != c)
175 MathArray MathArray::glueChars() const
178 const_iterator it = begin();
179 while (it != end()) {
180 if (it->nucleus() && it->nucleus()->asCharInset()) {
181 string s = charSequence(it, end());
182 MathTextCodes c = it->nucleus()->asCharInset()->code();
183 ar.push_back(MathAtom(new MathStringInset(s, c)));
194 void MathArray::write(MathWriteInfo & wi) const
196 glueChars().write1(wi);
200 void MathArray::write1(MathWriteInfo & wi) const
202 for (const_iterator it = begin(); it != end(); ++it) {
203 MathInset * p = it->nucleus();
206 if (MathScriptInset const * q = asScript(it)) {
216 void MathArray::writeNormal(ostream & os) const
218 for (const_iterator it = begin(); it != end(); ++it) {
219 MathInset * p = it->nucleus();
222 if (MathScriptInset const * q = asScript(it)) {
223 q->writeNormal(p, os);
232 void MathArray::validate(LaTeXFeatures & features) const
234 for (const_iterator it = begin(); it != end(); ++it)
235 it->nucleus()->validate(features);
239 void MathArray::pop_back()
242 lyxerr << "pop_back from empty array!\n";
249 MathArray::const_iterator MathArray::begin() const
255 MathArray::const_iterator MathArray::end() const
261 MathArray::iterator MathArray::begin()
267 MathArray::iterator MathArray::end()