]> git.lyx.org Git - lyx.git/blob - src/mathed/array.C
patch from Andre and more array changes by me
[lyx.git] / src / mathed / array.C
1
2 #include <config.h>
3
4 #ifdef __GNUG__
5 #pragma implementation
6 #endif
7
8 #include "array.h"
9 #include "math_defs.h"
10
11
12 // Is this still needed? (Lgb)
13 static inline
14 void * my_memcpy(void * ps_in, void const * pt_in, size_t n)
15 {
16         char * ps = static_cast<char *>(ps_in);
17         char const * pt = static_cast<char const *>(pt_in);
18         while (n--) *ps++ = *pt++;
19         return ps_in;
20 }
21
22
23 int MathedArray::empty() const
24 {
25         return (last_ == 0);
26 }
27    
28
29 int MathedArray::last() const
30 {
31         return last_;
32 }
33
34
35 void MathedArray::last(int l)
36 {
37         last_ = l;
38 }
39
40
41 int MathedArray::maxsize() const
42 {
43         return maxsize_;
44 }
45
46
47 void MathedArray::resize(int newsize)
48 {
49         if (newsize < ARRAY_MIN_SIZE)
50                 newsize = ARRAY_MIN_SIZE;
51         newsize += ARRAY_STEP - (newsize % ARRAY_STEP);
52         bf_.resize(newsize);
53         if (last_ >= newsize) last_ = newsize - 1;
54         maxsize_ = newsize;
55         bf_[last_] = 0;
56 }
57
58
59 MathedArray::MathedArray(int size) 
60 {
61         maxsize_ = (size < ARRAY_MIN_SIZE) ? ARRAY_MIN_SIZE : size;
62         bf_.resize(maxsize_);
63         last_ = 0;
64 }
65
66
67 void MathedArray::move(int p, int shift)
68 {
69         if (p <= last_) {
70                 if (last_ + shift >= maxsize_) { 
71                     resize(last_ + shift);
72                 }
73                 memmove(&bf_[p + shift], &bf_[p], last_ - p);
74                 last_ += shift;
75                 bf_[last_] = 0;
76         }
77 }
78
79
80 void MathedArray::mergeF(MathedArray * a, int p, int dx)
81 {
82         my_memcpy(&bf_[p], &a->bf_[0], dx);
83 }
84
85
86 void MathedArray::raw_pointer_copy(MathedInset ** p, int pos) const
87 {
88         my_memcpy(p, &bf_[pos], sizeof(MathedInset*));
89 }
90
91
92 void MathedArray::raw_pointer_insert(void * p, int pos, int len)
93 {
94         my_memcpy(&bf_[pos], &p, len);
95 }
96
97
98 void MathedArray::strange_copy(MathedArray * dest, int dpos,
99                                 int spos, int len)
100 {
101         my_memcpy(&dest[dpos], &bf_[spos], len);
102 }
103
104
105 byte MathedArray::operator[](int i) const
106 {
107         return bf_[i];
108 }
109
110
111 byte & MathedArray::operator[](int i)
112 {
113         return bf_[i];
114 }
115
116
117 void MathedArray::insert(int pos, byte c)
118 {
119         if (pos < 0) pos = last_;
120         if (pos >= maxsize_) 
121                 resize(maxsize_ + ARRAY_STEP);
122         bf_[pos] = c;
123         if (pos >= last_)
124                 last_ = pos + 1;
125 }