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