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