]> git.lyx.org Git - lyx.git/blob - src/mathed/array.C
mathed11.diff from Andre
[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 static_cast<int>(bf_.size());
44 }
45
46
47 void MathedArray::need_size(int needed)
48 {
49         if (needed >= maxsize()) 
50                 resize(needed);
51 }
52
53
54 void MathedArray::resize(int newsize)
55 {
56         if (newsize < ARRAY_MIN_SIZE)
57                 newsize = ARRAY_MIN_SIZE;
58         newsize += ARRAY_STEP - (newsize % ARRAY_STEP);
59         bf_.resize(newsize);
60         if (last_ >= newsize) last_ = newsize - 1;
61         bf_[last_] = 0;
62 }
63
64
65 MathedArray::MathedArray(int size) 
66 {
67         int newsize = (size < ARRAY_MIN_SIZE) ? ARRAY_MIN_SIZE : size;
68         bf_.resize(newsize);
69         last_ = 0;
70 }
71
72
73 void MathedArray::move(int p, int shift)
74 {
75         if (p <= last_) {
76                 need_size(last_ + shift);
77                 memmove(&bf_[p + shift], &bf_[p], last_ - p);
78                 last_ += shift;
79                 bf_[last_] = 0;
80         }
81 }
82
83
84 void MathedArray::mergeF(MathedArray * a, int p, int dx)
85 {
86         my_memcpy(&bf_[p], &a->bf_[0], dx);
87 }
88
89
90 void MathedArray::raw_pointer_copy(MathedInset ** p, int pos) const
91 {
92         my_memcpy(p, &bf_[pos], sizeof(MathedInset*));
93 }
94
95
96 void MathedArray::raw_pointer_insert(void * p, int pos, int len)
97 {
98         my_memcpy(&bf_[pos], &p, len);
99 }
100
101
102 void MathedArray::strange_copy(MathedArray * dest, int dpos,
103                                 int spos, int len)
104 {
105         my_memcpy(&dest[dpos], &bf_[spos], len);
106 }
107
108
109 byte MathedArray::operator[](int i) const
110 {
111         return bf_[i];
112 }
113
114
115 byte & MathedArray::operator[](int i)
116 {
117         return bf_[i];
118 }
119
120
121 void MathedArray::insert(int pos, byte c)
122 {
123         if (pos < 0) pos = last_;
124
125         // I think this should be replaced by  need_size(pos).  Note that the
126         // current code looks troublesome if  pos > maxsize() + ARRAY_STEP.
127         if (pos >= maxsize()) 
128                 resize(maxsize() + ARRAY_STEP);
129         bf_[pos] = c;
130         if (pos >= last_)
131                 last_ = pos + 1;
132 }