10 #include "math_inset.h"
12 #include "support/LOstream.h"
17 // Is this still needed? (Lgb)
19 void * my_memcpy(void * ps_in, void const * pt_in, size_t n)
21 char * ps = static_cast<char *>(ps_in);
22 char const * pt = static_cast<char const *>(pt_in);
23 while (n--) *ps++ = *pt++;
28 MathedArray::MathedArray()
29 : bf_(1, '\0'), last_(0)
33 MathedArray::~MathedArray()
36 // let's leak for a while...
42 MathedInset * inset = it.GetInset();
51 MathedArray::MathedArray(MathedArray const & array)
53 // this "implementation" is obviously wrong: MathedIter should be
54 // implemented by MathedArray (not the other way round) but I think
55 // getting the _interface_ of MathedArray right is more important right
63 // we'll not yet get exeption safety
67 MathedInset * inset = it.GetInset();
68 inset = inset->Clone();
69 raw_pointer_insert(inset, it.getPos() + 1, sizeof(inset));
76 MathedArray & MathedArray::operator=(MathedArray const & array)
78 MathedArray tmp(array);
83 void MathedArray::clear()
90 void MathedArray::swap(MathedArray & array)
94 std::swap(last_, array.last_);
99 MathedArray::iterator MathedArray::begin()
105 MathedArray::iterator MathedArray::end()
111 MathedArray::const_iterator MathedArray::begin() const
117 MathedArray::const_iterator MathedArray::end() const
123 int MathedArray::empty() const
129 int MathedArray::last() const
135 void MathedArray::last(int l)
141 void MathedArray::need_size(int needed)
143 if (needed >= static_cast<int>(bf_.size()))
148 void MathedArray::resize(int newsize)
150 // still a bit smelly...
152 bf_.resize(newsize + 1);
153 if (last_ >= newsize)
159 void MathedArray::move(int p, int shift)
162 need_size(last_ + shift);
163 memmove(&bf_[p + shift], &bf_[p], last_ - p);
171 void MathedArray::shrink(int pos1, int pos2)
173 if (pos1 == 0 && pos2 >= last())
177 if (pos1 > 0 && bf_[pos1] > ' ') {
178 for (int p = pos1; p >= 0; --p) {
179 if (MathIsFont(bf_[p])) {
189 if (pos2 > 0 && bf_[pos2] >= ' ' && MathIsFont(bf_[pos2 - 1]))
192 int dx = pos2 - pos1;
195 strange_copy(&a, (fc) ? 1 : 0, pos1, dx);
208 MathedInset * inset = it.GetInset();
209 inset = inset->Clone();
210 a.raw_pointer_insert(inset, it.getPos() + 1, sizeof(inset));
219 void MathedArray::insert(MathedArray::iterator pos,
220 MathedArray::const_iterator beg,
221 MathedArray::const_iterator end)
223 bf_.insert(pos, beg, end);
224 last_ = bf_.size() - 1;
227 void MathedArray::merge(MathedArray const & a, int p)
229 my_memcpy(&bf_[p], &a.bf_[0], a.last());
234 void MathedArray::raw_pointer_copy(MathedInset ** p, int pos) const
236 my_memcpy(p, &bf_[pos], sizeof(MathedInset*));
241 void MathedArray::insertInset(int pos, MathedInset * p, int type)
243 //bf_.insert(pos, type);
244 InsetTable tmp(pos, p);
245 insetList_.push_back(tmp);
249 MathedInset * MathedArray::getInset(int pos)
251 InsetList::const_iterator cit = insetList_.begin();
252 InsetList::const_iterator end = insetList_.end();
253 for (; cit != end; ++cit) {
254 if ((*cit).pos == pos)
259 // We would really like to throw an exception instead... (Lgb)
260 // throw inset_not_found();
264 void MathedArray::raw_pointer_insert(void * p, int pos, int len)
266 my_memcpy(&bf_[pos], &p, len);
271 void MathedArray::strange_copy(MathedArray * dest, int dpos,
274 my_memcpy(&dest->bf_[dpos], &bf_[spos], len);
278 byte MathedArray::operator[](int i) const
284 byte & MathedArray::operator[](int i)
290 void MathedArray::dump(ostream & os) const
292 buffer_type::const_iterator cit = bf_.begin();
293 buffer_type::const_iterator end = bf_.end();
294 for (; cit != end; ++cit) {