1 | // file : xsd/cxx/tree/std-ostream-operators.hxx |
---|
2 | // author : Boris Kolpackov <boris@codesynthesis.com> |
---|
3 | // copyright : Copyright (c) 2005-2008 Code Synthesis Tools CC |
---|
4 | // license : GNU GPL v2 + exceptions; see accompanying LICENSE file |
---|
5 | |
---|
6 | #ifndef XSD_CXX_TREE_STD_OSTREAM_OPERATORS_HXX |
---|
7 | #define XSD_CXX_TREE_STD_OSTREAM_OPERATORS_HXX |
---|
8 | |
---|
9 | #include <ostream> |
---|
10 | |
---|
11 | #include <xsd/cxx/tree/elements.hxx> |
---|
12 | #include <xsd/cxx/tree/containers.hxx> |
---|
13 | #include <xsd/cxx/tree/types.hxx> |
---|
14 | #include <xsd/cxx/tree/list.hxx> |
---|
15 | |
---|
16 | namespace xsd |
---|
17 | { |
---|
18 | namespace cxx |
---|
19 | { |
---|
20 | namespace tree |
---|
21 | { |
---|
22 | // type |
---|
23 | // |
---|
24 | template <typename C> |
---|
25 | inline std::basic_ostream<C>& |
---|
26 | operator<< (std::basic_ostream<C>& os, const type&) |
---|
27 | { |
---|
28 | return os; |
---|
29 | } |
---|
30 | |
---|
31 | |
---|
32 | // simple_type |
---|
33 | // |
---|
34 | template <typename C, typename B> |
---|
35 | inline std::basic_ostream<C>& |
---|
36 | operator<< (std::basic_ostream<C>& os, const simple_type<B>&) |
---|
37 | { |
---|
38 | return os; |
---|
39 | } |
---|
40 | |
---|
41 | |
---|
42 | // fundamental_base |
---|
43 | // |
---|
44 | template <typename X, typename C, typename B> |
---|
45 | inline |
---|
46 | std::basic_ostream<C>& |
---|
47 | operator<< (std::basic_ostream<C>& os, fundamental_base<X, C, B> x) |
---|
48 | { |
---|
49 | X& r (x); |
---|
50 | return os << r; |
---|
51 | } |
---|
52 | |
---|
53 | // optional: see containers.hxx |
---|
54 | // |
---|
55 | |
---|
56 | // list |
---|
57 | // |
---|
58 | |
---|
59 | // This is an xsd:list-style format (space-separated). |
---|
60 | // |
---|
61 | template <typename C, typename X, bool fund> |
---|
62 | std::basic_ostream<C>& |
---|
63 | operator<< (std::basic_ostream<C>& os, const list<X, C, fund>& v) |
---|
64 | { |
---|
65 | for (typename list<X, C, fund>::const_iterator |
---|
66 | b (v.begin ()), e (v.end ()), i (b); i != e; ++i) |
---|
67 | { |
---|
68 | if (i != b) |
---|
69 | os << C (' '); |
---|
70 | |
---|
71 | os << *i; |
---|
72 | } |
---|
73 | |
---|
74 | return os; |
---|
75 | } |
---|
76 | |
---|
77 | |
---|
78 | // Operators for built-in types. |
---|
79 | // |
---|
80 | |
---|
81 | |
---|
82 | // string |
---|
83 | // |
---|
84 | template <typename C, typename B> |
---|
85 | inline std::basic_ostream<C>& |
---|
86 | operator<< (std::basic_ostream<C>& os, const string<C, B>& v) |
---|
87 | { |
---|
88 | const std::basic_string<C>& r (v); |
---|
89 | return os << r; |
---|
90 | } |
---|
91 | |
---|
92 | |
---|
93 | // normalized_string |
---|
94 | // |
---|
95 | template <typename C, typename B> |
---|
96 | inline std::basic_ostream<C>& |
---|
97 | operator<< (std::basic_ostream<C>& os, const normalized_string<C, B>& v) |
---|
98 | { |
---|
99 | const B& r (v); |
---|
100 | return os << r; |
---|
101 | } |
---|
102 | |
---|
103 | |
---|
104 | // token |
---|
105 | // |
---|
106 | template <typename C, typename B> |
---|
107 | inline std::basic_ostream<C>& |
---|
108 | operator<< (std::basic_ostream<C>& os, const token<C, B>& v) |
---|
109 | { |
---|
110 | const B& r (v); |
---|
111 | return os << r; |
---|
112 | } |
---|
113 | |
---|
114 | |
---|
115 | // nmtoken |
---|
116 | // |
---|
117 | template <typename C, typename B> |
---|
118 | inline std::basic_ostream<C>& |
---|
119 | operator<< (std::basic_ostream<C>& os, const nmtoken<C, B>& v) |
---|
120 | { |
---|
121 | const B& r (v); |
---|
122 | return os << r; |
---|
123 | } |
---|
124 | |
---|
125 | |
---|
126 | // nmtokens |
---|
127 | // |
---|
128 | template <typename C, typename B, typename nmtoken> |
---|
129 | inline std::basic_ostream<C>& |
---|
130 | operator<< (std::basic_ostream<C>& os, const nmtokens<C, B, nmtoken>& v) |
---|
131 | { |
---|
132 | const list<nmtoken, C>& r (v); |
---|
133 | return os << r; |
---|
134 | } |
---|
135 | |
---|
136 | |
---|
137 | // name |
---|
138 | // |
---|
139 | template <typename C, typename B> |
---|
140 | inline std::basic_ostream<C>& |
---|
141 | operator<< (std::basic_ostream<C>& os, const name<C, B>& v) |
---|
142 | { |
---|
143 | const B& r (v); |
---|
144 | return os << r; |
---|
145 | } |
---|
146 | |
---|
147 | |
---|
148 | // ncname |
---|
149 | // |
---|
150 | template <typename C, typename B> |
---|
151 | inline std::basic_ostream<C>& |
---|
152 | operator<< (std::basic_ostream<C>& os, const ncname<C, B>& v) |
---|
153 | { |
---|
154 | const B& r (v); |
---|
155 | return os << r; |
---|
156 | } |
---|
157 | |
---|
158 | |
---|
159 | // language |
---|
160 | // |
---|
161 | template <typename C, typename B> |
---|
162 | inline std::basic_ostream<C>& |
---|
163 | operator<< (std::basic_ostream<C>& os, const language<C, B>& v) |
---|
164 | { |
---|
165 | const B& r (v); |
---|
166 | return os << r; |
---|
167 | } |
---|
168 | |
---|
169 | |
---|
170 | // id |
---|
171 | // |
---|
172 | template <typename C, typename B> |
---|
173 | inline std::basic_ostream<C>& |
---|
174 | operator<< (std::basic_ostream<C>& os, const id<C, B>& v) |
---|
175 | { |
---|
176 | const B& r (v); |
---|
177 | return os << r; |
---|
178 | } |
---|
179 | |
---|
180 | |
---|
181 | // idref |
---|
182 | // |
---|
183 | template <typename X, typename C, typename B> |
---|
184 | inline std::basic_ostream<C>& |
---|
185 | operator<< (std::basic_ostream<C>& os, const idref<X, C, B>& v) |
---|
186 | { |
---|
187 | const B& r (v); |
---|
188 | return os << r; |
---|
189 | } |
---|
190 | |
---|
191 | |
---|
192 | // idrefs |
---|
193 | // |
---|
194 | template <typename C, typename B, typename idref> |
---|
195 | inline std::basic_ostream<C>& |
---|
196 | operator<< (std::basic_ostream<C>& os, const idrefs<C, B, idref>& v) |
---|
197 | { |
---|
198 | const list<idref, C>& r (v); |
---|
199 | return os << r; |
---|
200 | } |
---|
201 | |
---|
202 | |
---|
203 | // uri |
---|
204 | // |
---|
205 | template <typename C, typename B> |
---|
206 | inline std::basic_ostream<C>& |
---|
207 | operator<< (std::basic_ostream<C>& os, const uri<C, B>& v) |
---|
208 | { |
---|
209 | const std::basic_string<C>& r (v); |
---|
210 | return os << r; |
---|
211 | } |
---|
212 | |
---|
213 | |
---|
214 | // qname |
---|
215 | // |
---|
216 | template <typename C, typename B, typename uri, typename ncname> |
---|
217 | inline std::basic_ostream<C>& |
---|
218 | operator<< (std::basic_ostream<C>& os, |
---|
219 | const qname<C, B, uri, ncname>& n) |
---|
220 | { |
---|
221 | if (n.qualified ()) |
---|
222 | os << n.namespace_ () << C ('#'); |
---|
223 | |
---|
224 | return os << n.name (); |
---|
225 | } |
---|
226 | |
---|
227 | |
---|
228 | // base64_binary |
---|
229 | // |
---|
230 | template <typename C, typename B> |
---|
231 | inline std::basic_ostream<C>& |
---|
232 | operator<< (std::basic_ostream<C>& os, const base64_binary<C, B>& v) |
---|
233 | { |
---|
234 | return os << v.encode (); |
---|
235 | } |
---|
236 | |
---|
237 | |
---|
238 | // hex_binary |
---|
239 | // |
---|
240 | template <typename C, typename B> |
---|
241 | inline std::basic_ostream<C>& |
---|
242 | operator<< (std::basic_ostream<C>& os, const hex_binary<C, B>& v) |
---|
243 | { |
---|
244 | return os << v.encode (); |
---|
245 | } |
---|
246 | |
---|
247 | |
---|
248 | // entity |
---|
249 | // |
---|
250 | template <typename C, typename B> |
---|
251 | inline std::basic_ostream<C>& |
---|
252 | operator<< (std::basic_ostream<C>& os, const entity<C, B>& v) |
---|
253 | { |
---|
254 | const B& r (v); |
---|
255 | return os << r; |
---|
256 | } |
---|
257 | |
---|
258 | |
---|
259 | // entities |
---|
260 | // |
---|
261 | template <typename C, typename B, typename entity> |
---|
262 | inline std::basic_ostream<C>& |
---|
263 | operator<< (std::basic_ostream<C>& os, const entities<C, B, entity>& v) |
---|
264 | { |
---|
265 | const list<entity, C>& r (v); |
---|
266 | return os << r; |
---|
267 | } |
---|
268 | } |
---|
269 | } |
---|
270 | } |
---|
271 | |
---|
272 | #include <xsd/cxx/tree/date-time-ostream.txx> |
---|
273 | |
---|
274 | #endif // XSD_CXX_TREE_STD_OSTREAM_OPERATORS_HXX |
---|