]> git.lyx.org Git - lyx.git/blob - src/mathed/array.C
mathed25.diff
[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 MathedArray::MathedArray()
22         : bf_(1, 0), last_(0)
23 {}
24
25
26 MathedArray::iterator MathedArray::begin() 
27 {
28         return bf_.begin();
29 }
30
31
32 MathedArray::iterator MathedArray::end() 
33 {
34         return bf_.end();
35 }
36
37
38 MathedArray::const_iterator MathedArray::begin() const
39 {
40         return bf_.begin();
41 }
42
43
44 MathedArray::const_iterator MathedArray::end() const
45 {
46         return bf_.end();
47 }
48
49
50 int MathedArray::empty() const
51 {
52         return (last_ == 0);
53 }
54    
55
56 int MathedArray::last() const
57 {
58         return last_;
59 }
60
61
62 void MathedArray::last(int l)
63 {
64         last_ = l;
65 }
66
67
68 void MathedArray::need_size(int needed)
69 {
70         if (needed >= static_cast<int>(bf_.size()))
71                 resize(needed);
72 }
73
74
75 void MathedArray::resize(int newsize)
76 {
77         // still a bit smelly...
78         ++newsize;
79         bf_.resize(newsize + 1);
80         if (last_ >= newsize)
81                 last_ = newsize - 1;
82         bf_[last_] = 0;
83 }
84
85
86 void MathedArray::move(int p, int shift)
87 {
88         if (p <= last_) {
89                 need_size(last_ + shift);
90                 memmove(&bf_[p + shift], &bf_[p], last_ - p);
91                 last_ += shift;
92                 bf_[last_] = 0;
93         }
94 }
95
96
97 #if 0
98 void MathedArray::insert(MathedArray::iterator pos,
99                          MathedArray::const_iterator beg,
100                          MathedArray::const_iterator end)
101 {
102         bf_.insert(pos, beg, end);
103         last_ = bf_.size() - 1;
104 }
105 #else
106 void MathedArray::mergeF(MathedArray * a, int p, int dx)
107 {
108         my_memcpy(&bf_[p], &a->bf_[0], dx);
109 }
110 #endif
111
112
113 void MathedArray::raw_pointer_copy(MathedInset ** p, int pos) const
114 {
115         my_memcpy(p, &bf_[pos], sizeof(MathedInset*));
116 }
117
118
119 #if 0
120 void MathedArray::insertInset(int pos, MathedInset * p, int type)
121 {
122         //bf_.insert(pos, type);
123         InsetTable tmp(pos, p);
124         insetList_.push_back(tmp);
125 }
126
127
128 MathedInset * MathedArray::getInset(int pos) 
129 {
130         InsetList::const_iterator cit = insetList_.begin();
131         InsetList::const_iterator end = insetList_.end();
132         for (; cit != end; ++cit) {
133                 if ((*cit).pos == pos)
134                         return (*cit).inset;
135         }
136         // not found
137         return 0;
138         // We would really like to throw an exception instead... (Lgb)
139         // throw inset_not_found();
140 }
141
142 #else
143 void MathedArray::raw_pointer_insert(void * p, int pos, int len)
144 {
145         my_memcpy(&bf_[pos], &p, len);
146 }
147 #endif
148
149
150 void MathedArray::strange_copy(MathedArray * dest, int dpos,
151                                 int spos, int len)
152 {
153         my_memcpy(&dest->bf_[dpos], &bf_[spos], len);
154 }
155
156
157 byte MathedArray::operator[](int i) const
158 {
159         return bf_[i];
160 }
161
162
163 byte & MathedArray::operator[](int i)
164 {
165         return bf_[i];
166 }