10 #include "math_inset.h"
12 // Is this still needed? (Lgb)
14 void * my_memcpy(void * ps_in, void const * pt_in, size_t n)
16 char * ps = static_cast<char *>(ps_in);
17 char const * pt = static_cast<char const *>(pt_in);
18 while (n--) *ps++ = *pt++;
23 MathedArray::MathedArray()
24 : bf_(1, '\0'), last_(0)
28 MathedArray::~MathedArray()
31 // let's leak for a while...
37 MathedInset * inset = it.GetInset();
46 MathedArray::MathedArray(MathedArray const & array)
48 // this "implementation" is obviously wrong: MathedIter should be
49 // implemented by MathedArray (not the other way round) but I think
50 // getting the _interface_ of MathedArray right is more important right
58 // we'll not yet get exeption safety
62 MathedInset * inset = it.GetInset();
63 inset = inset->Clone();
64 raw_pointer_insert(inset, it.getPos() + 1, sizeof(inset));
71 MathedArray & MathedArray::operator=(MathedArray const & array)
73 MathedArray tmp(array);
78 void MathedArray::clear()
85 void MathedArray::swap(MathedArray & array)
89 std::swap(last_, array.last_);
94 MathedArray::iterator MathedArray::begin()
100 MathedArray::iterator MathedArray::end()
106 MathedArray::const_iterator MathedArray::begin() const
112 MathedArray::const_iterator MathedArray::end() const
118 int MathedArray::empty() const
124 int MathedArray::last() const
130 void MathedArray::last(int l)
136 void MathedArray::need_size(int needed)
138 if (needed >= static_cast<int>(bf_.size()))
143 void MathedArray::resize(int newsize)
145 // still a bit smelly...
147 bf_.resize(newsize + 1);
148 if (last_ >= newsize)
154 void MathedArray::move(int p, int shift)
157 need_size(last_ + shift);
158 memmove(&bf_[p + shift], &bf_[p], last_ - p);
166 void MathedArray::shrink(int pos1, int pos2)
168 if (pos1 == 0 && pos2 >= last())
172 if (pos1 > 0 && bf_[pos1] > ' ') {
173 for (int p = pos1; p >= 0; --p) {
174 if (MathIsFont(bf_[p])) {
184 if (pos2 > 0 && bf_[pos2] >= ' ' && MathIsFont(bf_[pos2 - 1]))
187 int dx = pos2 - pos1;
190 strange_copy(&a, (fc) ? 1 : 0, pos1, dx);
203 MathedInset * inset = it.GetInset();
204 inset = inset->Clone();
205 a.raw_pointer_insert(inset, it.getPos() + 1, sizeof(inset));
214 void MathedArray::insert(MathedArray::iterator pos,
215 MathedArray::const_iterator beg,
216 MathedArray::const_iterator end)
218 bf_.insert(pos, beg, end);
219 last_ = bf_.size() - 1;
222 void MathedArray::merge(MathedArray const & a, int p)
224 my_memcpy(&bf_[p], &a.bf_[0], a.last());
229 void MathedArray::raw_pointer_copy(MathedInset ** p, int pos) const
231 my_memcpy(p, &bf_[pos], sizeof(MathedInset*));
236 void MathedArray::insertInset(int pos, MathedInset * p, int type)
238 //bf_.insert(pos, type);
239 InsetTable tmp(pos, p);
240 insetList_.push_back(tmp);
244 MathedInset * MathedArray::getInset(int pos)
246 InsetList::const_iterator cit = insetList_.begin();
247 InsetList::const_iterator end = insetList_.end();
248 for (; cit != end; ++cit) {
249 if ((*cit).pos == pos)
254 // We would really like to throw an exception instead... (Lgb)
255 // throw inset_not_found();
259 void MathedArray::raw_pointer_insert(void * p, int pos, int len)
261 my_memcpy(&bf_[pos], &p, len);
266 void MathedArray::strange_copy(MathedArray * dest, int dpos,
269 my_memcpy(&dest->bf_[dpos], &bf_[spos], len);
273 byte MathedArray::operator[](int i) const
279 byte & MathedArray::operator[](int i)