10 #include "math_inset.h"
12 #include "support/LOstream.h"
20 void * my_memcpy(void * ps_in, void const * pt_in, size_t n)
22 char * ps = static_cast<char *>(ps_in);
23 char const * pt = static_cast<char const *>(pt_in);
24 while (n--) *ps++ = *pt++;
31 MathedArray::MathedArray()
32 : bf_(1, '\0'), last_(0)
36 MathedArray::~MathedArray()
39 // let's leak for a while...
45 MathedInset * inset = it.GetInset();
54 MathedArray::MathedArray(MathedArray const & array)
56 // this "implementation" is obviously wrong: MathedIter should be
57 // implemented by MathedArray (not the other way round) but I think
58 // getting the _interface_ of MathedArray right is more important right
69 void MathedArray::deep_copy()
74 MathedInset * inset = it.GetInset();
75 inset = inset->Clone();
76 raw_pointer_insert(inset, it.getPos() + 1);
83 MathedArray & MathedArray::operator=(MathedArray const & array)
85 MathedArray tmp(array);
90 void MathedArray::clear()
97 void MathedArray::swap(MathedArray & array)
101 std::swap(last_, array.last_);
106 MathedArray::iterator MathedArray::begin()
112 MathedArray::iterator MathedArray::end()
118 MathedArray::const_iterator MathedArray::begin() const
124 MathedArray::const_iterator MathedArray::end() const
130 int MathedArray::empty() const
136 int MathedArray::last() const
142 void MathedArray::last(int l)
148 void MathedArray::need_size(int needed)
150 if (needed >= static_cast<int>(bf_.size()))
155 void MathedArray::resize(int newsize)
157 // still a bit smelly...
159 bf_.resize(newsize + 1);
160 if (last_ >= newsize)
166 void MathedArray::move(int p, int shift)
169 need_size(last_ + shift);
170 memmove(&bf_[p + shift], &bf_[p], last_ - p);
178 void MathedArray::shrink(int pos1, int pos2)
180 if (pos1 == 0 && pos2 >= last())
184 if (pos1 > 0 && bf_[pos1] > ' ') {
185 for (int p = pos1; p >= 0; --p) {
186 if (MathIsFont(bf_[p])) {
196 if (pos2 > 0 && bf_[pos2] >= ' ' && MathIsFont(bf_[pos2 - 1]))
199 int dx = pos2 - pos1;
202 strange_copy(&a, (fc) ? 1 : 0, pos1, dx);
216 void MathedArray::insert(MathedArray::iterator pos,
217 MathedArray::const_iterator beg,
218 MathedArray::const_iterator end)
220 bf_.insert(pos, beg, end);
221 last_ = bf_.size() - 1;
224 void MathedArray::merge(MathedArray const & a, int p)
226 my_memcpy(&bf_[p], &a.bf_[0], a.last());
231 void MathedArray::raw_pointer_copy(MathedInset ** p, int pos) const
233 my_memcpy(p, &bf_[pos], sizeof(MathedInset*));
238 void MathedArray::insertInset(int pos, MathedInset * p, int type)
240 //bf_.insert(pos, type);
241 InsetTable tmp(pos, p);
242 insetList_.push_back(tmp);
246 MathedInset * MathedArray::getInset(int pos)
248 InsetList::const_iterator cit = insetList_.begin();
249 InsetList::const_iterator end = insetList_.end();
250 for (; cit != end; ++cit) {
251 if ((*cit).pos == pos)
256 // We would really like to throw an exception instead... (Lgb)
257 // throw inset_not_found();
261 void MathedArray::raw_pointer_insert(void * p, int pos)
263 my_memcpy(&bf_[pos], &p, sizeof(p));
268 void MathedArray::strange_copy(MathedArray * dest, int dpos,
271 my_memcpy(&dest->bf_[dpos], &bf_[spos], len);
275 byte MathedArray::operator[](int i) const
281 byte & MathedArray::operator[](int i)
287 void MathedArray::dump(ostream & os) const
289 buffer_type::const_iterator cit = bf_.begin();
290 buffer_type::const_iterator end = bf_.end();
291 for (; cit != end; ++cit) {