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)
27 MathedArray::~MathedArray()
30 // let's leak for a while...
36 MathedInset * inset = it.GetInset();
45 MathedArray::MathedArray(MathedArray const & array)
47 // this "implementation" is obviously wrong: MathedIter should be
48 // implemented by MathedArray (not the other way round) but I think
49 // getting the _interface_ of MathedArray right is more important right
57 // 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::swap(MathedArray & array)
82 std::swap(last_, array.last_);
87 MathedArray::iterator MathedArray::begin()
93 MathedArray::iterator MathedArray::end()
99 MathedArray::const_iterator MathedArray::begin() const
105 MathedArray::const_iterator MathedArray::end() const
111 int MathedArray::empty() const
117 int MathedArray::last() const
123 void MathedArray::last(int l)
129 void MathedArray::need_size(int needed)
131 if (needed >= static_cast<int>(bf_.size()))
136 void MathedArray::resize(int newsize)
138 // still a bit smelly...
140 bf_.resize(newsize + 1);
141 if (last_ >= newsize)
147 void MathedArray::move(int p, int shift)
150 need_size(last_ + shift);
151 memmove(&bf_[p + shift], &bf_[p], last_ - p);
159 void MathedArray::insert(MathedArray::iterator pos,
160 MathedArray::const_iterator beg,
161 MathedArray::const_iterator end)
163 bf_.insert(pos, beg, end);
164 last_ = bf_.size() - 1;
167 void MathedArray::mergeF(MathedArray * a, int p, int dx)
169 my_memcpy(&bf_[p], &a->bf_[0], dx);
174 void MathedArray::raw_pointer_copy(MathedInset ** p, int pos) const
176 my_memcpy(p, &bf_[pos], sizeof(MathedInset*));
181 void MathedArray::insertInset(int pos, MathedInset * p, int type)
183 //bf_.insert(pos, type);
184 InsetTable tmp(pos, p);
185 insetList_.push_back(tmp);
189 MathedInset * MathedArray::getInset(int pos)
191 InsetList::const_iterator cit = insetList_.begin();
192 InsetList::const_iterator end = insetList_.end();
193 for (; cit != end; ++cit) {
194 if ((*cit).pos == pos)
199 // We would really like to throw an exception instead... (Lgb)
200 // throw inset_not_found();
204 void MathedArray::raw_pointer_insert(void * p, int pos, int len)
206 my_memcpy(&bf_[pos], &p, len);
211 void MathedArray::strange_copy(MathedArray * dest, int dpos,
214 my_memcpy(&dest->bf_[dpos], &bf_[spos], len);
218 byte MathedArray::operator[](int i) const
224 byte & MathedArray::operator[](int i)