]> git.lyx.org Git - lyx.git/blob - src/mathed/math_mathmlstream.C
Let UnknownInset inherit from NestInset instead of DimInset to enable it to
[lyx.git] / src / mathed / math_mathmlstream.C
1
2 #ifdef __GNUG__
3 #pragma implementation 
4 #endif
5
6 #include <config.h>
7
8 #include "math_mathmlstream.h"
9 #include "math_inset.h"
10 #include "math_extern.h"
11 #include "debug.h"
12 #include "support/lyxalgo.h"
13 #include "support/LOstream.h"
14
15
16 using std::ostream;
17 using std::strlen;
18
19 namespace {
20
21         bool isAlpha(char c) 
22         {
23                 return ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z');
24         }
25
26 }
27
28 WriteStream::WriteStream(ostream & os, bool fragile, bool latex)
29         : os_(os), fragile_(fragile), firstitem_(false), latex_(latex),
30           pendingspace_(false), line_(0)
31 {}
32
33
34 WriteStream::WriteStream(ostream & os)
35         : os_(os), fragile_(false), firstitem_(false), latex_(false),
36           pendingspace_(false), line_(0)
37 {}
38
39
40 WriteStream::~WriteStream()
41 {
42         if (pendingspace_)
43                 os_ << ' ';
44 }
45
46
47 void WriteStream::addlines(unsigned int n)
48 {
49         line_ += n;
50 }
51
52
53 void WriteStream::pendingSpace(bool how)
54 {
55         pendingspace_ = how;
56 }
57
58
59 WriteStream & operator<<(WriteStream & ws, MathAtom const & at)
60 {
61         at->write(ws);
62         return ws;
63 }
64
65
66 WriteStream & operator<<(WriteStream & ws, MathArray const & ar)
67 {
68         write(ar, ws);
69         return ws;
70 }
71
72
73 WriteStream & operator<<(WriteStream & ws, char const * s)
74 {
75         if (ws.pendingSpace() && strlen(s) > 0) {
76                 if (isAlpha(s[0]))
77                         ws.os() << ' ';
78                 ws.pendingSpace(false);
79         }
80         ws.os() << s;
81         ws.addlines(int(lyx::count(s, s + strlen(s), '\n')));
82         return ws;
83 }
84
85
86 WriteStream & operator<<(WriteStream & ws, char c)
87 {
88         if (ws.pendingSpace()) {
89                 if (isAlpha(c))
90                         ws.os() << ' ';
91                 ws.pendingSpace(false);
92         }
93         ws.os() << c;
94         if (c == '\n')
95                 ws.addlines(1);
96         return ws;
97 }
98
99
100 WriteStream & operator<<(WriteStream & ws, int i)
101 {
102         ws.os() << i;
103         return ws;
104 }
105
106
107 WriteStream & operator<<(WriteStream & ws, unsigned int i)
108 {
109         ws.os() << i;
110         return ws;
111 }
112
113
114 //////////////////////////////////////////////////////////////////////
115
116
117 MathMLStream::MathMLStream(ostream & os)
118         : os_(os), tab_(0), line_(0), lastchar_(0)
119 {}
120
121
122 MathMLStream & operator<<(MathMLStream & ms, MathAtom const & at)
123 {
124         at->mathmlize(ms);
125         return ms;
126 }
127
128
129 MathMLStream & operator<<(MathMLStream & ms, MathArray const & ar)
130 {
131         mathmlize(ar, ms);
132         return ms;
133 }
134
135
136 MathMLStream & operator<<(MathMLStream & ms, char const * s)
137 {
138         ms.os() << s;
139         return ms;
140 }
141
142
143 MathMLStream & operator<<(MathMLStream & ms, char c)
144 {
145         ms.os() << c;
146         return ms;
147 }
148
149
150 MathMLStream & operator<<(MathMLStream & ms, MTag const & t)
151 {
152         ++ms.tab();
153         ms.cr();
154         ms.os() << '<' << t.tag_ << '>';
155         return ms;
156 }
157
158
159 MathMLStream & operator<<(MathMLStream & ms, ETag const & t)
160 {
161         ms.cr();
162         if (ms.tab() > 0)
163                 --ms.tab();
164         ms.os() << "</" << t.tag_ << '>';
165         return ms;
166 }
167
168
169 void MathMLStream::cr()
170 {
171         os() << '\n';
172         for (int i = 0; i < tab(); ++i)
173                 os() << ' ';
174 }
175
176
177
178 //////////////////////////////////////////////////////////////////////
179
180
181 MapleStream & operator<<(MapleStream & ms, MathAtom const & at)
182 {
183         at->maplize(ms);
184         return ms;
185 }
186
187
188 MapleStream & operator<<(MapleStream & ms, MathArray const & ar)
189 {
190         maplize(ar, ms);
191         return ms;
192 }
193
194
195 MapleStream & operator<<(MapleStream & ms, char const * s)
196 {
197         ms.os() << s;
198         return ms;
199 }
200
201
202 MapleStream & operator<<(MapleStream & ms, char c)
203 {
204         ms.os() << c;
205         return ms;
206 }
207
208
209 MapleStream & operator<<(MapleStream & ms, int i)
210 {
211         ms.os() << i;
212         return ms;
213 }
214
215
216 //////////////////////////////////////////////////////////////////////
217
218
219 MathematicaStream & operator<<(MathematicaStream & ms, MathAtom const & at)
220 {
221         at->mathematicize(ms);
222         return ms;
223 }
224
225
226 MathematicaStream & operator<<(MathematicaStream & ms, MathArray const & ar)
227 {
228         mathematicize(ar, ms);
229         return ms;
230 }
231
232
233 MathematicaStream & operator<<(MathematicaStream & ms, char const * s)
234 {
235         ms.os() << s;
236         return ms;
237 }
238
239
240 MathematicaStream & operator<<(MathematicaStream & ms, char c)
241 {
242         ms.os() << c;
243         return ms;
244 }
245
246
247 MathematicaStream & operator<<(MathematicaStream & ms, int i)
248 {
249         ms.os() << i;
250         return ms;
251 }
252
253
254
255 //////////////////////////////////////////////////////////////////////
256
257
258 OctaveStream & operator<<(OctaveStream & ns, MathAtom const & at)
259 {
260         at->octavize(ns);
261         return ns;
262 }
263
264
265 OctaveStream & operator<<(OctaveStream & ns, MathArray const & ar)
266 {
267         octavize(ar, ns);
268         return ns;
269 }
270
271
272 OctaveStream & operator<<(OctaveStream & ns, char const * s)
273 {
274         ns.os() << s;
275         return ns;
276 }
277
278
279 OctaveStream & operator<<(OctaveStream & ns, char c)
280 {
281         ns.os() << c;
282         return ns;
283 }
284
285
286 OctaveStream & operator<<(OctaveStream & ns, int i)
287 {
288         ns.os() << i;
289         return ns;
290 }
291
292
293 //////////////////////////////////////////////////////////////////////
294
295
296 NormalStream & operator<<(NormalStream & ns, MathAtom const & at)
297 {
298         at->normalize(ns);
299         return ns;
300 }
301
302
303 NormalStream & operator<<(NormalStream & ns, MathArray const & ar)
304 {
305         normalize(ar, ns);
306         return ns;
307 }
308
309
310 NormalStream & operator<<(NormalStream & ns, char const * s)
311 {
312         ns.os() << s;
313         return ns;
314 }
315
316
317 NormalStream & operator<<(NormalStream & ns, char c)
318 {
319         ns.os() << c;
320         return ns;
321 }
322
323
324 NormalStream & operator<<(NormalStream & ns, int i)
325 {
326         ns.os() << i;
327         return ns;
328 }
329
330
331
332 //////////////////////////////////////////////////////////////////////
333