5 #include "math_inset.h"
6 #include "math_charinset.h"
9 #include "mathed/support.h"
14 MathArray::MathArray()
18 MathArray::~MathArray()
24 MathArray::MathArray(MathArray const & array)
27 deep_copy(begin(), end());
31 MathArray::MathArray(MathArray const & array, int from, int to)
32 : bf_(array.begin() + from, array.begin() + to)
34 deep_copy(begin(), end());
38 void MathArray::deep_copy(iterator from, iterator to)
40 for (iterator it = from; it != to; ++it)
45 int MathArray::last() const
51 void MathArray::substitute(MathMacro const & m)
54 for (iterator it = begin(); it != end(); ++it)
55 (*it)->substitute(tmp, m);
60 MathArray & MathArray::operator=(MathArray const & array)
68 MathInset * MathArray::nextInset(int pos)
70 return (pos == size()) ? 0 : bf_[pos];
74 MathInset const * MathArray::nextInset(int pos) const
76 return (pos == size()) ? 0 : bf_[pos];
80 void MathArray::insert(int pos, MathInset * p)
82 bf_.insert(begin() + pos, p);
86 void MathArray::insert(int pos, MathArray const & array)
88 bf_.insert(begin() + pos, array.begin(), array.end());
89 deep_copy(begin() + pos, begin() + pos + array.size());
93 void MathArray::push_back(MathInset * p)
99 void MathArray::push_back(MathArray const & array)
101 insert(size(), array);
105 void MathArray::clear()
111 void MathArray::swap(MathArray & array)
118 bool MathArray::empty() const
124 int MathArray::size() const
130 void MathArray::erase()
136 void MathArray::erase(int pos)
143 void MathArray::erase(int pos1, int pos2)
145 for (iterator it = begin() + pos1; it != begin() + pos2; ++it)
147 bf_.erase(begin() + pos1, begin() + pos2);
151 MathInset * MathArray::back() const
153 return size() ? bf_.back() : 0;
157 void MathArray::dump2(ostream & os) const
159 for (const_iterator it = begin(); it != end(); ++it)
164 void MathArray::dump(ostream & os) const
166 for (const_iterator it = begin(); it != end(); ++it)
167 os << "<" << *it << ">";
171 std::ostream & operator<<(std::ostream & os, MathArray const & ar)
177 // returns sequence of char with same code starting at it up to end
178 // it might be less, though...
179 string charSequence(MathArray::const_iterator it, MathArray::const_iterator end)
182 MathCharInset const * p = (*it)->asCharInset();
186 MathTextCodes c = p->code();
187 while (it != end && (p = (*it)->asCharInset()) && p->code() == c) {
195 void MathArray::write(ostream & os, bool fragile) const
197 for (const_iterator it = begin(); it != end(); ) {
198 MathCharInset const * p = (*it)->asCharInset();
200 // special handling for character sequences with the same code
201 string s = charSequence(it, end());
207 (*it)->write(os, fragile);
214 void MathArray::writeNormal(ostream & os) const
225 void MathArray::validate(LaTeXFeatures & features) const
227 for (const_iterator it = begin(); it != end(); ++it)
228 (*it)->validate(features);
232 void MathArray::pop_back()
235 lyxerr << "pop_back from empty array!\n";
243 MathArray::const_iterator MathArray::begin() const
249 MathArray::const_iterator MathArray::end() const
255 MathArray::iterator MathArray::begin()
261 MathArray::iterator MathArray::end()