| 1 | // file : xsd/cxx/parser/xml-schema.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_PARSER_XML_SCHEMA_HXX |
|---|
| 7 | #define XSD_CXX_PARSER_XML_SCHEMA_HXX |
|---|
| 8 | |
|---|
| 9 | #include <string> |
|---|
| 10 | #include <vector> |
|---|
| 11 | #include <cstddef> // std::size_t |
|---|
| 12 | |
|---|
| 13 | namespace xsd |
|---|
| 14 | { |
|---|
| 15 | namespace cxx |
|---|
| 16 | { |
|---|
| 17 | namespace parser |
|---|
| 18 | { |
|---|
| 19 | // String sequence. Used for the NMTOKENS and IDREFS types. |
|---|
| 20 | // |
|---|
| 21 | template <typename C> |
|---|
| 22 | class string_sequence: public std::vector<std::basic_string<C> > |
|---|
| 23 | { |
|---|
| 24 | public: |
|---|
| 25 | typedef std::basic_string<C> value_type; |
|---|
| 26 | typedef std::vector<value_type> base; |
|---|
| 27 | typedef typename base::size_type size_type; |
|---|
| 28 | |
|---|
| 29 | string_sequence (); |
|---|
| 30 | |
|---|
| 31 | explicit |
|---|
| 32 | string_sequence (size_type n, const value_type& x = value_type ()); |
|---|
| 33 | |
|---|
| 34 | template <typename I> |
|---|
| 35 | string_sequence (const I& begin, const I& end); |
|---|
| 36 | }; |
|---|
| 37 | |
|---|
| 38 | template <typename C> |
|---|
| 39 | bool |
|---|
| 40 | operator== (const string_sequence<C>&, const string_sequence<C>&); |
|---|
| 41 | |
|---|
| 42 | template <typename C> |
|---|
| 43 | bool |
|---|
| 44 | operator!= (const string_sequence<C>&, const string_sequence<C>&); |
|---|
| 45 | |
|---|
| 46 | |
|---|
| 47 | // QName |
|---|
| 48 | // |
|---|
| 49 | template <typename C> |
|---|
| 50 | class qname |
|---|
| 51 | { |
|---|
| 52 | public: |
|---|
| 53 | explicit |
|---|
| 54 | qname (const std::basic_string<C>& name); |
|---|
| 55 | |
|---|
| 56 | qname (const std::basic_string<C>& prefix, |
|---|
| 57 | const std::basic_string<C>& name); |
|---|
| 58 | |
|---|
| 59 | void |
|---|
| 60 | swap (qname&); |
|---|
| 61 | |
|---|
| 62 | const std::basic_string<C>& |
|---|
| 63 | prefix () const; |
|---|
| 64 | |
|---|
| 65 | std::basic_string<C>& |
|---|
| 66 | prefix (); |
|---|
| 67 | |
|---|
| 68 | void |
|---|
| 69 | prefix (const std::basic_string<C>&); |
|---|
| 70 | |
|---|
| 71 | const std::basic_string<C>& |
|---|
| 72 | name () const; |
|---|
| 73 | |
|---|
| 74 | std::basic_string<C>& |
|---|
| 75 | name (); |
|---|
| 76 | |
|---|
| 77 | void |
|---|
| 78 | name (const std::basic_string<C>&); |
|---|
| 79 | |
|---|
| 80 | private: |
|---|
| 81 | std::basic_string<C> prefix_; |
|---|
| 82 | std::basic_string<C> name_; |
|---|
| 83 | }; |
|---|
| 84 | |
|---|
| 85 | template <typename C> |
|---|
| 86 | bool |
|---|
| 87 | operator== (const qname<C>&, const qname<C>&); |
|---|
| 88 | |
|---|
| 89 | template <typename C> |
|---|
| 90 | bool |
|---|
| 91 | operator!= (const qname<C>&, const qname<C>&); |
|---|
| 92 | |
|---|
| 93 | |
|---|
| 94 | // Binary buffer. Used for the base64Binary and hexBinary types. |
|---|
| 95 | // |
|---|
| 96 | class buffer |
|---|
| 97 | { |
|---|
| 98 | public: |
|---|
| 99 | typedef std::size_t size_t; |
|---|
| 100 | |
|---|
| 101 | class bounds {}; // Out of bounds exception. |
|---|
| 102 | |
|---|
| 103 | public: |
|---|
| 104 | ~buffer (); |
|---|
| 105 | |
|---|
| 106 | explicit |
|---|
| 107 | buffer (size_t size = 0); |
|---|
| 108 | buffer (size_t size, size_t capacity); |
|---|
| 109 | buffer (const void* data, size_t size); |
|---|
| 110 | buffer (const void* data, size_t size, size_t capacity); |
|---|
| 111 | |
|---|
| 112 | // If the assume_ownership argument is true, the buffer will |
|---|
| 113 | // assume the ownership of the data and will release the memory |
|---|
| 114 | // by calling operator delete (). |
|---|
| 115 | // |
|---|
| 116 | buffer (void* data, |
|---|
| 117 | size_t size, |
|---|
| 118 | size_t capacity, |
|---|
| 119 | bool assume_ownership); |
|---|
| 120 | |
|---|
| 121 | buffer (const buffer&); |
|---|
| 122 | |
|---|
| 123 | public: |
|---|
| 124 | buffer& |
|---|
| 125 | operator= (const buffer&); |
|---|
| 126 | |
|---|
| 127 | public: |
|---|
| 128 | size_t |
|---|
| 129 | capacity () const; |
|---|
| 130 | |
|---|
| 131 | // Returns true if the underlying buffer has moved. |
|---|
| 132 | // |
|---|
| 133 | bool |
|---|
| 134 | capacity (size_t); |
|---|
| 135 | |
|---|
| 136 | public: |
|---|
| 137 | size_t |
|---|
| 138 | size () const; |
|---|
| 139 | |
|---|
| 140 | // Returns true if the underlying buffer has moved. |
|---|
| 141 | // |
|---|
| 142 | bool |
|---|
| 143 | size (size_t); |
|---|
| 144 | |
|---|
| 145 | public: |
|---|
| 146 | const char* |
|---|
| 147 | data () const; |
|---|
| 148 | |
|---|
| 149 | char* |
|---|
| 150 | data (); |
|---|
| 151 | |
|---|
| 152 | const char* |
|---|
| 153 | begin () const; |
|---|
| 154 | |
|---|
| 155 | char* |
|---|
| 156 | begin (); |
|---|
| 157 | |
|---|
| 158 | const char* |
|---|
| 159 | end () const; |
|---|
| 160 | |
|---|
| 161 | char* |
|---|
| 162 | end (); |
|---|
| 163 | |
|---|
| 164 | public: |
|---|
| 165 | void |
|---|
| 166 | swap (buffer&); |
|---|
| 167 | |
|---|
| 168 | private: |
|---|
| 169 | bool |
|---|
| 170 | capacity (size_t capacity, bool copy); |
|---|
| 171 | |
|---|
| 172 | private: |
|---|
| 173 | char* data_; |
|---|
| 174 | size_t size_; |
|---|
| 175 | size_t capacity_; |
|---|
| 176 | }; |
|---|
| 177 | |
|---|
| 178 | bool |
|---|
| 179 | operator== (const buffer&, const buffer&); |
|---|
| 180 | |
|---|
| 181 | bool |
|---|
| 182 | operator!= (const buffer&, const buffer&); |
|---|
| 183 | |
|---|
| 184 | |
|---|
| 185 | // Time and date types. |
|---|
| 186 | // |
|---|
| 187 | |
|---|
| 188 | class time_zone |
|---|
| 189 | { |
|---|
| 190 | public: |
|---|
| 191 | time_zone (); |
|---|
| 192 | time_zone (short hours, short minutes); |
|---|
| 193 | |
|---|
| 194 | // Returns true if time zone is specified. |
|---|
| 195 | // |
|---|
| 196 | bool |
|---|
| 197 | zone_present () const; |
|---|
| 198 | |
|---|
| 199 | // Resets the time zone to the 'not specified' state. |
|---|
| 200 | // |
|---|
| 201 | void |
|---|
| 202 | zone_reset (); |
|---|
| 203 | |
|---|
| 204 | short |
|---|
| 205 | zone_hours () const; |
|---|
| 206 | |
|---|
| 207 | void |
|---|
| 208 | zone_hours (short); |
|---|
| 209 | |
|---|
| 210 | short |
|---|
| 211 | zone_minutes () const; |
|---|
| 212 | |
|---|
| 213 | void |
|---|
| 214 | zone_minutes (short); |
|---|
| 215 | |
|---|
| 216 | private: |
|---|
| 217 | bool present_; |
|---|
| 218 | short hours_; |
|---|
| 219 | short minutes_; |
|---|
| 220 | }; |
|---|
| 221 | |
|---|
| 222 | bool |
|---|
| 223 | operator== (const time_zone&, const time_zone&); |
|---|
| 224 | |
|---|
| 225 | bool |
|---|
| 226 | operator!= (const time_zone&, const time_zone&); |
|---|
| 227 | |
|---|
| 228 | |
|---|
| 229 | class gday: public time_zone |
|---|
| 230 | { |
|---|
| 231 | public: |
|---|
| 232 | explicit |
|---|
| 233 | gday (unsigned short day); |
|---|
| 234 | gday (unsigned short day, short zone_hours, short zone_minutes); |
|---|
| 235 | |
|---|
| 236 | unsigned short |
|---|
| 237 | day () const; |
|---|
| 238 | |
|---|
| 239 | void |
|---|
| 240 | day (unsigned short); |
|---|
| 241 | |
|---|
| 242 | private: |
|---|
| 243 | unsigned short day_; |
|---|
| 244 | }; |
|---|
| 245 | |
|---|
| 246 | bool |
|---|
| 247 | operator== (const gday&, const gday&); |
|---|
| 248 | |
|---|
| 249 | bool |
|---|
| 250 | operator!= (const gday&, const gday&); |
|---|
| 251 | |
|---|
| 252 | |
|---|
| 253 | class gmonth: public time_zone |
|---|
| 254 | { |
|---|
| 255 | public: |
|---|
| 256 | explicit |
|---|
| 257 | gmonth (unsigned short month); |
|---|
| 258 | gmonth (unsigned short month, short zone_hours, short zone_minutes); |
|---|
| 259 | |
|---|
| 260 | unsigned short |
|---|
| 261 | month () const; |
|---|
| 262 | |
|---|
| 263 | void |
|---|
| 264 | month (unsigned short); |
|---|
| 265 | |
|---|
| 266 | private: |
|---|
| 267 | unsigned short month_; |
|---|
| 268 | }; |
|---|
| 269 | |
|---|
| 270 | bool |
|---|
| 271 | operator== (const gmonth&, const gmonth&); |
|---|
| 272 | |
|---|
| 273 | bool |
|---|
| 274 | operator!= (const gmonth&, const gmonth&); |
|---|
| 275 | |
|---|
| 276 | |
|---|
| 277 | class gyear: public time_zone |
|---|
| 278 | { |
|---|
| 279 | public: |
|---|
| 280 | explicit |
|---|
| 281 | gyear (int year); |
|---|
| 282 | gyear (int year, short zone_hours, short zone_minutes); |
|---|
| 283 | |
|---|
| 284 | int |
|---|
| 285 | year () const; |
|---|
| 286 | |
|---|
| 287 | void |
|---|
| 288 | year (int); |
|---|
| 289 | |
|---|
| 290 | private: |
|---|
| 291 | int year_; |
|---|
| 292 | }; |
|---|
| 293 | |
|---|
| 294 | bool |
|---|
| 295 | operator== (const gyear&, const gyear&); |
|---|
| 296 | |
|---|
| 297 | bool |
|---|
| 298 | operator!= (const gyear&, const gyear&); |
|---|
| 299 | |
|---|
| 300 | |
|---|
| 301 | class gmonth_day: public time_zone |
|---|
| 302 | { |
|---|
| 303 | public: |
|---|
| 304 | gmonth_day (unsigned short month, unsigned short day); |
|---|
| 305 | gmonth_day (unsigned short month, unsigned short day, |
|---|
| 306 | short zone_hours, short zone_minutes); |
|---|
| 307 | |
|---|
| 308 | unsigned short |
|---|
| 309 | month () const; |
|---|
| 310 | |
|---|
| 311 | void |
|---|
| 312 | month (unsigned short); |
|---|
| 313 | |
|---|
| 314 | unsigned short |
|---|
| 315 | day () const; |
|---|
| 316 | |
|---|
| 317 | void |
|---|
| 318 | day (unsigned short); |
|---|
| 319 | |
|---|
| 320 | private: |
|---|
| 321 | unsigned short month_; |
|---|
| 322 | unsigned short day_; |
|---|
| 323 | }; |
|---|
| 324 | |
|---|
| 325 | bool |
|---|
| 326 | operator== (const gmonth_day&, const gmonth_day&); |
|---|
| 327 | |
|---|
| 328 | bool |
|---|
| 329 | operator!= (const gmonth_day&, const gmonth_day&); |
|---|
| 330 | |
|---|
| 331 | |
|---|
| 332 | class gyear_month: public time_zone |
|---|
| 333 | { |
|---|
| 334 | public: |
|---|
| 335 | gyear_month (int year, unsigned short month); |
|---|
| 336 | gyear_month (int year, unsigned short month, |
|---|
| 337 | short zone_hours, short zone_minutes); |
|---|
| 338 | |
|---|
| 339 | int |
|---|
| 340 | year () const; |
|---|
| 341 | |
|---|
| 342 | void |
|---|
| 343 | year (int); |
|---|
| 344 | |
|---|
| 345 | unsigned short |
|---|
| 346 | month () const; |
|---|
| 347 | |
|---|
| 348 | void |
|---|
| 349 | month (unsigned short); |
|---|
| 350 | |
|---|
| 351 | private: |
|---|
| 352 | int year_; |
|---|
| 353 | unsigned short month_; |
|---|
| 354 | }; |
|---|
| 355 | |
|---|
| 356 | bool |
|---|
| 357 | operator== (const gyear_month&, const gyear_month&); |
|---|
| 358 | |
|---|
| 359 | bool |
|---|
| 360 | operator!= (const gyear_month&, const gyear_month&); |
|---|
| 361 | |
|---|
| 362 | |
|---|
| 363 | class date: public time_zone |
|---|
| 364 | { |
|---|
| 365 | public: |
|---|
| 366 | date (int year, unsigned short month, unsigned short day); |
|---|
| 367 | date (int year, unsigned short month, unsigned short day, |
|---|
| 368 | short zone_hours, short zone_minutes); |
|---|
| 369 | |
|---|
| 370 | int |
|---|
| 371 | year () const; |
|---|
| 372 | |
|---|
| 373 | void |
|---|
| 374 | year (int); |
|---|
| 375 | |
|---|
| 376 | unsigned short |
|---|
| 377 | month () const; |
|---|
| 378 | |
|---|
| 379 | void |
|---|
| 380 | month (unsigned short); |
|---|
| 381 | |
|---|
| 382 | unsigned short |
|---|
| 383 | day () const; |
|---|
| 384 | |
|---|
| 385 | void |
|---|
| 386 | day (unsigned short); |
|---|
| 387 | |
|---|
| 388 | private: |
|---|
| 389 | int year_; |
|---|
| 390 | unsigned short month_; |
|---|
| 391 | unsigned short day_; |
|---|
| 392 | }; |
|---|
| 393 | |
|---|
| 394 | bool |
|---|
| 395 | operator== (const date&, const date&); |
|---|
| 396 | |
|---|
| 397 | bool |
|---|
| 398 | operator!= (const date&, const date&); |
|---|
| 399 | |
|---|
| 400 | |
|---|
| 401 | class time: public time_zone |
|---|
| 402 | { |
|---|
| 403 | public: |
|---|
| 404 | time (unsigned short hours, unsigned short minutes, double seconds); |
|---|
| 405 | time (unsigned short hours, unsigned short minutes, double seconds, |
|---|
| 406 | short zone_hours, short zone_minutes); |
|---|
| 407 | |
|---|
| 408 | unsigned short |
|---|
| 409 | hours () const; |
|---|
| 410 | |
|---|
| 411 | void |
|---|
| 412 | hours (unsigned short); |
|---|
| 413 | |
|---|
| 414 | unsigned short |
|---|
| 415 | minutes () const; |
|---|
| 416 | |
|---|
| 417 | void |
|---|
| 418 | minutes (unsigned short); |
|---|
| 419 | |
|---|
| 420 | double |
|---|
| 421 | seconds () const; |
|---|
| 422 | |
|---|
| 423 | void |
|---|
| 424 | seconds (double); |
|---|
| 425 | |
|---|
| 426 | private: |
|---|
| 427 | unsigned short hours_; |
|---|
| 428 | unsigned short minutes_; |
|---|
| 429 | double seconds_; |
|---|
| 430 | }; |
|---|
| 431 | |
|---|
| 432 | bool |
|---|
| 433 | operator== (const time&, const time&); |
|---|
| 434 | |
|---|
| 435 | bool |
|---|
| 436 | operator!= (const time&, const time&); |
|---|
| 437 | |
|---|
| 438 | |
|---|
| 439 | class date_time: public time_zone |
|---|
| 440 | { |
|---|
| 441 | public: |
|---|
| 442 | date_time (int year, unsigned short month, unsigned short day, |
|---|
| 443 | unsigned short hours, unsigned short minutes, double seconds); |
|---|
| 444 | |
|---|
| 445 | date_time (int year, unsigned short month, unsigned short day, |
|---|
| 446 | unsigned short hours, unsigned short minutes, double seconds, |
|---|
| 447 | short zone_hours, short zone_minutes); |
|---|
| 448 | |
|---|
| 449 | int |
|---|
| 450 | year () const; |
|---|
| 451 | |
|---|
| 452 | void |
|---|
| 453 | year (int); |
|---|
| 454 | |
|---|
| 455 | unsigned short |
|---|
| 456 | month () const; |
|---|
| 457 | |
|---|
| 458 | void |
|---|
| 459 | month (unsigned short); |
|---|
| 460 | |
|---|
| 461 | unsigned short |
|---|
| 462 | day () const; |
|---|
| 463 | |
|---|
| 464 | void |
|---|
| 465 | day (unsigned short); |
|---|
| 466 | |
|---|
| 467 | unsigned short |
|---|
| 468 | hours () const; |
|---|
| 469 | |
|---|
| 470 | void |
|---|
| 471 | hours (unsigned short); |
|---|
| 472 | |
|---|
| 473 | unsigned short |
|---|
| 474 | minutes () const; |
|---|
| 475 | |
|---|
| 476 | void |
|---|
| 477 | minutes (unsigned short); |
|---|
| 478 | |
|---|
| 479 | double |
|---|
| 480 | seconds () const; |
|---|
| 481 | |
|---|
| 482 | void |
|---|
| 483 | seconds (double); |
|---|
| 484 | |
|---|
| 485 | private: |
|---|
| 486 | int year_; |
|---|
| 487 | unsigned short month_; |
|---|
| 488 | unsigned short day_; |
|---|
| 489 | unsigned short hours_; |
|---|
| 490 | unsigned short minutes_; |
|---|
| 491 | double seconds_; |
|---|
| 492 | }; |
|---|
| 493 | |
|---|
| 494 | bool |
|---|
| 495 | operator== (const date_time&, const date_time&); |
|---|
| 496 | |
|---|
| 497 | bool |
|---|
| 498 | operator!= (const date_time&, const date_time&); |
|---|
| 499 | |
|---|
| 500 | |
|---|
| 501 | class duration |
|---|
| 502 | { |
|---|
| 503 | public: |
|---|
| 504 | duration (bool negative, |
|---|
| 505 | unsigned int years, unsigned int months, unsigned int days, |
|---|
| 506 | unsigned int hours, unsigned int minutes, double seconds); |
|---|
| 507 | |
|---|
| 508 | bool |
|---|
| 509 | negative () const; |
|---|
| 510 | |
|---|
| 511 | void |
|---|
| 512 | negative (bool); |
|---|
| 513 | |
|---|
| 514 | unsigned int |
|---|
| 515 | years () const; |
|---|
| 516 | |
|---|
| 517 | void |
|---|
| 518 | years (unsigned int); |
|---|
| 519 | |
|---|
| 520 | unsigned int |
|---|
| 521 | months () const; |
|---|
| 522 | |
|---|
| 523 | void |
|---|
| 524 | months (unsigned int); |
|---|
| 525 | |
|---|
| 526 | unsigned int |
|---|
| 527 | days () const; |
|---|
| 528 | |
|---|
| 529 | void |
|---|
| 530 | days (unsigned int); |
|---|
| 531 | |
|---|
| 532 | unsigned int |
|---|
| 533 | hours () const; |
|---|
| 534 | |
|---|
| 535 | void |
|---|
| 536 | hours (unsigned int); |
|---|
| 537 | |
|---|
| 538 | unsigned int |
|---|
| 539 | minutes () const; |
|---|
| 540 | |
|---|
| 541 | void |
|---|
| 542 | minutes (unsigned int); |
|---|
| 543 | |
|---|
| 544 | double |
|---|
| 545 | seconds () const; |
|---|
| 546 | |
|---|
| 547 | void |
|---|
| 548 | seconds (double); |
|---|
| 549 | |
|---|
| 550 | private: |
|---|
| 551 | bool negative_; |
|---|
| 552 | unsigned int years_; |
|---|
| 553 | unsigned int months_; |
|---|
| 554 | unsigned int days_; |
|---|
| 555 | unsigned int hours_; |
|---|
| 556 | unsigned int minutes_; |
|---|
| 557 | double seconds_; |
|---|
| 558 | }; |
|---|
| 559 | |
|---|
| 560 | bool |
|---|
| 561 | operator== (const duration&, const duration&); |
|---|
| 562 | |
|---|
| 563 | bool |
|---|
| 564 | operator!= (const duration&, const duration&); |
|---|
| 565 | } |
|---|
| 566 | } |
|---|
| 567 | } |
|---|
| 568 | |
|---|
| 569 | #include <xsd/cxx/parser/xml-schema.ixx> |
|---|
| 570 | #include <xsd/cxx/parser/xml-schema.txx> |
|---|
| 571 | |
|---|
| 572 | #endif // XSD_CXX_PARSER_XML_SCHEMA_HXX |
|---|