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