[111] | 1 | // file : xsd/cxx/tree/stream-extraction.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_STREAM_EXTRACTION_HXX |
---|
| 7 | #define XSD_CXX_TREE_STREAM_EXTRACTION_HXX |
---|
| 8 | |
---|
| 9 | #include <xsd/cxx/tree/elements.hxx> |
---|
| 10 | #include <xsd/cxx/tree/types.hxx> |
---|
| 11 | #include <xsd/cxx/tree/list.hxx> |
---|
| 12 | |
---|
| 13 | #include <xsd/cxx/tree/istream.hxx> |
---|
| 14 | |
---|
| 15 | namespace xsd |
---|
| 16 | { |
---|
| 17 | namespace cxx |
---|
| 18 | { |
---|
| 19 | namespace tree |
---|
| 20 | { |
---|
| 21 | // type |
---|
| 22 | // |
---|
| 23 | template <typename S> |
---|
| 24 | inline _type:: |
---|
| 25 | _type (istream<S>&, flags, container* c) |
---|
| 26 | : container_ (c) |
---|
| 27 | { |
---|
| 28 | } |
---|
| 29 | |
---|
| 30 | // simple_type |
---|
| 31 | // |
---|
| 32 | template <typename B> |
---|
| 33 | template <typename S> |
---|
| 34 | inline simple_type<B>:: |
---|
| 35 | simple_type (istream<S>& s, flags f, container* c) |
---|
| 36 | : type (s, f, c) |
---|
| 37 | { |
---|
| 38 | } |
---|
| 39 | |
---|
| 40 | // fundamental_base |
---|
| 41 | // |
---|
| 42 | template <typename X, typename C, typename B> |
---|
| 43 | template <typename S> |
---|
| 44 | inline fundamental_base<X, C, B>:: |
---|
| 45 | fundamental_base (istream<S>& s, flags f, container* c) |
---|
| 46 | : B (s, f, c) |
---|
| 47 | { |
---|
| 48 | X& r (*this); |
---|
| 49 | s >> r; |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | // list |
---|
| 53 | // |
---|
| 54 | template <typename X, typename C> |
---|
| 55 | template <typename S> |
---|
| 56 | list<X, C, false>:: |
---|
| 57 | list (istream<S>& s, flags f, container* c) |
---|
| 58 | : sequence<X> (f, c) |
---|
| 59 | { |
---|
| 60 | std::size_t size; |
---|
| 61 | istream_common::as_size<std::size_t> as_size (size); |
---|
| 62 | s >> as_size; |
---|
| 63 | |
---|
| 64 | if (size > 0) |
---|
| 65 | { |
---|
| 66 | this->reserve (size); |
---|
| 67 | |
---|
| 68 | while (size--) |
---|
| 69 | { |
---|
| 70 | std::auto_ptr<X> p (new X (s, f, c)); |
---|
| 71 | push_back (p); |
---|
| 72 | } |
---|
| 73 | } |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | template <typename X, typename C> |
---|
| 77 | template <typename S> |
---|
| 78 | list<X, C, true>:: |
---|
| 79 | list (istream<S>& s, flags f, container* c) |
---|
| 80 | : sequence<X> (f, c) |
---|
| 81 | { |
---|
| 82 | std::size_t size; |
---|
| 83 | istream_common::as_size<std::size_t> as_size (size); |
---|
| 84 | s >> as_size; |
---|
| 85 | |
---|
| 86 | if (size > 0) |
---|
| 87 | { |
---|
| 88 | this->reserve (size); |
---|
| 89 | |
---|
| 90 | while (size--) |
---|
| 91 | { |
---|
| 92 | X x; |
---|
| 93 | s >> x; |
---|
| 94 | push_back (x); |
---|
| 95 | } |
---|
| 96 | } |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | // Extraction operators for built-in types. |
---|
| 100 | // |
---|
| 101 | |
---|
| 102 | |
---|
| 103 | // string |
---|
| 104 | // |
---|
| 105 | template <typename C, typename B> |
---|
| 106 | template <typename S> |
---|
| 107 | inline string<C, B>:: |
---|
| 108 | string (istream<S>& s, flags f, container* c) |
---|
| 109 | : B (s, f, c) |
---|
| 110 | { |
---|
| 111 | std::basic_string<C>& r (*this); |
---|
| 112 | s >> r; |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | |
---|
| 116 | // normalized_string |
---|
| 117 | // |
---|
| 118 | template <typename C, typename B> |
---|
| 119 | template <typename S> |
---|
| 120 | inline normalized_string<C, B>:: |
---|
| 121 | normalized_string (istream<S>& s, flags f, container* c) |
---|
| 122 | : B (s, f, c) |
---|
| 123 | { |
---|
| 124 | } |
---|
| 125 | |
---|
| 126 | |
---|
| 127 | // token |
---|
| 128 | // |
---|
| 129 | template <typename C, typename B> |
---|
| 130 | template <typename S> |
---|
| 131 | inline token<C, B>:: |
---|
| 132 | token (istream<S>& s, flags f, container* c) |
---|
| 133 | : B (s, f, c) |
---|
| 134 | { |
---|
| 135 | } |
---|
| 136 | |
---|
| 137 | |
---|
| 138 | // nmtoken |
---|
| 139 | // |
---|
| 140 | template <typename C, typename B> |
---|
| 141 | template <typename S> |
---|
| 142 | inline nmtoken<C, B>:: |
---|
| 143 | nmtoken (istream<S>& s, flags f, container* c) |
---|
| 144 | : B (s, f, c) |
---|
| 145 | { |
---|
| 146 | } |
---|
| 147 | |
---|
| 148 | |
---|
| 149 | // nmtokens |
---|
| 150 | // |
---|
| 151 | template <typename C, typename B, typename nmtoken> |
---|
| 152 | template <typename S> |
---|
| 153 | inline nmtokens<C, B, nmtoken>:: |
---|
| 154 | nmtokens (istream<S>& s, flags f, container* c) |
---|
| 155 | : B (s, f, c), base_type (s, f, c) |
---|
| 156 | { |
---|
| 157 | } |
---|
| 158 | |
---|
| 159 | |
---|
| 160 | // name |
---|
| 161 | // |
---|
| 162 | template <typename C, typename B> |
---|
| 163 | template <typename S> |
---|
| 164 | inline name<C, B>:: |
---|
| 165 | name (istream<S>& s, flags f, container* c) |
---|
| 166 | : B (s, f, c) |
---|
| 167 | { |
---|
| 168 | } |
---|
| 169 | |
---|
| 170 | |
---|
| 171 | // ncname |
---|
| 172 | // |
---|
| 173 | template <typename C, typename B> |
---|
| 174 | template <typename S> |
---|
| 175 | inline ncname<C, B>:: |
---|
| 176 | ncname (istream<S>& s, flags f, container* c) |
---|
| 177 | : B (s, f, c) |
---|
| 178 | { |
---|
| 179 | } |
---|
| 180 | |
---|
| 181 | |
---|
| 182 | // language |
---|
| 183 | // |
---|
| 184 | template <typename C, typename B> |
---|
| 185 | template <typename S> |
---|
| 186 | inline language<C, B>:: |
---|
| 187 | language (istream<S>& s, flags f, container* c) |
---|
| 188 | : B (s, f, c) |
---|
| 189 | { |
---|
| 190 | } |
---|
| 191 | |
---|
| 192 | |
---|
| 193 | // id |
---|
| 194 | // |
---|
| 195 | template <typename C, typename B> |
---|
| 196 | template <typename S> |
---|
| 197 | inline id<C, B>:: |
---|
| 198 | id (istream<S>& s, flags f, container* c) |
---|
| 199 | : B (s, f, c), identity_ (*this) |
---|
| 200 | { |
---|
| 201 | register_id (); |
---|
| 202 | } |
---|
| 203 | |
---|
| 204 | |
---|
| 205 | // idref |
---|
| 206 | // |
---|
| 207 | template <typename X, typename C, typename B> |
---|
| 208 | template <typename S> |
---|
| 209 | inline idref<X, C, B>:: |
---|
| 210 | idref (istream<S>& s, flags f, container* c) |
---|
| 211 | : B (s, f, c), identity_ (*this) |
---|
| 212 | { |
---|
| 213 | } |
---|
| 214 | |
---|
| 215 | |
---|
| 216 | // idrefs |
---|
| 217 | // |
---|
| 218 | template <typename C, typename B, typename idref> |
---|
| 219 | template <typename S> |
---|
| 220 | inline idrefs<C, B, idref>:: |
---|
| 221 | idrefs (istream<S>& s, flags f, container* c) |
---|
| 222 | : B (s, f, c), base_type (s, f, c) |
---|
| 223 | { |
---|
| 224 | } |
---|
| 225 | |
---|
| 226 | |
---|
| 227 | // uri |
---|
| 228 | // |
---|
| 229 | template <typename C, typename B> |
---|
| 230 | template <typename S> |
---|
| 231 | inline uri<C, B>:: |
---|
| 232 | uri (istream<S>& s, flags f, container* c) |
---|
| 233 | : B (s, f, c) |
---|
| 234 | { |
---|
| 235 | std::basic_string<C>& r (*this); |
---|
| 236 | s >> r; |
---|
| 237 | } |
---|
| 238 | |
---|
| 239 | |
---|
| 240 | // qname |
---|
| 241 | // |
---|
| 242 | template <typename C, typename B, typename uri, typename ncname> |
---|
| 243 | template <typename S> |
---|
| 244 | inline qname<C, B, uri, ncname>:: |
---|
| 245 | qname (istream<S>& s, flags f, container* c) |
---|
| 246 | : B (s, f, c), ns_ (s), name_ (s) |
---|
| 247 | { |
---|
| 248 | } |
---|
| 249 | |
---|
| 250 | |
---|
| 251 | // base64_binary |
---|
| 252 | // |
---|
| 253 | template <typename C, typename B> |
---|
| 254 | template <typename S> |
---|
| 255 | inline base64_binary<C, B>:: |
---|
| 256 | base64_binary (istream<S>& s, flags f, container* c) |
---|
| 257 | : B (s, f, c) |
---|
| 258 | { |
---|
| 259 | buffer<C>& r (*this); |
---|
| 260 | s >> r; |
---|
| 261 | } |
---|
| 262 | |
---|
| 263 | |
---|
| 264 | // hex_binary |
---|
| 265 | // |
---|
| 266 | template <typename C, typename B> |
---|
| 267 | template <typename S> |
---|
| 268 | inline hex_binary<C, B>:: |
---|
| 269 | hex_binary (istream<S>& s, flags f, container* c) |
---|
| 270 | : B (s, f, c) |
---|
| 271 | { |
---|
| 272 | buffer<C>& r (*this); |
---|
| 273 | s >> r; |
---|
| 274 | } |
---|
| 275 | |
---|
| 276 | |
---|
| 277 | // entity |
---|
| 278 | // |
---|
| 279 | template <typename C, typename B> |
---|
| 280 | template <typename S> |
---|
| 281 | inline entity<C, B>:: |
---|
| 282 | entity (istream<S>& s, flags f, container* c) |
---|
| 283 | : B (s, f, c) |
---|
| 284 | { |
---|
| 285 | } |
---|
| 286 | |
---|
| 287 | |
---|
| 288 | // entities |
---|
| 289 | // |
---|
| 290 | template <typename C, typename B, typename entity> |
---|
| 291 | template <typename S> |
---|
| 292 | inline entities<C, B, entity>:: |
---|
| 293 | entities (istream<S>& s, flags f, container* c) |
---|
| 294 | : B (s, f, c), base_type (s, f, c) |
---|
| 295 | { |
---|
| 296 | } |
---|
| 297 | } |
---|
| 298 | } |
---|
| 299 | } |
---|
| 300 | |
---|
| 301 | #include <xsd/cxx/tree/date-time-extraction.txx> |
---|
| 302 | |
---|
| 303 | #endif // XSD_CXX_TREE_STREAM_EXTRACTION_HXX |
---|