]> git.lyx.org Git - lyx.git/blob - src/mathed/math_data.C
Reduce Michael's buglist.
[lyx.git] / src / mathed / math_data.C
1 #ifdef __GNUG__
2 #pragma implementation
3 #endif
4
5 #include "math_data.h"
6 #include "math_inset.h"
7 #include "math_deliminset.h"
8 #include "math_charinset.h"
9 #include "math_scriptinset.h"
10 #include "math_stringinset.h"
11 #include "math_matrixinset.h"
12 #include "math_mathmlstream.h"
13 #include "math_support.h"
14 #include "math_replace.h"
15 #include "debug.h"
16 #include "support/LAssert.h"
17
18
19 MathArray::MathArray()
20 {}
21
22
23 MathArray::MathArray(MathArray const & ar, size_type from, size_type to)
24         : bf_(ar.begin() + from, ar.begin() + to)
25 {}
26
27
28 MathArray::MathArray(iterator from, iterator to)
29         : bf_(from, to)
30 {}
31
32
33 void MathArray::substitute(MathMacro const & m)
34 {
35         for (iterator it = begin(); it != end(); ++it)
36                 it->nucleus()->substitute(m);
37 }
38
39
40 MathAtom & MathArray::at(size_type pos)
41 {
42         lyx::Assert(pos < size());
43         return bf_[pos];
44 }
45
46
47 MathAtom const & MathArray::at(size_type pos) const
48 {
49         lyx::Assert(pos < size());
50         return bf_[pos];
51 }
52
53
54 void MathArray::insert(size_type pos, MathAtom const & t)
55 {
56         bf_.insert(begin() + pos, t);
57 }
58
59
60 void MathArray::insert(size_type pos, MathArray const & ar)
61 {
62         bf_.insert(begin() + pos, ar.begin(), ar.end());
63 }
64
65
66 void MathArray::push_back(MathAtom const & t)
67 {       
68         bf_.push_back(t);
69 }
70
71
72 void MathArray::push_back(MathArray const & ar)
73 {
74         insert(size(), ar);
75 }
76
77
78 void MathArray::clear()
79 {
80         erase();
81 }
82
83
84 void MathArray::swap(MathArray & ar)
85 {
86         if (this != &ar) 
87                 bf_.swap(ar.bf_);
88 }
89
90
91 bool MathArray::empty() const
92 {
93         return bf_.empty();
94 }
95
96
97 MathArray::size_type MathArray::size() const
98 {
99         return bf_.size();
100 }
101
102
103 void MathArray::erase()
104 {
105         bf_.erase(begin(), end());
106 }
107
108
109 void MathArray::erase(size_type pos)
110 {
111         if (pos < size())
112                 erase(pos, pos + 1);
113 }
114
115
116 void MathArray::erase(iterator pos1, iterator pos2)
117 {
118         bf_.erase(pos1, pos2);
119 }
120
121
122 void MathArray::erase(iterator pos)
123 {
124         bf_.erase(pos);
125 }
126
127
128 void MathArray::erase(size_type pos1, size_type pos2)
129 {
130         bf_.erase(begin() + pos1, begin() + pos2);
131 }
132
133
134 MathAtom & MathArray::back()
135 {
136         return bf_.back();
137 }
138
139
140 MathAtom & MathArray::front()
141 {
142         return bf_.front();
143 }
144
145
146 MathAtom const & MathArray::front() const
147 {
148         return bf_.front();
149 }
150
151
152 void MathArray::dump2() const
153 {
154         NormalStream ns(lyxerr);
155         for (const_iterator it = begin(); it != end(); ++it)
156                 ns << it->nucleus() << ' ';
157 }
158
159
160 void MathArray::dump() const
161 {
162         NormalStream ns(lyxerr);
163         for (const_iterator it = begin(); it != end(); ++it)
164                 ns << "<" << it->nucleus() << ">";
165 }
166
167
168 void MathArray::validate(LaTeXFeatures & features) const
169 {
170         for (const_iterator it = begin(); it != end(); ++it)
171                 if (it->nucleus())
172                         it->nucleus()->validate(features);
173 }
174
175
176 void MathArray::pop_back()
177 {       
178         if (!size()) {
179                 lyxerr << "pop_back from empty array!\n";
180                 return;
181         }
182         bf_.pop_back();
183 }
184
185
186 MathArray::const_iterator MathArray::begin() const
187 {
188         return bf_.begin();
189 }
190
191
192 MathArray::const_iterator MathArray::end() const
193 {
194         return bf_.end();
195 }
196
197
198 MathArray::iterator MathArray::begin()
199 {
200         return bf_.begin();
201 }
202
203
204 MathArray::iterator MathArray::end()
205 {
206         return bf_.end();
207 }
208
209
210 bool MathArray::match(MathArray const & ar) const
211 {
212         if (size() != ar.size())
213                 return false;
214         for (const_iterator it = begin(), jt = ar.begin(); it != end(); ++it, ++jt)
215                 if (!it->nucleus()->match(jt->nucleus()))
216                         return false;
217         return true;
218 }
219
220
221 void MathArray::replace(ReplaceData & rep)
222 {
223         for (size_type i = 0; i < size(); ++i) {
224                 iterator it = begin() + i;
225                 const_iterator rt = rep.from.begin();
226                 const_iterator et = rep.from.end();
227                 for (const_iterator jt = it; jt != end() && rt != et; ++jt, ++rt)
228                         if (!jt->nucleus()->match(rt->nucleus()))
229                                 break;
230                 if (rt == et) {
231                         // match found
232                         lyxerr << "match found!\n";
233                         erase(it, it + rep.from.size());
234                         insert(i, rep.to);
235                 }
236         }
237
238         for (const_iterator it = begin(); it != end(); ++it)
239                 it->nucleus()->replace(rep);
240 }