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
66 void MathedArray::deep_copy()
71 MathedInset * inset = it.GetInset();
72 inset = inset->Clone();
73 raw_pointer_insert(inset, it.getPos() + 1);
80 MathedArray & MathedArray::operator=(MathedArray const & array)
82 MathedArray tmp(array);
87 void MathedArray::clear()
94 void MathedArray::swap(MathedArray & array)
98 std::swap(last_, array.last_);
103 MathedArray::iterator MathedArray::begin()
109 MathedArray::iterator MathedArray::end()
115 MathedArray::const_iterator MathedArray::begin() const
121 MathedArray::const_iterator MathedArray::end() const
127 int MathedArray::empty() const
133 int MathedArray::last() const
139 void MathedArray::last(int l)
145 void MathedArray::need_size(int needed)
147 if (needed >= static_cast<int>(bf_.size()))
152 void MathedArray::resize(int newsize)
154 // still a bit smelly...
156 bf_.resize(newsize + 1);
157 if (last_ >= newsize)
163 void MathedArray::move(int p, int shift)
166 need_size(last_ + shift);
167 memmove(&bf_[p + shift], &bf_[p], last_ - p);
175 void MathedArray::shrink(int pos1, int pos2)
177 if (pos1 == 0 && pos2 >= last())
181 if (pos1 > 0 && bf_[pos1] > ' ') {
182 for (int p = pos1; p >= 0; --p) {
183 if (MathIsFont(bf_[p])) {
193 if (pos2 > 0 && bf_[pos2] >= ' ' && MathIsFont(bf_[pos2 - 1]))
196 int dx = pos2 - pos1;
199 strange_copy(&a, (fc) ? 1 : 0, pos1, dx);
213 void MathedArray::insert(MathedArray::iterator pos,
214 MathedArray::const_iterator beg,
215 MathedArray::const_iterator end)
217 bf_.insert(pos, beg, end);
218 last_ = bf_.size() - 1;
221 void MathedArray::merge(MathedArray const & a, int p)
223 my_memcpy(&bf_[p], &a.bf_[0], a.last());
228 void MathedArray::raw_pointer_copy(MathedInset ** p, int pos) const
230 my_memcpy(p, &bf_[pos], sizeof(MathedInset*));
235 void MathedArray::insertInset(int pos, MathedInset * p, int type)
237 //bf_.insert(pos, type);
238 InsetTable tmp(pos, p);
239 insetList_.push_back(tmp);
243 MathedInset * MathedArray::getInset(int pos)
245 InsetList::const_iterator cit = insetList_.begin();
246 InsetList::const_iterator end = insetList_.end();
247 for (; cit != end; ++cit) {
248 if ((*cit).pos == pos)
253 // We would really like to throw an exception instead... (Lgb)
254 // throw inset_not_found();
258 void MathedArray::raw_pointer_insert(void * p, int pos)
260 my_memcpy(&bf_[pos], &p, sizeof(p));
265 void MathedArray::strange_copy(MathedArray * dest, int dpos,
268 my_memcpy(&dest->bf_[dpos], &bf_[spos], len);
272 byte MathedArray::operator[](int i) const
278 byte & MathedArray::operator[](int i)
284 void MathedArray::dump(ostream & os) const
286 buffer_type::const_iterator cit = bf_.begin();
287 buffer_type::const_iterator end = bf_.end();
288 for (; cit != end; ++cit) {