10 #include "math_iter.h"
11 #include "math_inset.h"
12 #include "math_macro.h"
14 #include "support/LOstream.h"
19 #ifndef CXX_GLOBAL_CSTD
27 void * my_memcpy(void * ps_in, void const * pt_in, size_t n)
29 char * ps = static_cast<char *>(ps_in);
30 char const * pt = static_cast<char const *>(pt_in);
31 while (n--) *ps++ = *pt++;
38 MathedArray::MathedArray()
39 : bf_(1, '\0'), last_(0)
43 MathedArray::~MathedArray()
46 // let's leak for a while...
52 MathedInset * inset = it.GetInset();
61 MathedArray::MathedArray(MathedArray const & array)
63 // this "implementation" is obviously wrong: MathedIter should be
64 // implemented by MathedArray (not the other way round) but I think
65 // getting the _interface_ of MathedArray right is more important right
77 void MathedArray::deep_copy()
82 MathedInset * inset = it.GetInset();
83 inset = inset->Clone();
84 raw_pointer_insert(inset, it.getPos() + 1);
91 void MathedArray::substitute(MathMacro * m)
99 MathedInset * inset = it.GetInset();
100 if (inset->GetType() == LM_OT_MACRO_ARG) {
101 int n = static_cast<MathMacroArgument *>(inset)->number() - 1;
102 //lyxerr << "substituting an argument inset: " << n << "\n";
103 inset = m->arg(n)->Clone();
105 inset->substitute(m);
108 MathParInset * pinset = static_cast<MathParInset *>(inset);
109 int n = pinset->getMaxArgumentIdx();
110 int idx = pinset->getArgumentIdx();
111 for (int i = 0; i <= n; ++i) {
112 pinset->setArgumentIdx(i);
113 pinset->GetData().substitute(m);
115 pinset->setArgumentIdx(idx);
119 //lyxerr << "substituting in an ordinary inset\n";
121 raw_pointer_insert(inset, it.getPos() + 1);
128 MathedArray & MathedArray::operator=(MathedArray const & array)
130 MathedArray tmp(array);
136 void MathedArray::push_back(MathedInset * inset, int t)
141 it.insertInset(inset, t);
145 void MathedArray::push_back(byte b, MathedTextCodes c)
154 void MathedArray::clear()
162 void MathedArray::swap(MathedArray & array)
164 if (this != &array) {
166 std::swap(last_, array.last_);
171 MathedArray::iterator MathedArray::begin()
177 MathedArray::iterator MathedArray::end()
183 MathedArray::const_iterator MathedArray::begin() const
189 MathedArray::const_iterator MathedArray::end() const
195 int MathedArray::empty() const
201 int MathedArray::last() const
207 void MathedArray::last(int l)
213 void MathedArray::need_size(int needed)
215 if (needed >= static_cast<int>(bf_.size()))
220 void MathedArray::resize(int newsize)
222 // still a bit smelly...
224 bf_.resize(newsize + 1);
225 if (last_ >= newsize)
231 void MathedArray::move(int p, int shift)
234 need_size(last_ + shift);
235 memmove(&bf_[p + shift], &bf_[p], last_ - p);
243 void MathedArray::shrink(int pos1, int pos2)
245 if (pos1 == 0 && pos2 >= last())
249 if (pos1 > 0 && bf_[pos1] > ' ') {
250 for (int p = pos1; p >= 0; --p) {
251 if (MathIsFont(bf_[p])) {
261 if (pos2 > 0 && bf_[pos2] >= ' ' && MathIsFont(bf_[pos2 - 1]))
264 int dx = pos2 - pos1;
267 strange_copy(&a, (fc) ? 1 : 0, pos1, dx);
281 void MathedArray::insert(MathedArray::iterator pos,
282 MathedArray::const_iterator beg,
283 MathedArray::const_iterator end)
285 bf_.insert(pos, beg, end);
286 last_ = bf_.size() - 1;
289 void MathedArray::merge(MathedArray const & a, int p)
291 my_memcpy(&bf_[p], &a.bf_[0], a.last());
296 void MathedArray::raw_pointer_copy(MathedInset ** p, int pos) const
298 my_memcpy(p, &bf_[pos], sizeof(MathedInset*));
303 void MathedArray::insertInset(int pos, MathedInset * p, int type)
305 //bf_.insert(pos, type);
306 InsetTable tmp(pos, p);
307 insetList_.push_back(tmp);
311 MathedInset * MathedArray::getInset(int pos)
313 InsetList::const_iterator cit = insetList_.begin();
314 InsetList::const_iterator end = insetList_.end();
315 for (; cit != end; ++cit) {
316 if ((*cit).pos == pos)
321 // We would really like to throw an exception instead... (Lgb)
322 // throw inset_not_found();
326 void MathedArray::raw_pointer_insert(void * p, int pos)
328 my_memcpy(&bf_[pos], &p, sizeof(p));
333 void MathedArray::strange_copy(MathedArray * dest, int dpos,
336 my_memcpy(&dest->bf_[dpos], &bf_[spos], len);
340 byte MathedArray::operator[](int i) const
346 byte & MathedArray::operator[](int i)
352 void MathedArray::dump2(ostream & os) const
354 buffer_type::const_iterator cit = bf_.begin();
355 buffer_type::const_iterator end = bf_.end();
356 for (; cit != end; ++cit) {
363 void MathedArray::dump(ostream & os) const
365 MathedIter it( const_cast<MathedArray*>(this) );
368 MathedInset * inset = it.GetInset();
369 os << "<inset: " << inset << ">";
375 else if (it.IsScript())
377 else if (it.IsFont())
378 os << "<font: " << int(it.at()) << ">";
379 else if (it.at() >= 32 && it.at() < 127)
382 os << "<unknown: " << int(it.at()) << ">";