10 #include "math_inset.h"
12 #include "support/LOstream.h"
18 void * my_memcpy(void * ps_in, void const * pt_in, size_t n)
20 char * ps = static_cast<char *>(ps_in);
21 char const * pt = static_cast<char const *>(pt_in);
22 while (n--) *ps++ = *pt++;
27 MathedArray::MathedArray()
28 : bf_(1, '\0'), last_(0)
32 MathedArray::~MathedArray()
35 // let's leak for a while...
41 MathedInset * inset = it.GetInset();
50 MathedArray::MathedArray(MathedArray const & array)
52 // this "implementation" is obviously wrong: MathedIter should be
53 // implemented by MathedArray (not the other way round) but I think
54 // getting the _interface_ of MathedArray right is more important right
65 void MathedArray::deep_copy()
70 MathedInset * inset = it.GetInset();
71 inset = inset->Clone();
72 raw_pointer_insert(inset, it.getPos() + 1);
79 MathedArray & MathedArray::operator=(MathedArray const & array)
81 MathedArray tmp(array);
86 void MathedArray::clear()
93 void MathedArray::swap(MathedArray & array)
97 std::swap(last_, array.last_);
102 MathedArray::iterator MathedArray::begin()
108 MathedArray::iterator MathedArray::end()
114 MathedArray::const_iterator MathedArray::begin() const
120 MathedArray::const_iterator MathedArray::end() const
126 int MathedArray::empty() const
132 int MathedArray::last() const
138 void MathedArray::last(int l)
144 void MathedArray::need_size(int needed)
146 if (needed >= static_cast<int>(bf_.size()))
151 void MathedArray::resize(int newsize)
153 // still a bit smelly...
155 bf_.resize(newsize + 1);
156 if (last_ >= newsize)
162 void MathedArray::move(int p, int shift)
165 need_size(last_ + shift);
166 memmove(&bf_[p + shift], &bf_[p], last_ - p);
174 void MathedArray::shrink(int pos1, int pos2)
176 if (pos1 == 0 && pos2 >= last())
180 if (pos1 > 0 && bf_[pos1] > ' ') {
181 for (int p = pos1; p >= 0; --p) {
182 if (MathIsFont(bf_[p])) {
192 if (pos2 > 0 && bf_[pos2] >= ' ' && MathIsFont(bf_[pos2 - 1]))
195 int dx = pos2 - pos1;
198 strange_copy(&a, (fc) ? 1 : 0, pos1, dx);
212 void MathedArray::insert(MathedArray::iterator pos,
213 MathedArray::const_iterator beg,
214 MathedArray::const_iterator end)
216 bf_.insert(pos, beg, end);
217 last_ = bf_.size() - 1;
220 void MathedArray::merge(MathedArray const & a, int p)
222 my_memcpy(&bf_[p], &a.bf_[0], a.last());
227 void MathedArray::raw_pointer_copy(MathedInset ** p, int pos) const
229 my_memcpy(p, &bf_[pos], sizeof(MathedInset*));
234 void MathedArray::insertInset(int pos, MathedInset * p, int type)
236 //bf_.insert(pos, type);
237 InsetTable tmp(pos, p);
238 insetList_.push_back(tmp);
242 MathedInset * MathedArray::getInset(int pos)
244 InsetList::const_iterator cit = insetList_.begin();
245 InsetList::const_iterator end = insetList_.end();
246 for (; cit != end; ++cit) {
247 if ((*cit).pos == pos)
252 // We would really like to throw an exception instead... (Lgb)
253 // throw inset_not_found();
257 void MathedArray::raw_pointer_insert(void * p, int pos)
259 my_memcpy(&bf_[pos], &p, sizeof(p));
264 void MathedArray::strange_copy(MathedArray * dest, int dpos,
267 my_memcpy(&dest->bf_[dpos], &bf_[spos], len);
271 byte MathedArray::operator[](int i) const
277 byte & MathedArray::operator[](int i)
283 void MathedArray::dump(ostream & os) const
285 buffer_type::const_iterator cit = bf_.begin();
286 buffer_type::const_iterator end = bf_.end();
287 for (; cit != end; ++cit) {