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