8 #include "math_inset.h"
9 #include "math_deliminset.h"
10 #include "math_charinset.h"
11 #include "math_scriptinset.h"
12 #include "math_stringinset.h"
13 #include "math_matrixinset.h"
14 #include "math_mathmlstream.h"
15 #include "math_support.h"
16 #include "math_replace.h"
18 #include "support/LAssert.h"
21 MathArray::MathArray()
25 MathArray::MathArray(MathArray const & ar, size_type from, size_type to)
26 : bf_(ar.begin() + from, ar.begin() + to)
30 MathArray::MathArray(iterator from, iterator to)
35 void MathArray::substitute(MathMacro const & m)
37 for (iterator it = begin(); it != end(); ++it)
38 it->nucleus()->substitute(m);
42 MathAtom & MathArray::at(size_type pos)
44 lyx::Assert(pos < size());
49 MathAtom const & MathArray::at(size_type pos) const
51 lyx::Assert(pos < size());
56 void MathArray::insert(size_type pos, MathAtom const & t)
58 bf_.insert(begin() + pos, t);
62 void MathArray::insert(size_type pos, MathArray const & ar)
64 bf_.insert(begin() + pos, ar.begin(), ar.end());
68 void MathArray::push_back(MathAtom const & t)
74 void MathArray::push_back(MathArray const & ar)
80 void MathArray::clear()
86 void MathArray::swap(MathArray & ar)
93 bool MathArray::empty() const
99 MathArray::size_type MathArray::size() const
105 void MathArray::erase()
107 bf_.erase(begin(), end());
111 void MathArray::erase(size_type pos)
118 void MathArray::erase(iterator pos1, iterator pos2)
120 bf_.erase(pos1, pos2);
124 void MathArray::erase(iterator pos)
130 void MathArray::erase(size_type pos1, size_type pos2)
132 bf_.erase(begin() + pos1, begin() + pos2);
136 MathAtom & MathArray::back()
142 MathAtom & MathArray::front()
148 MathAtom const & MathArray::front() const
154 void MathArray::dump2() const
156 NormalStream ns(lyxerr);
157 for (const_iterator it = begin(); it != end(); ++it)
158 ns << it->nucleus() << ' ';
162 void MathArray::dump() const
164 NormalStream ns(lyxerr);
165 for (const_iterator it = begin(); it != end(); ++it)
166 ns << "<" << it->nucleus() << ">";
170 void MathArray::validate(LaTeXFeatures & features) const
172 for (const_iterator it = begin(); it != end(); ++it)
174 it->nucleus()->validate(features);
178 void MathArray::pop_back()
181 lyxerr << "pop_back from empty array!\n";
188 MathArray::const_iterator MathArray::begin() const
194 MathArray::const_iterator MathArray::end() const
200 MathArray::iterator MathArray::begin()
206 MathArray::iterator MathArray::end()
212 bool MathArray::match(MathArray const & ar) const
214 return size() == ar.size() && matchpart(ar, 0);
218 bool MathArray::matchpart(MathArray const & ar, pos_type pos) const
220 if (size() < ar.size() + pos)
222 const_iterator it = begin() + pos;
223 for (const_iterator jt = ar.begin(); jt != ar.end(); ++jt, ++it)
224 if (!jt->nucleus()->match(it->nucleus()))
230 void MathArray::replace(ReplaceData & rep)
232 for (size_type i = 0; i < size(); ++i) {
233 iterator it = begin() + i;
234 const_iterator rt = rep.from.begin();
235 const_iterator et = rep.from.end();
236 for (const_iterator jt = it; jt != end() && rt != et; ++jt, ++rt)
237 if (!jt->nucleus()->match(rt->nucleus()))
241 lyxerr << "match found!\n";
242 erase(it, it + rep.from.size());
247 for (const_iterator it = begin(); it != end(); ++it)
248 it->nucleus()->replace(rep);
252 bool MathArray::contains(MathArray const & ar) const
254 for (size_type i = 0; i + ar.size() <= size(); ++i) {
255 const_iterator it = begin() + i;
256 const_iterator rt = ar.begin();
257 const_iterator et = ar.end();
258 for (const_iterator jt = it; rt != et; ++jt, ++rt)
259 if (!jt->nucleus()->match(rt->nucleus()))
265 for (const_iterator it = begin(); it != end(); ++it)
266 if (it->nucleus()->contains(ar))