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