]> git.lyx.org Git - lyx.git/blob - src/mathed/math_mathmlstream.C
enable direct input of #1...#9; some whitespace changes
[lyx.git] / src / mathed / math_mathmlstream.C
1 #include <config.h>
2
3 #include "math_mathmlstream.h"
4 #include "math_inset.h"
5 #include "math_extern.h"
6 #include "debug.h"
7
8 #include <algorithm>
9
10
11 MathMLStream::MathMLStream(std::ostream & os)
12         : os_(os), tab_(0), line_(0), lastchar_(0)
13 {}
14
15
16 MathMLStream & operator<<(MathMLStream & ms, MathInset const * p)
17 {
18         if (p)
19                 p->mathmlize(ms);
20         else
21                 lyxerr << "operator<<(MathMLStream, NULL) called\n";
22         return ms;
23 }
24
25
26 MathMLStream & operator<<(MathMLStream & ms, MathArray const & ar)
27 {
28         mathmlize(ar, ms);
29         return ms;
30 }
31
32
33 MathMLStream & operator<<(MathMLStream & ms, char const * s)
34 {
35         ms.os() << s;
36         return ms;
37 }
38
39
40 MathMLStream & operator<<(MathMLStream & ms, char c)
41 {
42         ms.os() << c;
43         return ms;
44 }
45
46
47 MathMLStream & operator<<(MathMLStream & ms, MTag const & t)
48 {
49         ++ms.tab();
50         ms.cr();
51         ms.os() << '<' << t.tag_ << '>';
52         return ms;
53 }
54
55
56 MathMLStream & operator<<(MathMLStream & ms, ETag const & t)
57 {
58         ms.cr();
59         if (ms.tab() > 0)
60                 --ms.tab();
61         ms.os() << "</" << t.tag_ << '>';
62         return ms;
63 }
64
65
66 void MathMLStream::cr()
67 {
68         os() << '\n';
69         for (int i = 0; i < tab(); ++i)
70                 os() << ' ';
71 }
72
73
74
75 //////////////////////////////////////////////////////////////////////
76
77
78 MapleStream & operator<<(MapleStream & ms, MathInset const * p)
79 {
80         if (p)
81                 p->maplize(ms);
82         else
83                 lyxerr << "operator<<(MapleStream, NULL) called\n";
84         return ms;
85 }
86
87
88 MapleStream & operator<<(MapleStream & ms, MathArray const & ar)
89 {
90         maplize(ar, ms);
91         return ms;
92 }
93
94
95 MapleStream & operator<<(MapleStream & ms, char const * s)
96 {
97         ms.os() << s;
98         return ms;
99 }
100
101
102 MapleStream & operator<<(MapleStream & ms, char c)
103 {
104         ms.os() << c;
105         return ms;
106 }
107
108
109 MapleStream & operator<<(MapleStream & ms, int i)
110 {
111         ms.os() << i;
112         return ms;
113 }
114
115
116 //////////////////////////////////////////////////////////////////////
117
118
119 OctaveStream & operator<<(OctaveStream & ns, MathInset const * p)
120 {
121         if (p)
122                 p->octavize(ns);
123         else
124                 lyxerr << "operator<<(OctaveStream, NULL) called\n";
125         return ns;
126 }
127
128
129 OctaveStream & operator<<(OctaveStream & ns, MathArray const & ar)
130 {
131         octavize(ar, ns);
132         return ns;
133 }
134
135
136 OctaveStream & operator<<(OctaveStream & ns, char const * s)
137 {
138         ns.os() << s;
139         return ns;
140 }
141
142
143 OctaveStream & operator<<(OctaveStream & ns, char c)
144 {
145         ns.os() << c;
146         return ns;
147 }
148
149
150 //////////////////////////////////////////////////////////////////////
151
152
153 NormalStream & operator<<(NormalStream & ns, MathInset const * p)
154 {
155         if (p)
156                 p->normalize(ns);
157         else
158                 lyxerr << "operator<<(NormalStream, NULL) called\n";
159         return ns;
160 }
161
162
163 NormalStream & operator<<(NormalStream & ns, MathArray const & ar)
164 {
165         normalize(ar, ns);
166         return ns;
167 }
168
169
170 NormalStream & operator<<(NormalStream & ns, char const * s)
171 {
172         ns.os() << s;
173         return ns;
174 }
175
176
177 NormalStream & operator<<(NormalStream & ns, char c)
178 {
179         ns.os() << c;
180         return ns;
181 }
182
183
184
185 //////////////////////////////////////////////////////////////////////
186
187
188 WriteStream::WriteStream(std::ostream & os, bool fragile)
189         : os_(os), fragile_(fragile), line_(0)
190 {}
191
192
193 WriteStream::WriteStream(std::ostream & os)
194         : os_(os), fragile_(false), line_(0)
195 {}
196
197
198 WriteStream & operator<<(WriteStream & ws, MathInset const * p)
199 {
200         if (p)
201                 p->write(ws);
202         else
203                 lyxerr << "operator<<(WriteStream, NULL) called\n";
204         return ws;
205 }
206
207
208 WriteStream & operator<<(WriteStream & ws, MathArray const & ar)
209 {
210         write(ar, ws);
211         return ws;
212 }
213
214
215 WriteStream & operator<<(WriteStream & ws, char const * s)
216 {
217         ws.os() << s;
218         ws.line() += std::count(s, s + strlen(s), '\n');
219         return ws;
220 }
221
222
223 WriteStream & operator<<(WriteStream & ws, char c)
224 {
225         ws.os() << c;
226         if (c == '\n')
227                 ++ws.line();
228         return ws;
229 }
230
231
232 WriteStream & operator<<(WriteStream & ws, int i)
233 {
234         ws.os() << i;
235         return ws;
236 }
237
238
239 WriteStream & operator<<(WriteStream & ws, unsigned int i)
240 {
241         ws.os() << i;
242         return ws;
243 }