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