From f0510d2f90467de8e8f260b47d79a9baaf9bef17 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 17 Sep 2009 07:15:29 +0200 Subject: Start tracking XSD with git --- libxsd/FLOSSE | 89 + libxsd/GPLv2 | 340 ++ libxsd/INSTALL | 17 + libxsd/LICENSE | 26 + libxsd/README | 13 + libxsd/makefile | 20 + libxsd/xsd/cxx/auto-array.hxx | 114 + libxsd/xsd/cxx/compilers/vc-7/post.hxx | 6 + libxsd/xsd/cxx/compilers/vc-7/pre.hxx | 36 + libxsd/xsd/cxx/compilers/vc-8/post.hxx | 6 + libxsd/xsd/cxx/compilers/vc-8/pre.hxx | 28 + libxsd/xsd/cxx/config.hxx | 15 + libxsd/xsd/cxx/exceptions.hxx | 21 + libxsd/xsd/cxx/parser/document.hxx | 90 + libxsd/xsd/cxx/parser/document.txx | 129 + libxsd/xsd/cxx/parser/elements.hxx | 95 + libxsd/xsd/cxx/parser/elements.txx | 60 + libxsd/xsd/cxx/parser/error-handler.hxx | 57 + libxsd/xsd/cxx/parser/error-handler.txx | 41 + libxsd/xsd/cxx/parser/exceptions.hxx | 153 + libxsd/xsd/cxx/parser/exceptions.ixx | 129 + libxsd/xsd/cxx/parser/exceptions.txx | 59 + libxsd/xsd/cxx/parser/expat/elements.hxx | 344 ++ libxsd/xsd/cxx/parser/expat/elements.txx | 822 +++++ libxsd/xsd/cxx/parser/map.hxx | 79 + libxsd/xsd/cxx/parser/map.ixx | 27 + libxsd/xsd/cxx/parser/map.txx | 31 + libxsd/xsd/cxx/parser/non-validating/parser.hxx | 248 ++ libxsd/xsd/cxx/parser/non-validating/parser.txx | 464 +++ .../cxx/parser/non-validating/xml-schema-pimpl.hxx | 791 ++++ .../cxx/parser/non-validating/xml-schema-pimpl.ixx | 129 + .../cxx/parser/non-validating/xml-schema-pimpl.txx | 2068 +++++++++++ .../cxx/parser/non-validating/xml-schema-pskel.hxx | 647 ++++ .../cxx/parser/non-validating/xml-schema-pskel.ixx | 1249 +++++++ .../cxx/parser/non-validating/xml-schema-pskel.txx | 69 + libxsd/xsd/cxx/parser/schema-exceptions.hxx | 187 + libxsd/xsd/cxx/parser/schema-exceptions.ixx | 145 + libxsd/xsd/cxx/parser/schema-exceptions.txx | 75 + libxsd/xsd/cxx/parser/substitution-map.hxx | 230 ++ libxsd/xsd/cxx/parser/substitution-map.txx | 76 + libxsd/xsd/cxx/parser/validating/exceptions.hxx | 153 + libxsd/xsd/cxx/parser/validating/exceptions.ixx | 163 + libxsd/xsd/cxx/parser/validating/exceptions.txx | 97 + .../xsd/cxx/parser/validating/inheritance-map.hxx | 92 + .../xsd/cxx/parser/validating/inheritance-map.txx | 65 + libxsd/xsd/cxx/parser/validating/parser.hxx | 471 +++ libxsd/xsd/cxx/parser/validating/parser.txx | 667 ++++ .../xsd/cxx/parser/validating/xml-schema-pimpl.hxx | 1121 ++++++ .../xsd/cxx/parser/validating/xml-schema-pimpl.ixx | 676 ++++ .../xsd/cxx/parser/validating/xml-schema-pimpl.txx | 2746 ++++++++++++++ .../xsd/cxx/parser/validating/xml-schema-pskel.hxx | 647 ++++ .../xsd/cxx/parser/validating/xml-schema-pskel.ixx | 1249 +++++++ .../xsd/cxx/parser/validating/xml-schema-pskel.txx | 69 + libxsd/xsd/cxx/parser/xerces/elements.hxx | 462 +++ libxsd/xsd/cxx/parser/xerces/elements.txx | 964 +++++ libxsd/xsd/cxx/parser/xml-schema.hxx | 572 +++ libxsd/xsd/cxx/parser/xml-schema.ixx | 1022 ++++++ libxsd/xsd/cxx/parser/xml-schema.txx | 34 + libxsd/xsd/cxx/post.hxx | 13 + libxsd/xsd/cxx/pre.hxx | 15 + libxsd/xsd/cxx/ro-string.hxx | 430 +++ libxsd/xsd/cxx/ro-string.txx | 133 + libxsd/xsd/cxx/tree/ace-cdr-stream-common.hxx | 26 + libxsd/xsd/cxx/tree/ace-cdr-stream-extraction.hxx | 334 ++ libxsd/xsd/cxx/tree/ace-cdr-stream-insertion.hxx | 249 ++ libxsd/xsd/cxx/tree/bits/literals.hxx | 183 + libxsd/xsd/cxx/tree/bits/literals.ixx | 606 ++++ libxsd/xsd/cxx/tree/buffer.hxx | 336 ++ libxsd/xsd/cxx/tree/buffer.txx | 153 + libxsd/xsd/cxx/tree/comparison-map.hxx | 109 + libxsd/xsd/cxx/tree/comparison-map.txx | 287 ++ libxsd/xsd/cxx/tree/containers-wildcard.hxx | 1335 +++++++ libxsd/xsd/cxx/tree/containers.hxx | 1398 ++++++++ libxsd/xsd/cxx/tree/containers.txx | 284 ++ libxsd/xsd/cxx/tree/date-time-extraction.txx | 157 + libxsd/xsd/cxx/tree/date-time-insertion.txx | 188 + libxsd/xsd/cxx/tree/date-time-ostream.txx | 324 ++ libxsd/xsd/cxx/tree/date-time.hxx | 1951 ++++++++++ libxsd/xsd/cxx/tree/date-time.ixx | 893 +++++ libxsd/xsd/cxx/tree/date-time.txx | 94 + libxsd/xsd/cxx/tree/element-map.hxx | 146 + libxsd/xsd/cxx/tree/element-map.txx | 71 + libxsd/xsd/cxx/tree/elements.hxx | 1448 ++++++++ libxsd/xsd/cxx/tree/elements.txx | 57 + libxsd/xsd/cxx/tree/error-handler.hxx | 62 + libxsd/xsd/cxx/tree/error-handler.txx | 34 + libxsd/xsd/cxx/tree/exceptions.hxx | 1036 ++++++ libxsd/xsd/cxx/tree/exceptions.ixx | 467 +++ libxsd/xsd/cxx/tree/exceptions.txx | 338 ++ libxsd/xsd/cxx/tree/facet.hxx | 43 + libxsd/xsd/cxx/tree/istream-fwd.hxx | 21 + libxsd/xsd/cxx/tree/istream.hxx | 258 ++ libxsd/xsd/cxx/tree/list.hxx | 132 + libxsd/xsd/cxx/tree/ostream.hxx | 245 ++ libxsd/xsd/cxx/tree/parsing.hxx | 12 + libxsd/xsd/cxx/tree/parsing.txx | 915 +++++ libxsd/xsd/cxx/tree/parsing/boolean.hxx | 76 + libxsd/xsd/cxx/tree/parsing/byte.hxx | 80 + libxsd/xsd/cxx/tree/parsing/date-time.txx | 702 ++++ libxsd/xsd/cxx/tree/parsing/decimal.hxx | 85 + libxsd/xsd/cxx/tree/parsing/double.hxx | 94 + libxsd/xsd/cxx/tree/parsing/element-map.txx | 42 + libxsd/xsd/cxx/tree/parsing/float.hxx | 94 + libxsd/xsd/cxx/tree/parsing/int.hxx | 80 + libxsd/xsd/cxx/tree/parsing/long.hxx | 80 + libxsd/xsd/cxx/tree/parsing/short.hxx | 80 + libxsd/xsd/cxx/tree/parsing/unsigned-byte.hxx | 80 + libxsd/xsd/cxx/tree/parsing/unsigned-int.hxx | 80 + libxsd/xsd/cxx/tree/parsing/unsigned-long.hxx | 80 + libxsd/xsd/cxx/tree/parsing/unsigned-short.hxx | 80 + libxsd/xsd/cxx/tree/serialization.hxx | 66 + libxsd/xsd/cxx/tree/serialization.txx | 762 ++++ libxsd/xsd/cxx/tree/serialization/boolean.hxx | 52 + libxsd/xsd/cxx/tree/serialization/byte.hxx | 46 + libxsd/xsd/cxx/tree/serialization/date-time.txx | 620 ++++ libxsd/xsd/cxx/tree/serialization/decimal.hxx | 126 + libxsd/xsd/cxx/tree/serialization/double.hxx | 96 + libxsd/xsd/cxx/tree/serialization/element-map.txx | 40 + libxsd/xsd/cxx/tree/serialization/float.hxx | 94 + libxsd/xsd/cxx/tree/serialization/int.hxx | 46 + libxsd/xsd/cxx/tree/serialization/long.hxx | 46 + libxsd/xsd/cxx/tree/serialization/short.hxx | 46 + .../xsd/cxx/tree/serialization/unsigned-byte.hxx | 46 + libxsd/xsd/cxx/tree/serialization/unsigned-int.hxx | 46 + .../xsd/cxx/tree/serialization/unsigned-long.hxx | 46 + .../xsd/cxx/tree/serialization/unsigned-short.hxx | 46 + libxsd/xsd/cxx/tree/std-ostream-map.hxx | 110 + libxsd/xsd/cxx/tree/std-ostream-map.txx | 279 ++ libxsd/xsd/cxx/tree/std-ostream-operators.hxx | 274 ++ libxsd/xsd/cxx/tree/stream-extraction-map.hxx | 97 + libxsd/xsd/cxx/tree/stream-extraction-map.txx | 294 ++ libxsd/xsd/cxx/tree/stream-extraction.hxx | 303 ++ libxsd/xsd/cxx/tree/stream-insertion-map.hxx | 150 + libxsd/xsd/cxx/tree/stream-insertion-map.txx | 325 ++ libxsd/xsd/cxx/tree/stream-insertion.hxx | 273 ++ libxsd/xsd/cxx/tree/text.hxx | 30 + libxsd/xsd/cxx/tree/text.txx | 77 + libxsd/xsd/cxx/tree/type-factory-map.hxx | 151 + libxsd/xsd/cxx/tree/type-factory-map.txx | 436 +++ libxsd/xsd/cxx/tree/type-serializer-map.hxx | 217 ++ libxsd/xsd/cxx/tree/type-serializer-map.txx | 539 +++ libxsd/xsd/cxx/tree/types.hxx | 3788 ++++++++++++++++++++ libxsd/xsd/cxx/tree/types.txx | 610 ++++ libxsd/xsd/cxx/tree/xdr-stream-common.hxx | 26 + libxsd/xsd/cxx/tree/xdr-stream-extraction.hxx | 295 ++ libxsd/xsd/cxx/tree/xdr-stream-insertion.hxx | 259 ++ libxsd/xsd/cxx/version.hxx | 29 + libxsd/xsd/cxx/xml/bits/literals.hxx | 83 + libxsd/xsd/cxx/xml/bits/literals.ixx | 261 ++ libxsd/xsd/cxx/xml/dom/auto-ptr.hxx | 158 + .../xsd/cxx/xml/dom/bits/error-handler-proxy.hxx | 61 + .../xsd/cxx/xml/dom/bits/error-handler-proxy.txx | 80 + libxsd/xsd/cxx/xml/dom/elements.hxx | 36 + libxsd/xsd/cxx/xml/dom/elements.txx | 57 + libxsd/xsd/cxx/xml/dom/parsing-header.hxx | 24 + libxsd/xsd/cxx/xml/dom/parsing-source.hxx | 138 + libxsd/xsd/cxx/xml/dom/parsing-source.txx | 458 +++ libxsd/xsd/cxx/xml/dom/serialization-header.hxx | 81 + libxsd/xsd/cxx/xml/dom/serialization-header.txx | 192 + libxsd/xsd/cxx/xml/dom/serialization-source.hxx | 152 + libxsd/xsd/cxx/xml/dom/serialization-source.txx | 394 ++ libxsd/xsd/cxx/xml/dom/wildcard-source.hxx | 31 + libxsd/xsd/cxx/xml/dom/wildcard-source.txx | 39 + libxsd/xsd/cxx/xml/elements.hxx | 113 + libxsd/xsd/cxx/xml/elements.txx | 73 + libxsd/xsd/cxx/xml/error-handler.hxx | 60 + libxsd/xsd/cxx/xml/qualified-name.hxx | 84 + .../xsd/cxx/xml/sax/bits/error-handler-proxy.hxx | 81 + .../xsd/cxx/xml/sax/bits/error-handler-proxy.txx | 89 + libxsd/xsd/cxx/xml/sax/std-input-source.hxx | 174 + libxsd/xsd/cxx/xml/std-memory-manager.hxx | 50 + libxsd/xsd/cxx/xml/string.hxx | 90 + libxsd/xsd/cxx/xml/string.ixx | 225 ++ libxsd/xsd/cxx/xml/string.txx | 441 +++ libxsd/xsd/cxx/zc-istream.hxx | 92 + libxsd/xsd/cxx/zc-istream.txx | 94 + 176 files changed, 51708 insertions(+) create mode 100644 libxsd/FLOSSE create mode 100644 libxsd/GPLv2 create mode 100644 libxsd/INSTALL create mode 100644 libxsd/LICENSE create mode 100644 libxsd/README create mode 100644 libxsd/makefile create mode 100644 libxsd/xsd/cxx/auto-array.hxx create mode 100644 libxsd/xsd/cxx/compilers/vc-7/post.hxx create mode 100644 libxsd/xsd/cxx/compilers/vc-7/pre.hxx create mode 100644 libxsd/xsd/cxx/compilers/vc-8/post.hxx create mode 100644 libxsd/xsd/cxx/compilers/vc-8/pre.hxx create mode 100644 libxsd/xsd/cxx/config.hxx create mode 100644 libxsd/xsd/cxx/exceptions.hxx create mode 100644 libxsd/xsd/cxx/parser/document.hxx create mode 100644 libxsd/xsd/cxx/parser/document.txx create mode 100644 libxsd/xsd/cxx/parser/elements.hxx create mode 100644 libxsd/xsd/cxx/parser/elements.txx create mode 100644 libxsd/xsd/cxx/parser/error-handler.hxx create mode 100644 libxsd/xsd/cxx/parser/error-handler.txx create mode 100644 libxsd/xsd/cxx/parser/exceptions.hxx create mode 100644 libxsd/xsd/cxx/parser/exceptions.ixx create mode 100644 libxsd/xsd/cxx/parser/exceptions.txx create mode 100644 libxsd/xsd/cxx/parser/expat/elements.hxx create mode 100644 libxsd/xsd/cxx/parser/expat/elements.txx create mode 100644 libxsd/xsd/cxx/parser/map.hxx create mode 100644 libxsd/xsd/cxx/parser/map.ixx create mode 100644 libxsd/xsd/cxx/parser/map.txx create mode 100644 libxsd/xsd/cxx/parser/non-validating/parser.hxx create mode 100644 libxsd/xsd/cxx/parser/non-validating/parser.txx create mode 100644 libxsd/xsd/cxx/parser/non-validating/xml-schema-pimpl.hxx create mode 100644 libxsd/xsd/cxx/parser/non-validating/xml-schema-pimpl.ixx create mode 100644 libxsd/xsd/cxx/parser/non-validating/xml-schema-pimpl.txx create mode 100644 libxsd/xsd/cxx/parser/non-validating/xml-schema-pskel.hxx create mode 100644 libxsd/xsd/cxx/parser/non-validating/xml-schema-pskel.ixx create mode 100644 libxsd/xsd/cxx/parser/non-validating/xml-schema-pskel.txx create mode 100644 libxsd/xsd/cxx/parser/schema-exceptions.hxx create mode 100644 libxsd/xsd/cxx/parser/schema-exceptions.ixx create mode 100644 libxsd/xsd/cxx/parser/schema-exceptions.txx create mode 100644 libxsd/xsd/cxx/parser/substitution-map.hxx create mode 100644 libxsd/xsd/cxx/parser/substitution-map.txx create mode 100644 libxsd/xsd/cxx/parser/validating/exceptions.hxx create mode 100644 libxsd/xsd/cxx/parser/validating/exceptions.ixx create mode 100644 libxsd/xsd/cxx/parser/validating/exceptions.txx create mode 100644 libxsd/xsd/cxx/parser/validating/inheritance-map.hxx create mode 100644 libxsd/xsd/cxx/parser/validating/inheritance-map.txx create mode 100644 libxsd/xsd/cxx/parser/validating/parser.hxx create mode 100644 libxsd/xsd/cxx/parser/validating/parser.txx create mode 100644 libxsd/xsd/cxx/parser/validating/xml-schema-pimpl.hxx create mode 100644 libxsd/xsd/cxx/parser/validating/xml-schema-pimpl.ixx create mode 100644 libxsd/xsd/cxx/parser/validating/xml-schema-pimpl.txx create mode 100644 libxsd/xsd/cxx/parser/validating/xml-schema-pskel.hxx create mode 100644 libxsd/xsd/cxx/parser/validating/xml-schema-pskel.ixx create mode 100644 libxsd/xsd/cxx/parser/validating/xml-schema-pskel.txx create mode 100644 libxsd/xsd/cxx/parser/xerces/elements.hxx create mode 100644 libxsd/xsd/cxx/parser/xerces/elements.txx create mode 100644 libxsd/xsd/cxx/parser/xml-schema.hxx create mode 100644 libxsd/xsd/cxx/parser/xml-schema.ixx create mode 100644 libxsd/xsd/cxx/parser/xml-schema.txx create mode 100644 libxsd/xsd/cxx/post.hxx create mode 100644 libxsd/xsd/cxx/pre.hxx create mode 100644 libxsd/xsd/cxx/ro-string.hxx create mode 100644 libxsd/xsd/cxx/ro-string.txx create mode 100644 libxsd/xsd/cxx/tree/ace-cdr-stream-common.hxx create mode 100644 libxsd/xsd/cxx/tree/ace-cdr-stream-extraction.hxx create mode 100644 libxsd/xsd/cxx/tree/ace-cdr-stream-insertion.hxx create mode 100644 libxsd/xsd/cxx/tree/bits/literals.hxx create mode 100644 libxsd/xsd/cxx/tree/bits/literals.ixx create mode 100644 libxsd/xsd/cxx/tree/buffer.hxx create mode 100644 libxsd/xsd/cxx/tree/buffer.txx create mode 100644 libxsd/xsd/cxx/tree/comparison-map.hxx create mode 100644 libxsd/xsd/cxx/tree/comparison-map.txx create mode 100644 libxsd/xsd/cxx/tree/containers-wildcard.hxx create mode 100644 libxsd/xsd/cxx/tree/containers.hxx create mode 100644 libxsd/xsd/cxx/tree/containers.txx create mode 100644 libxsd/xsd/cxx/tree/date-time-extraction.txx create mode 100644 libxsd/xsd/cxx/tree/date-time-insertion.txx create mode 100644 libxsd/xsd/cxx/tree/date-time-ostream.txx create mode 100644 libxsd/xsd/cxx/tree/date-time.hxx create mode 100644 libxsd/xsd/cxx/tree/date-time.ixx create mode 100644 libxsd/xsd/cxx/tree/date-time.txx create mode 100644 libxsd/xsd/cxx/tree/element-map.hxx create mode 100644 libxsd/xsd/cxx/tree/element-map.txx create mode 100644 libxsd/xsd/cxx/tree/elements.hxx create mode 100644 libxsd/xsd/cxx/tree/elements.txx create mode 100644 libxsd/xsd/cxx/tree/error-handler.hxx create mode 100644 libxsd/xsd/cxx/tree/error-handler.txx create mode 100644 libxsd/xsd/cxx/tree/exceptions.hxx create mode 100644 libxsd/xsd/cxx/tree/exceptions.ixx create mode 100644 libxsd/xsd/cxx/tree/exceptions.txx create mode 100644 libxsd/xsd/cxx/tree/facet.hxx create mode 100644 libxsd/xsd/cxx/tree/istream-fwd.hxx create mode 100644 libxsd/xsd/cxx/tree/istream.hxx create mode 100644 libxsd/xsd/cxx/tree/list.hxx create mode 100644 libxsd/xsd/cxx/tree/ostream.hxx create mode 100644 libxsd/xsd/cxx/tree/parsing.hxx create mode 100644 libxsd/xsd/cxx/tree/parsing.txx create mode 100644 libxsd/xsd/cxx/tree/parsing/boolean.hxx create mode 100644 libxsd/xsd/cxx/tree/parsing/byte.hxx create mode 100644 libxsd/xsd/cxx/tree/parsing/date-time.txx create mode 100644 libxsd/xsd/cxx/tree/parsing/decimal.hxx create mode 100644 libxsd/xsd/cxx/tree/parsing/double.hxx create mode 100644 libxsd/xsd/cxx/tree/parsing/element-map.txx create mode 100644 libxsd/xsd/cxx/tree/parsing/float.hxx create mode 100644 libxsd/xsd/cxx/tree/parsing/int.hxx create mode 100644 libxsd/xsd/cxx/tree/parsing/long.hxx create mode 100644 libxsd/xsd/cxx/tree/parsing/short.hxx create mode 100644 libxsd/xsd/cxx/tree/parsing/unsigned-byte.hxx create mode 100644 libxsd/xsd/cxx/tree/parsing/unsigned-int.hxx create mode 100644 libxsd/xsd/cxx/tree/parsing/unsigned-long.hxx create mode 100644 libxsd/xsd/cxx/tree/parsing/unsigned-short.hxx create mode 100644 libxsd/xsd/cxx/tree/serialization.hxx create mode 100644 libxsd/xsd/cxx/tree/serialization.txx create mode 100644 libxsd/xsd/cxx/tree/serialization/boolean.hxx create mode 100644 libxsd/xsd/cxx/tree/serialization/byte.hxx create mode 100644 libxsd/xsd/cxx/tree/serialization/date-time.txx create mode 100644 libxsd/xsd/cxx/tree/serialization/decimal.hxx create mode 100644 libxsd/xsd/cxx/tree/serialization/double.hxx create mode 100644 libxsd/xsd/cxx/tree/serialization/element-map.txx create mode 100644 libxsd/xsd/cxx/tree/serialization/float.hxx create mode 100644 libxsd/xsd/cxx/tree/serialization/int.hxx create mode 100644 libxsd/xsd/cxx/tree/serialization/long.hxx create mode 100644 libxsd/xsd/cxx/tree/serialization/short.hxx create mode 100644 libxsd/xsd/cxx/tree/serialization/unsigned-byte.hxx create mode 100644 libxsd/xsd/cxx/tree/serialization/unsigned-int.hxx create mode 100644 libxsd/xsd/cxx/tree/serialization/unsigned-long.hxx create mode 100644 libxsd/xsd/cxx/tree/serialization/unsigned-short.hxx create mode 100644 libxsd/xsd/cxx/tree/std-ostream-map.hxx create mode 100644 libxsd/xsd/cxx/tree/std-ostream-map.txx create mode 100644 libxsd/xsd/cxx/tree/std-ostream-operators.hxx create mode 100644 libxsd/xsd/cxx/tree/stream-extraction-map.hxx create mode 100644 libxsd/xsd/cxx/tree/stream-extraction-map.txx create mode 100644 libxsd/xsd/cxx/tree/stream-extraction.hxx create mode 100644 libxsd/xsd/cxx/tree/stream-insertion-map.hxx create mode 100644 libxsd/xsd/cxx/tree/stream-insertion-map.txx create mode 100644 libxsd/xsd/cxx/tree/stream-insertion.hxx create mode 100644 libxsd/xsd/cxx/tree/text.hxx create mode 100644 libxsd/xsd/cxx/tree/text.txx create mode 100644 libxsd/xsd/cxx/tree/type-factory-map.hxx create mode 100644 libxsd/xsd/cxx/tree/type-factory-map.txx create mode 100644 libxsd/xsd/cxx/tree/type-serializer-map.hxx create mode 100644 libxsd/xsd/cxx/tree/type-serializer-map.txx create mode 100644 libxsd/xsd/cxx/tree/types.hxx create mode 100644 libxsd/xsd/cxx/tree/types.txx create mode 100644 libxsd/xsd/cxx/tree/xdr-stream-common.hxx create mode 100644 libxsd/xsd/cxx/tree/xdr-stream-extraction.hxx create mode 100644 libxsd/xsd/cxx/tree/xdr-stream-insertion.hxx create mode 100644 libxsd/xsd/cxx/version.hxx create mode 100644 libxsd/xsd/cxx/xml/bits/literals.hxx create mode 100644 libxsd/xsd/cxx/xml/bits/literals.ixx create mode 100644 libxsd/xsd/cxx/xml/dom/auto-ptr.hxx create mode 100644 libxsd/xsd/cxx/xml/dom/bits/error-handler-proxy.hxx create mode 100644 libxsd/xsd/cxx/xml/dom/bits/error-handler-proxy.txx create mode 100644 libxsd/xsd/cxx/xml/dom/elements.hxx create mode 100644 libxsd/xsd/cxx/xml/dom/elements.txx create mode 100644 libxsd/xsd/cxx/xml/dom/parsing-header.hxx create mode 100644 libxsd/xsd/cxx/xml/dom/parsing-source.hxx create mode 100644 libxsd/xsd/cxx/xml/dom/parsing-source.txx create mode 100644 libxsd/xsd/cxx/xml/dom/serialization-header.hxx create mode 100644 libxsd/xsd/cxx/xml/dom/serialization-header.txx create mode 100644 libxsd/xsd/cxx/xml/dom/serialization-source.hxx create mode 100644 libxsd/xsd/cxx/xml/dom/serialization-source.txx create mode 100644 libxsd/xsd/cxx/xml/dom/wildcard-source.hxx create mode 100644 libxsd/xsd/cxx/xml/dom/wildcard-source.txx create mode 100644 libxsd/xsd/cxx/xml/elements.hxx create mode 100644 libxsd/xsd/cxx/xml/elements.txx create mode 100644 libxsd/xsd/cxx/xml/error-handler.hxx create mode 100644 libxsd/xsd/cxx/xml/qualified-name.hxx create mode 100644 libxsd/xsd/cxx/xml/sax/bits/error-handler-proxy.hxx create mode 100644 libxsd/xsd/cxx/xml/sax/bits/error-handler-proxy.txx create mode 100644 libxsd/xsd/cxx/xml/sax/std-input-source.hxx create mode 100644 libxsd/xsd/cxx/xml/std-memory-manager.hxx create mode 100644 libxsd/xsd/cxx/xml/string.hxx create mode 100644 libxsd/xsd/cxx/xml/string.ixx create mode 100644 libxsd/xsd/cxx/xml/string.txx create mode 100644 libxsd/xsd/cxx/zc-istream.hxx create mode 100644 libxsd/xsd/cxx/zc-istream.txx (limited to 'libxsd') diff --git a/libxsd/FLOSSE b/libxsd/FLOSSE new file mode 100644 index 0000000..cbf8b2c --- /dev/null +++ b/libxsd/FLOSSE @@ -0,0 +1,89 @@ +1. Intent + +We want specified Free/Libre and Open Source Software ("FLOSS") to be +able to use the specified GPL-licensed XSD runtime library (libxsd) and +XSD generated code (collectively called the "Program") despite the fact +that not all FLOSS licenses are compatible with version 2 of the GNU +General Public License (the "GPL"). + +It is our intent to allow distribution of the entire Derivative Work +(including the Program) under one or more of the FLOSS licenses listed +in section 3 (section 2.a). It is also our intent to disallow simple +relicensing of the Program for the sole purpose of using it in +proprietary applications (section 2.b and 2.c). As an example, consider +two hypothetical scenarios: + + a) You created a program that uses the XSD generated code and the XSD + runtime library to access information in XML instance documents. + Your program performs useful computations based on this information + (sections 2.b and 2.c are satisfied). You distribute your program, + including the XSD generated code and the XSD runtime library under + the BSD license and make it available at no charge to all third + parties (section 2.a is satisfied). Later you (or someone else) may + choose to base their proprietary application on your code since the + BSD license does not prohibit it. + + This scenario falls under this FLOSS Exception. + + + b) You created a library that uses the XSD generated code and the XSD + runtime library to access information in XML instance documents. You + did not add to the library any other useful code that uses the XSD + generated code or the XSD runtime library (neither section 2.b nor + 2.c is satisfied). You distribute your library, including the XSD + generated code and the XSD runtime library under the BSD license and + make it available at no charge to all third parties (section 2.a + is satisfied). Later you base your proprietary application on this + library since the BSD license does not prohibit it. + + This scenario does not fall under this FLOSS Exception (neither + section 2.b nor 2.c is satisfied). You created the library for the + sole purpose of making the XSD generated code and the XSD runtime + library available to your proprietary application. + + +2. Legal Terms and Conditions + +As a special exception to the terms and conditions of version 2 of +the GPL you are free to distribute a verbatim copy of the Program +as part of the Derivative Work that is formed from the Program or +any part thereof and one or more works (each, a "FLOSS Work") as +long as you also meet all of these conditions: + + a) You must cause the Derivative Work that in whole or in part + contains or is derived from the Program or any part thereof, + to be licensed as a whole at no charge to all third parties + under the terms of one or more of the licenses listed in + section 3. + + b) The Derivative Work should contain one or more FLOSS Work that + can be reasonably considered as derived from the Program or some + part thereof. + + c) The Derivative Work should not contain any part of the Program + that cannot be reasonably considered as a base of one or more + FLOSS Work. + + +3. FLOSS License List + + a) Any license listed in the "GPL-Compatible Free Software Licenses" + and the "GPL-Incompatible Free Software Licenses" sections of the + License List as published by the Free Software Foundation (FSF): + + http://www.gnu.org/licenses/license-list.html + + +4. Definitions + +Terms used, but not defined, herein shall have the meaning provided in +the GPL. + +Derivative Work means a derivative work under copyright law. + + +5. Applicability + +You may choose to redistribute a copy of the Program exclusively under +the terms of the GPL by removing the FLOSS Exception notice from that +copy of the Program. diff --git a/libxsd/GPLv2 b/libxsd/GPLv2 new file mode 100644 index 0000000..3912109 --- /dev/null +++ b/libxsd/GPLv2 @@ -0,0 +1,340 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. diff --git a/libxsd/INSTALL b/libxsd/INSTALL new file mode 100644 index 0000000..537f00a --- /dev/null +++ b/libxsd/INSTALL @@ -0,0 +1,17 @@ +Prerequisites + + run-time: + + - libxerces-c >= 2.5.0 http://xerces.apache.org/xerces-c/ + + +Building libxsd + + No building is necessary at the moment. + + +Installing libxsd + + Not supported in this version. You may want to copy libxsd/xsd + to $(prefix)/include so that you have $(prefix)/include/xsd/*. + diff --git a/libxsd/LICENSE b/libxsd/LICENSE new file mode 100644 index 0000000..42346bf --- /dev/null +++ b/libxsd/LICENSE @@ -0,0 +1,26 @@ +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License version 2 as +published by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +In addition, as a special exception, Code Synthesis Tools CC gives +permission to link this program with the Xerces-C++ library (or with +modified versions of Xerces-C++ that use the same license as Xerces-C++), +and distribute linked combinations including the two. You must obey +the GNU General Public License version 2 in all respects for all of +the code used other than Xerces-C++. If you modify this copy of the +program, you may extend this exception to your version of the program, +but you are not obligated to do so. If you do not wish to do so, delete +this exception statement from your version. + +In addition, Code Synthesis Tools CC makes a special exception for +the Free/Libre and Open Source Software (FLOSS) which is described +in the accompanying FLOSSE file. diff --git a/libxsd/README b/libxsd/README new file mode 100644 index 0000000..328d8b2 --- /dev/null +++ b/libxsd/README @@ -0,0 +1,13 @@ +libxsd is a runtime library for language mappings generated by +XSD, a W3C XML Schema to C++ data binding compiler. + + +See the LICENSE file for distribution conditions. + +See the INSTALL file for prerequisites and installation instructions. + +The project page is at http://codesynthesis.com/projects/xsd/ + +Send bug reports or any other feedback to the xsd-users@codesynthesis.com +mailing list. + diff --git a/libxsd/makefile b/libxsd/makefile new file mode 100644 index 0000000..7024fef --- /dev/null +++ b/libxsd/makefile @@ -0,0 +1,20 @@ +# file : libxsd/makefile +# author : Boris Kolpackov +# copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../build/bootstrap.make + +install := $(out_base)/.install + +.PHONY: $(install) + +$(install): + $(call install-dir,$(src_base)/xsd,$(install_inc_dir)/xsd) + $(call install-data,$(src_base)/FLOSSE,$(install_doc_dir)/libxsd/FLOSSE) + $(call install-data,$(src_base)/GPLv2,$(install_doc_dir)/libxsd/GPLv2) + $(call install-data,$(src_base)/LICENSE,$(install_doc_dir)/libxsd/LICENSE) + $(call install-data,$(src_base)/README,$(install_doc_dir)/libxsd/README) + + +$(call include,$(bld_root)/install.make) diff --git a/libxsd/xsd/cxx/auto-array.hxx b/libxsd/xsd/cxx/auto-array.hxx new file mode 100644 index 0000000..b9ef09e --- /dev/null +++ b/libxsd/xsd/cxx/auto-array.hxx @@ -0,0 +1,114 @@ +// file : xsd/cxx/auto-array.hxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_AUTO_ARRAY_HXX +#define XSD_CXX_AUTO_ARRAY_HXX + +#include // std::size_t + +namespace xsd +{ + namespace cxx + { + template + struct std_deallocator + { + void + deallocate (T* p) + { + delete[] p; + } + }; + + // Simple automatic array. The second template parameter is + // an optional deallocator type. If not specified, delete[] + // is used. + // + template > + struct auto_array + { + auto_array (T a[]) + : a_ (a), d_ (0) + { + } + + auto_array (T a[], D& d) + : a_ (a), d_ (&d) + { + } + + ~auto_array () + { + if (d_ != 0) + d_->deallocate (a_); + else + delete[] a_; + } + + T& + operator[] (std::size_t index) const + { + return a_[index]; + } + + T* + get () const + { + return a_; + } + + T* + release () + { + T* tmp (a_); + a_ = 0; + return tmp; + } + + void + reset (T a[] = 0) + { + if (a_ != a) + { + if (d_ != 0) + d_->deallocate (a_); + else + delete[] a_; + + a_ = a; + } + } + + typedef void (auto_array::*bool_convertible)(); + + operator bool_convertible () const + { + return a_ ? &auto_array::true_ : 0; + } + + private: + auto_array (const auto_array&); + + auto_array& + operator= (const auto_array&); + + private: + void + true_ (); + + private: + T* a_; + D* d_; + }; + + template + void auto_array:: + true_ () + { + } + } +} + +#endif // XSD_CXX_AUTO_ARRAY_HXX diff --git a/libxsd/xsd/cxx/compilers/vc-7/post.hxx b/libxsd/xsd/cxx/compilers/vc-7/post.hxx new file mode 100644 index 0000000..13efa6a --- /dev/null +++ b/libxsd/xsd/cxx/compilers/vc-7/post.hxx @@ -0,0 +1,6 @@ +// file : xsd/cxx/compilers/vc-7/post.hxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#pragma warning (pop) diff --git a/libxsd/xsd/cxx/compilers/vc-7/pre.hxx b/libxsd/xsd/cxx/compilers/vc-7/pre.hxx new file mode 100644 index 0000000..1d431a7 --- /dev/null +++ b/libxsd/xsd/cxx/compilers/vc-7/pre.hxx @@ -0,0 +1,36 @@ +// file : xsd/cxx/compilers/vc-7/pre.hxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + + +#if (_MSC_VER < 1310) +# error Microsoft Visual C++ 7.0 (.NET 2002) is not supported. +#endif + + +// These warnings had to be disabled "for good". +// +#pragma warning (disable:4250) // inherits via dominance +#pragma warning (disable:4505) // unreferenced local function has been removed +#pragma warning (disable:4661) // no definition for explicit instantiation + + +// Push warning state. +// +#pragma warning (push, 3) + + +// Disabled warnings. +// +#pragma warning (disable:4355) // passing 'this' to a member +#pragma warning (disable:4584) // is already a base-class +#pragma warning (disable:4800) // forcing value to bool +#pragma warning (disable:4275) // non dll-interface base +#pragma warning (disable:4251) // base needs to have dll-interface +#pragma warning (disable:4224) // nonstandard extension (/Za option) + + +// Elevated warnings. +// +#pragma warning (2:4239) // standard doesn't allow this conversion diff --git a/libxsd/xsd/cxx/compilers/vc-8/post.hxx b/libxsd/xsd/cxx/compilers/vc-8/post.hxx new file mode 100644 index 0000000..6a4328f --- /dev/null +++ b/libxsd/xsd/cxx/compilers/vc-8/post.hxx @@ -0,0 +1,6 @@ +// file : xsd/cxx/compilers/vc-8/post.hxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#pragma warning (pop) diff --git a/libxsd/xsd/cxx/compilers/vc-8/pre.hxx b/libxsd/xsd/cxx/compilers/vc-8/pre.hxx new file mode 100644 index 0000000..bd7c890 --- /dev/null +++ b/libxsd/xsd/cxx/compilers/vc-8/pre.hxx @@ -0,0 +1,28 @@ +// file : xsd/cxx/compilers/vc-8/pre.hxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// These warnings had to be disabled "for good". +// +#pragma warning (disable:4250) // inherits via dominance +#pragma warning (disable:4661) // no definition for explicit instantiation + + +// Push warning state. +// +#pragma warning (push, 3) + + +// Disabled warnings. +// +#pragma warning (disable:4355) // passing 'this' to a member +#pragma warning (disable:4800) // forcing value to bool +#pragma warning (disable:4275) // non dll-interface base +#pragma warning (disable:4251) // base needs to have dll-interface +#pragma warning (disable:4224) // nonstandard extension (/Za option) + + +// Elevated warnings. +// +#pragma warning (2:4239) // standard doesn't allow this conversion diff --git a/libxsd/xsd/cxx/config.hxx b/libxsd/xsd/cxx/config.hxx new file mode 100644 index 0000000..feb0e12 --- /dev/null +++ b/libxsd/xsd/cxx/config.hxx @@ -0,0 +1,15 @@ +// file : xsd/cxx/config.hxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_CONFIG_HXX +#define XSD_CXX_CONFIG_HXX + +#include + +// Macro to suppress unused variable warning. +// +#define XSD_UNUSED(x) (void)x + +#endif // XSD_CXX_CONFIG_HXX diff --git a/libxsd/xsd/cxx/exceptions.hxx b/libxsd/xsd/cxx/exceptions.hxx new file mode 100644 index 0000000..d6d0ef9 --- /dev/null +++ b/libxsd/xsd/cxx/exceptions.hxx @@ -0,0 +1,21 @@ +// file : xsd/cxx/exceptions.hxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_EXCEPTIONS_HXX +#define XSD_CXX_EXCEPTIONS_HXX + +#include // std::exception + +namespace xsd +{ + namespace cxx + { + struct exception: std::exception + { + }; + } +} + +#endif // XSD_CXX_EXCEPTIONS_HXX diff --git a/libxsd/xsd/cxx/parser/document.hxx b/libxsd/xsd/cxx/parser/document.hxx new file mode 100644 index 0000000..dd8be4a --- /dev/null +++ b/libxsd/xsd/cxx/parser/document.hxx @@ -0,0 +1,90 @@ +// file : xsd/cxx/parser/document.hxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_PARSER_DOCUMENT_HXX +#define XSD_CXX_PARSER_DOCUMENT_HXX + +#include +#include // std::size_t + +#include +#include + +namespace xsd +{ + namespace cxx + { + namespace parser + { + // If you want to use a different underlying XML parser, all you + // need to do is to route events to this interface. + // + template + class document + { + public: + virtual + ~document (); + + document (parser_base& root, + const std::basic_string& ns, + const std::basic_string& name); + + public: + // The type argument is a type name and namespace from the + // xsi:type attribute in the form " " with + // the space and namespace part absent if the type does not + // have a namespace or 0 if xsi:type is not present. + // + void + start_element (const ro_string& ns, + const ro_string& name, + const ro_string* type); + + void + end_element (const ro_string& ns, const ro_string& name); + + void + attribute (const ro_string& ns, + const ro_string& name, + const ro_string& value); + + void + characters (const ro_string&); + + protected: + document (); + + // This function is called to obtain the root element type parser. + // If the returned pointed is 0 then the whole document content + // is ignored. + // + virtual parser_base* + start_root_element (const ro_string& ns, + const ro_string& name, + const ro_string* type); + + // This function is called to indicate the completion of document + // parsing. The parser argument contains the pointer returned by + // start_root_element. + // + virtual void + end_root_element (const ro_string& ns, + const ro_string& name, + parser_base* parser); + + private: + parser_base* root_; + std::basic_string ns_; + std::basic_string name_; + std::size_t depth_; + }; + } + } +} + +#include + +#endif // XSD_CXX_PARSER_DOCUMENT_HXX diff --git a/libxsd/xsd/cxx/parser/document.txx b/libxsd/xsd/cxx/parser/document.txx new file mode 100644 index 0000000..451eb71 --- /dev/null +++ b/libxsd/xsd/cxx/parser/document.txx @@ -0,0 +1,129 @@ +// file : xsd/cxx/parser/document.txx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include + +#include + +namespace xsd +{ + namespace cxx + { + namespace parser + { + // document + // + template + document:: + ~document () + { + } + + template + document:: + document (parser_base& root, + const std::basic_string& ns, + const std::basic_string& name) + : root_ (&root), ns_ (ns), name_ (name), depth_ (0) + { + } + + template + document:: + document () + : root_ (0), depth_ (0) + { + } + + template + void document:: + start_element (const ro_string& ns, + const ro_string& name, + const ro_string* type) + { + if (depth_++ > 0) + { + if (root_) + root_->_start_element (ns, name, type); + } + else + { + root_ = start_root_element (ns, name, type); + + if (root_) + { + // pre () is called by the user. + // + root_->_pre_impl (); + } + } + } + + template + void document:: + end_element (const ro_string& ns, const ro_string& name) + { + assert (depth_ > 0); + + if (--depth_ > 0) + { + if (root_) + root_->_end_element (ns, name); + } + else + { + if (root_) + { + root_->_post_impl (); + // + // post() is called by the user. + } + + end_root_element (ns, name, root_); + } + } + + template + void document:: + attribute (const ro_string& ns, + const ro_string& name, + const ro_string& value) + { + if (root_) + root_->_attribute (ns, name, value); + } + + template + void document:: + characters (const ro_string& s) + { + if (root_) + root_->_characters (s); + } + + template + parser_base* document:: + start_root_element (const ro_string& ns, + const ro_string& name, + const ro_string*) + { + if (name_ == name && ns_ == ns) + { + return root_; + } + else + throw expected_element (ns_, name_, ns, name); + } + + template + void document:: + end_root_element (const ro_string&, + const ro_string&, + parser_base*) + { + } + } + } +} diff --git a/libxsd/xsd/cxx/parser/elements.hxx b/libxsd/xsd/cxx/parser/elements.hxx new file mode 100644 index 0000000..e900189 --- /dev/null +++ b/libxsd/xsd/cxx/parser/elements.hxx @@ -0,0 +1,95 @@ +// file : xsd/cxx/parser/elements.hxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_PARSER_ELEMENTS_HXX +#define XSD_CXX_PARSER_ELEMENTS_HXX + +#include + +namespace xsd +{ + namespace cxx + { + namespace parser + { + // pre() and post() are overridable pre/post callbacks, i.e., the + // derived parser can override them without calling the base version. + // _pre() and _post() are not overridable pre/post callbacks in the + // sense that the derived parser may override them but has to call + // the base version. The call sequence is as shown below: + // + // pre () + // _pre () + // _post () + // post () + // + template + class parser_base + { + public: + virtual + ~parser_base (); + + virtual void + pre (); + + virtual void + _pre (); + + // The type argument is a type name and namespace from the + // xsi:type attribute in the form " " with + // the space and namespace part absent if the type does not + // have a namespace or 0 if xsi:type is not present. + // + virtual void + _start_element (const ro_string& ns, + const ro_string& name, + const ro_string* type) = 0; + + virtual void + _end_element (const ro_string& ns, + const ro_string& name) = 0; + + virtual void + _attribute (const ro_string& ns, + const ro_string& name, + const ro_string& value) = 0; + + virtual void + _characters (const ro_string&) = 0; + + virtual void + _post (); + + // The post() signature varies depending on the parser return + // type. + // + + // Implementation callbacks for _pre and _post. The _pre and _post + // callbacks should never be called directly. Instead, the *_impl + // versions should be used. By default _pre_impl and _post_impl + // simply call _pre and _post respectively. + // + virtual void + _pre_impl (); + + virtual void + _post_impl (); + + public: + // Dynamic type in the form " " with + // the space and namespace part absent if the type does + // not have a namespace. Used in polymorphism-aware code. + // + virtual const C* + _dynamic_type () const; + }; + } + } +} + +#include + +#endif // XSD_CXX_PARSER_ELEMENTS_HXX diff --git a/libxsd/xsd/cxx/parser/elements.txx b/libxsd/xsd/cxx/parser/elements.txx new file mode 100644 index 0000000..3bfb7be --- /dev/null +++ b/libxsd/xsd/cxx/parser/elements.txx @@ -0,0 +1,60 @@ +// file : xsd/cxx/parser/elements.txx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsd +{ + namespace cxx + { + namespace parser + { + // parser_base + // + template + parser_base:: + ~parser_base () + { + } + + template + void parser_base:: + pre () + { + } + + template + void parser_base:: + _pre () + { + } + + template + void parser_base:: + _post () + { + } + + template + void parser_base:: + _pre_impl () + { + _pre (); + } + + template + void parser_base:: + _post_impl () + { + _post (); + } + + template + const C* parser_base:: + _dynamic_type () const + { + return 0; + } + } + } +} diff --git a/libxsd/xsd/cxx/parser/error-handler.hxx b/libxsd/xsd/cxx/parser/error-handler.hxx new file mode 100644 index 0000000..b44974f --- /dev/null +++ b/libxsd/xsd/cxx/parser/error-handler.hxx @@ -0,0 +1,57 @@ +// file : xsd/cxx/parser/error-handler.hxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_PARSER_ERROR_HANDLER_HXX +#define XSD_CXX_PARSER_ERROR_HANDLER_HXX + +#include + +#include + +namespace xsd +{ + namespace cxx + { + namespace parser + { + template + class error_handler: public xml::error_handler + { + typedef typename xml::error_handler::severity severity; + + public: + error_handler () + : failed_ (false) + { + } + + virtual bool + handle (const std::basic_string& id, + unsigned long line, + unsigned long column, + severity s, + const std::basic_string& message); + + void + throw_if_failed () const; + + void + reset () + { + failed_ = false; + diagnostics_.clear (); + } + + private: + bool failed_; + diagnostics diagnostics_; + }; + } + } +} + +#include + +#endif // XSD_CXX_PARSER_ERROR_HANDLER_HXX diff --git a/libxsd/xsd/cxx/parser/error-handler.txx b/libxsd/xsd/cxx/parser/error-handler.txx new file mode 100644 index 0000000..9b5feb7 --- /dev/null +++ b/libxsd/xsd/cxx/parser/error-handler.txx @@ -0,0 +1,41 @@ +// file : xsd/cxx/parser/error-handler.txx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsd +{ + namespace cxx + { + namespace parser + { + template + bool error_handler:: + handle (const std::basic_string& id, + unsigned long line, + unsigned long column, + severity s, + const std::basic_string& message) + { + diagnostics_.push_back ( + error (s == severity::warning + ? cxx::parser::severity::warning + : cxx::parser::severity::error, + id, line, column, message)); + + if (!failed_ && s != severity::warning) + failed_ = true; + + return true; + } + + template + void error_handler:: + throw_if_failed () const + { + if (failed_) + throw parsing (diagnostics_); + } + } + } +} diff --git a/libxsd/xsd/cxx/parser/exceptions.hxx b/libxsd/xsd/cxx/parser/exceptions.hxx new file mode 100644 index 0000000..a19fb7d --- /dev/null +++ b/libxsd/xsd/cxx/parser/exceptions.hxx @@ -0,0 +1,153 @@ +// file : xsd/cxx/parser/exceptions.hxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_PARSER_EXCEPTIONS_HXX +#define XSD_CXX_PARSER_EXCEPTIONS_HXX + +#include +#include +#include + +#include // xsd::cxx::exception +#include + +namespace xsd +{ + namespace cxx + { + namespace parser + { + // + // + template + struct exception: xsd::cxx::exception + { + friend + std::basic_ostream& + operator<< (std::basic_ostream& os, const exception& e) + { + e.print (os); + return os; + } + + protected: + virtual void + print (std::basic_ostream&) const = 0; + }; + + + // + // + struct severity + { + enum value + { + warning, + error + }; + + severity (value v) : v_ (v) {} + operator value () const { return v_; } + + private: + value v_; + }; + + template + struct error + { + error (cxx::parser::severity, + const std::basic_string& id, + unsigned long line, + unsigned long column, + const std::basic_string& message); + + cxx::parser::severity + severity () const + { + return severity_; + } + + const std::basic_string& + id () const + { + return id_; + } + + unsigned long + line () const + { + return line_; + } + + unsigned long + column () const + { + return column_; + } + + const std::basic_string& + message () const + { + return message_; + } + + private: + cxx::parser::severity severity_; + std::basic_string id_; + unsigned long line_; + unsigned long column_; + std::basic_string message_; + }; + + // See exceptions.ixx for operator<< (error). + + + // + // + template + struct diagnostics: std::vector > + { + }; + + // See exceptions.ixx for operator<< (diagnostics). + + // + // + template + struct parsing: exception + { + virtual + ~parsing () throw (); + + parsing (); + + parsing (const cxx::parser::diagnostics&); + + const cxx::parser::diagnostics& + diagnostics () const + { + return diagnostics_; + } + + virtual const char* + what () const throw (); + + protected: + virtual void + print (std::basic_ostream&) const; + + private: + cxx::parser::diagnostics diagnostics_; + }; + } + } +} + +#include + +#endif // XSD_CXX_PARSER_EXCEPTIONS_HXX + +#include diff --git a/libxsd/xsd/cxx/parser/exceptions.ixx b/libxsd/xsd/cxx/parser/exceptions.ixx new file mode 100644 index 0000000..b583ed0 --- /dev/null +++ b/libxsd/xsd/cxx/parser/exceptions.ixx @@ -0,0 +1,129 @@ +// file : xsd/cxx/parser/exceptions.ixx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#if defined(XSD_CXX_PARSER_USE_CHAR) || !defined(XSD_CXX_PARSER_USE_WCHAR) + +#ifndef XSD_CXX_PARSER_EXCEPTIONS_IXX_CHAR +#define XSD_CXX_PARSER_EXCEPTIONS_IXX_CHAR + +namespace xsd +{ + namespace cxx + { + namespace parser + { + // error + // + inline + std::basic_ostream& + operator<< (std::basic_ostream& os, const error& e) + { + return os << e.id () << ':' << e.line () << ':' << e.column () + << (e.severity () == severity::error + ? " error: " + : " warning: ") << e.message (); + } + + + // diagnostics + // + inline + std::basic_ostream& + operator<< (std::basic_ostream& os, const diagnostics& d) + { + for (diagnostics::const_iterator b (d.begin ()), i (b); + i != d.end (); + ++i) + { + if (i != b) + os << "\n"; + + os << *i; + } + + return os; + } + + // parsing + // + template<> + inline + void parsing:: + print (std::basic_ostream& os) const + { + if (diagnostics_.empty ()) + os << "instance document parsing failed"; + else + os << diagnostics_; + } + } + } +} + +#endif // XSD_CXX_PARSER_EXCEPTIONS_IXX_CHAR +#endif // XSD_CXX_PARSER_USE_CHAR + + +#if defined(XSD_CXX_PARSER_USE_WCHAR) || !defined(XSD_CXX_PARSER_USE_CHAR) + +#ifndef XSD_CXX_PARSER_EXCEPTIONS_IXX_WCHAR +#define XSD_CXX_PARSER_EXCEPTIONS_IXX_WCHAR + +namespace xsd +{ + namespace cxx + { + namespace parser + { + // error + // + inline + std::basic_ostream& + operator<< (std::basic_ostream& os, const error& e) + { + return os << e.id () << L':' << e.line () << L':' << e.column () + << (e.severity () == severity::error + ? L" error: " + : L" warning: ") << e.message (); + } + + // diagnostics + // + inline + std::basic_ostream& + operator<< (std::basic_ostream& os, + const diagnostics& d) + { + for (diagnostics::const_iterator b (d.begin ()), i (b); + i != d.end (); + ++i) + { + if (i != b) + os << L"\n"; + + os << *i; + } + + return os; + } + + // parsing + // + template<> + inline + void parsing:: + print (std::basic_ostream& os) const + { + if (diagnostics_.empty ()) + os << L"instance document parsing failed"; + else + os << diagnostics_; + } + } + } +} + +#endif // XSD_CXX_PARSER_EXCEPTIONS_IXX_WCHAR +#endif // XSD_CXX_PARSER_USE_WCHAR diff --git a/libxsd/xsd/cxx/parser/exceptions.txx b/libxsd/xsd/cxx/parser/exceptions.txx new file mode 100644 index 0000000..ddb20b0 --- /dev/null +++ b/libxsd/xsd/cxx/parser/exceptions.txx @@ -0,0 +1,59 @@ +// file : xsd/cxx/parser/exceptions.txx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsd +{ + namespace cxx + { + namespace parser + { + // error + // + template + error:: + error (cxx::parser::severity s, + const std::basic_string& id, + unsigned long line, + unsigned long column, + const std::basic_string& message) + : severity_ (s), + id_ (id), + line_ (line), + column_ (column), + message_ (message) + { + } + + + // parsing + // + template + parsing:: + ~parsing () throw () + { + } + + template + parsing:: + parsing () + { + } + + template + parsing:: + parsing (const cxx::parser::diagnostics& diagnostics) + : diagnostics_ (diagnostics) + { + } + + template + const char* parsing:: + what () const throw () + { + return "instance document parsing failed"; + } + } + } +} diff --git a/libxsd/xsd/cxx/parser/expat/elements.hxx b/libxsd/xsd/cxx/parser/expat/elements.hxx new file mode 100644 index 0000000..a0de3e3 --- /dev/null +++ b/libxsd/xsd/cxx/parser/expat/elements.hxx @@ -0,0 +1,344 @@ +// file : xsd/cxx/parser/expat/elements.hxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_PARSER_EXPAT_ELEMENTS_HXX +#define XSD_CXX_PARSER_EXPAT_ELEMENTS_HXX + +#include +#include +#include // std::size_t +#include + +#include + +// We only support UTF-8 expat for now. +// +#ifdef XML_UNICODE +#error UTF-16 expat (XML_UNICODE defined) is not supported +#endif + +#include + +#include +#include +#include +#include +#include + +namespace xsd +{ + namespace cxx + { + namespace parser + { + namespace expat + { + // Simple auto pointer for Expat's XML_Parser object. + // + struct parser_auto_ptr + { + ~parser_auto_ptr () + { + if (parser_ != 0) + XML_ParserFree (parser_); + } + + explicit + parser_auto_ptr (XML_Parser parser = 0) + : parser_ (parser) + { + } + + parser_auto_ptr& + operator= (XML_Parser parser) + { + if (parser_ != 0) + XML_ParserFree (parser_); + + parser_ = parser; + return *this; + } + + public: + operator XML_Parser () + { + return parser_; + } + + private: + parser_auto_ptr (const parser_auto_ptr&); + + parser_auto_ptr& + operator= (const parser_auto_ptr&); + + private: + XML_Parser parser_; + }; + + + // + // + template + struct document: cxx::parser::document // VC 7.1 likes it qualified + { + public: + document (parser_base&, + const C* root_element_name, + bool polymorphic = false); + + document (parser_base&, + const std::basic_string& root_element_name, + bool polymorphic = false); + + document (parser_base&, + const C* root_element_namespace, + const C* root_element_name, + bool polymorphic = false); + + document (parser_base&, + const std::basic_string& root_element_namespace, + const std::basic_string& root_element_name, + bool polymorphic = false); + + protected: + document (bool polymorphic = false); + + public: + // Parse a local file. The file is accessed with std::ifstream + // in binary mode. The std::ios_base::failure exception is used + // to report io errors (badbit and failbit). + void + parse (const std::basic_string& file); + + // Parse a local file with a user-provided error_handler + // object. The file is accessed with std::ifstream in binary + // mode. The std::ios_base::failure exception is used to report + // io errors (badbit and failbit). + // + void + parse (const std::basic_string& file, xml::error_handler&); + + public: + // System id is a "system" identifier of the resources (e.g., + // URI or a full file path). Public id is a "public" identifier + // of the resource (e.g., application-specific name or relative + // file path). System id is used to resolve relative paths. + // In diagnostics messages system id is used if public id is + // not available. Otherwise public id is used. + // + + // Parse std::istream. + // + void + parse (std::istream&); + + // Parse std::istream with a user-provided error_handler object. + // + void + parse (std::istream&, xml::error_handler&); + + // Parse std::istream with a system id. + // + void + parse (std::istream&, const std::basic_string& system_id); + + // Parse std::istream with a system id and a user-provided + // error_handler object. + // + void + parse (std::istream&, + const std::basic_string& system_id, + xml::error_handler&); + + // Parse std::istream with system and public ids. + // + void + parse (std::istream&, + const std::basic_string& system_id, + const std::basic_string& public_id); + + // Parse std::istream with system and public ids and a user-provided + // error_handler object. + // + void + parse (std::istream&, + const std::basic_string& system_id, + const std::basic_string& public_id, + xml::error_handler&); + + public: + // Parse a chunk of input. You can call these functions multiple + // times with the last call having the last argument true. + // + void + parse (const void* data, std::size_t size, bool last); + + void + parse (const void* data, std::size_t size, bool last, + xml::error_handler&); + + void + parse (const void* data, std::size_t size, bool last, + const std::basic_string& system_id); + + void + parse (const void* data, std::size_t size, bool last, + const std::basic_string& system_id, + xml::error_handler&); + + void + parse (const void* data, std::size_t size, bool last, + const std::basic_string& system_id, + const std::basic_string& public_id); + + void + parse (const void* data, std::size_t size, bool last, + const std::basic_string& system_id, + const std::basic_string& public_id, + xml::error_handler&); + + public: + // Low-level Expat-specific parsing API. A typical use case + // would look like this (pseudo-code): + // + // xxx_pimpl root; + // document doc (root, "root"); + // + // root.pre (); + // doc.parse_begin (xml_parser, "file.xml"); + // + // while (more_stuff_to_parse &&) + // { + // // Call XML_Parse or XML_ParseBuffer. + // + // if (status == XML_STATUS_ERROR) + // break; + // } + // + // // Call parse_end even in case of an error to translate + // // XML and Schema errors to exceptions or error_handler + // // calls. + // // + // doc.parse_end (); + // result_type result (root.post_xxx ()); + // + // Notes: + // + // 1. If your XML instances use XML namespaces, the + // XML_ParserCreateNS functions should be used to create the + // XML parser. Space (XML_Char (' ')) should be used as a + // separator (the second argument to XML_ParserCreateNS). + // + void + parse_begin (XML_Parser); + + void + parse_begin (XML_Parser, const std::basic_string& public_id); + + void + parse_begin (XML_Parser, xml::error_handler&); + + void + parse_begin (XML_Parser, + const std::basic_string& public_id, + xml::error_handler&); + void + parse_end (); + + // Event routing. + // + public: + static void XMLCALL + start_element_thunk_ (void*, const XML_Char*, const XML_Char**); + + static void XMLCALL + end_element_thunk_ (void*, const XML_Char*); + + static void XMLCALL + characters_thunk_ (void*, const XML_Char*, int); + + static void XMLCALL + start_namespace_decl_thunk_ ( + void*, const XML_Char*, const XML_Char*); + + static void XMLCALL + end_namespace_decl_thunk_ (void*, const XML_Char*); + + protected: + void + start_element_ (const XML_Char* ns_name, const XML_Char** atts); + + void + end_element_ (const XML_Char* ns_name); + + void + characters_ (const XML_Char* s, std::size_t n); + + void + start_namespace_decl_ (const XML_Char* prefix, const XML_Char* ns); + + void + end_namespace_decl_ (const XML_Char* prefix); + + protected: + void + set (); + + void + clear (); + + bool + parse (std::istream&, + const std::basic_string* system_id, + const std::basic_string* public_id, + xml::error_handler&); + + bool + parse (const void* data, std::size_t size, bool last, + const std::basic_string* system_id, + const std::basic_string* public_id, + xml::error_handler&); + + + void + translate_schema_exception (const schema_exception& e); + + protected: + XML_Parser xml_parser_; + parser_auto_ptr auto_xml_parser_; + + xml::error_handler* eh_; + error_handler default_eh_; + std::basic_string public_id_; + + bool polymorphic_; + + // Namespace-prefix mapping. Only maintained in the polymorphic + // case. + // + struct ns_decl + { + ns_decl (const std::basic_string& p, + const std::basic_string& n) + : prefix (p), ns (n) + { + } + + std::basic_string prefix; + std::basic_string ns; + }; + + typedef std::vector ns_decls; + + ns_decls ns_decls_; + }; + } + } + } +} + +#include + +#endif // XSD_CXX_PARSER_EXPAT_ELEMENTS_HXX diff --git a/libxsd/xsd/cxx/parser/expat/elements.txx b/libxsd/xsd/cxx/parser/expat/elements.txx new file mode 100644 index 0000000..5a60eb5 --- /dev/null +++ b/libxsd/xsd/cxx/parser/expat/elements.txx @@ -0,0 +1,822 @@ +// file : xsd/cxx/parser/expat/elements.txx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include // std::bad_alloc +#include +#include +#include // std::strchr +#include + +#include // xml::bits::{xml_prefix, etc} + +namespace xsd +{ + namespace cxx + { + namespace parser + { + namespace expat + { + + // document + // + + template + document:: + document (parser_base& p, + const std::basic_string& name, + bool polymorphic) + : cxx::parser::document (p, std::basic_string (), name), + xml_parser_ (0), + eh_ (0), + polymorphic_ (polymorphic) + { + } + + template + document:: + document (parser_base& p, + const C* name, + bool polymorphic) + : cxx::parser::document (p, std::basic_string (), name), + xml_parser_ (0), + eh_ (0), + polymorphic_ (polymorphic) + { + } + + template + document:: + document (parser_base& p, + const C* ns, + const C* name, + bool polymorphic) + : cxx::parser::document (p, ns, name), + xml_parser_ (0), + eh_ (0), + polymorphic_ (polymorphic) + { + } + + template + document:: + document (parser_base& p, + const std::basic_string& ns, + const std::basic_string& name, + bool polymorphic) + : cxx::parser::document (p, ns, name), + xml_parser_ (0), + eh_ (0), + polymorphic_ (polymorphic) + { + } + + template + document:: + document (bool polymorphic) + : xml_parser_ (0), + eh_ (0), + polymorphic_ (polymorphic) + { + } + + // file + // + + template + void document:: + parse (const std::basic_string& file) + { + std::ifstream ifs; + ifs.exceptions (std::ios_base::badbit | std::ios_base::failbit); + ifs.open (file.c_str (), std::ios_base::in | std::ios_base::binary); + + parse (ifs, file); + } + + template + void document:: + parse (const std::basic_string& file, xml::error_handler& eh) + { + std::ifstream ifs; + ifs.exceptions (std::ios_base::badbit | std::ios_base::failbit); + ifs.open (file.c_str (), std::ios_base::in | std::ios_base::binary); + + parse (ifs, file, eh); + } + + + // istream + // + + template + void document:: + parse (std::istream& is) + { + parse (is, 0, 0, default_eh_); + } + + template + void document:: + parse (std::istream& is, xml::error_handler& eh) + { + if (!parse (is, 0, 0, eh)) + throw parsing (); + } + + template + void document:: + parse (std::istream& is, const std::basic_string& system_id) + { + default_eh_.reset (); + parse (is, &system_id, 0, default_eh_); + } + + template + void document:: + parse (std::istream& is, + const std::basic_string& system_id, + xml::error_handler& eh) + { + if (!parse (is, &system_id, 0, eh)) + throw parsing (); + } + + template + void document:: + parse (std::istream& is, + const std::basic_string& system_id, + const std::basic_string& public_id) + { + default_eh_.reset (); + parse (is, &system_id, &public_id, default_eh_); + } + + template + void document:: + parse (std::istream& is, + const std::basic_string& system_id, + const std::basic_string& public_id, + xml::error_handler& eh) + { + if (!parse (is, &system_id, &public_id, eh)) + throw parsing (); + } + + // data + // + + template + void document:: + parse (const void* data, std::size_t size, bool last) + { + default_eh_.reset (); + parse (data, size, last, 0, 0, default_eh_); + } + + template + void document:: + parse (const void* data, std::size_t size, bool last, + xml::error_handler& eh) + { + if (!parse (data, size, last, 0, 0, eh)) + throw parsing (); + } + + template + void document:: + parse (const void* data, std::size_t size, bool last, + const std::basic_string& system_id) + { + default_eh_.reset (); + parse (data, size, last, &system_id, 0, default_eh_); + } + + template + void document:: + parse (const void* data, std::size_t size, bool last, + const std::basic_string& system_id, + xml::error_handler& eh) + { + if (!parse (data, size, last, &system_id, 0, eh)) + throw parsing (); + } + + template + void document:: + parse (const void* data, std::size_t size, bool last, + const std::basic_string& system_id, + const std::basic_string& public_id) + { + default_eh_.reset (); + parse (data, size, last, &system_id, &public_id, default_eh_); + } + + template + void document:: + parse (const void* data, std::size_t size, bool last, + const std::basic_string& system_id, + const std::basic_string& public_id, + xml::error_handler& eh) + { + if (!parse (data, size, last, &system_id, &public_id, eh)) + throw parsing (); + } + + // Implementation details. + // + + namespace bits + { + struct stream_exception_controller + { + ~stream_exception_controller () + { + std::ios_base::iostate s = is_.rdstate (); + s &= ~std::ios_base::failbit; + + // If our error state (sans failbit) intersects with the + // exception state then that means we have an active + // exception and changing error/exception state will + // cause another to be thrown. + // + if (!(old_state_ & s)) + { + // Clear failbit if it was caused by eof. + // + if (is_.fail () && is_.eof ()) + is_.clear (s); + + is_.exceptions (old_state_); + } + } + + stream_exception_controller (std::istream& is) + : is_ (is), old_state_ (is_.exceptions ()) + { + is_.exceptions (old_state_ & ~std::ios_base::failbit); + } + + private: + stream_exception_controller (const stream_exception_controller&); + + stream_exception_controller& + operator= (const stream_exception_controller&); + + private: + std::istream& is_; + std::ios_base::iostate old_state_; + }; + }; + + template + bool document:: + parse (std::istream& is, + const std::basic_string* system_id, + const std::basic_string* public_id, + xml::error_handler& eh) + { + parser_auto_ptr parser (XML_ParserCreateNS (0, XML_Char (' '))); + + if (parser == 0) + throw std::bad_alloc (); + + if (system_id || public_id) + parse_begin (parser, system_id ? *system_id : *public_id, eh); + else + parse_begin (parser, eh); + + // Temporarily unset the exception failbit. Also clear the + // fail bit when we reset the old state if it was caused + // by eof. + // + bits::stream_exception_controller sec (is); + + char buf[16384]; // 4 x page size. + + bool r (true); + + do + { + is.read (buf, sizeof (buf)); + + if (is.bad () || (is.fail () && !is.eof ())) + { + // If the stream is not using exceptions then the user + // will have to test for stream failures before calling + // post. + // + break; + } + + if (XML_Parse ( + parser, buf, is.gcount (), is.eof ()) == XML_STATUS_ERROR) + { + r = false; + break; + } + } while (!is.eof ()); + + parse_end (); + return r; + } + + template + bool document:: + parse (const void* data, + std::size_t size, + bool last, + const std::basic_string* system_id, + const std::basic_string* public_id, + xml::error_handler& eh) + { + // First call. + // + if (auto_xml_parser_ == 0) + { + auto_xml_parser_ = XML_ParserCreateNS (0, XML_Char (' ')); + + if (auto_xml_parser_ == 0) + throw std::bad_alloc (); + + if (system_id || public_id) + parse_begin (auto_xml_parser_, + system_id ? *system_id : *public_id, eh); + else + parse_begin (auto_xml_parser_, eh); + } + + bool r (XML_Parse (xml_parser_, + static_cast (data), + static_cast (size), + last) != XML_STATUS_ERROR); + parse_end (); + return r; + } + + // XML_Parser + // + + template + void document:: + parse_begin (XML_Parser parser) + { + xml_parser_ = parser; + eh_ = &default_eh_; + public_id_.clear (); + set (); + } + + template + void document:: + parse_begin (XML_Parser parser, + const std::basic_string& public_id) + { + xml_parser_ = parser; + eh_ = &default_eh_; + public_id_ = public_id; + set (); + } + + template + void document:: + parse_begin (XML_Parser parser, xml::error_handler& eh) + { + xml_parser_ = parser; + eh_ = &eh; + public_id_.clear (); + set (); + } + + template + void document:: + parse_begin (XML_Parser parser, + const std::basic_string& public_id, + xml::error_handler& eh) + { + xml_parser_ = parser; + eh_ = &eh; + public_id_ = public_id; + set (); + } + + template + void document:: + parse_end () + { + XML_Error e (XML_GetErrorCode (xml_parser_)); + + if (e == XML_ERROR_NONE || e == XML_ERROR_ABORTED) + { + clear (); + xml_parser_ = 0; + auto_xml_parser_ = 0; + } + else + { + unsigned long l = XML_GetCurrentLineNumber (xml_parser_); + unsigned long c = XML_GetCurrentColumnNumber (xml_parser_); + std::basic_string message (XML_ErrorString (e)); + + eh_->handle (public_id_, + l, c, + xml::error_handler::severity::fatal, + message); + + clear (); + xml_parser_ = 0; + auto_xml_parser_ = 0; + + // We don't want to throw an empty parsing exception here + // since the user probably already knows about the error. + } + + if (eh_ == &default_eh_) + default_eh_.throw_if_failed (); + } + + // + // + template + void document:: + set () + { + assert (xml_parser_ != 0); + + XML_SetUserData(xml_parser_, this); + + XML_SetStartElementHandler (xml_parser_, start_element_thunk_); + XML_SetEndElementHandler (xml_parser_, end_element_thunk_); + XML_SetCharacterDataHandler (xml_parser_, characters_thunk_); + + if (polymorphic_) + { + XML_SetNamespaceDeclHandler (xml_parser_, + start_namespace_decl_thunk_, + end_namespace_decl_thunk_); + } + } + + template + void document:: + clear () + { + assert (xml_parser_ != 0); + + XML_SetUserData (xml_parser_, 0); + XML_SetStartElementHandler (xml_parser_, 0); + XML_SetEndElementHandler (xml_parser_, 0); + XML_SetCharacterDataHandler (xml_parser_, 0); + + if (polymorphic_) + XML_SetNamespaceDeclHandler (xml_parser_, 0, 0); + } + + template + void document:: + translate_schema_exception (const schema_exception& e) + { + unsigned long l = XML_GetCurrentLineNumber (xml_parser_); + unsigned long c = XML_GetCurrentColumnNumber (xml_parser_); + + eh_->handle (public_id_, + l, c, + xml::error_handler::severity::fatal, + e.message ()); + + XML_StopParser (xml_parser_, false); + } + + // Event routing. + // + + // Expat thunks. + // + template + void XMLCALL document:: + start_element_thunk_ (void* data, + const XML_Char* ns_name, + const XML_Char** atts) + { + document& d (*reinterpret_cast (data)); + d.start_element_ (ns_name, atts); + } + + template + void XMLCALL document:: + end_element_thunk_ (void* data, const XML_Char* ns_name) + { + document& d (*reinterpret_cast (data)); + d.end_element_ (ns_name); + } + + template + void XMLCALL document:: + characters_thunk_ (void* data, const XML_Char* s, int n) + { + document& d (*reinterpret_cast (data)); + d.characters_ (s, static_cast (n)); + } + + template + void XMLCALL document:: + start_namespace_decl_thunk_ (void* data, + const XML_Char* prefix, + const XML_Char* ns) + { + document& d (*reinterpret_cast (data)); + d.start_namespace_decl_ (prefix, ns); + } + + template + void XMLCALL document:: + end_namespace_decl_thunk_ (void* data, const XML_Char* prefix) + { + document& d (*reinterpret_cast (data)); + d.end_namespace_decl_ (prefix); + } + + namespace bits + { + inline void + split_name (const XML_Char* s, + const char*& ns, std::size_t& ns_s, + const char*& name, std::size_t& name_s) + { + const char* p (std::strchr (s, ' ')); + + if (p) + { + ns = s; + ns_s = p - s; + name = p + 1; + } + else + { + ns = s; + ns_s = 0; + name = s; + } + + name_s = std::char_traits::length (name); + } + } + + template + void document:: + start_element_ (const XML_Char* ns_name, const XML_Char** atts) + { + // Current Expat (2.0.0) has a (mis)-feature of a possibility of + // calling callbacks even after the non-resumable XML_StopParser + // call. The following code accounts for this. + // + { + XML_ParsingStatus s; + XML_GetParsingStatus (xml_parser_, &s); + if (s.parsing == XML_FINISHED) + return; + } + + typedef std::basic_string string; + + const char* ns_p; + const char* name_p; + size_t ns_s, name_s; + + bits::split_name (ns_name, ns_p, ns_s, name_p, name_s); + + { + const ro_string ns (ns_p, ns_s), name (name_p, name_s); + + if (!polymorphic_) + { + try + { + start_element (ns, name, 0); + } + catch (const schema_exception& e) + { + translate_schema_exception (e); + return; + } + } + else + { + // Search for the xsi:type attribute. + // + const XML_Char** p = atts; // VC8 can't handle p (atts) + for (; *p != 0; p += 2) + { + bits::split_name (*p, ns_p, ns_s, name_p, name_s); + const ro_string ns (ns_p, ns_s), name (name_p, name_s); + + if (name == xml::bits::type () && + ns == xml::bits::xsi_namespace ()) + break; + } + + if (*p == 0) + { + try + { + start_element (ns, name, 0); + } + catch (const schema_exception& e) + { + translate_schema_exception (e); + return; + } + } + else + { + // @@ Need proper QName validation. + // + // Get the qualified type name and try to resolve it. + // + ro_string qn (*(p + 1)); + + ro_string tp, tn; + typename ro_string::size_type pos (qn.find (C (':'))); + + try + { + if (pos != ro_string::npos) + { + tp.assign (qn.data (), pos); + tn.assign (qn.data () + pos + 1); + + if (tp.empty ()) + throw dynamic_type (qn); + } + else + tn.assign (qn.data (), qn.size ()); + + if (tn.empty ()) + throw dynamic_type (qn); + + // Search our namespace declaration stack. Note that + // we need to do this even if prefix is empty. Sun CC + // 5.7 blows if we use const_reverse_iterator. + // + ro_string tns; + for (typename ns_decls::reverse_iterator + it (ns_decls_.rbegin ()), e (ns_decls_.rend ()); + it != e; ++it) + { + if (it->prefix == tp) + { + tns.assign (it->ns); + break; + } + } + + if (!tp.empty () && tns.empty ()) + { + // The 'xml' prefix requires special handling. + // + if (tp == xml::bits::xml_prefix ()) + tns.assign (xml::bits::xml_namespace ()); + else + throw dynamic_type (qn); + } + + // Construct the compound type id. + // + string id (tn.data (), tn.size ()); + + if (!tns.empty ()) + { + id += C (' '); + id.append (tns.data (), tns.size ()); + } + + ro_string ro_id (id); + start_element (ns, name, &ro_id); + } + catch (const schema_exception& e) + { + translate_schema_exception (e); + return; + } + } + } + } + + for (; *atts != 0; atts += 2) + { + bits::split_name (*atts, ns_p, ns_s, name_p, name_s); + + const ro_string ns (ns_p, ns_s), name (name_p, name_s); + const ro_string value (*(atts + 1)); + + try + { + attribute (ns, name, value); + } + catch (const schema_exception& e) + { + translate_schema_exception (e); + break; + } + } + } + + template + void document:: + end_element_ (const XML_Char* ns_name) + { + // Current Expat (2.0.0) has a (mis)-feature of a possibility of + // calling callbacks even after the non-resumable XML_StopParser + // call. The following code accounts for this. + // + { + XML_ParsingStatus s; + XML_GetParsingStatus (xml_parser_, &s); + if (s.parsing == XML_FINISHED) + return; + } + + const char* ns_p; + const char* name_p; + size_t ns_s, name_s; + + bits::split_name (ns_name, ns_p, ns_s, name_p, name_s); + + const ro_string ns (ns_p, ns_s), name (name_p, name_s); + + try + { + end_element (ns, name); + } + catch (const schema_exception& e) + { + translate_schema_exception (e); + } + } + + template + void document:: + characters_ (const XML_Char* s, std::size_t n) + { + // Current Expat (2.0.0) has a (mis)-feature of a possibility of + // calling callbacks even after the non-resumable XML_StopParser + // call. The following code accounts for this. + // + { + XML_ParsingStatus s; + XML_GetParsingStatus (xml_parser_, &s); + if (s.parsing == XML_FINISHED) + return; + } + + if (n != 0) + { + const ro_string str (s, n); + + try + { + characters (str); + } + catch (const schema_exception& e) + { + translate_schema_exception (e); + } + } + } + + template + void document:: + start_namespace_decl_ (const XML_Char* p, const XML_Char* ns) + { + // prefix is 0 for default namespace + // namespace is 0 when unsetting default namespace + // + if (polymorphic_) + ns_decls_.push_back (ns_decl ((p ? p : ""), (ns ? ns : ""))); + } + + template + void document:: + end_namespace_decl_ (const XML_Char* p) + { + // prefix is 0 for default namespace + // + if (polymorphic_) + { + // Here we assume the prefixes are removed in the reverse + // order of them being added. This appears to how every + // sensible implementation works. + // + assert (p + ? ns_decls_.back ().prefix == p + : ns_decls_.back ().prefix.empty ()); + + ns_decls_.pop_back (); + } + } + } + } + } +} diff --git a/libxsd/xsd/cxx/parser/map.hxx b/libxsd/xsd/cxx/parser/map.hxx new file mode 100644 index 0000000..7d3696a --- /dev/null +++ b/libxsd/xsd/cxx/parser/map.hxx @@ -0,0 +1,79 @@ +// file : xsd/cxx/parser/map.hxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_PARSER_MAP_HXX +#define XSD_CXX_PARSER_MAP_HXX + +#include +#include + +#include +#include + +namespace xsd +{ + namespace cxx + { + namespace parser + { + // Parser map. Used in the polymorphic document parsing. + // + template + struct parser_map + { + virtual + ~parser_map (); + + // The type argument is the type name and namespace from the + // xsi:type attribute or substitution group map in the form + // " " with the space and namespace part + // absent if the type does not have a namespace. + // + virtual parser_base* + find (const ro_string& type) const = 0; + }; + + + // Parser map implementation. + // + template + struct parser_map_impl: parser_map + { + parser_map_impl (); + + void + insert (parser_base&); + + virtual parser_base* + find (const ro_string& type) const; + + private: + parser_map_impl (const parser_map_impl&); + + parser_map_impl& + operator= (const parser_map_impl&); + + private: + struct string_comparison + { + bool + operator() (const C* x, const C* y) const + { + ro_string s (x); + return s.compare (y) < 0; + } + }; + + typedef std::map*, string_comparison> map; + map map_; + }; + } + } +} + +#include +#include + +#endif // XSD_CXX_PARSER_MAP_HXX diff --git a/libxsd/xsd/cxx/parser/map.ixx b/libxsd/xsd/cxx/parser/map.ixx new file mode 100644 index 0000000..17ac4e4 --- /dev/null +++ b/libxsd/xsd/cxx/parser/map.ixx @@ -0,0 +1,27 @@ +// file : xsd/cxx/parser/map.ixx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsd +{ + namespace cxx + { + namespace parser + { + // parser_map_impl + // + template + inline parser_map_impl::parser_map_impl () + { + } + + template + inline void parser_map_impl:: + insert (parser_base& parser) + { + map_[parser._dynamic_type ()] = &parser; + } + } + } +} diff --git a/libxsd/xsd/cxx/parser/map.txx b/libxsd/xsd/cxx/parser/map.txx new file mode 100644 index 0000000..5d31894 --- /dev/null +++ b/libxsd/xsd/cxx/parser/map.txx @@ -0,0 +1,31 @@ +// file : xsd/cxx/parser/map.txx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsd +{ + namespace cxx + { + namespace parser + { + // parser_map + // + template + parser_map:: + ~parser_map () + { + } + + // parser_map_impl + // + template + parser_base* parser_map_impl:: + find (const ro_string& type) const + { + typename map::const_iterator i (map_.find (type.data ())); + return i != map_.end () ? i->second : 0; + } + } + } +} diff --git a/libxsd/xsd/cxx/parser/non-validating/parser.hxx b/libxsd/xsd/cxx/parser/non-validating/parser.hxx new file mode 100644 index 0000000..480d8ab --- /dev/null +++ b/libxsd/xsd/cxx/parser/non-validating/parser.hxx @@ -0,0 +1,248 @@ +// file : xsd/cxx/parser/non-validating/parser.hxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_PARSER_NON_VALIDATING_PARSER_HXX +#define XSD_CXX_PARSER_NON_VALIDATING_PARSER_HXX + +#include +#include +#include // std::size_t + +#include +#include + +namespace xsd +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + // + // + template + struct empty_content: parser_base + { + // The _*_any_* functions are called when wildcard content + // is encountered. Use them to handle mixed content models, + // any/anyAttribute, and anyType/anySimpleType. By default + // these functions do nothing. + // + + // The type argument is a type name and namespace from the + // xsi:type attribute in the form " " with + // the space and namespace part absent if the type does not + // have a namespace or 0 if xsi:type is not present. + // + virtual void + _start_any_element (const ro_string& ns, + const ro_string& name, + const ro_string* type); + + virtual void + _end_any_element (const ro_string& ns, + const ro_string& name); + + virtual void + _any_attribute (const ro_string& ns, + const ro_string& name, + const ro_string& value); + + virtual void + _any_characters (const ro_string&); + + + // + // + virtual bool + _start_element_impl (const ro_string&, + const ro_string&, + const ro_string*); + + virtual bool + _end_element_impl (const ro_string&, + const ro_string&); + + virtual bool + _attribute_impl (const ro_string&, + const ro_string&, + const ro_string&); + + virtual bool + _characters_impl (const ro_string&); + + + // + // + virtual void + _start_element (const ro_string& ns, + const ro_string& name, + const ro_string* type); + + virtual void + _end_element (const ro_string& ns, + const ro_string& name); + + virtual void + _attribute (const ro_string& ns, + const ro_string& name, + const ro_string& value); + + virtual void + _characters (const ro_string& s); + }; + + + // + // + template + struct simple_content: empty_content + { + // + // + virtual void + _attribute (const ro_string& ns, + const ro_string& name, + const ro_string& value); + + virtual void + _characters (const ro_string&); + }; + + + // + // + template + struct complex_content: empty_content + { + // + // + virtual void + _start_element (const ro_string& ns, + const ro_string& name, + const ro_string* type); + + virtual void + _end_element (const ro_string& ns, + const ro_string& name); + + virtual void + _attribute (const ro_string& ns, + const ro_string& name, + const ro_string& value); + + virtual void + _characters (const ro_string&); + + + // + // + virtual void + _pre_impl (); + + virtual void + _post_impl (); + + protected: + struct state + { + state () + : any_ (false), depth_ (0), parser_ (0) + { + } + + bool any_; + std::size_t depth_; + parser_base* parser_; + }; + + // Optimized state stack for non-recursive case (one element). + // + struct state_stack + { + state_stack () + : size_ (0) + { + } + + void + push (const state& s) + { + if (size_ > 0) + rest_.push (top_); + + top_ = s; + ++size_; + } + + void + pop () + { + if (size_ > 1) + { + top_ = rest_.top (); + rest_.pop (); + } + + --size_; + } + + const state& + top () const + { + return top_; + } + + state& + top () + { + return top_; + } + + state& + under_top () + { + return rest_.top (); + } + + private: + state top_; + std::stack rest_; + std::size_t size_; + }; + + state_stack context_; + }; + + + // Base for xsd:list. + // + template + struct list_base: simple_content + { + virtual void + _xsd_parse_item (const ro_string&) = 0; + + virtual void + _pre_impl (); + + virtual void + _characters (const ro_string&); + + virtual void + _post_impl (); + + protected: + std::basic_string buf_; + }; + } + } + } +} + +#include + +#endif // XSD_CXX_PARSER_NON_VALIDATING_PARSER_HXX diff --git a/libxsd/xsd/cxx/parser/non-validating/parser.txx b/libxsd/xsd/cxx/parser/non-validating/parser.txx new file mode 100644 index 0000000..d379d7a --- /dev/null +++ b/libxsd/xsd/cxx/parser/non-validating/parser.txx @@ -0,0 +1,464 @@ +// file : xsd/cxx/parser/non-validating/parser.txx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include + +#include + +namespace xsd +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + + // empty_content + // + + template + void empty_content:: + _start_any_element (const ro_string&, + const ro_string&, + const ro_string*) + { + } + + template + void empty_content:: + _end_any_element (const ro_string&, + const ro_string&) + { + } + + template + void empty_content:: + _any_attribute (const ro_string&, + const ro_string&, + const ro_string&) + { + } + + template + void empty_content:: + _any_characters (const ro_string&) + { + } + + // + // + template + bool empty_content:: + _start_element_impl (const ro_string&, + const ro_string&, + const ro_string*) + { + return false; + } + + template + bool empty_content:: + _end_element_impl (const ro_string&, + const ro_string&) + { + return false; + } + + template + bool empty_content:: + _attribute_impl (const ro_string&, + const ro_string&, + const ro_string&) + { + return false; + } + + template + bool empty_content:: + _characters_impl (const ro_string&) + { + return false; + } + + template + void empty_content:: + _start_element (const ro_string& ns, + const ro_string& name, + const ro_string* type) + { + if (!_start_element_impl (ns, name, type)) + _start_any_element (ns, name, type); + } + + template + void empty_content:: + _end_element (const ro_string& ns, + const ro_string& name) + { + if (!_end_element_impl (ns, name)) + _end_any_element (ns, name); + } + + template + void empty_content:: + _attribute (const ro_string& ns, + const ro_string& name, + const ro_string& value) + { + // Weed out special attributes: xsi:type, xsi:nil, + // xsi:schemaLocation and noNamespaceSchemaLocation. + // See section 3.2.7 in Structures for details. + // + if (ns == xml::bits::xsi_namespace () && + (name == xml::bits::type () || + name == xml::bits::nil () || + name == xml::bits::schema_location () || + name == xml::bits::no_namespace_schema_location ())) + return; + + // Also some parsers (notably Xerces-C++) supplies us with + // namespace-prefix mapping attributes. + // + if (ns == xml::bits::xmlns_namespace ()) + return; + + if (!_attribute_impl (ns, name, value)) + _any_attribute (ns, name, value); + } + + template + void empty_content:: + _characters (const ro_string& s) + { + if (!_characters_impl (s)) + _any_characters (s); + } + + + // simple_content + // + + template + void simple_content:: + _attribute (const ro_string& ns, + const ro_string& name, + const ro_string& value) + { + // Weed out special attributes: xsi:type, xsi:nil, + // xsi:schemaLocation and xsi:noNamespaceSchemaLocation. + // See section 3.2.7 in Structures for details. + // + if (ns == xml::bits::xsi_namespace () && + (name == xml::bits::type () || + name == xml::bits::nil () || + name == xml::bits::schema_location () || + name == xml::bits::no_namespace_schema_location ())) + return; + + // Also some parsers (notably Xerces-C++) supplies us with + // namespace-prefix mapping attributes. + // + if (ns == xml::bits::xmlns_namespace ()) + return; + + if (!_attribute_impl (ns, name, value)) + _any_attribute (ns, name, value); + } + + template + void simple_content:: + _characters (const ro_string& str) + { + _characters_impl (str); + } + + + // complex_content + // + + template + void complex_content:: + _start_element (const ro_string& ns, + const ro_string& name, + const ro_string* type) + { + state& s (context_.top ()); + + if (s.depth_++ > 0) + { + if (s.any_) + _start_any_element (ns, name, type); + else if (s.parser_) + s.parser_->_start_element (ns, name, type); + } + else + { + if (!_start_element_impl (ns, name, type)) + { + _start_any_element (ns, name, type); + s.any_ = true; + } + else if (s.parser_ != 0) + s.parser_->_pre_impl (); + } + } + + template + void complex_content:: + _end_element (const ro_string& ns, + const ro_string& name) + { + // To understand what's going on here it is helpful to think of + // a "total depth" as being the sum of individual depths over + // all elements. + // + + if (context_.top ().depth_ == 0) + { + state& s (context_.under_top ()); // One before last. + + if (--s.depth_ > 0) + { + // Indirect recursion. + // + if (s.parser_) + s.parser_->_end_element (ns, name); + } + else + { + // Direct recursion. + // + assert (this == s.parser_); + + this->_post_impl (); + + if (!_end_element_impl (ns, name)) + assert (false); + } + } + else + { + state& s (context_.top ()); + + if (--s.depth_ > 0) + { + if (s.any_) + _end_any_element (ns, name); + else if (s.parser_) + s.parser_->_end_element (ns, name); + } + else + { + if (s.parser_ != 0 && !s.any_) + s.parser_->_post_impl (); + + if (!_end_element_impl (ns, name)) + { + s.any_ = false; + _end_any_element (ns, name); + } + } + } + } + + template + void complex_content:: + _attribute (const ro_string& ns, + const ro_string& name, + const ro_string& value) + { + // Weed out special attributes: xsi:type, xsi:nil, + // xsi:schemaLocation and xsi:noNamespaceSchemaLocation. + // See section 3.2.7 in Structures for details. + // + if (ns == xml::bits::xsi_namespace () && + (name == xml::bits::type () || + name == xml::bits::nil () || + name == xml::bits::schema_location () || + name == xml::bits::no_namespace_schema_location ())) + return; + + // Also some parsers (notably Xerces-C++) supplies us with + // namespace-prefix mapping attributes. + // + if (ns == xml::bits::xmlns_namespace ()) + return; + + state& s (context_.top ()); + + if (s.depth_ > 0) + { + if (s.any_) + _any_attribute (ns, name, value); + else if (s.parser_) + s.parser_->_attribute (ns, name, value); + } + else + { + if (!_attribute_impl (ns, name, value)) + _any_attribute (ns, name, value); + } + } + + template + void complex_content:: + _characters (const ro_string& str) + { + state& s (context_.top ()); + + if (s.depth_ > 0) + { + if (s.any_) + _any_characters (str); + else if (s.parser_) + s.parser_->_characters (str); + } + else + { + if (!_characters_impl (str)) + _any_characters (str); + } + } + + template + void complex_content:: + _pre_impl () + { + context_.push (state ()); + this->_pre (); + } + + template + void complex_content:: + _post_impl () + { + this->_post (); + context_.pop (); + } + + // list_base + // + namespace bits + { + // Find first non-space character. + // + template + typename ro_string::size_type + find_ns (const C* s, + typename ro_string::size_type size, + typename ro_string::size_type pos) + { + while (pos < size && + (s[pos] == C (0x20) || s[pos] == C (0x0A) || + s[pos] == C (0x0D) || s[pos] == C (0x09))) + ++pos; + + return pos < size ? pos : ro_string::npos; + } + + // Find first space character. + // + template + typename ro_string::size_type + find_s (const C* s, + typename ro_string::size_type size, + typename ro_string::size_type pos) + { + while (pos < size && + s[pos] != C (0x20) && s[pos] != C (0x0A) && + s[pos] != C (0x0D) && s[pos] != C (0x09)) + ++pos; + + return pos < size ? pos : ro_string::npos; + } + } + + // Relevant XML Schema Part 2: Datatypes sections: 4.2.1.2, 4.3.6. + // + + template + void list_base:: + _pre_impl () + { + simple_content::_pre_impl (); + buf_.clear (); + } + + template + void list_base:: + _characters (const ro_string& s) + { + typedef typename ro_string::size_type size_type; + + const C* data (s.data ()); + size_type size (s.size ()); + + // Handle the previous chunk if we start with a ws. + // + if (!buf_.empty () && + (data[0] == C (0x20) || data[0] == C (0x0A) || + data[0] == C (0x0D) || data[0] == C (0x09))) + { + ro_string tmp (buf_); // Private copy ctor. + _xsd_parse_item (tmp); + buf_.clear (); + } + + // Traverse the data while logically collapsing spaces. + // + for (size_type i (bits::find_ns (data, size, 0)); + i != ro_string::npos;) + { + size_type j (bits::find_s (data, size, i)); + + if (j != ro_string::npos) + { + if (buf_.empty ()) + { + ro_string tmp (data + i, j - i); // Private copy ctor. + _xsd_parse_item (tmp); + } + else + { + // Assemble the first item in str from buf_ and s. + // + std::basic_string str; + str.swap (buf_); + str.append (data + i, j - i); + ro_string tmp (str); // Private copy ctor. + _xsd_parse_item (tmp); + } + + i = bits::find_ns (data, size, j); + } + else + { + // Last fragment, append it to the buf_. + // + buf_.append (data + i, size - i); + break; + } + } + } + + template + void list_base:: + _post_impl () + { + // Handle the last item. + // + if (!buf_.empty ()) + { + ro_string tmp (buf_); // Private copy ctor. + _xsd_parse_item (tmp); + } + + simple_content::_post_impl (); + } + } + } + } +} diff --git a/libxsd/xsd/cxx/parser/non-validating/xml-schema-pimpl.hxx b/libxsd/xsd/cxx/parser/non-validating/xml-schema-pimpl.hxx new file mode 100644 index 0000000..0e8443d --- /dev/null +++ b/libxsd/xsd/cxx/parser/non-validating/xml-schema-pimpl.hxx @@ -0,0 +1,791 @@ +// file : xsd/cxx/parser/non-validating/xml-schema-pimpl.hxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_PARSER_NON_VALIDATING_XML_SCHEMA_PIMPL_HXX +#define XSD_CXX_PARSER_NON_VALIDATING_XML_SCHEMA_PIMPL_HXX + +#include + +#include + +namespace xsd +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + // any_type + // + template + struct any_type_pimpl: virtual any_type_pskel + { + virtual void + post_any_type (); + }; + + // any_simple_type + // + template + struct any_simple_type_pimpl: virtual any_simple_type_pskel + { + virtual void + post_any_simple_type (); + }; + + // boolean + // + template + struct boolean_pimpl: virtual boolean_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual bool + post_boolean (); + + protected: + std::basic_string str_; + }; + + + // 8-bit + // + template + struct byte_pimpl: virtual byte_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual signed char + post_byte (); + + protected: + std::basic_string str_; + }; + + + template + struct unsigned_byte_pimpl: virtual unsigned_byte_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual unsigned char + post_unsigned_byte (); + + protected: + std::basic_string str_; + }; + + + // 16-bit + // + template + struct short_pimpl: virtual short_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual short + post_short (); + + protected: + std::basic_string str_; + }; + + + template + struct unsigned_short_pimpl: virtual unsigned_short_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual unsigned short + post_unsigned_short (); + + protected: + std::basic_string str_; + }; + + + // 32-bit + // + template + struct int_pimpl: virtual int_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual int + post_int (); + + protected: + std::basic_string str_; + }; + + + template + struct unsigned_int_pimpl: virtual unsigned_int_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual unsigned int + post_unsigned_int (); + + protected: + std::basic_string str_; + }; + + + // 64-bit + // + template + struct long_pimpl: virtual long_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual long long + post_long (); + + protected: + std::basic_string str_; + }; + + + template + struct unsigned_long_pimpl: virtual unsigned_long_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual unsigned long long + post_unsigned_long (); + + protected: + std::basic_string str_; + }; + + + // Arbitrary-length integers. + // + template + struct integer_pimpl: virtual integer_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual long long + post_integer (); + + protected: + std::basic_string str_; + }; + + template + struct negative_integer_pimpl: virtual negative_integer_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual long long + post_negative_integer (); + + protected: + std::basic_string str_; + }; + + template + struct non_positive_integer_pimpl: virtual non_positive_integer_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual long long + post_non_positive_integer (); + + protected: + std::basic_string str_; + }; + + template + struct positive_integer_pimpl: virtual positive_integer_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual unsigned long long + post_positive_integer (); + + protected: + std::basic_string str_; + }; + + template + struct non_negative_integer_pimpl: virtual non_negative_integer_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual unsigned long long + post_non_negative_integer (); + + protected: + std::basic_string str_; + }; + + + // Floats. + // + template + struct float_pimpl: virtual float_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual float + post_float (); + + protected: + std::basic_string str_; + }; + + + template + struct double_pimpl: virtual double_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual double + post_double (); + + protected: + std::basic_string str_; + }; + + + template + struct decimal_pimpl: virtual decimal_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual double + post_decimal (); + + protected: + std::basic_string str_; + }; + + + // Strings. + // + template + struct string_pimpl: virtual string_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual std::basic_string + post_string (); + + protected: + std::basic_string str_; + }; + + template + struct normalized_string_pimpl: virtual normalized_string_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual std::basic_string + post_normalized_string (); + + protected: + std::basic_string str_; + }; + + template + struct token_pimpl: virtual token_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual std::basic_string + post_token (); + + protected: + std::basic_string str_; + }; + + template + struct name_pimpl: virtual name_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual std::basic_string + post_name (); + + protected: + std::basic_string str_; + }; + + template + struct nmtoken_pimpl: virtual nmtoken_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual std::basic_string + post_nmtoken (); + + protected: + std::basic_string str_; + }; + + template + struct nmtokens_pimpl: virtual nmtokens_pskel + { + virtual void + _pre (); + + virtual void + _xsd_parse_item (const ro_string&); + + virtual string_sequence + post_nmtokens (); + + protected: + string_sequence seq_; + nmtoken_pimpl parser_; + }; + + template + struct ncname_pimpl: virtual ncname_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual std::basic_string + post_ncname (); + + protected: + std::basic_string str_; + }; + + template + struct id_pimpl: virtual id_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual std::basic_string + post_id (); + + protected: + std::basic_string str_; + }; + + template + struct idref_pimpl: virtual idref_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual std::basic_string + post_idref (); + + protected: + std::basic_string str_; + }; + + template + struct idrefs_pimpl: virtual idrefs_pskel + { + virtual void + _pre (); + + virtual void + _xsd_parse_item (const ro_string&); + + virtual string_sequence + post_idrefs (); + + protected: + string_sequence seq_; + idref_pimpl parser_; + }; + + // language + // + template + struct language_pimpl: virtual language_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual std::basic_string + post_language (); + + protected: + std::basic_string str_; + }; + + // anyURI + // + template + struct uri_pimpl: virtual uri_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual std::basic_string + post_uri (); + + protected: + std::basic_string str_; + }; + + // QName + // + template + struct qname_pimpl: virtual qname_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual qname + post_qname (); + + protected: + std::basic_string str_; + }; + + // base64Binary + // + template + struct base64_binary_pimpl: virtual base64_binary_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual std::auto_ptr + post_base64_binary (); + + protected: + std::basic_string str_; + }; + + // hexBinary + // + template + struct hex_binary_pimpl: virtual hex_binary_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual std::auto_ptr + post_hex_binary (); + + protected: + std::basic_string str_; + }; + + // gday + // + template + struct gday_pimpl: virtual gday_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual gday + post_gday (); + + protected: + std::basic_string str_; + }; + + // gmonth + // + template + struct gmonth_pimpl: virtual gmonth_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual gmonth + post_gmonth (); + + protected: + std::basic_string str_; + }; + + // gyear + // + template + struct gyear_pimpl: virtual gyear_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual gyear + post_gyear (); + + protected: + std::basic_string str_; + }; + + // gmonth_day + // + template + struct gmonth_day_pimpl: virtual gmonth_day_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual gmonth_day + post_gmonth_day (); + + protected: + std::basic_string str_; + }; + + // gyear_month + // + template + struct gyear_month_pimpl: virtual gyear_month_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual gyear_month + post_gyear_month (); + + protected: + std::basic_string str_; + }; + + // date + // + template + struct date_pimpl: virtual date_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual date + post_date (); + + protected: + std::basic_string str_; + }; + + // time + // + template + struct time_pimpl: virtual time_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual time + post_time (); + + protected: + std::basic_string str_; + }; + + // date_time + // + template + struct date_time_pimpl: virtual date_time_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual date_time + post_date_time (); + + protected: + std::basic_string str_; + }; + + // duration + // + template + struct duration_pimpl: virtual duration_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual duration + post_duration (); + + protected: + std::basic_string str_; + }; + + // + // + namespace bits + { + // float literals: INF -INF NaN + // + template + const C* + positive_inf (); + + template + const C* + negative_inf (); + + template + const C* + nan (); + + // boolean literals + // + template + const C* + true_ (); + + template + const C* + one (); + } + } + } + } +} + +#include + +#endif // XSD_CXX_PARSER_NON_VALIDATING_XML_SCHEMA_PIMPL_HXX + +#include diff --git a/libxsd/xsd/cxx/parser/non-validating/xml-schema-pimpl.ixx b/libxsd/xsd/cxx/parser/non-validating/xml-schema-pimpl.ixx new file mode 100644 index 0000000..0220117 --- /dev/null +++ b/libxsd/xsd/cxx/parser/non-validating/xml-schema-pimpl.ixx @@ -0,0 +1,129 @@ +// file : xsd/cxx/parser/non-validating/xml-schema-pimpl.ixx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#if defined(XSD_CXX_PARSER_USE_CHAR) || !defined(XSD_CXX_PARSER_USE_WCHAR) + +#ifndef XSD_CXX_PARSER_NON_VALIDATING_XML_SCHEMA_PIMPL_IXX_CHAR +#define XSD_CXX_PARSER_NON_VALIDATING_XML_SCHEMA_PIMPL_IXX_CHAR + +namespace xsd +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + namespace bits + { + // + // + template<> + inline const char* + positive_inf () + { + return "INF"; + } + + template<> + inline const char* + negative_inf () + { + return "-INF"; + } + + template<> + inline const char* + nan () + { + return "NaN"; + } + + // + // + template<> + inline const char* + true_ () + { + return "true"; + } + + template<> + inline const char* + one () + { + return "1"; + } + } + } + } + } +} + +#endif // XSD_CXX_PARSER_NON_VALIDATING_XML_SCHEMA_PIMPL_IXX_CHAR +#endif // XSD_CXX_PARSER_USE_CHAR + + +#if defined(XSD_CXX_PARSER_USE_WCHAR) || !defined(XSD_CXX_PARSER_USE_CHAR) + +#ifndef XSD_CXX_PARSER_NON_VALIDATING_XML_SCHEMA_PIMPL_IXX_WCHAR +#define XSD_CXX_PARSER_NON_VALIDATING_XML_SCHEMA_PIMPL_IXX_WCHAR + +namespace xsd +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + namespace bits + { + // + // + template<> + inline const wchar_t* + positive_inf () + { + return L"INF"; + } + + template<> + inline const wchar_t* + negative_inf () + { + return L"-INF"; + } + + template<> + inline const wchar_t* + nan () + { + return L"NaN"; + } + + // + // + template<> + inline const wchar_t* + true_ () + { + return L"true"; + } + + template<> + inline const wchar_t* + one () + { + return L"1"; + } + } + } + } + } +} + +#endif // XSD_CXX_PARSER_NON_VALIDATING_XML_SCHEMA_PIMPL_IXX_WCHAR +#endif // XSD_CXX_PARSER_USE_WCHAR diff --git a/libxsd/xsd/cxx/parser/non-validating/xml-schema-pimpl.txx b/libxsd/xsd/cxx/parser/non-validating/xml-schema-pimpl.txx new file mode 100644 index 0000000..5ce50d6 --- /dev/null +++ b/libxsd/xsd/cxx/parser/non-validating/xml-schema-pimpl.txx @@ -0,0 +1,2068 @@ +// file : xsd/cxx/parser/non-validating/xml-schema-pimpl.txx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include +#include + +#include + +namespace xsd +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + // Note that most of the types implemented here cannot have + // whitespaces in the value. As result we don't need to waste + // time collapsing whitespaces. All we need to do is trim the + // string representation which can be done without copying. + // + + // any_type + // + + template + void any_type_pimpl:: + post_any_type () + { + } + + // any_simple_type + // + + template + void any_simple_type_pimpl:: + post_any_simple_type () + { + } + + // boolean + // + template + void boolean_pimpl:: + _pre () + { + str_.clear (); + } + + template + void boolean_pimpl:: + _characters (const ro_string& s) + { + str_ += s; + } + + template + bool boolean_pimpl:: + post_boolean () + { + std::basic_string tmp; + tmp.swap (str_); + + ro_string str (tmp); + trim (str); + + return str == bits::true_ () || str == bits::one (); + } + + // byte + // + + template + void byte_pimpl:: + _pre () + { + str_.clear (); + } + + template + void byte_pimpl:: + _characters (const ro_string& s) + { + str_ += s; + } + + template + signed char byte_pimpl:: + post_byte () + { + std::basic_string tmp; + tmp.swap (str_); + + ro_string str (tmp); + trim (str); + + short t; + zc_istream is (str); + is >> t; + + return static_cast (t); + } + + // unsigned_byte + // + + template + void unsigned_byte_pimpl:: + _pre () + { + str_.clear (); + } + + template + void unsigned_byte_pimpl:: + _characters (const ro_string& s) + { + str_ += s; + } + + template + unsigned char unsigned_byte_pimpl:: + post_unsigned_byte () + { + std::basic_string tmp; + tmp.swap (str_); + + ro_string str (tmp); + trim (str); + + unsigned short t; + zc_istream is (str); + is >> t; + + return static_cast (t); + } + + // short + // + + template + void short_pimpl:: + _pre () + { + str_.clear (); + } + + template + void short_pimpl:: + _characters (const ro_string& s) + { + str_ += s; + } + + template + short short_pimpl:: + post_short () + { + std::basic_string tmp; + tmp.swap (str_); + + ro_string str (tmp); + trim (str); + + short t; + zc_istream is (str); + is >> t; + + return t; + } + + // unsigned_short + // + + template + void unsigned_short_pimpl:: + _pre () + { + str_.clear (); + } + + template + void unsigned_short_pimpl:: + _characters (const ro_string& s) + { + str_ += s; + } + + template + unsigned short unsigned_short_pimpl:: + post_unsigned_short () + { + std::basic_string tmp; + tmp.swap (str_); + + ro_string str (tmp); + trim (str); + + unsigned short t; + zc_istream is (str); + is >> t; + + return t; + } + + // int + // + + template + void int_pimpl:: + _pre () + { + str_.clear (); + } + + template + void int_pimpl:: + _characters (const ro_string& s) + { + str_ += s; + } + + template + int int_pimpl:: + post_int () + { + std::basic_string tmp; + tmp.swap (str_); + + ro_string str (tmp); + trim (str); + + int t; + zc_istream is (str); + is >> t; + + return t; + } + + // unsigned_int + // + + template + void unsigned_int_pimpl:: + _pre () + { + str_.clear (); + } + + template + void unsigned_int_pimpl:: + _characters (const ro_string& s) + { + str_ += s; + } + + template + unsigned int unsigned_int_pimpl:: + post_unsigned_int () + { + std::basic_string tmp; + tmp.swap (str_); + + ro_string str (tmp); + trim (str); + + unsigned int t; + zc_istream is (str); + is >> t; + + return t; + } + + // long + // + template + void long_pimpl:: + _pre () + { + str_.clear (); + } + + template + void long_pimpl:: + _characters (const ro_string& s) + { + str_ += s; + } + + template + long long long_pimpl:: + post_long () + { + std::basic_string tmp; + tmp.swap (str_); + + ro_string str (tmp); + trim (str); + + long long t; + zc_istream is (str); + is >> t; + + return t; + } + + // unsigned_long + // + template + void unsigned_long_pimpl:: + _pre () + { + str_.clear (); + } + + template + void unsigned_long_pimpl:: + _characters (const ro_string& s) + { + str_ += s; + } + + template + unsigned long long unsigned_long_pimpl:: + post_unsigned_long () + { + std::basic_string tmp; + tmp.swap (str_); + + ro_string str (tmp); + trim (str); + + unsigned long long t; + zc_istream is (str); + is >> t; + + return t; + } + + // integer + // + template + void integer_pimpl:: + _pre () + { + str_.clear (); + } + + template + void integer_pimpl:: + _characters (const ro_string& s) + { + str_ += s; + } + + template + long long integer_pimpl:: + post_integer () + { + std::basic_string tmp; + tmp.swap (str_); + + ro_string str (tmp); + trim (str); + + long long t; + zc_istream is (str); + is >> t; + + return t; + } + + // negative_integer + // + template + void negative_integer_pimpl:: + _pre () + { + str_.clear (); + } + + template + void negative_integer_pimpl:: + _characters (const ro_string& s) + { + str_ += s; + } + + template + long long negative_integer_pimpl:: + post_negative_integer () + { + std::basic_string tmp; + tmp.swap (str_); + + ro_string str (tmp); + trim (str); + + long long t; + zc_istream is (str); + is >> t; + + return t; + } + + // non_positive_integer + // + template + void non_positive_integer_pimpl:: + _pre () + { + str_.clear (); + } + + template + void non_positive_integer_pimpl:: + _characters (const ro_string& s) + { + str_ += s; + } + + template + long long non_positive_integer_pimpl:: + post_non_positive_integer () + { + std::basic_string tmp; + tmp.swap (str_); + + ro_string str (tmp); + trim (str); + + long long t; + zc_istream is (str); + is >> t; + + return t; + } + + // positive_integer + // + template + void positive_integer_pimpl:: + _pre () + { + str_.clear (); + } + + template + void positive_integer_pimpl:: + _characters (const ro_string& s) + { + str_ += s; + } + + template + unsigned long long positive_integer_pimpl:: + post_positive_integer () + { + std::basic_string tmp; + tmp.swap (str_); + + ro_string str (tmp); + trim (str); + + unsigned long long t; + zc_istream is (str); + is >> t; + + return t; + } + + // non_negative_integer + // + template + void non_negative_integer_pimpl:: + _pre () + { + str_.clear (); + } + + template + void non_negative_integer_pimpl:: + _characters (const ro_string& s) + { + str_ += s; + } + + template + unsigned long long non_negative_integer_pimpl:: + post_non_negative_integer () + { + std::basic_string tmp; + tmp.swap (str_); + + ro_string str (tmp); + trim (str); + + unsigned long long t; + zc_istream is (str); + is >> t; + + return t; + } + + // float + // + template + void float_pimpl:: + _pre () + { + str_.clear (); + } + + template + void float_pimpl:: + _characters (const ro_string& s) + { + str_ += s; + } + + template + float float_pimpl:: + post_float () + { + std::basic_string tmp; + tmp.swap (str_); + + ro_string str (tmp); + trim (str); + + if (str == bits::positive_inf ()) + return std::numeric_limits::infinity (); + + if (str == bits::negative_inf ()) + return -std::numeric_limits::infinity (); + + if (str == bits::nan ()) + return std::numeric_limits::quiet_NaN (); + + float t; + zc_istream is (str); + is.imbue (std::locale::classic ()); + is >> t; + + return t; + } + + // double + // + template + void double_pimpl:: + _pre () + { + str_.clear (); + } + + template + void double_pimpl:: + _characters (const ro_string& s) + { + str_ += s; + } + + template + double double_pimpl:: + post_double () + { + std::basic_string tmp; + tmp.swap (str_); + + ro_string str (tmp); + trim (str); + + if (str == bits::positive_inf ()) + return std::numeric_limits::infinity (); + + if (str == bits::negative_inf ()) + return -std::numeric_limits::infinity (); + + if (str == bits::nan ()) + return std::numeric_limits::quiet_NaN (); + + double t; + zc_istream is (str); + is.imbue (std::locale::classic ()); + is >> t; + + return t; + } + + // decimal + // + template + void decimal_pimpl:: + _pre () + { + str_.clear (); + } + + template + void decimal_pimpl:: + _characters (const ro_string& s) + { + str_ += s; + } + + template + double decimal_pimpl:: + post_decimal () + { + std::basic_string tmp; + tmp.swap (str_); + + ro_string str (tmp); + trim (str); + + double t; + zc_istream is (str); + is.imbue (std::locale::classic ()); + is >> t; + + return t; + } + + + // string + // + template + void string_pimpl:: + _pre () + { + str_.clear (); + } + + template + void string_pimpl:: + _characters (const ro_string& s) + { + str_ += s; + } + + template + std::basic_string string_pimpl:: + post_string () + { + std::basic_string r; + r.swap (str_); + return r; + } + + // normalized_string + // + template + void normalized_string_pimpl:: + _pre () + { + str_.clear (); + } + + template + void normalized_string_pimpl:: + _characters (const ro_string& s) + { + str_ += s; + } + + template + std::basic_string normalized_string_pimpl:: + post_normalized_string () + { + typedef typename std::basic_string::size_type size_type; + + size_type size (str_.size ()); + + for (size_type i (0); i < size; ++i) + { + C& c = str_[i]; + + if (c == C (0x0A) || c == C (0x0D) || c == C (0x09)) + c = C (0x20); + } + + std::basic_string r; + r.swap (str_); + return r; + } + + // token + // + template + void token_pimpl:: + _pre () + { + str_.clear (); + } + + template + void token_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + template + std::basic_string token_pimpl:: + post_token () + { + typedef typename std::basic_string::size_type size_type; + + size_type size (str_.size ()); + size_type j (0); + + bool subs (false); + + for (size_type i (0); i < size; ++i) + { + C c = str_[i]; + + if (c == C (0x20) || c == C (0x0A) || + c == C (0x0D) || c == C (0x09)) + { + subs = true; + } + else + { + if (subs) + { + subs = false; + str_[j++] = C (0x20); + } + + str_[j++] = c; + } + } + + str_.resize (j); + + std::basic_string r; + r.swap (str_); + return r; + } + + // name + // + template + void name_pimpl:: + _pre () + { + str_.clear (); + } + + template + void name_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + template + std::basic_string name_pimpl:: + post_name () + { + ro_string tmp (str_); + str_.resize (trim_right (tmp)); + + std::basic_string r; + r.swap (str_); + return r; + } + + // nmtoken + // + template + void nmtoken_pimpl:: + _pre () + { + str_.clear (); + } + + template + void nmtoken_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + template + std::basic_string nmtoken_pimpl:: + post_nmtoken () + { + ro_string tmp (str_); + str_.resize (trim_right (tmp)); + + std::basic_string r; + r.swap (str_); + return r; + } + + // nmtokens + // + template + void nmtokens_pimpl:: + _pre () + { + nmtokens_pskel::_pre (); + seq_.clear (); + } + + template + string_sequence nmtokens_pimpl:: + post_nmtokens () + { + string_sequence r; + r.swap (seq_); + return r; + } + + template + void nmtokens_pimpl:: + _xsd_parse_item (const ro_string& s) + { + parser_.pre (); + parser_._pre (); + parser_._characters (s); + parser_._post (); + seq_.push_back (parser_.post_nmtoken ()); + } + + // ncname + // + template + void ncname_pimpl:: + _pre () + { + str_.clear (); + } + + template + void ncname_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + template + std::basic_string ncname_pimpl:: + post_ncname () + { + ro_string tmp (str_); + str_.resize (trim_right (tmp)); + + std::basic_string r; + r.swap (str_); + return r; + } + + // id + // + template + void id_pimpl:: + _pre () + { + str_.clear (); + } + + template + void id_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + template + std::basic_string id_pimpl:: + post_id () + { + ro_string tmp (str_); + str_.resize (trim_right (tmp)); + + std::basic_string r; + r.swap (str_); + return r; + } + + // idref + // + template + void idref_pimpl:: + _pre () + { + str_.clear (); + } + + template + void idref_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + template + std::basic_string idref_pimpl:: + post_idref () + { + ro_string tmp (str_); + str_.resize (trim_right (tmp)); + + std::basic_string r; + r.swap (str_); + return r; + } + + // idrefs + // + template + void idrefs_pimpl:: + _pre () + { + idrefs_pskel::_pre (); + seq_.clear (); + } + + template + string_sequence idrefs_pimpl:: + post_idrefs () + { + string_sequence r; + r.swap (seq_); + return r; + } + + template + void idrefs_pimpl:: + _xsd_parse_item (const ro_string& s) + { + parser_.pre (); + parser_._pre (); + parser_._characters (s); + parser_._post (); + seq_.push_back (parser_.post_idref ()); + } + + // language + // + template + void language_pimpl:: + _pre () + { + str_.clear (); + } + + template + void language_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + template + std::basic_string language_pimpl:: + post_language () + { + ro_string tmp (str_); + str_.resize (trim_right (tmp)); + + std::basic_string r; + r.swap (str_); + return r; + } + + // uri + // + template + void uri_pimpl:: + _pre () + { + str_.clear (); + } + + template + void uri_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + template + std::basic_string uri_pimpl:: + post_uri () + { + ro_string tmp (str_); + str_.resize (trim_right (tmp)); + + std::basic_string r; + r.swap (str_); + return r; + } + + // qname + // + template + void qname_pimpl:: + _pre () + { + str_.clear (); + } + + template + void qname_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + template + qname qname_pimpl:: + post_qname () + { + typedef typename ro_string::size_type size_type; + + ro_string tmp (str_); + size_type size (trim_right (tmp)); + size_type pos (tmp.find (C (':'))); + + if (pos != ro_string::npos) + { + std::basic_string prefix (tmp.data (), pos++); + std::basic_string name (tmp.data () + pos, size - pos); + return qname (prefix, name); + } + else + { + str_.resize (size); + return qname (str_); + } + } + + // base64_binary + // + template + void base64_binary_pimpl:: + _pre () + { + str_.clear (); + } + + template + void base64_binary_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + namespace bits + { + template + inline unsigned char + base64_decode (C c) + { + unsigned char r (0xFF); + + if (c >= C('A') && c <= C ('Z')) + r = static_cast (c - C ('A')); + else if (c >= C('a') && c <= C ('z')) + r = static_cast (c - C ('a') + 26); + else if (c >= C('0') && c <= C ('9')) + r = static_cast (c - C ('0') + 52); + else if (c == C ('+')) + r = 62; + else if (c == C ('/')) + r = 63; + + return r; + } + } + + template + std::auto_ptr base64_binary_pimpl:: + post_base64_binary () + { + typedef typename std::basic_string::size_type size_type; + + size_type size (str_.size ()); + const C* src (str_.c_str ()); + + // Remove all whitespaces. + // + { + size_type j (0); + + bool subs (false); + + for (size_type i (0); i < size; ++i) + { + C c = str_[i]; + + if (c == C (0x20) || c == C (0x0A) || + c == C (0x0D) || c == C (0x09)) + { + subs = true; + } + else + { + if (subs) + subs = false; + + str_[j++] = c; + } + } + + size = j; + str_.resize (size); + } + + // Our length should be a multiple of four. + // + size_type quad_count (size / 4); + size_type capacity (quad_count * 3 + 1); + + std::auto_ptr buf (new buffer (capacity, capacity)); + char* dst (buf->data ()); + + size_type si (0), di (0); // Source and destination indexes. + + // Process all quads except the last one. + // + unsigned char b1, b2, b3, b4; + + for (size_type q (0); q < quad_count - 1; ++q) + { + b1 = bits::base64_decode (src[si++]); + b2 = bits::base64_decode (src[si++]); + b3 = bits::base64_decode (src[si++]); + b4 = bits::base64_decode (src[si++]); + + dst[di++] = (b1 << 2) | (b2 >> 4); + dst[di++] = (b2 << 4) | (b3 >> 2); + dst[di++] = (b3 << 6) | b4; + } + + // Process the last quad. The first two octets are always there. + // + b1 = bits::base64_decode (src[si++]); + b2 = bits::base64_decode (src[si++]); + + C e3 (src[si++]); + C e4 (src[si++]); + + if (e4 == C ('=')) + { + if (e3 == C ('=')) + { + // Two pads. Last 4 bits in b2 should be zero. + // + dst[di++] = (b1 << 2) | (b2 >> 4); + } + else + { + // One pad. Last 2 bits in b3 should be zero. + // + b3 = bits::base64_decode (e3); + + dst[di++] = (b1 << 2) | (b2 >> 4); + dst[di++] = (b2 << 4) | (b3 >> 2); + } + } + else + { + // No pads. + // + b3 = bits::base64_decode (e3); + b4 = bits::base64_decode (e4); + + dst[di++] = (b1 << 2) | (b2 >> 4); + dst[di++] = (b2 << 4) | (b3 >> 2); + dst[di++] = (b3 << 6) | b4; + } + + // Set the real size. + // + buf->size (di); + + return buf; + } + + // hex_binary + // + template + void hex_binary_pimpl:: + _pre () + { + str_.clear (); + } + + template + void hex_binary_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + namespace bits + { + template + inline unsigned char + hex_decode (C c) + { + unsigned char r (0xFF); + + if (c >= C('0') && c <= C ('9')) + r = static_cast (c - C ('0')); + else if (c >= C ('A') && c <= C ('F')) + r = static_cast (10 + (c - C ('A'))); + else if (c >= C ('a') && c <= C ('f')) + r = static_cast (10 + (c - C ('a'))); + + return r; + } + } + + template + std::auto_ptr hex_binary_pimpl:: + post_hex_binary () + { + typedef typename ro_string::size_type size_type; + + ro_string tmp (str_); + size_type size (trim_right (tmp)); + + buffer::size_t n (size / 2); + std::auto_ptr buf (new buffer (n)); + + const C* src (tmp.data ()); + char* dst (buf->data ()); + + for (buffer::size_t i (0); i < n; ++i) + { + unsigned char h (bits::hex_decode (src[2 * i])); + unsigned char l (bits::hex_decode (src[2 * i + 1])); + dst[i] = (h << 4) | l; + } + + return buf; + } + + // time_zone + // + namespace bits + { + // Datatypes 3.2.7.3. + // + template + void + parse_tz (const C* s, + typename std::basic_string::size_type n, + short& h, short& m) + { + // time_zone := Z|(+|-)HH:MM + // + if (n == 0) + { + return; + } + else if (s[0] == 'Z') + { + h = 0; + m = 0; + } + else if (n == 6) + { + // Parse hours. + // + h = 10 * (s[1] - '0') + (s[2] - '0'); + + // Parse minutes. + // + m = 10 * (s[4] - '0') + (s[5] - '0'); + + if (s[0] == '-') + { + h = -h; + m = -m; + } + } + } + } + + // gday + // + template + void gday_pimpl:: + _pre () + { + str_.clear (); + } + + template + void gday_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + template + gday gday_pimpl:: + post_gday () + { + typedef typename ro_string::size_type size_type; + + ro_string tmp (str_); + size_type size (trim_right (tmp)); + const C* s (tmp.data ()); + + unsigned short day (0); + bool z (false); + short zh (0), zm (0); + + // gday := ---DD[Z|(+|-)HH:MM] + // + if (size >= 5) + { + day = 10 * (s[3] - '0') + (s[4] - '0'); + + if (size > 5) + { + bits::parse_tz (s + 5, size - 5, zh, zm); + z = true; + } + } + + return z ? gday (day, zh, zm) : gday (day); + } + + // gmonth + // + template + void gmonth_pimpl:: + _pre () + { + str_.clear (); + } + + template + void gmonth_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + template + gmonth gmonth_pimpl:: + post_gmonth () + { + typedef typename ro_string::size_type size_type; + + ro_string tmp (str_); + size_type size (trim_right (tmp)); + const C* s (tmp.data ()); + + unsigned short month (0); + bool z (false); + short zh (0), zm (0); + + // gmonth := --MM[Z|(+|-)HH:MM] + // + if (size >= 4) + { + month = 10 * (s[2] - '0') + (s[3] - '0'); + + if (size > 4) + { + bits::parse_tz (s + 4, size - 4, zh, zm); + z = true; + } + } + + return z ? gmonth (month, zh, zm) : gmonth (month); + } + + // gyear + // + template + void gyear_pimpl:: + _pre () + { + str_.clear (); + } + + template + void gyear_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + template + gyear gyear_pimpl:: + post_gyear () + { + typedef typename ro_string::size_type size_type; + + ro_string tmp (str_); + size_type size (trim_right (tmp)); + const C* s (tmp.data ()); + + int year (0); + bool z (false); + short zh (0), zm (0); + + // gyear := [-]CCYY[N]*[Z|(+|-)HH:MM] + // + + if (size >= 4) + { + // Find the end of the year token. + // + size_type pos (4); + for (; pos < size; ++pos) + { + C c (s[pos]); + + if (c == C ('Z') || c == C ('+') || c == C ('-')) + break; + } + + ro_string year_fragment (s, pos); + zc_istream is (year_fragment); + is >> year; + + if (pos < size) + { + bits::parse_tz (s + pos, size - pos, zh, zm); + z = true; + } + } + + return z ? gyear (year, zh, zm) : gyear (year); + } + + // gmonth_day + // + template + void gmonth_day_pimpl:: + _pre () + { + str_.clear (); + } + + template + void gmonth_day_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + template + gmonth_day gmonth_day_pimpl:: + post_gmonth_day () + { + typedef typename ro_string::size_type size_type; + + ro_string tmp (str_); + size_type size (trim_right (tmp)); + const C* s (tmp.data ()); + + unsigned short month (0), day (0); + bool z (false); + short zh (0), zm (0); + + // gmonth_day := --MM-DD[Z|(+|-)HH:MM] + // + if (size >= 7) + { + month = 10 * (s[2] - '0') + (s[3] - '0'); + day = 10 * (s[5] - '0') + (s[6] - '0'); + + if (size > 7) + { + bits::parse_tz (s + 7, size - 7, zh, zm); + z = true; + } + } + + return z + ? gmonth_day (month, day, zh, zm) + : gmonth_day (month, day); + } + + // gyear_month + // + template + void gyear_month_pimpl:: + _pre () + { + str_.clear (); + } + + template + void gyear_month_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + template + gyear_month gyear_month_pimpl:: + post_gyear_month () + { + typedef typename ro_string::size_type size_type; + + ro_string tmp (str_); + size_type size (trim_right (tmp)); + const C* s (tmp.data ()); + + int year (0); + unsigned short month (0); + bool z (false); + short zh (0), zm (0); + + // gyear_month := [-]CCYY[N]*-MM[Z|(+|-)HH:MM] + // + + if (size >= 7) + { + // Find the end of the year token. + // + size_type pos (tmp.find (C ('-'), 4)); + + if (pos != ro_string::npos && (size - pos - 1) >= 2) + { + ro_string year_fragment (s, pos); + zc_istream yis (year_fragment); + yis >> year; + + month = 10 * (s[pos + 1] - '0') + (s[pos + 2] - '0'); + + pos += 3; + + if (pos < size) + { + bits::parse_tz (s + pos, size - pos, zh, zm); + z = true; + } + } + } + + return z + ? gyear_month (year, month, zh, zm) + : gyear_month (year, month); + } + + // date + // + template + void date_pimpl:: + _pre () + { + str_.clear (); + } + + template + void date_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + template + date date_pimpl:: + post_date () + { + typedef typename ro_string::size_type size_type; + + ro_string tmp (str_); + size_type size (trim_right (tmp)); + const C* s (tmp.data ()); + + int year (0); + unsigned short month (0), day (0); + bool z (false); + short zh (0), zm (0); + + // date := [-]CCYY[N]*-MM-DD[Z|(+|-)HH:MM] + // + + if (size >= 10) + { + // Find the end of the year token. + // + size_type pos (tmp.find (C ('-'), 4)); + + if (pos != ro_string::npos && (size - pos - 1) >= 5) + { + ro_string year_fragment (s, pos); + zc_istream yis (year_fragment); + yis >> year; + + month = 10 * (s[pos + 1] - '0') + (s[pos + 2] - '0'); + day = 10 * (s[pos + 4] - '0') + (s[pos + 5] - '0'); + + pos += 6; + + if (pos < size) + { + bits::parse_tz (s + pos, size - pos, zh, zm); + z = true; + } + } + } + + return z + ? date (year, month, day, zh, zm) + : date (year, month, day); + } + + // time + // + template + void time_pimpl:: + _pre () + { + str_.clear (); + } + + template + void time_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + template + time time_pimpl:: + post_time () + { + typedef typename ro_string::size_type size_type; + + ro_string tmp (str_); + size_type size (trim_right (tmp)); + const C* s (tmp.data ()); + + unsigned short hours (0), minutes (0); + double seconds (0.0); + bool z (false); + short zh (0), zm (0); + + // time := HH:MM:SS[.S+][Z|(+|-)HH:MM] + // + + if (size >= 8) + { + hours = 10 * (s[0] - '0') + (s[1] - '0'); + minutes = 10 * (s[3] - '0') + (s[4] - '0'); + + // Find the end of the seconds fragment. + // + size_type pos (8); + for (; pos < size; ++pos) + { + C c (s[pos]); + + if (c == C ('Z') || c == C ('+') || c == C ('-')) + break; + } + + ro_string seconds_fragment (s + 6, pos - 6); + zc_istream sis (seconds_fragment); + sis >> seconds; + + if (pos < size) + { + bits::parse_tz (s + pos, size - pos, zh, zm); + z = true; + } + } + + return z + ? time (hours, minutes, seconds, zh, zm) + : time (hours, minutes, seconds); + } + + + // date_time + // + template + void date_time_pimpl:: + _pre () + { + str_.clear (); + } + + template + void date_time_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + template + date_time date_time_pimpl:: + post_date_time () + { + typedef typename ro_string::size_type size_type; + + ro_string tmp (str_); + size_type size (trim_right (tmp)); + const C* s (tmp.data ()); + + int year (0); + unsigned short month (0), day (0), hours (0), minutes (0); + double seconds (0.0); + bool z (false); + short zh (0), zm (0); + + // date_time := [-]CCYY[N]*-MM-DDTHH:MM:SS[.S+][Z|(+|-)HH:MM] + // + + if (size >= 19) + { + // Find the end of the year token. + // + size_type pos (tmp.find (C ('-'), 4)); + + if (pos != ro_string::npos && (size - pos - 1) >= 14) + { + ro_string year_fragment (s, pos); + zc_istream yis (year_fragment); + yis >> year; + + month = 10 * (s[pos + 1] - '0') + (s[pos + 2] - '0'); + day = 10 * (s[pos + 4] - '0') + (s[pos + 5] - '0'); + + pos += 7; // Point to the first H. + + hours = 10 * (s[pos] - '0') + (s[pos + 1] - '0'); + minutes = 10 * (s[pos + 3] - '0') + (s[pos + 4] - '0'); + + // Find the end of the seconds fragment. + // + pos += 6; // Point to the first S. + + size_type sec_end (pos + 2); + for (; sec_end < size; ++sec_end) + { + C c (s[sec_end]); + + if (c == C ('Z') || c == C ('+') || c == C ('-')) + break; + } + + ro_string seconds_fragment (s + pos, sec_end - pos); + zc_istream sis (seconds_fragment); + sis >> seconds; + + if (sec_end < size) + { + bits::parse_tz (s + sec_end, size - sec_end, zh, zm); + z = true; + } + } + } + + return z + ? date_time (year, month, day, hours, minutes, seconds, zh, zm) + : date_time (year, month, day, hours, minutes, seconds); + } + + // duration + // + template + void duration_pimpl:: + _pre () + { + str_.clear (); + } + + template + void duration_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + namespace bits + { + template + inline typename ro_string::size_type + duration_delim (const C* s, + typename ro_string::size_type pos, + typename ro_string::size_type size) + { + const C* p (s + pos); + for (; p < (s + size); ++p) + { + if (*p == C ('Y') || *p == C ('D') || *p == C ('M') || + *p == C ('H') || *p == C ('M') || *p == C ('S') || + *p == C ('T')) + break; + } + + return p - s; + } + } + + template + duration duration_pimpl:: + post_duration () + { + typedef typename ro_string::size_type size_type; + + ro_string tmp (str_); + size_type size (trim_right (tmp)); + + bool negative (false); + unsigned int years (0), months (0), days (0), hours (0), minutes (0); + double seconds (0.0); + + // duration := [-]P[nY][nM][nD][TnHnMn[.n+]S] + // + const C* s (tmp.data ()); + + if (size >= 3) + { + size_type pos (0); + + if (s[0] == C ('-')) + { + negative = true; + pos++; + } + + pos++; // Skip 'P'. + + size_type del (bits::duration_delim (s, pos, size)); + + if (del != size && s[del] == C ('Y')) + { + ro_string fragment (s + pos, del - pos); + zc_istream is (fragment); + is >> years; + + pos = del + 1; + del = bits::duration_delim (s, pos, size); + } + + if (del != size && s[del] == C ('M')) + { + ro_string fragment (s + pos, del - pos); + zc_istream is (fragment); + is >> months; + + pos = del + 1; + del = bits::duration_delim (s, pos, size); + } + + if (del != size && s[del] == C ('D')) + { + ro_string fragment (s + pos, del - pos); + zc_istream is (fragment); + is >> days; + + pos = del + 1; + del = bits::duration_delim (s, pos, size); + } + + if (del != size && s[del] == C ('T')) + { + pos = del + 1; + del = bits::duration_delim (s, pos, size); + + if (del != size && s[del] == C ('H')) + { + ro_string fragment (s + pos, del - pos); + zc_istream is (fragment); + is >> hours; + + pos = del + 1; + del = bits::duration_delim (s, pos, size); + } + + if (del != size && s[del] == C ('M')) + { + ro_string fragment (s + pos, del - pos); + zc_istream is (fragment); + is >> minutes; + + pos = del + 1; + del = bits::duration_delim (s, pos, size); + } + + if (del != size && s[del] == C ('S')) + { + ro_string fragment (s + pos, del - pos); + zc_istream is (fragment); + is >> seconds; + } + } + } + + return duration ( + negative, years, months, days, hours, minutes, seconds); + } + } + } + } +} diff --git a/libxsd/xsd/cxx/parser/non-validating/xml-schema-pskel.hxx b/libxsd/xsd/cxx/parser/non-validating/xml-schema-pskel.hxx new file mode 100644 index 0000000..7b90b91 --- /dev/null +++ b/libxsd/xsd/cxx/parser/non-validating/xml-schema-pskel.hxx @@ -0,0 +1,647 @@ +// file : xsd/cxx/parser/non-validating/xml-schema-pskel.hxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_PARSER_NON_VALIDATING_XML_SCHEMA_PSKEL_HXX +#define XSD_CXX_PARSER_NON_VALIDATING_XML_SCHEMA_PSKEL_HXX + +#include +#include // auto_ptr + +#include +#include + +namespace xsd +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + // anyType and anySimpleType. All events are routed to the + // _any_* callbacks. + // + template + struct any_type_pskel: complex_content + { + virtual bool + _start_element_impl (const ro_string&, + const ro_string&, + const ro_string*); + + virtual bool + _end_element_impl (const ro_string&, + const ro_string&); + + virtual bool + _attribute_impl (const ro_string&, + const ro_string&, + const ro_string&); + + virtual bool + _characters_impl (const ro_string&); + + virtual void + post_any_type () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct any_simple_type_pskel: simple_content + { + virtual bool + _characters_impl (const ro_string&); + + virtual void + post_any_simple_type () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + + // Boolean. + // + template + struct boolean_pskel: simple_content + { + virtual bool + post_boolean () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + + // 8-bit + // + template + struct byte_pskel: simple_content + { + virtual signed char + post_byte () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct unsigned_byte_pskel: simple_content + { + virtual unsigned char + post_unsigned_byte () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + + // 16-bit + // + template + struct short_pskel: simple_content + { + virtual short + post_short () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct unsigned_short_pskel: simple_content + { + virtual unsigned short + post_unsigned_short () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + + // 32-bit + // + template + struct int_pskel: simple_content + { + virtual int + post_int () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct unsigned_int_pskel: simple_content + { + virtual unsigned int + post_unsigned_int () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + + // 64-bit + // + template + struct long_pskel: simple_content + { + virtual long long + post_long () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct unsigned_long_pskel: simple_content + { + virtual unsigned long long + post_unsigned_long () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + + // Arbitrary-length integers. + // + template + struct integer_pskel: simple_content + { + virtual long long + post_integer () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct negative_integer_pskel: simple_content + { + virtual long long + post_negative_integer () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct non_positive_integer_pskel: simple_content + { + virtual long long + post_non_positive_integer () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct positive_integer_pskel: simple_content + { + virtual unsigned long long + post_positive_integer () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct non_negative_integer_pskel: simple_content + { + virtual unsigned long long + post_non_negative_integer () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + + // Floats. + // + template + struct float_pskel: simple_content + { + virtual float + post_float () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct double_pskel: simple_content + { + virtual double + post_double () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct decimal_pskel: simple_content + { + virtual double + post_decimal () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + + // Strings. + // + template + struct string_pskel: simple_content + { + virtual std::basic_string + post_string () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct normalized_string_pskel: simple_content + { + virtual std::basic_string + post_normalized_string () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct token_pskel: simple_content + { + virtual std::basic_string + post_token () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct name_pskel: simple_content + { + virtual std::basic_string + post_name () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct nmtoken_pskel: simple_content + { + virtual std::basic_string + post_nmtoken () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct nmtokens_pskel: list_base + { + virtual string_sequence + post_nmtokens () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct ncname_pskel: simple_content + { + virtual std::basic_string + post_ncname () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct id_pskel: simple_content + { + virtual std::basic_string + post_id () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct idref_pskel: simple_content + { + virtual std::basic_string + post_idref () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct idrefs_pskel: list_base + { + virtual string_sequence + post_idrefs () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + // Language. + // + template + struct language_pskel: simple_content + { + virtual std::basic_string + post_language () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + // URI. + // + template + struct uri_pskel: simple_content + { + virtual std::basic_string + post_uri () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + // QName. + // + template + struct qname_pskel: simple_content + { + virtual qname + post_qname () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + // Base64 and hex binaries. + // + template + struct base64_binary_pskel: simple_content + { + virtual std::auto_ptr + post_base64_binary () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct hex_binary_pskel: simple_content + { + virtual std::auto_ptr + post_hex_binary () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + // Time and date types. + // + template + struct gday_pskel: simple_content + { + virtual gday + post_gday () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct gmonth_pskel: simple_content + { + virtual gmonth + post_gmonth () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct gyear_pskel: simple_content + { + virtual gyear + post_gyear () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct gmonth_day_pskel: simple_content + { + virtual gmonth_day + post_gmonth_day () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct gyear_month_pskel: simple_content + { + virtual gyear_month + post_gyear_month () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct date_pskel: simple_content + { + virtual date + post_date () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct time_pskel: simple_content + { + virtual time + post_time () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct date_time_pskel: simple_content + { + virtual date_time + post_date_time () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct duration_pskel: simple_content + { + virtual duration + post_duration () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + } + } + } +} + +#include + +#endif // XSD_CXX_PARSER_NON_VALIDATING_XML_SCHEMA_PSKEL_HXX + +#include diff --git a/libxsd/xsd/cxx/parser/non-validating/xml-schema-pskel.ixx b/libxsd/xsd/cxx/parser/non-validating/xml-schema-pskel.ixx new file mode 100644 index 0000000..3a42c9d --- /dev/null +++ b/libxsd/xsd/cxx/parser/non-validating/xml-schema-pskel.ixx @@ -0,0 +1,1249 @@ +// file : xsd/cxx/parser/non-validating/xml-schema-pskel.ixx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#if defined(XSD_CXX_PARSER_USE_CHAR) || !defined(XSD_CXX_PARSER_USE_WCHAR) + +#ifndef XSD_CXX_PARSER_NON_VALIDATING_XML_SCHEMA_PSKEL_IXX_CHAR +#define XSD_CXX_PARSER_NON_VALIDATING_XML_SCHEMA_PSKEL_IXX_CHAR + +namespace xsd +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + template<> + inline const char* any_type_pskel:: + _static_type () + { + return "anyType http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* any_type_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* any_simple_type_pskel:: + _static_type () + { + return "anySimpleType http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* any_simple_type_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* boolean_pskel:: + _static_type () + { + return "boolean http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* boolean_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* byte_pskel:: + _static_type () + { + return "byte http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* byte_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* unsigned_byte_pskel:: + _static_type () + { + return "unsignedByte http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* unsigned_byte_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* short_pskel:: + _static_type () + { + return "short http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* short_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* unsigned_short_pskel:: + _static_type () + { + return "unsignedShort http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* unsigned_short_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* int_pskel:: + _static_type () + { + return "int http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* int_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* unsigned_int_pskel:: + _static_type () + { + return "unsignedInt http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* unsigned_int_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* long_pskel:: + _static_type () + { + return "long http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* long_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* unsigned_long_pskel:: + _static_type () + { + return "unsignedLong http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* unsigned_long_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* integer_pskel:: + _static_type () + { + return "integer http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* integer_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* negative_integer_pskel:: + _static_type () + { + return "negativeInteger http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* negative_integer_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* non_positive_integer_pskel:: + _static_type () + { + return "nonPositiveInteger http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* non_positive_integer_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* positive_integer_pskel:: + _static_type () + { + return "positiveInteger http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* positive_integer_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* non_negative_integer_pskel:: + _static_type () + { + return "nonNegativeInteger http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* non_negative_integer_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* float_pskel:: + _static_type () + { + return "float http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* float_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* double_pskel:: + _static_type () + { + return "double http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* double_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* decimal_pskel:: + _static_type () + { + return "decimal http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* decimal_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* string_pskel:: + _static_type () + { + return "string http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* string_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* normalized_string_pskel:: + _static_type () + { + return "normalizedString http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* normalized_string_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* token_pskel:: + _static_type () + { + return "token http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* token_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* name_pskel:: + _static_type () + { + return "Name http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* name_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* nmtoken_pskel:: + _static_type () + { + return "NMTOKEN http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* nmtoken_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* nmtokens_pskel:: + _static_type () + { + return "NMTOKENS http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* nmtokens_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* ncname_pskel:: + _static_type () + { + return "NCName http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* ncname_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* id_pskel:: + _static_type () + { + return "ID http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* id_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* idref_pskel:: + _static_type () + { + return "IDREF http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* idref_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* idrefs_pskel:: + _static_type () + { + return "IDREFS http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* idrefs_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* language_pskel:: + _static_type () + { + return "language http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* language_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* uri_pskel:: + _static_type () + { + return "anyURI http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* uri_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* qname_pskel:: + _static_type () + { + return "QName http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* qname_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* base64_binary_pskel:: + _static_type () + { + return "base64Binary http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* base64_binary_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* hex_binary_pskel:: + _static_type () + { + return "hexBinary http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* hex_binary_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* gday_pskel:: + _static_type () + { + return "gDay http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* gday_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* gmonth_pskel:: + _static_type () + { + return "gMonth http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* gmonth_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* gyear_pskel:: + _static_type () + { + return "gYear http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* gyear_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* gmonth_day_pskel:: + _static_type () + { + return "gMonthDay http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* gmonth_day_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* gyear_month_pskel:: + _static_type () + { + return "gYearMonth http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* gyear_month_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* date_pskel:: + _static_type () + { + return "date http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* date_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* time_pskel:: + _static_type () + { + return "time http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* time_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* date_time_pskel:: + _static_type () + { + return "dateTime http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* date_time_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* duration_pskel:: + _static_type () + { + return "duration http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* duration_pskel:: + _dynamic_type () const + { + return _static_type (); + } + } + } + } +} + +#endif // XSD_CXX_PARSER_NON_VALIDATING_XML_SCHEMA_PSKEL_IXX_CHAR +#endif // XSD_CXX_PARSER_USE_CHAR + + +#if defined(XSD_CXX_PARSER_USE_WCHAR) || !defined(XSD_CXX_PARSER_USE_CHAR) + +#ifndef XSD_CXX_PARSER_NON_VALIDATING_XML_SCHEMA_PSKEL_IXX_WCHAR +#define XSD_CXX_PARSER_NON_VALIDATING_XML_SCHEMA_PSKEL_IXX_WCHAR + +namespace xsd +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + template<> + inline const wchar_t* any_type_pskel:: + _static_type () + { + return L"anyType http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* any_type_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* any_simple_type_pskel:: + _static_type () + { + return L"anySimpleType http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* any_simple_type_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* boolean_pskel:: + _static_type () + { + return L"boolean http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* boolean_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* byte_pskel:: + _static_type () + { + return L"byte http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* byte_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* unsigned_byte_pskel:: + _static_type () + { + return L"unsignedByte http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* unsigned_byte_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* short_pskel:: + _static_type () + { + return L"short http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* short_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* unsigned_short_pskel:: + _static_type () + { + return L"unsignedShort http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* unsigned_short_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* int_pskel:: + _static_type () + { + return L"int http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* int_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* unsigned_int_pskel:: + _static_type () + { + return L"unsignedInt http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* unsigned_int_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* long_pskel:: + _static_type () + { + return L"long http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* long_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* unsigned_long_pskel:: + _static_type () + { + return L"unsignedLong http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* unsigned_long_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* integer_pskel:: + _static_type () + { + return L"integer http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* integer_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* negative_integer_pskel:: + _static_type () + { + return L"negativeInteger http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* negative_integer_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* non_positive_integer_pskel:: + _static_type () + { + return L"nonPositiveInteger http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* non_positive_integer_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* positive_integer_pskel:: + _static_type () + { + return L"positiveInteger http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* positive_integer_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* non_negative_integer_pskel:: + _static_type () + { + return L"nonNegativeInteger http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* non_negative_integer_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* float_pskel:: + _static_type () + { + return L"float http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* float_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* double_pskel:: + _static_type () + { + return L"double http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* double_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* decimal_pskel:: + _static_type () + { + return L"decimal http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* decimal_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* string_pskel:: + _static_type () + { + return L"string http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* string_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* normalized_string_pskel:: + _static_type () + { + return L"normalizedString http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* normalized_string_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* token_pskel:: + _static_type () + { + return L"token http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* token_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* name_pskel:: + _static_type () + { + return L"Name http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* name_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* nmtoken_pskel:: + _static_type () + { + return L"NMTOKEN http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* nmtoken_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* nmtokens_pskel:: + _static_type () + { + return L"NMTOKENS http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* nmtokens_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* ncname_pskel:: + _static_type () + { + return L"NCName http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* ncname_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* id_pskel:: + _static_type () + { + return L"ID http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* id_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* idref_pskel:: + _static_type () + { + return L"IDREF http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* idref_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* idrefs_pskel:: + _static_type () + { + return L"IDREFS http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* idrefs_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* language_pskel:: + _static_type () + { + return L"language http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* language_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* uri_pskel:: + _static_type () + { + return L"anyURI http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* uri_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* qname_pskel:: + _static_type () + { + return L"QName http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* qname_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* base64_binary_pskel:: + _static_type () + { + return L"base64Binary http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* base64_binary_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* hex_binary_pskel:: + _static_type () + { + return L"hexBinary http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* hex_binary_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* gday_pskel:: + _static_type () + { + return L"gDay http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* gday_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* gmonth_pskel:: + _static_type () + { + return L"gMonth http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* gmonth_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* gyear_pskel:: + _static_type () + { + return L"gYear http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* gyear_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* gmonth_day_pskel:: + _static_type () + { + return L"gMonthDay http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* gmonth_day_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* gyear_month_pskel:: + _static_type () + { + return L"gYearMonth http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* gyear_month_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* date_pskel:: + _static_type () + { + return L"date http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* date_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* time_pskel:: + _static_type () + { + return L"time http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* time_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* date_time_pskel:: + _static_type () + { + return L"dateTime http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* date_time_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* duration_pskel:: + _static_type () + { + return L"duration http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* duration_pskel:: + _dynamic_type () const + { + return _static_type (); + } + } + } + } +} + +#endif // XSD_CXX_PARSER_NON_VALIDATING_XML_SCHEMA_PSKEL_IXX_WCHAR +#endif // XSD_CXX_PARSER_USE_WCHAR diff --git a/libxsd/xsd/cxx/parser/non-validating/xml-schema-pskel.txx b/libxsd/xsd/cxx/parser/non-validating/xml-schema-pskel.txx new file mode 100644 index 0000000..899eae6 --- /dev/null +++ b/libxsd/xsd/cxx/parser/non-validating/xml-schema-pskel.txx @@ -0,0 +1,69 @@ +// file : xsd/cxx/parser/non-validating/xml-schema-pskel.txx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsd +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + // any_type + // + + template + bool any_type_pskel:: + _start_element_impl (const ro_string& ns, + const ro_string& name, + const ro_string* type) + { + _start_any_element (ns, name, type); + this->complex_content::context_.top ().any_ = true; + return true; + } + + template + bool any_type_pskel:: + _end_element_impl (const ro_string& ns, const ro_string& name) + { + this->complex_content::context_.top ().any_ = false; + _end_any_element (ns, name); + return true; + } + + + template + bool any_type_pskel:: + _attribute_impl (const ro_string& ns, + const ro_string& name, + const ro_string& value) + { + _any_attribute (ns, name, value); + return true; + } + + template + bool any_type_pskel:: + _characters_impl (const ro_string& s) + { + _any_characters (s); + return true; + } + + // any_simple_type + // + + template + bool any_simple_type_pskel:: + _characters_impl (const ro_string& s) + { + _any_characters (s); + return true; + } + } + } + } +} diff --git a/libxsd/xsd/cxx/parser/schema-exceptions.hxx b/libxsd/xsd/cxx/parser/schema-exceptions.hxx new file mode 100644 index 0000000..f1fb358 --- /dev/null +++ b/libxsd/xsd/cxx/parser/schema-exceptions.hxx @@ -0,0 +1,187 @@ +// file : xsd/cxx/parser/schema-exceptions.hxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_PARSER_SCHEMA_EXCEPTIONS_HXX +#define XSD_CXX_PARSER_SCHEMA_EXCEPTIONS_HXX + +#include + +namespace xsd +{ + namespace cxx + { + namespace parser + { + template + struct schema_exception + { + public: + virtual + ~schema_exception () + { + } + + unsigned long + line () const + { + return line_; + } + + void + line (unsigned long l) + { + line_ = l; + } + + unsigned long + column () const + { + return column_; + } + + void + column (unsigned long c) + { + column_ = c; + } + + const std::basic_string& + id () const + { + return id_; + } + + void + id (const std::basic_string& id) + { + id_ = id; + } + + virtual std::basic_string + message () const = 0; + + protected: + unsigned long line_; + unsigned long column_; + std::basic_string id_; + }; + + // + // + template + struct expected_element: schema_exception + { + virtual + ~expected_element (); + + expected_element (const std::basic_string& expected_namespace, + const std::basic_string& expected_name); + + expected_element (const std::basic_string& expected_namespace, + const std::basic_string& expected_name, + const std::basic_string& encountered_namespace, + const std::basic_string& encountered_name); + + const std::basic_string& + expected_namespace () const + { + return expected_namespace_; + } + + const std::basic_string& + expected_name () const + { + return expected_name_; + } + + // Encountered element namespace and name are empty if none + // encountered. + // + const std::basic_string& + encountered_namespace () const + { + return encountered_namespace_; + } + + const std::basic_string& + encountered_name () const + { + return encountered_name_; + } + + virtual std::basic_string + message () const; + + private: + std::basic_string expected_namespace_; + std::basic_string expected_name_; + + std::basic_string encountered_namespace_; + std::basic_string encountered_name_; + }; + + + // + // + template + struct unexpected_element: schema_exception + { + virtual + ~unexpected_element (); + + unexpected_element (const std::basic_string& encountered_namespace, + const std::basic_string& encountered_name); + + const std::basic_string& + encountered_namespace () const + { + return encountered_namespace_; + } + + const std::basic_string& + encountered_name () const + { + return encountered_name_; + } + + virtual std::basic_string + message () const; + + private: + std::basic_string encountered_namespace_; + std::basic_string encountered_name_; + }; + + // + // + template + struct dynamic_type: schema_exception + { + virtual + ~dynamic_type () throw (); + + dynamic_type (const std::basic_string& type); + + const std::basic_string& + type () const + { + return type_; + } + + virtual std::basic_string + message () const; + + private: + std::basic_string type_; + }; + } + } +} + +#include + +#endif // XSD_CXX_PARSER_SCHEMA_EXCEPTIONS_HXX + +#include diff --git a/libxsd/xsd/cxx/parser/schema-exceptions.ixx b/libxsd/xsd/cxx/parser/schema-exceptions.ixx new file mode 100644 index 0000000..98cc2db --- /dev/null +++ b/libxsd/xsd/cxx/parser/schema-exceptions.ixx @@ -0,0 +1,145 @@ +// file : xsd/cxx/parser/schema-exceptions.ixx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#if defined(XSD_CXX_PARSER_USE_CHAR) || !defined(XSD_CXX_PARSER_USE_WCHAR) + +#ifndef XSD_CXX_PARSER_SCHEMA_EXCEPTIONS_IXX_CHAR +#define XSD_CXX_PARSER_SCHEMA_EXCEPTIONS_IXX_CHAR + +namespace xsd +{ + namespace cxx + { + namespace parser + { + // expected_element + // + template<> + inline + std::basic_string expected_element:: + message () const + { + std::basic_string r ("expected element '"); + r += expected_namespace_; + r += expected_namespace_.empty () ? "" : "#"; + r += expected_name_; + r += "'"; + + if (!encountered_name_.empty ()) + { + r += " instead of '"; + r += encountered_namespace_; + r += encountered_namespace_.empty () ? "" : "#"; + r += encountered_name_; + r += "'"; + } + + return r; + } + + // unexpected_element + // + template<> + inline + std::basic_string unexpected_element:: + message () const + { + std::basic_string r ("unexpected element '"); + r += encountered_namespace_; + r += encountered_namespace_.empty () ? "" : "#"; + r += encountered_name_; + r += "'"; + return r; + } + + // dynamic_type + // + template<> + inline + std::basic_string dynamic_type:: + message () const + { + std::basic_string r ("invalid xsi:type '"); + r += type_; + r += "'"; + return r; + } + } + } +} + +#endif // XSD_CXX_PARSER_SCHEMA_EXCEPTIONS_IXX_CHAR +#endif // XSD_CXX_PARSER_USE_CHAR + + +#if defined(XSD_CXX_PARSER_USE_WCHAR) || !defined(XSD_CXX_PARSER_USE_CHAR) + +#ifndef XSD_CXX_PARSER_SCHEMA_EXCEPTIONS_IXX_WCHAR +#define XSD_CXX_PARSER_SCHEMA_EXCEPTIONS_IXX_WCHAR + +namespace xsd +{ + namespace cxx + { + namespace parser + { + // expected_element + // + template<> + inline + std::basic_string expected_element:: + message () const + { + std::basic_string r (L"expected element '"); + r += expected_namespace_; + r += expected_namespace_.empty () ? L"" : L"#"; + r += expected_name_; + r += L"'"; + + if (!encountered_name_.empty ()) + { + r += L" instead of '"; + r += encountered_namespace_; + r += encountered_namespace_.empty () ? L"" : L"#"; + r += encountered_name_; + r += L"'"; + } + + return r; + } + + // unexpected_element + // + template<> + inline + std::basic_string unexpected_element:: + message () const + { + std::basic_string r (L"unexpected element '"); + r += encountered_namespace_; + r += encountered_namespace_.empty () ? L"" : L"#"; + r += encountered_name_; + r += L"'"; + return r; + } + + // dynamic_type + // + template<> + inline + std::basic_string dynamic_type:: + message () const + { + std::basic_string r (L"invalid xsi:type '"); + r += type_; + r += L"'"; + return r; + } + } + } +} + +#endif // XSD_CXX_PARSER_SCHEMA_EXCEPTIONS_IXX_WCHAR +#endif // XSD_CXX_PARSER_USE_WCHAR diff --git a/libxsd/xsd/cxx/parser/schema-exceptions.txx b/libxsd/xsd/cxx/parser/schema-exceptions.txx new file mode 100644 index 0000000..0d19604 --- /dev/null +++ b/libxsd/xsd/cxx/parser/schema-exceptions.txx @@ -0,0 +1,75 @@ +// file : xsd/cxx/parser/schema-exceptions.txx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsd +{ + namespace cxx + { + namespace parser + { + // expected_element + // + template + expected_element:: + ~expected_element () + { + } + + template + expected_element:: + expected_element (const std::basic_string& expected_namespace, + const std::basic_string& expected_name) + : expected_namespace_ (expected_namespace), + expected_name_ (expected_name) + { + } + + template + expected_element:: + expected_element (const std::basic_string& expected_namespace, + const std::basic_string& expected_name, + const std::basic_string& encountered_namespace, + const std::basic_string& encountered_name) + : expected_namespace_ (expected_namespace), + expected_name_ (expected_name), + encountered_namespace_ (encountered_namespace), + encountered_name_ (encountered_name) + { + } + + // unexpected_element + // + template + unexpected_element:: + ~unexpected_element () + { + } + + template + unexpected_element:: + unexpected_element (const std::basic_string& encountered_namespace, + const std::basic_string& encountered_name) + : encountered_namespace_ (encountered_namespace), + encountered_name_ (encountered_name) + { + } + + // dynamic_type + // + template + dynamic_type:: + ~dynamic_type () throw () + { + } + + template + dynamic_type:: + dynamic_type (const std::basic_string& type) + : type_ (type) + { + } + } + } +} diff --git a/libxsd/xsd/cxx/parser/substitution-map.hxx b/libxsd/xsd/cxx/parser/substitution-map.hxx new file mode 100644 index 0000000..60c0ec8 --- /dev/null +++ b/libxsd/xsd/cxx/parser/substitution-map.hxx @@ -0,0 +1,230 @@ +// file : xsd/cxx/parser/substitution-map.hxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_PARSER_SUBSTITUTION_MAP_HXX +#define XSD_CXX_PARSER_SUBSTITUTION_MAP_HXX + +#include +#include // std::size_t + +#include + +namespace xsd +{ + namespace cxx + { + namespace parser + { + template + struct substitution_map_key + { + substitution_map_key (const C* ns, const C* name) + : ns_ (ns), name_ (name) + { + } + + substitution_map_key (const ro_string& ns, + const ro_string& name) + : ns_ (ns.data (), ns.size ()), + name_ (name.data (), name.size ()) + { + } + + substitution_map_key (const substitution_map_key& x) + : ns_ (x.ns_.data (), x.ns_.size ()), + name_ (x.name_.data (), x.name_.size ()) + { + } + + private: + substitution_map_key& + operator= (const substitution_map_key&); + + public: + const ro_string& + ns () const + { + return ns_; + } + + const ro_string& + name () const + { + return name_; + } + + private: + const ro_string ns_; + const ro_string name_; + }; + + template + inline bool + operator< (const substitution_map_key& x, + const substitution_map_key& y) + { + int r (x.name ().compare (y.name ())); + return r < 0 || (r == 0 && x.ns () < y.ns ()); + } + + template + struct substitution_map_value + { + substitution_map_value (const C* ns, const C* name, const C* type) + : ns_ (ns), name_ (name), type_ (type) + { + } + + substitution_map_value (const substitution_map_value& x) + : ns_ (x.ns_.data (), x.ns_.size ()), + name_ (x.name_.data (), x.name_.size ()), + type_ (x.type_.data (), x.type_.size ()) + { + } + + substitution_map_value& + operator= (const substitution_map_value& x) + { + if (this != &x) + { + ns_.assign (x.ns_.data (), x.ns_.size ()); + name_.assign (x.name_.data (), x.name_.size ()); + type_.assign (x.type_.data (), x.type_.size ()); + } + + return *this; + } + + public: + const ro_string& + ns () const + { + return ns_; + } + + const ro_string& + name () const + { + return name_; + } + + const ro_string& + type () const + { + return type_; + } + + private: + ro_string ns_; + ro_string name_; + ro_string type_; + }; + + template + struct substitution_map + { + void + insert (const C* member_ns, + const C* member_name, + const C* root_ns, + const C* root_name, + const C* member_type) + { + key k (member_ns, member_name); + value v (root_ns, root_name, member_type); + map_.insert (std::pair (k, v)); + } + + // Check and get the type set if found. + // + bool + check (const ro_string& ns, + const ro_string& name, + const C* root_ns, + const C* root_name, + const ro_string*& type) const + { + + return map_.empty () + ? false + : check_ (ns, name, root_ns, root_name, &type); + } + + // Check but don't care about the type. + // + bool + check (const ro_string& ns, + const ro_string& name, + const C* root_ns, + const C* root_name) const + { + + return map_.empty () + ? false + : check_ (ns, name, root_ns, root_name, 0); + } + + private: + bool + check_ (const ro_string& ns, + const ro_string& name, + const C* root_ns, + const C* root_name, + const ro_string** type) const; + + private: + typedef substitution_map_key key; + typedef substitution_map_value value; + typedef std::map map; + + map map_; + }; + + + // Translation unit initializer. + // + template + struct substitution_map_init + { + static substitution_map* map; + static std::size_t count; + + substitution_map_init (); + ~substitution_map_init (); + }; + + template + substitution_map* substitution_map_init::map = 0; + + template + std::size_t substitution_map_init::count = 0; + + template + inline substitution_map& + substitution_map_instance () + { + return *substitution_map_init::map; + } + + + // Map entry initializer. + // + template + struct substitution_map_entry + { + substitution_map_entry (const C* member_ns, + const C* member_name, + const C* root_ns, + const C* root_name, + const C* member_type); + }; + } + } +} + +#include + +#endif // XSD_CXX_PARSER_SUBSTITUTION_MAP_HXX + diff --git a/libxsd/xsd/cxx/parser/substitution-map.txx b/libxsd/xsd/cxx/parser/substitution-map.txx new file mode 100644 index 0000000..c9d4cb1 --- /dev/null +++ b/libxsd/xsd/cxx/parser/substitution-map.txx @@ -0,0 +1,76 @@ +// file : xsd/cxx/parser/substitution-map.txx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsd +{ + namespace cxx + { + namespace parser + { + template + bool substitution_map:: + check_ (const ro_string& ns, + const ro_string& name, + const C* root_ns, + const C* root_name, + const ro_string** type) const + { + key k (ns, name); + typename map::const_iterator i (map_.find (k)); + + if (i == map_.end ()) + return false; + + const value& v (i->second); + + bool r (false); + + if (v.name () == root_name && v.ns () == root_ns) + r = true; + else + r = check_ (v.ns (), v.name (), root_ns, root_name, 0); + + if (r && type != 0 && *type == 0) + *type = &v.type (); + + return r; + } + + // substitution_map_init + // + template + substitution_map_init:: + substitution_map_init () + { + if (count == 0) + map = new substitution_map; + + ++count; + } + + template + substitution_map_init:: + ~substitution_map_init () + { + if (--count == 0) + delete map; + } + + // substitution_map_entry + // + template + substitution_map_entry:: + substitution_map_entry (const C* member_ns, + const C* member_name, + const C* root_ns, + const C* root_name, + const C* member_type) + { + substitution_map_instance ().insert ( + member_ns, member_name, root_ns, root_name, member_type); + } + } + } +} diff --git a/libxsd/xsd/cxx/parser/validating/exceptions.hxx b/libxsd/xsd/cxx/parser/validating/exceptions.hxx new file mode 100644 index 0000000..1112c60 --- /dev/null +++ b/libxsd/xsd/cxx/parser/validating/exceptions.hxx @@ -0,0 +1,153 @@ +// file : xsd/cxx/parser/validating/exceptions.hxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_PARSER_VALIDATING_EXCEPTIONS_HXX +#define XSD_CXX_PARSER_VALIDATING_EXCEPTIONS_HXX + +#include + +#include +#include + +namespace xsd +{ + namespace cxx + { + namespace parser + { + namespace validating + { + // + // + template + struct expected_attribute: schema_exception + { + virtual + ~expected_attribute (); + + expected_attribute (const std::basic_string& expected_namespace, + const std::basic_string& expected_name); + + const std::basic_string& + expected_namespace () const + { + return expected_namespace_; + } + + const std::basic_string& + expected_name () const + { + return expected_name_; + } + + virtual std::basic_string + message () const; + + private: + std::basic_string expected_namespace_; + std::basic_string expected_name_; + }; + + // + // + template + struct unexpected_attribute: schema_exception + { + virtual + ~unexpected_attribute (); + + unexpected_attribute ( + const std::basic_string& encountered_namespace, + const std::basic_string& encountered_name); + + + const std::basic_string& + encountered_namespace () const + { + return encountered_namespace_; + } + + const std::basic_string& + encountered_name () const + { + return encountered_name_; + } + + virtual std::basic_string + message () const; + + private: + std::basic_string encountered_namespace_; + std::basic_string encountered_name_; + }; + + + // + // + template + struct unexpected_characters: schema_exception + { + virtual + ~unexpected_characters (); + + unexpected_characters (const std::basic_string& s); + + const std::basic_string& + characters () const + { + return characters_; + } + + virtual std::basic_string + message () const; + + private: + std::basic_string characters_; + }; + + // + // + template + struct invalid_value: schema_exception + { + virtual + ~invalid_value (); + + invalid_value (const C* type, const std::basic_string& value); + + invalid_value (const C* type, const ro_string& value); + + invalid_value (const std::basic_string& type, + const std::basic_string& value); + + const std::basic_string& + type () const + { + return type_; + } + + const std::basic_string& + value () const + { + return value_; + } + + virtual std::basic_string + message () const; + + private: + std::basic_string type_; + std::basic_string value_; + }; + } + } + } +} + +#include + +#endif // XSD_CXX_PARSER_VALIDATING_EXCEPTIONS_HXX + +#include diff --git a/libxsd/xsd/cxx/parser/validating/exceptions.ixx b/libxsd/xsd/cxx/parser/validating/exceptions.ixx new file mode 100644 index 0000000..6535cb8 --- /dev/null +++ b/libxsd/xsd/cxx/parser/validating/exceptions.ixx @@ -0,0 +1,163 @@ +// file : xsd/cxx/parser/validating/exceptions.ixx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#if defined(XSD_CXX_PARSER_USE_CHAR) || !defined(XSD_CXX_PARSER_USE_WCHAR) + +#ifndef XSD_CXX_PARSER_VALIDATING_EXCEPTIONS_IXX_CHAR +#define XSD_CXX_PARSER_VALIDATING_EXCEPTIONS_IXX_CHAR + +namespace xsd +{ + namespace cxx + { + namespace parser + { + namespace validating + { + // expected_attribute + // + template<> + inline + std::basic_string expected_attribute:: + message () const + { + std::basic_string r ("expected attribute '"); + r += expected_namespace_; + r += expected_namespace_.empty () ? "" : "#"; + r += expected_name_; + r += "'"; + return r; + } + + // unexpected_attribute + // + template<> + inline + std::basic_string unexpected_attribute:: + message () const + { + std::basic_string r ("unexpected attribute '"); + r += encountered_namespace_; + r += encountered_namespace_.empty () ? "" : "#"; + r += encountered_name_; + r += "'"; + return r; + } + + // unexpected_characters + // + template<> + inline + std::basic_string unexpected_characters:: + message () const + { + std::basic_string r ("unexpected characters '"); + r += characters_; + r += "'"; + return r; + } + + // invalid_value + // + template<> + inline + std::basic_string invalid_value:: + message () const + { + std::basic_string r ("'"); + r += value_; + r += "' is not a valid value representation "; + r += "for type '"; + r += type_; + r += "'"; + return r; + } + } + } + } +} + +#endif // XSD_CXX_PARSER_VALIDATING_EXCEPTIONS_IXX_CHAR +#endif // XSD_CXX_PARSER_USE_CHAR + + +#if defined(XSD_CXX_PARSER_USE_WCHAR) || !defined(XSD_CXX_PARSER_USE_CHAR) + +#ifndef XSD_CXX_PARSER_VALIDATING_EXCEPTIONS_IXX_WCHAR +#define XSD_CXX_PARSER_VALIDATING_EXCEPTIONS_IXX_WCHAR + +namespace xsd +{ + namespace cxx + { + namespace parser + { + namespace validating + { + // expected_attribute + // + template<> + inline + std::basic_string expected_attribute:: + message () const + { + std::basic_string r (L"expected attribute '"); + r += expected_namespace_; + r += expected_namespace_.empty () ? L"" : L"#"; + r += expected_name_; + r += L"'"; + return r; + } + + // unexpected_attribute + // + template<> + inline + std::basic_string unexpected_attribute:: + message () const + { + std::basic_string r (L"unexpected attribute '"); + r += encountered_namespace_; + r += encountered_namespace_.empty () ? L"" : L"#"; + r += encountered_name_; + r += L"'"; + return r; + } + + // unexpected_characters + // + template<> + inline + std::basic_string unexpected_characters:: + message () const + { + std::basic_string r (L"unexpected characters '"); + r += characters_; + r += L"'"; + return r; + } + + // invalid_value + // + template<> + inline + std::basic_string invalid_value:: + message () const + { + std::basic_string r (L"'"); + r += value_; + r += L"' is not a valid value representation "; + r += L"for type '"; + r += type_; + r += L"'"; + return r; + } + } + } + } +} + +#endif // XSD_CXX_PARSER_VALIDATING_EXCEPTIONS_IXX_WCHAR +#endif // XSD_CXX_PARSER_USE_WCHAR diff --git a/libxsd/xsd/cxx/parser/validating/exceptions.txx b/libxsd/xsd/cxx/parser/validating/exceptions.txx new file mode 100644 index 0000000..f8ffe80 --- /dev/null +++ b/libxsd/xsd/cxx/parser/validating/exceptions.txx @@ -0,0 +1,97 @@ +// file : xsd/cxx/parser/validating/exceptions.txx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsd +{ + namespace cxx + { + namespace parser + { + namespace validating + { + // expected_attribute + // + template + expected_attribute:: + ~expected_attribute () + { + } + + template + expected_attribute:: + expected_attribute (const std::basic_string& expected_namespace, + const std::basic_string& expected_name) + : expected_namespace_ (expected_namespace), + expected_name_ (expected_name) + { + } + + // unexpected_attribute + // + template + unexpected_attribute:: + ~unexpected_attribute () + { + } + + template + unexpected_attribute:: + unexpected_attribute (const std::basic_string& encountered_namespace, + const std::basic_string& encountered_name) + : encountered_namespace_ (encountered_namespace), + encountered_name_ (encountered_name) + { + } + + // unexpected_characters + // + template + unexpected_characters:: + ~unexpected_characters () + { + } + + template + unexpected_characters:: + unexpected_characters (const std::basic_string& s) + : characters_ (s) + { + } + + // invalid_value + // + template + invalid_value:: + ~invalid_value () + { + } + + template + invalid_value:: + invalid_value (const C* type, + const std::basic_string& value) + : type_ (type), value_ (value) + { + } + + template + invalid_value:: + invalid_value (const C* type, + const ro_string& value) + : type_ (type), value_ (value) + { + } + + template + invalid_value:: + invalid_value (const std::basic_string& type, + const std::basic_string& value) + : type_ (type), value_ (value) + { + } + } + } + } +} diff --git a/libxsd/xsd/cxx/parser/validating/inheritance-map.hxx b/libxsd/xsd/cxx/parser/validating/inheritance-map.hxx new file mode 100644 index 0000000..ebd1d03 --- /dev/null +++ b/libxsd/xsd/cxx/parser/validating/inheritance-map.hxx @@ -0,0 +1,92 @@ +// file : xsd/cxx/parser/validating/inheritance-map.hxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_PARSER_VALIDATING_INHERITANCE_MAP_HXX +#define XSD_CXX_PARSER_VALIDATING_INHERITANCE_MAP_HXX + +#include +#include // std::size_t + +#include + +namespace xsd +{ + namespace cxx + { + namespace parser + { + namespace validating + { + template + struct string_comparison + { + bool + operator() (const C* x, const C* y) const + { + ro_string s (x); + return s.compare (y) < 0; + } + }; + + template + struct inheritance_map + { + void + insert (const C* derived, const C* base) + { + map_[derived] = base; + } + + bool + check (const C* derived, const ro_string& base) const; + + private: + typedef std::map > map; + map map_; + }; + + + // Translation unit initializer. + // + template + struct inheritance_map_init + { + static inheritance_map* map; + static std::size_t count; + + inheritance_map_init (); + ~inheritance_map_init (); + }; + + template + inheritance_map* inheritance_map_init::map = 0; + + template + std::size_t inheritance_map_init::count = 0; + + template + inline inheritance_map& + inheritance_map_instance () + { + return *inheritance_map_init::map; + } + + + // Map entry initializer. + // + template + struct inheritance_map_entry + { + inheritance_map_entry (const C* derived, const C* base); + }; + } + } + } +} + +#include + +#endif // XSD_CXX_PARSER_VALIDATING_INHERITANCE_MAP_HXX + diff --git a/libxsd/xsd/cxx/parser/validating/inheritance-map.txx b/libxsd/xsd/cxx/parser/validating/inheritance-map.txx new file mode 100644 index 0000000..5e70409 --- /dev/null +++ b/libxsd/xsd/cxx/parser/validating/inheritance-map.txx @@ -0,0 +1,65 @@ +// file : xsd/cxx/parser/validating/inheritance-map.txx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsd +{ + namespace cxx + { + namespace parser + { + namespace validating + { + template + bool inheritance_map:: + check (const C* derived, const ro_string& base) const + { + if (base == derived) + return true; + + typename map::const_iterator i (map_.find (derived)); + + if (i != map_.end ()) + { + if (base == i->second) + return true; + else + return check (i->second, base); + } + + return false; + } + + // inheritance_map_init + // + template + inheritance_map_init:: + inheritance_map_init () + { + if (count == 0) + map = new inheritance_map; + + ++count; + } + + template + inheritance_map_init:: + ~inheritance_map_init () + { + if (--count == 0) + delete map; + } + + // inheritance_map_entry + // + template + inheritance_map_entry:: + inheritance_map_entry (const C* derived, const C* base) + { + inheritance_map_instance ().insert (derived, base); + } + } + } + } +} diff --git a/libxsd/xsd/cxx/parser/validating/parser.hxx b/libxsd/xsd/cxx/parser/validating/parser.hxx new file mode 100644 index 0000000..4feb898 --- /dev/null +++ b/libxsd/xsd/cxx/parser/validating/parser.hxx @@ -0,0 +1,471 @@ +// file : xsd/cxx/parser/validating/parser.hxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_PARSER_VALIDATING_PARSER_HXX +#define XSD_CXX_PARSER_VALIDATING_PARSER_HXX + +#include +#include // std::size_t +#include // std::memcpy + +#include +#include + +namespace xsd +{ + namespace cxx + { + namespace parser + { + namespace validating + { + // + // + template + struct empty_content: parser_base + { + // These functions are called when wildcard content + // is encountered. Use them to handle mixed content + // models, any/anyAttribute, and anyType/anySimpleType. + // By default these functions do nothing. + // + + // The type argument is a type name and namespace from the + // xsi:type attribute in the form " " with + // the space and namespace part absent if the type does not + // have a namespace or 0 if xsi:type is not present. + // + virtual void + _start_any_element (const ro_string& ns, + const ro_string& name, + const ro_string* type); + + virtual void + _end_any_element (const ro_string& ns, + const ro_string& name); + + virtual void + _any_attribute (const ro_string& ns, + const ro_string& name, + const ro_string& value); + + virtual void + _any_characters (const ro_string&); + + + // + // + virtual bool + _start_element_impl (const ro_string&, + const ro_string&, + const ro_string*); + + virtual bool + _end_element_impl (const ro_string&, + const ro_string&); + + virtual bool + _attribute_impl (const ro_string&, + const ro_string&, + const ro_string&); + + virtual bool + _characters_impl (const ro_string&); + + + // + // + virtual void + _start_element (const ro_string&, + const ro_string&, + const ro_string*); + + virtual void + _end_element (const ro_string&, + const ro_string&); + + virtual void + _attribute (const ro_string&, + const ro_string&, + const ro_string&); + + virtual void + _characters (const ro_string&); + + + // + // + virtual void + _expected_element (const C* expected_ns, + const C* expected_name); + + virtual void + _expected_element (const C* expected_ns, + const C* expected_name, + const ro_string& encountered_ns, + const ro_string& encountered_name); + + virtual void + _unexpected_element (const ro_string& ns, + const ro_string& name); + + virtual void + _expected_attribute (const C* expected_ns, + const C* expected_name); + + virtual void + _unexpected_attribute (const ro_string& ns, + const ro_string& name, + const ro_string& value); + + virtual void + _unexpected_characters (const ro_string&); + }; + + + // + // + template + struct simple_content: empty_content + { + // + // + virtual void + _attribute (const ro_string& ns, + const ro_string& name, + const ro_string& value); + + virtual void + _characters (const ro_string&); + + // + // + virtual bool + _attribute_impl (const ro_string&, + const ro_string&, + const ro_string&); + + // + // + virtual void + _pre_impl (); + + virtual void + _post_impl (); + + + // Implementation callbacks. + // + virtual void + _pre_a_validate (); + + virtual void + _post_a_validate (); + + + // Attribute validation: during phase one we are searching for + // matching attributes (Structures, section 3.4.4, clause 2.1). + // During phase two we are searching for attribute wildcards + // (section 3.4.4, clause 2.2). Both phases run across + // inheritance hierarchy from derived to base for extension + // only. Both functions return true if the match was found and + // validation has been performed. + // + virtual bool + _attribute_impl_phase_one (const ro_string& ns, + const ro_string& name, + const ro_string& value); + + virtual bool + _attribute_impl_phase_two (const ro_string& ns, + const ro_string& name, + const ro_string& value); + }; + + + // + // + template + struct complex_content: empty_content + { + // + // + virtual void + _start_element (const ro_string& ns, + const ro_string& name, + const ro_string* type); + + virtual void + _end_element (const ro_string& ns, + const ro_string& name); + + virtual void + _attribute (const ro_string& ns, + const ro_string& name, + const ro_string& value); + + virtual void + _characters (const ro_string&); + + // + // + virtual bool + _attribute_impl (const ro_string&, + const ro_string&, + const ro_string&); + + // + // + virtual void + _pre_impl (); + + virtual void + _post_impl (); + + + // Implementation callbacks. + // + virtual void + _pre_e_validate (); + + virtual void + _post_e_validate (); + + virtual void + _pre_a_validate (); + + virtual void + _post_a_validate (); + + + // Attribute validation: during phase one we are searching for + // matching attributes (Structures, section 3.4.4, clause 2.1). + // During phase two we are searching for attribute wildcards + // (section 3.4.4, clause 2.2). Both phases run across + // inheritance hierarchy from derived to base for extension + // only. Both functions return true if the match was found and + // validation has been performed. + // + virtual bool + _attribute_impl_phase_one (const ro_string& ns, + const ro_string& name, + const ro_string& value); + + virtual bool + _attribute_impl_phase_two (const ro_string& ns, + const ro_string& name, + const ro_string& value); + protected: + struct state + { + state () + : any_ (false), depth_ (0), parser_ (0) + { + } + + bool any_; + std::size_t depth_; + parser_base* parser_; + }; + + // Optimized state stack for non-recursive case (one element). + // + struct state_stack + { + state_stack () + : size_ (0) + { + } + + void + push (const state& s) + { + if (size_ > 0) + rest_.push (top_); + + top_ = s; + ++size_; + } + + void + pop () + { + if (size_ > 1) + { + top_ = rest_.top (); + rest_.pop (); + } + + --size_; + } + + const state& + top () const + { + return top_; + } + + state& + top () + { + return top_; + } + + state& + under_top () + { + return rest_.top (); + } + + private: + state top_; + std::stack rest_; + std::size_t size_; + }; + + state_stack context_; + }; + + // Base for xsd:list. + // + template + struct list_base: simple_content + { + virtual void + _xsd_parse_item (const ro_string&) = 0; + + virtual void + _pre_impl (); + + virtual void + _characters (const ro_string&); + + virtual void + _post_impl (); + + protected: + std::basic_string buf_; + }; + } + + // POD stack with pre-allocated first element. You may + // need to pad your elements to get the proper alignment. + // + struct pod_stack + { + ~pod_stack () + { + delete[] data_; + } + + pod_stack (std::size_t element_size, void* first_element) + : el_size_ (element_size), first_ (first_element), + data_ (0), size_ (0), capacity_ (0) + { + } + + public: + void + pop () + { + --size_; + } + + void + push () + { + if (size_ > capacity_) + grow (); + + ++size_; + } + + void* + top () + { + return size_ == 1 ? first_ : data_ + (size_ - 1) * el_size_; + } + + void* + under_top () + { + return size_ == 2 ? first_ : data_ + (size_ - 2) * el_size_; + } + + std::size_t + element_size () const + { + return el_size_; + } + + private: + void + grow () + { + std::size_t c (capacity_ ? capacity_ * 2 : 8); + char* d (new char[c * el_size_]); + + if (size_ > 1) + std::memcpy (d, data_, (size_ - 1) * el_size_); + + delete[] data_; + + data_ = d; + capacity_ = c; + } + + private: + std::size_t el_size_; + void* first_; + char* data_; + std::size_t size_; + std::size_t capacity_; + }; + + namespace validating + { + // Validation state stack for the 'all' particle. + // + struct all_stack + { + all_stack (std::size_t n, unsigned char* first) + : stack_ (n, first) + { + } + + void + push () + { + stack_.push (); + + unsigned char* p (static_cast (stack_.top ())); + + for (std::size_t i (0); i < stack_.element_size (); ++i) + p[i] = 0; + } + + void + pop () + { + stack_.pop (); + } + + unsigned char* + top () + { + return static_cast (stack_.top ()); + } + + private: + pod_stack stack_; + }; + } + } + } +} + +#include + +#endif // XSD_CXX_PARSER_VALIDATING_PARSER_HXX diff --git a/libxsd/xsd/cxx/parser/validating/parser.txx b/libxsd/xsd/cxx/parser/validating/parser.txx new file mode 100644 index 0000000..4cf9b7e --- /dev/null +++ b/libxsd/xsd/cxx/parser/validating/parser.txx @@ -0,0 +1,667 @@ +// file : xsd/cxx/parser/validating/parser.txx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include + +#include +#include + +namespace xsd +{ + namespace cxx + { + namespace parser + { + namespace validating + { + + // empty_content + // + + + template + void empty_content:: + _start_any_element (const ro_string&, + const ro_string&, + const ro_string*) + { + } + + template + void empty_content:: + _end_any_element (const ro_string&, + const ro_string&) + { + } + + template + void empty_content:: + _any_attribute (const ro_string&, + const ro_string&, + const ro_string&) + { + } + + template + void empty_content:: + _any_characters (const ro_string&) + { + } + + // + // + template + bool empty_content:: + _start_element_impl (const ro_string&, + const ro_string&, + const ro_string*) + { + return false; + } + + template + bool empty_content:: + _end_element_impl (const ro_string&, + const ro_string&) + { + return false; + } + + template + bool empty_content:: + _attribute_impl (const ro_string&, + const ro_string&, + const ro_string&) + { + return false; + } + + template + bool empty_content:: + _characters_impl (const ro_string&) + { + return false; + } + + // + // + template + void empty_content:: + _start_element (const ro_string& ns, + const ro_string& name, + const ro_string* type) + { + if (!_start_element_impl (ns, name, type)) + _unexpected_element (ns, name); + } + + template + void empty_content:: + _end_element (const ro_string& ns, + const ro_string& name) + { + if (!_end_element_impl (ns, name)) + _unexpected_element (ns, name); + } + + template + void empty_content:: + _attribute (const ro_string& ns, + const ro_string& name, + const ro_string& value) + { + // Weed out special attributes: xsi:type, xsi:nil, + // xsi:schemaLocation and noNamespaceSchemaLocation. + // See section 3.2.7 in Structures for details. + // + if (ns == xml::bits::xsi_namespace () && + (name == xml::bits::type () || + name == xml::bits::nil () || + name == xml::bits::schema_location () || + name == xml::bits::no_namespace_schema_location ())) + return; + + // Also some parsers (notably Xerces-C++) supplies us with + // namespace-prefix mapping attributes. + // + if (ns == xml::bits::xmlns_namespace ()) + return; + + if (!_attribute_impl (ns, name, value)) + _unexpected_attribute (ns, name, value); + } + + template + void empty_content:: + _characters (const ro_string& s) + { + if (!_characters_impl (s)) + _unexpected_characters (s); + } + + // + // + template + void empty_content:: + _expected_element (const C* ex_ns, const C* ex_name) + { + throw expected_element (ex_ns, ex_name); + } + + template + void empty_content:: + _expected_element (const C* ex_ns, + const C* ex_name, + const ro_string& en_ns, + const ro_string& en_name) + { + throw expected_element (ex_ns, ex_name, en_ns, en_name); + } + + template + void empty_content:: + _unexpected_element (const ro_string& ns, + const ro_string& name) + { + throw unexpected_element (ns, name); + } + + template + void empty_content:: + _expected_attribute (const C* ex_ns, const C* ex_name) + { + throw expected_attribute (ex_ns, ex_name); + } + + template + void empty_content:: + _unexpected_attribute (const ro_string& ns, + const ro_string& name, + const ro_string&) + { + throw unexpected_attribute (ns, name); + } + + template + void empty_content:: + _unexpected_characters (const ro_string& s) + { + throw unexpected_characters (s); + } + + + // simple_content + // + + template + void simple_content:: + _attribute (const ro_string& ns, + const ro_string& name, + const ro_string& value) + { + // Weed out special attributes: xsi:type, xsi:nil, + // xsi:schemaLocation and xsi:noNamespaceSchemaLocation. + // See section 3.2.7 in Structures for details. + // + if (ns == xml::bits::xsi_namespace () && + (name == xml::bits::type () || + name == xml::bits::nil () || + name == xml::bits::schema_location () || + name == xml::bits::no_namespace_schema_location ())) + return; + + // Also some parsers (notably Xerces-C++) supplies us with + // namespace-prefix mapping attributes. + // + if (ns == xml::bits::xmlns_namespace ()) + return; + + if (!_attribute_impl (ns, name, value)) + _unexpected_attribute (ns, name, value); + } + + template + void simple_content:: + _characters (const ro_string& str) + { + if (!_characters_impl (str)) + { + // Mixed content is implemented in the generated code + // by overriding _characters_impl and forwarding to + // _any_characters. + // + + // Scan the string for any non-whitespace characters + // (Structures, section 3.4.4, clause 1.3). + // + for (typename ro_string::size_type i (0), e (str.size ()); + i < e; ++i) + { + C c (str[i]); + + if (c != C (0x20) && // space + c != C (0x0D) && // carriage return + c != C (0x09) && // tab + c != C (0x0A)) + _unexpected_characters (str); + } + } + } + + template + void simple_content:: + _pre_impl () + { + this->_pre (); + _pre_a_validate (); + } + + template + void simple_content:: + _post_impl () + { + _post_a_validate (); + this->_post (); + } + + template + void simple_content:: + _pre_a_validate () + { + } + + template + void simple_content:: + _post_a_validate () + { + } + + template + bool simple_content:: + _attribute_impl (const ro_string& ns, + const ro_string& name, + const ro_string& value) + { + return _attribute_impl_phase_one (ns, name, value) || + _attribute_impl_phase_two (ns, name, value); + } + + template + bool simple_content:: + _attribute_impl_phase_one (const ro_string&, + const ro_string&, + const ro_string&) + { + return false; + } + + template + bool simple_content:: + _attribute_impl_phase_two (const ro_string&, + const ro_string&, + const ro_string&) + { + return false; + } + + + // complex_content + // + + + template + void complex_content:: + _start_element (const ro_string& ns, + const ro_string& name, + const ro_string* type) + { + state& s (context_.top ()); + + if (s.depth_++ > 0) + { + if (s.any_) + _start_any_element (ns, name, type); + else if (s.parser_) + s.parser_->_start_element (ns, name, type); + } + else + { + if (!_start_element_impl (ns, name, type)) + _unexpected_element (ns, name); + else if (s.parser_ != 0) + s.parser_->_pre_impl (); + } + } + + template + void complex_content:: + _end_element (const ro_string& ns, + const ro_string& name) + { + // To understand what's going on here it is helpful to think of + // a "total depth" as being the sum of individual depths over + // all elements. + // + + if (context_.top ().depth_ == 0) + { + state& s (context_.under_top ()); // One before last. + + if (--s.depth_ > 0) + { + // Indirect recursion. + // + if (s.parser_) + s.parser_->_end_element (ns, name); + } + else + { + // Direct recursion. + // + assert (this == s.parser_); + + this->_post_impl (); + + if (!_end_element_impl (ns, name)) + assert (false); + } + } + else + { + state& s (context_.top ()); + + if (--s.depth_ > 0) + { + if (s.any_) + _end_any_element (ns, name); + else if (s.parser_) + s.parser_->_end_element (ns, name); + } + else + { + if (s.parser_ != 0 && !s.any_) + s.parser_->_post_impl (); + + if (!_end_element_impl (ns, name)) + _unexpected_element (ns, name); + } + } + } + + template + void complex_content:: + _attribute (const ro_string& ns, + const ro_string& name, + const ro_string& value) + { + // Weed out special attributes: xsi:type, xsi:nil, + // xsi:schemaLocation and xsi:noNamespaceSchemaLocation. + // See section 3.2.7 in Structures for details. + // + if (ns == xml::bits::xsi_namespace () && + (name == xml::bits::type () || + name == xml::bits::nil () || + name == xml::bits::schema_location () || + name == xml::bits::no_namespace_schema_location ())) + return; + + // Also some parsers (notably Xerces-C++) supplies us with + // namespace-prefix mapping attributes. + // + if (ns == xml::bits::xmlns_namespace ()) + return; + + const state& s (context_.top ()); + + if (s.depth_ > 0) + { + if (s.any_) + _any_attribute (ns, name, value); + else if (s.parser_) + s.parser_->_attribute (ns, name, value); + } + else + { + if (!_attribute_impl (ns, name, value)) + _unexpected_attribute (ns, name, value); + } + } + + template + void complex_content:: + _characters (const ro_string& str) + { + const state& s (context_.top ()); + + if (s.depth_ > 0) + { + if (s.any_) + _any_characters (str); + else if (s.parser_) + s.parser_->_characters (str); + } + else + { + if (!_characters_impl (str)) + { + // Mixed content is implemented in the generated code + // by overriding _characters_impl and forwarding to + // _any_characters. + // + + // Scan the string for any non-whitespace characters + // (Structures, section 3.4.4, clause 1.3). + // + for (typename ro_string::size_type i (0), e (str.size ()); + i < e; ++i) + { + C c (str[i]); + + if (c != C (0x20) && // space + c != C (0x0D) && // carriage return + c != C (0x09) && // tab + c != C (0x0A)) + _unexpected_characters (str); + } + } + } + } + + template + void complex_content:: + _pre_impl () + { + context_.push (state ()); + this->_pre (); + _pre_a_validate (); + _pre_e_validate (); + } + + template + void complex_content:: + _post_impl () + { + _post_e_validate (); + _post_a_validate (); + this->_post (); + context_.pop (); + } + + template + void complex_content:: + _pre_e_validate () + { + } + + template + void complex_content:: + _post_e_validate () + { + } + + template + void complex_content:: + _pre_a_validate () + { + } + + template + void complex_content:: + _post_a_validate () + { + } + + template + bool complex_content:: + _attribute_impl (const ro_string& ns, + const ro_string& name, + const ro_string& value) + { + return _attribute_impl_phase_one (ns, name, value) || + _attribute_impl_phase_two (ns, name, value); + } + + template + bool complex_content:: + _attribute_impl_phase_one (const ro_string&, + const ro_string&, + const ro_string&) + { + return false; + } + + template + bool complex_content:: + _attribute_impl_phase_two (const ro_string&, + const ro_string&, + const ro_string&) + { + return false; + } + + + // list_base + // + namespace bits + { + // Find first non-space character. + // + template + typename ro_string::size_type + find_ns (const C* s, + typename ro_string::size_type size, + typename ro_string::size_type pos) + { + while (pos < size && + (s[pos] == C (0x20) || s[pos] == C (0x0A) || + s[pos] == C (0x0D) || s[pos] == C (0x09))) + ++pos; + + return pos < size ? pos : ro_string::npos; + } + + // Find first space character. + // + template + typename ro_string::size_type + find_s (const C* s, + typename ro_string::size_type size, + typename ro_string::size_type pos) + { + while (pos < size && + s[pos] != C (0x20) && s[pos] != C (0x0A) && + s[pos] != C (0x0D) && s[pos] != C (0x09)) + ++pos; + + return pos < size ? pos : ro_string::npos; + } + } + + // Relevant XML Schema Part 2: Datatypes sections: 4.2.1.2, 4.3.6. + // + + template + void list_base:: + _pre_impl () + { + simple_content::_pre_impl (); + buf_.clear (); + } + + template + void list_base:: + _characters (const ro_string& s) + { + typedef typename ro_string::size_type size_type; + + const C* data (s.data ()); + size_type size (s.size ()); + + // Handle the previous chunk if we start with a ws. + // + if (!buf_.empty () && + (data[0] == C (0x20) || data[0] == C (0x0A) || + data[0] == C (0x0D) || data[0] == C (0x09))) + { + ro_string tmp (buf_); // Private copy ctor. + _xsd_parse_item (tmp); + buf_.clear (); + } + + // Traverse the data while logically collapsing spaces. + // + for (size_type i (bits::find_ns (data, size, 0)); + i != ro_string::npos;) + { + size_type j (bits::find_s (data, size, i)); + + if (j != ro_string::npos) + { + if (buf_.empty ()) + { + ro_string tmp (data + i, j - i); // Private copy ctor. + _xsd_parse_item (tmp); + } + else + { + // Assemble the first item in str from buf_ and s. + // + std::basic_string str; + str.swap (buf_); + str.append (data + i, j - i); + ro_string tmp (str); // Private copy ctor. + _xsd_parse_item (tmp); + } + + i = bits::find_ns (data, size, j); + } + else + { + // Last fragment, append it to the buf_. + // + buf_.append (data + i, size - i); + break; + } + } + } + + template + void list_base:: + _post_impl () + { + // Handle the last item. + // + if (!buf_.empty ()) + { + ro_string tmp (buf_); // Private copy ctor. + _xsd_parse_item (tmp); + } + + simple_content::_post_impl (); + } + } + } + } +} diff --git a/libxsd/xsd/cxx/parser/validating/xml-schema-pimpl.hxx b/libxsd/xsd/cxx/parser/validating/xml-schema-pimpl.hxx new file mode 100644 index 0000000..5f2f03f --- /dev/null +++ b/libxsd/xsd/cxx/parser/validating/xml-schema-pimpl.hxx @@ -0,0 +1,1121 @@ +// file : xsd/cxx/parser/validating/xml-schema-pimpl.hxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_PARSER_VALIDATING_XML_SCHEMA_PIMPL_HXX +#define XSD_CXX_PARSER_VALIDATING_XML_SCHEMA_PIMPL_HXX + +#include + +#include + +namespace xsd +{ + namespace cxx + { + namespace parser + { + namespace validating + { + // any_type + // + template + struct any_type_pimpl: virtual any_type_pskel + { + virtual void + post_any_type (); + }; + + // any_simple_type + // + template + struct any_simple_type_pimpl: virtual any_simple_type_pskel + { + virtual void + post_any_simple_type (); + }; + + // boolean + // + template + struct boolean_pimpl: virtual boolean_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual bool + post_boolean (); + + protected: + std::basic_string str_; + bool value_; + }; + + + // 8-bit + // + template + struct byte_pimpl: virtual byte_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual signed char + post_byte (); + + protected: + std::basic_string str_; + signed char value_; + }; + + + template + struct unsigned_byte_pimpl: virtual unsigned_byte_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual unsigned char + post_unsigned_byte (); + + protected: + std::basic_string str_; + unsigned char value_; + }; + + + // 16-bit + // + template + struct short_pimpl: virtual short_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual short + post_short (); + + protected: + std::basic_string str_; + short value_; + }; + + + template + struct unsigned_short_pimpl: virtual unsigned_short_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual unsigned short + post_unsigned_short (); + + protected: + std::basic_string str_; + unsigned short value_; + }; + + + // 32-bit + // + template + struct int_pimpl: virtual int_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual int + post_int (); + + protected: + std::basic_string str_; + int value_; + }; + + + template + struct unsigned_int_pimpl: virtual unsigned_int_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual unsigned int + post_unsigned_int (); + + protected: + std::basic_string str_; + unsigned int value_; + }; + + + // 64-bit + // + template + struct long_pimpl: virtual long_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual long long + post_long (); + + protected: + std::basic_string str_; + long long value_; + }; + + + template + struct unsigned_long_pimpl: virtual unsigned_long_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual unsigned long long + post_unsigned_long (); + + protected: + std::basic_string str_; + unsigned long long value_; + }; + + + // Arbitrary-length integers. + // + template + struct integer_pimpl: virtual integer_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual long long + post_integer (); + + protected: + std::basic_string str_; + long long value_; + }; + + template + struct negative_integer_pimpl: virtual negative_integer_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual long long + post_negative_integer (); + + protected: + std::basic_string str_; + long long value_; + }; + + template + struct non_positive_integer_pimpl: virtual non_positive_integer_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual long long + post_non_positive_integer (); + + protected: + std::basic_string str_; + long long value_; + }; + + template + struct positive_integer_pimpl: virtual positive_integer_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual unsigned long long + post_positive_integer (); + + protected: + std::basic_string str_; + unsigned long long value_; + }; + + template + struct non_negative_integer_pimpl: virtual non_negative_integer_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual unsigned long long + post_non_negative_integer (); + + protected: + std::basic_string str_; + unsigned long long value_; + }; + + + // Floats. + // + template + struct float_pimpl: virtual float_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual float + post_float (); + + protected: + std::basic_string str_; + float value_; + }; + + + template + struct double_pimpl: virtual double_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual double + post_double (); + + protected: + std::basic_string str_; + double value_; + }; + + + template + struct decimal_pimpl: virtual decimal_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual double + post_decimal (); + + protected: + std::basic_string str_; + double value_; + }; + + + // Strings. + // + template + struct string_pimpl: virtual string_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual std::basic_string + post_string (); + + protected: + std::basic_string str_; + }; + + template + struct normalized_string_pimpl: virtual normalized_string_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual std::basic_string + post_normalized_string (); + + protected: + std::basic_string str_; + }; + + template + struct token_pimpl: virtual token_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual std::basic_string + post_token (); + + protected: + std::basic_string str_; + }; + + template + struct name_pimpl: virtual name_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual std::basic_string + post_name (); + + protected: + std::basic_string str_; + }; + + template + struct nmtoken_pimpl: virtual nmtoken_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual std::basic_string + post_nmtoken (); + + protected: + std::basic_string str_; + }; + + template + struct nmtokens_pimpl: virtual nmtokens_pskel + { + virtual void + _pre (); + + virtual void + _xsd_parse_item (const ro_string&); + + virtual void + _post (); + + virtual string_sequence + post_nmtokens (); + + protected: + string_sequence seq_; + nmtoken_pimpl parser_; + }; + + template + struct ncname_pimpl: virtual ncname_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual std::basic_string + post_ncname (); + + protected: + std::basic_string str_; + }; + + template + struct id_pimpl: virtual id_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual std::basic_string + post_id (); + + protected: + std::basic_string str_; + }; + + template + struct idref_pimpl: virtual idref_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual std::basic_string + post_idref (); + + protected: + std::basic_string str_; + }; + + template + struct idrefs_pimpl: virtual idrefs_pskel + { + virtual void + _pre (); + + virtual void + _xsd_parse_item (const ro_string&); + + virtual void + _post (); + + virtual string_sequence + post_idrefs (); + + protected: + string_sequence seq_; + idref_pimpl parser_; + }; + + // language + // + template + struct language_pimpl: virtual language_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual std::basic_string + post_language (); + + protected: + std::basic_string str_; + }; + + // anyURI + // + template + struct uri_pimpl: virtual uri_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual std::basic_string + post_uri (); + + protected: + std::basic_string str_; + }; + + // QName + // + template + struct qname_pimpl: virtual qname_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual qname + post_qname (); + + protected: + std::basic_string str_; + std::basic_string name_; + std::basic_string prefix_; + }; + + // base64Binary + // + template + struct base64_binary_pimpl: virtual base64_binary_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual std::auto_ptr + post_base64_binary (); + + protected: + std::basic_string str_; + std::auto_ptr buf_; + }; + + // hexBinary + // + template + struct hex_binary_pimpl: virtual hex_binary_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual std::auto_ptr + post_hex_binary (); + + protected: + std::basic_string str_; + std::auto_ptr buf_; + }; + + // gday + // + template + struct gday_pimpl: virtual gday_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual gday + post_gday (); + + protected: + std::basic_string str_; + unsigned short day_; + bool z_; + short zh_, zm_; + }; + + // gmonth + // + template + struct gmonth_pimpl: virtual gmonth_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual gmonth + post_gmonth (); + + protected: + std::basic_string str_; + unsigned short month_; + bool z_; + short zh_, zm_; + }; + + // gyear + // + template + struct gyear_pimpl: virtual gyear_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual gyear + post_gyear (); + + protected: + std::basic_string str_; + int year_; + bool z_; + short zh_, zm_; + }; + + // gmonth_day + // + template + struct gmonth_day_pimpl: virtual gmonth_day_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual gmonth_day + post_gmonth_day (); + + protected: + std::basic_string str_; + unsigned short month_; + unsigned short day_; + bool z_; + short zh_, zm_; + }; + + // gyear_month + // + template + struct gyear_month_pimpl: virtual gyear_month_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual gyear_month + post_gyear_month (); + + protected: + std::basic_string str_; + int year_; + unsigned short month_; + bool z_; + short zh_, zm_; + }; + + // date + // + template + struct date_pimpl: virtual date_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual date + post_date (); + + protected: + std::basic_string str_; + int year_; + unsigned short month_; + unsigned short day_; + bool z_; + short zh_, zm_; + }; + + // time + // + template + struct time_pimpl: virtual time_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual time + post_time (); + + protected: + std::basic_string str_; + unsigned short hours_; + unsigned short minutes_; + double seconds_; + bool z_; + short zh_, zm_; + }; + + // date_time + // + template + struct date_time_pimpl: virtual date_time_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual date_time + post_date_time (); + + protected: + std::basic_string str_; + int year_; + unsigned short month_; + unsigned short day_; + unsigned short hours_; + unsigned short minutes_; + double seconds_; + bool z_; + short zh_, zm_; + }; + + // duration + // + template + struct duration_pimpl: virtual duration_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual duration + post_duration (); + + protected: + std::basic_string str_; + bool negative_; + unsigned int years_; + unsigned int months_; + unsigned int days_; + unsigned int hours_; + unsigned int minutes_; + double seconds_; + }; + + // Literals. + // + namespace bits + { + template + const C* + boolean (); + + template + const C* + byte (); + + template + const C* + unsigned_byte (); + + template + const C* + short_ (); + + template + const C* + unsigned_short (); + + template + const C* + int_ (); + + template + const C* + unsigned_int (); + + template + const C* + long_ (); + + template + const C* + unsigned_long (); + + template + const C* + integer (); + + template + const C* + negative_integer (); + + template + const C* + non_positive_integer (); + + template + const C* + non_negative_integer (); + + template + const C* + positive_integer (); + + template + const C* + float_ (); + + template + const C* + double_ (); + + template + const C* + decimal (); + + template + const C* + name (); + + template + const C* + nmtoken (); + + template + const C* + nmtokens (); + + template + const C* + ncname (); + + template + const C* + id (); + + template + const C* + idref (); + + template + const C* + idrefs (); + + template + const C* + language (); + + template + const C* + qname (); + + template + const C* + base64_binary (); + + template + const C* + hex_binary (); + + template + const C* + gday (); + + template + const C* + gmonth (); + + template + const C* + gyear (); + + template + const C* + gmonth_day (); + + template + const C* + gyear_month (); + + template + const C* + date (); + + template + const C* + time (); + + template + const C* + date_time (); + + template + const C* + duration (); + + // float literals: INF -INF NaN + // + template + const C* + positive_inf (); + + template + const C* + negative_inf (); + + template + const C* + nan (); + + // boolean literals + // + template + const C* + true_ (); + + template + const C* + false_ (); + + template + const C* + one (); + + template + const C* + zero (); + } + } + } + } +} + +#include + +#endif // XSD_CXX_PARSER_VALIDATING_XML_SCHEMA_PIMPL_HXX + +#include diff --git a/libxsd/xsd/cxx/parser/validating/xml-schema-pimpl.ixx b/libxsd/xsd/cxx/parser/validating/xml-schema-pimpl.ixx new file mode 100644 index 0000000..61bbafb --- /dev/null +++ b/libxsd/xsd/cxx/parser/validating/xml-schema-pimpl.ixx @@ -0,0 +1,676 @@ +// file : xsd/cxx/parser/validating/xml-schema-pimpl.ixx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#if defined(XSD_CXX_PARSER_USE_CHAR) || !defined(XSD_CXX_PARSER_USE_WCHAR) + +#ifndef XSD_CXX_PARSER_VALIDATING_XML_SCHEMA_PIMPL_IXX_CHAR +#define XSD_CXX_PARSER_VALIDATING_XML_SCHEMA_PIMPL_IXX_CHAR + +namespace xsd +{ + namespace cxx + { + namespace parser + { + namespace validating + { + namespace bits + { + template<> + inline const char* + boolean () + { + return "boolean"; + } + + template<> + inline const char* + byte () + { + return "byte"; + } + + template<> + inline const char* + unsigned_byte () + { + return "unsignedByte"; + } + + template<> + inline const char* + short_ () + { + return "short"; + } + + template<> + inline const char* + unsigned_short () + { + return "unsignedShort"; + } + + template<> + inline const char* + int_ () + { + return "int"; + } + + template<> + inline const char* + unsigned_int () + { + return "unsignedInt"; + } + + template<> + inline const char* + long_ () + { + return "long"; + } + + template<> + inline const char* + unsigned_long () + { + return "unsignedLong"; + } + + template<> + inline const char* + integer () + { + return "integer"; + } + + template<> + inline const char* + negative_integer () + { + return "negativeInteger"; + } + + template<> + inline const char* + non_positive_integer () + { + return "nonPositiveInteger"; + } + + template<> + inline const char* + non_negative_integer () + { + return "nonNegativeInteger"; + } + + template<> + inline const char* + positive_integer () + { + return "positiveInteger"; + } + + template<> + inline const char* + float_ () + { + return "float"; + } + + template<> + inline const char* + double_ () + { + return "double"; + } + + template<> + inline const char* + decimal () + { + return "decimal"; + } + + template<> + inline const char* + name () + { + return "Name"; + } + + template<> + inline const char* + nmtoken () + { + return "NMTOKEN"; + } + + template<> + inline const char* + nmtokens () + { + return "NMTOKENS"; + } + + template<> + inline const char* + ncname () + { + return "NCName"; + } + + template<> + inline const char* + id () + { + return "ID"; + } + + template<> + inline const char* + idref () + { + return "IDREF"; + } + + template<> + inline const char* + idrefs () + { + return "IDREFS"; + } + + template<> + inline const char* + language () + { + return "language"; + } + + template<> + inline const char* + qname () + { + return "QName"; + } + + template<> + inline const char* + base64_binary () + { + return "base64Binary"; + } + + template<> + inline const char* + hex_binary () + { + return "hexBinary"; + } + + template<> + inline const char* + gday () + { + return "gDay"; + } + + template<> + inline const char* + gmonth () + { + return "gMonth"; + } + + template<> + inline const char* + gyear () + { + return "gYear"; + } + + template<> + inline const char* + gmonth_day () + { + return "gMonthDay"; + } + + template<> + inline const char* + gyear_month () + { + return "gYearMonth"; + } + + template<> + inline const char* + date () + { + return "date"; + } + + template<> + inline const char* + time () + { + return "time"; + } + + template<> + inline const char* + date_time () + { + return "dateTime"; + } + + template<> + inline const char* + duration () + { + return "duration"; + } + + // + // + template<> + inline const char* + positive_inf () + { + return "INF"; + } + + template<> + inline const char* + negative_inf () + { + return "-INF"; + } + + template<> + inline const char* + nan () + { + return "NaN"; + } + + // + // + template<> + inline const char* + true_ () + { + return "true"; + } + + template<> + inline const char* + false_ () + { + return "false"; + } + + template<> + inline const char* + one () + { + return "1"; + } + + template<> + inline const char* + zero () + { + return "0"; + } + } + } + } + } +} + +#endif // XSD_CXX_PARSER_VALIDATING_XML_SCHEMA_PIMPL_IXX_CHAR +#endif // XSD_CXX_PARSER_USE_CHAR + + +#if defined(XSD_CXX_PARSER_USE_WCHAR) || !defined(XSD_CXX_PARSER_USE_CHAR) + +#ifndef XSD_CXX_PARSER_VALIDATING_XML_SCHEMA_PIMPL_IXX_WCHAR +#define XSD_CXX_PARSER_VALIDATING_XML_SCHEMA_PIMPL_IXX_WCHAR + +namespace xsd +{ + namespace cxx + { + namespace parser + { + namespace validating + { + namespace bits + { + template<> + inline const wchar_t* + boolean () + { + return L"boolean"; + } + + template<> + inline const wchar_t* + byte () + { + return L"byte"; + } + + template<> + inline const wchar_t* + unsigned_byte () + { + return L"unsignedByte"; + } + + template<> + inline const wchar_t* + short_ () + { + return L"short"; + } + + template<> + inline const wchar_t* + unsigned_short () + { + return L"unsignedShort"; + } + + template<> + inline const wchar_t* + int_ () + { + return L"int"; + } + + template<> + inline const wchar_t* + unsigned_int () + { + return L"unsignedInt"; + } + + template<> + inline const wchar_t* + long_ () + { + return L"long"; + } + + template<> + inline const wchar_t* + unsigned_long () + { + return L"unsignedLong"; + } + + template<> + inline const wchar_t* + integer () + { + return L"integer"; + } + + template<> + inline const wchar_t* + negative_integer () + { + return L"negativeInteger"; + } + + template<> + inline const wchar_t* + non_positive_integer () + { + return L"nonPositiveInteger"; + } + + template<> + inline const wchar_t* + non_negative_integer () + { + return L"nonNegativeInteger"; + } + + template<> + inline const wchar_t* + positive_integer () + { + return L"positiveInteger"; + } + + template<> + inline const wchar_t* + float_ () + { + return L"float"; + } + + template<> + inline const wchar_t* + double_ () + { + return L"double"; + } + + template<> + inline const wchar_t* + decimal () + { + return L"decimal"; + } + + template<> + inline const wchar_t* + name () + { + return L"Name"; + } + + template<> + inline const wchar_t* + nmtoken () + { + return L"NMTOKEN"; + } + + template<> + inline const wchar_t* + nmtokens () + { + return L"NMTOKENS"; + } + + template<> + inline const wchar_t* + ncname () + { + return L"NCName"; + } + + template<> + inline const wchar_t* + id () + { + return L"ID"; + } + + template<> + inline const wchar_t* + idref () + { + return L"IDREF"; + } + + template<> + inline const wchar_t* + idrefs () + { + return L"IDREFS"; + } + + template<> + inline const wchar_t* + language () + { + return L"language"; + } + + template<> + inline const wchar_t* + qname () + { + return L"QName"; + } + + template<> + inline const wchar_t* + base64_binary () + { + return L"base64Binary"; + } + + template<> + inline const wchar_t* + hex_binary () + { + return L"hexBinary"; + } + + template<> + inline const wchar_t* + gday () + { + return L"gDay"; + } + + template<> + inline const wchar_t* + gmonth () + { + return L"gMonth"; + } + + template<> + inline const wchar_t* + gyear () + { + return L"gYear"; + } + + template<> + inline const wchar_t* + gmonth_day () + { + return L"gMonthDay"; + } + + template<> + inline const wchar_t* + gyear_month () + { + return L"gYearMonth"; + } + + template<> + inline const wchar_t* + date () + { + return L"date"; + } + + template<> + inline const wchar_t* + time () + { + return L"time"; + } + + template<> + inline const wchar_t* + date_time () + { + return L"dateTime"; + } + + template<> + inline const wchar_t* + duration () + { + return L"duration"; + } + + + // + // + template<> + inline const wchar_t* + positive_inf () + { + return L"INF"; + } + + template<> + inline const wchar_t* + negative_inf () + { + return L"-INF"; + } + + template<> + inline const wchar_t* + nan () + { + return L"NaN"; + } + + // + // + template<> + inline const wchar_t* + true_ () + { + return L"true"; + } + + template<> + inline const wchar_t* + false_ () + { + return L"false"; + } + + template<> + inline const wchar_t* + one () + { + return L"1"; + } + + template<> + inline const wchar_t* + zero () + { + return L"0"; + } + } + } + } + } +} + +#endif // XSD_CXX_PARSER_VALIDATING_XML_SCHEMA_PIMPL_IXX_WCHAR +#endif // XSD_CXX_PARSER_USE_WCHAR diff --git a/libxsd/xsd/cxx/parser/validating/xml-schema-pimpl.txx b/libxsd/xsd/cxx/parser/validating/xml-schema-pimpl.txx new file mode 100644 index 0000000..9dd30a3 --- /dev/null +++ b/libxsd/xsd/cxx/parser/validating/xml-schema-pimpl.txx @@ -0,0 +1,2746 @@ +// file : xsd/cxx/parser/validating/xml-schema-pimpl.txx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include +#include + +#include +#include + +namespace xsd +{ + namespace cxx + { + namespace parser + { + namespace validating + { + // Note that most of the types implemented here cannot have + // whitespaces in the value. As result we don't need to waste + // time collapsing whitespaces. All we need to do is trim the + // string representation which can be done without copying. + // + + // Character table. + // + namespace bits + { + const unsigned char ncname_mask = 0x1; + const unsigned char name_first_mask = 0x2; + const unsigned char name_mask = 0x4; + + template + struct char_table + { + static C table[0x80]; + }; + + template + C char_table::table[0x80] = + { + 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xD8, 0xD0, 0x00, 0x00, 0xD0, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xD8, 0x48, 0x58, 0x48, 0x48, 0x48, 0x40, 0x58, 0x48, 0x48, 0x48, 0x48, 0x48, 0x4D, 0x4D, 0x58, + 0x4D, 0x4D, 0x4D, 0x4D, 0x4D, 0x4D, 0x4D, 0x4D, 0x4D, 0x4D, 0x4E, 0x48, 0x50, 0x48, 0x58, 0x48, + 0x48, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, + 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x48, 0x48, 0x40, 0x48, 0x4F, + 0x48, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, + 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x48, 0x48, 0x48, 0x48, 0x48 + }; + } + + // any_type + // + + template + void any_type_pimpl:: + post_any_type () + { + } + + // any_simple_type + // + + template + void any_simple_type_pimpl:: + post_any_simple_type () + { + } + + // boolean + // + + template + void boolean_pimpl:: + _pre () + { + str_.clear (); + } + + template + void boolean_pimpl:: + _characters (const ro_string& s) + { + str_ += s; + } + + template + void boolean_pimpl:: + _post () + { + ro_string str (str_); + trim (str); + + if (str == bits::true_ () || str == bits::one ()) + value_ = true; + else if (str == bits::false_ () || str == bits::zero ()) + value_ = false; + else + throw invalid_value (bits::boolean (), str); + } + + template + bool boolean_pimpl:: + post_boolean () + { + return value_; + } + + // byte + // + + template + void byte_pimpl:: + _pre () + { + str_.clear (); + } + + template + void byte_pimpl:: + _characters (const ro_string& s) + { + str_ += s; + } + + template + void byte_pimpl:: + _post () + { + ro_string str (str_); + trim (str); + + short t; + zc_istream is (str); + + if (is >> t && is.exhausted () && t >= -128 && t <= 127) + value_ = static_cast (t); + else + throw invalid_value (bits::byte (), str); + } + + template + signed char byte_pimpl:: + post_byte () + { + return value_; + } + + // unsigned_byte + // + + template + void unsigned_byte_pimpl:: + _pre () + { + str_.clear (); + } + + template + void unsigned_byte_pimpl:: + _characters (const ro_string& s) + { + str_ += s; + } + + template + void unsigned_byte_pimpl:: + _post () + { + ro_string str (str_); + trim (str); + + unsigned short t; + zc_istream is (str); + + if (is >> t && is.exhausted () && t <= 255) + value_ = static_cast (t); + else + throw invalid_value (bits::unsigned_byte (), str); + } + + template + unsigned char unsigned_byte_pimpl:: + post_unsigned_byte () + { + return value_; + } + + // short + // + + template + void short_pimpl:: + _pre () + { + str_.clear (); + } + + template + void short_pimpl:: + _characters (const ro_string& s) + { + str_ += s; + } + + template + void short_pimpl:: + _post () + { + ro_string str (str_); + trim (str); + + zc_istream is (str); + + if (!(is >> value_ && is.exhausted ())) + throw invalid_value (bits::short_ (), str); + } + + template + short short_pimpl:: + post_short () + { + return value_; + } + + + // unsigned_short + // + + template + void unsigned_short_pimpl:: + _pre () + { + str_.clear (); + } + + template + void unsigned_short_pimpl:: + _characters (const ro_string& s) + { + str_ += s; + } + + template + void unsigned_short_pimpl:: + _post () + { + ro_string str (str_); + trim (str); + + zc_istream is (str); + + if (!(is >> value_ && is.exhausted ())) + throw invalid_value (bits::unsigned_short (), str); + } + + template + unsigned short unsigned_short_pimpl:: + post_unsigned_short () + { + return value_; + } + + // int + // + + template + void int_pimpl:: + _pre () + { + str_.clear (); + } + + template + void int_pimpl:: + _characters (const ro_string& s) + { + str_ += s; + } + + template + void int_pimpl:: + _post () + { + ro_string str (str_); + trim (str); + + zc_istream is (str); + + if (!(is >> value_ && is.exhausted ())) + throw invalid_value (bits::int_ (), str); + } + + template + int int_pimpl:: + post_int () + { + return value_; + } + + + // unsigned_int + // + + template + void unsigned_int_pimpl:: + _pre () + { + str_.clear (); + } + + template + void unsigned_int_pimpl:: + _characters (const ro_string& s) + { + str_ += s; + } + + template + void unsigned_int_pimpl:: + _post () + { + ro_string str (str_); + trim (str); + + zc_istream is (str); + + if (!(is >> value_ && is.exhausted ())) + throw invalid_value (bits::unsigned_int (), str); + } + + template + unsigned int unsigned_int_pimpl:: + post_unsigned_int () + { + return value_; + } + + + // long + // + template + void long_pimpl:: + _pre () + { + str_.clear (); + } + + template + void long_pimpl:: + _characters (const ro_string& s) + { + str_ += s; + } + + template + void long_pimpl:: + _post () + { + ro_string str (str_); + trim (str); + + zc_istream is (str); + + if (!(is >> value_ && is.exhausted ())) + throw invalid_value (bits::long_ (), str); + } + + template + long long long_pimpl:: + post_long () + { + return value_; + } + + // unsigned_long + // + template + void unsigned_long_pimpl:: + _pre () + { + str_.clear (); + } + + template + void unsigned_long_pimpl:: + _characters (const ro_string& s) + { + str_ += s; + } + + template + void unsigned_long_pimpl:: + _post () + { + ro_string str (str_); + trim (str); + + zc_istream is (str); + + if (!(is >> value_ && is.exhausted ())) + throw invalid_value (bits::unsigned_long (), str); + } + + template + unsigned long long unsigned_long_pimpl:: + post_unsigned_long () + { + return value_; + } + + + // integer + // + template + void integer_pimpl:: + _pre () + { + str_.clear (); + } + + template + void integer_pimpl:: + _characters (const ro_string& s) + { + str_ += s; + } + + template + void integer_pimpl:: + _post () + { + ro_string str (str_); + trim (str); + + zc_istream is (str); + + if (!(is >> value_ && is.exhausted ())) + throw invalid_value (bits::integer (), str); + } + + template + long long integer_pimpl:: + post_integer () + { + return value_; + } + + // negative_integer + // + template + void negative_integer_pimpl:: + _pre () + { + str_.clear (); + } + + template + void negative_integer_pimpl:: + _characters (const ro_string& s) + { + str_ += s; + } + + template + void negative_integer_pimpl:: + _post () + { + ro_string str (str_); + trim (str); + + zc_istream is (str); + + if (!(is >> value_ && is.exhausted () && value_ < 0)) + throw invalid_value (bits::negative_integer (), str); + } + + template + long long negative_integer_pimpl:: + post_negative_integer () + { + return value_; + } + + + // non_positive_integer + // + template + void non_positive_integer_pimpl:: + _pre () + { + str_.clear (); + } + + template + void non_positive_integer_pimpl:: + _characters (const ro_string& s) + { + str_ += s; + } + + template + void non_positive_integer_pimpl:: + _post () + { + ro_string str (str_); + trim (str); + + zc_istream is (str); + + if (!(is >> value_ && is.exhausted () && value_ <= 0)) + throw invalid_value (bits::non_positive_integer (), str); + } + + template + long long non_positive_integer_pimpl:: + post_non_positive_integer () + { + return value_; + } + + // positive_integer + // + template + void positive_integer_pimpl:: + _pre () + { + str_.clear (); + } + + template + void positive_integer_pimpl:: + _characters (const ro_string& s) + { + str_ += s; + } + + template + void positive_integer_pimpl:: + _post () + { + ro_string str (str_); + trim (str); + + zc_istream is (str); + + if (!(is >> value_ && is.exhausted () && value_ > 0)) + throw invalid_value (bits::positive_integer (), str); + } + + template + unsigned long long positive_integer_pimpl:: + post_positive_integer () + { + return value_; + } + + + // non_negative_integer + // + template + void non_negative_integer_pimpl:: + _pre () + { + str_.clear (); + } + + template + void non_negative_integer_pimpl:: + _characters (const ro_string& s) + { + str_ += s; + } + + template + void non_negative_integer_pimpl:: + _post () + { + ro_string str (str_); + trim (str); + + zc_istream is (str); + + if (!(is >> value_ && is.exhausted ())) + throw invalid_value (bits::non_negative_integer (), str); + } + + template + unsigned long long non_negative_integer_pimpl:: + post_non_negative_integer () + { + return value_; + } + + + // float + // + template + void float_pimpl:: + _pre () + { + str_.clear (); + } + + template + void float_pimpl:: + _characters (const ro_string& s) + { + str_ += s; + } + + template + void float_pimpl:: + _post () + { + ro_string str (str_); + trim (str); + + if (str == bits::positive_inf ()) + value_ = std::numeric_limits::infinity (); + else if (str == bits::negative_inf ()) + value_ = -std::numeric_limits::infinity (); + else if (str == bits::nan ()) + value_ = std::numeric_limits::quiet_NaN (); + else + { + zc_istream is (str); + is.imbue (std::locale::classic ()); + + if (!(is >> value_ && is.exhausted ())) + throw invalid_value (bits::float_ (), str); + } + } + + template + float float_pimpl:: + post_float () + { + return value_; + } + + + // double + // + template + void double_pimpl:: + _pre () + { + str_.clear (); + } + + template + void double_pimpl:: + _characters (const ro_string& s) + { + str_ += s; + } + + template + void double_pimpl:: + _post () + { + ro_string str (str_); + trim (str); + + if (str == bits::positive_inf ()) + value_ = std::numeric_limits::infinity (); + else if (str == bits::negative_inf ()) + value_ = -std::numeric_limits::infinity (); + else if (str == bits::nan ()) + value_ = std::numeric_limits::quiet_NaN (); + else + { + zc_istream is (str); + is.imbue (std::locale::classic ()); + + if (!(is >> value_ && is.exhausted ())) + throw invalid_value (bits::double_ (), str); + } + } + + template + double double_pimpl:: + post_double () + { + return value_; + } + + // decimal + // + template + void decimal_pimpl:: + _pre () + { + str_.clear (); + } + + template + void decimal_pimpl:: + _characters (const ro_string& s) + { + str_ += s; + } + + template + void decimal_pimpl:: + _post () + { + ro_string str (str_); + trim (str); + + zc_istream is (str); + is.imbue (std::locale::classic ()); + + //@@ TODO: now we accept scientific notations and INF/NaN. + // + if (!(is >> value_ && is.exhausted ())) + throw invalid_value (bits::decimal (), str); + } + + template + double decimal_pimpl:: + post_decimal () + { + return value_; + } + + // string + // + template + void string_pimpl:: + _pre () + { + str_.clear (); + } + + template + void string_pimpl:: + _characters (const ro_string& s) + { + str_ += s; + } + + template + std::basic_string string_pimpl:: + post_string () + { + std::basic_string r; + r.swap (str_); + return r; + } + + // normalized_string + // + template + void normalized_string_pimpl:: + _pre () + { + str_.clear (); + } + + template + void normalized_string_pimpl:: + _characters (const ro_string& s) + { + str_ += s; + } + + template + std::basic_string normalized_string_pimpl:: + post_normalized_string () + { + typedef typename std::basic_string::size_type size_type; + + size_type size (str_.size ()); + + for (size_type i (0); i < size; ++i) + { + C& c = str_[i]; + + if (c == C (0x0A) || c == C (0x0D) || c == C (0x09)) + c = C (0x20); + } + + std::basic_string r; + r.swap (str_); + return r; + } + + // token + // + template + void token_pimpl:: + _pre () + { + str_.clear (); + } + + template + void token_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + template + std::basic_string token_pimpl:: + post_token () + { + typedef typename std::basic_string::size_type size_type; + + size_type size (str_.size ()); + size_type j (0); + + bool subs (false); + + for (size_type i (0); i < size; ++i) + { + C c = str_[i]; + + if (c == C (0x20) || c == C (0x0A) || + c == C (0x0D) || c == C (0x09)) + { + subs = true; + } + else + { + if (subs) + { + subs = false; + str_[j++] = C (0x20); + } + + str_[j++] = c; + } + } + + str_.resize (j); + + std::basic_string r; + r.swap (str_); + return r; + } + + // name + // + template + void name_pimpl:: + _pre () + { + str_.clear (); + } + + template + void name_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + template + void name_pimpl:: + _post () + { + typedef typename ro_string::size_type size_type; + + ro_string tmp (str_); + size_type size (trim_right (tmp)); + + // For now we are only checking the US-ASCII characters. + // + + bool ok (size != 0); + + if (ok) + { + unsigned int c (static_cast (str_[0])); + + ok = c >= 0x80 || + (bits::char_table::table[c] & + bits::name_first_mask); + + if (ok) + { + for (size_type i (1); i < size; ++i) + { + c = static_cast (str_[i]); + + if (c < 0x80 && + !(bits::char_table::table[c] & + bits::name_mask)) + { + ok = false; + break; + } + } + } + } + + if (!ok) + throw invalid_value (bits::name (), tmp); + + str_.resize (size); + } + + template + std::basic_string name_pimpl:: + post_name () + { + std::basic_string r; + r.swap (str_); + return r; + } + + // nmtoken + // + template + void nmtoken_pimpl:: + _pre () + { + str_.clear (); + } + + template + void nmtoken_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + template + void nmtoken_pimpl:: + _post () + { + typedef typename ro_string::size_type size_type; + + ro_string tmp (str_); + size_type size (trim_right (tmp)); + + // For now we are only checking the US-ASCII characters. + // + + bool ok (size != 0); + + if (ok) + { + for (size_type i (0); i < size; ++i) + { + unsigned int c (static_cast (str_[i])); + + if (c < 0x80 && + !(bits::char_table::table[c] & + bits::name_mask)) + { + ok = false; + break; + } + } + } + + if (!ok) + throw invalid_value (bits::nmtoken (), tmp); + + str_.resize (size); + } + + template + std::basic_string nmtoken_pimpl:: + post_nmtoken () + { + std::basic_string r; + r.swap (str_); + return r; + } + + // nmtokens + // + template + void nmtokens_pimpl:: + _pre () + { + nmtokens_pskel::_pre (); + seq_.clear (); + } + + template + void nmtokens_pimpl:: + _post () + { + nmtokens_pskel::_post (); + + // Should have at least one element. + // + if (seq_.size () < 1) + { + ro_string tmp; + throw invalid_value (bits::nmtokens (), tmp); + } + } + + template + string_sequence nmtokens_pimpl:: + post_nmtokens () + { + string_sequence r; + r.swap (seq_); + return r; + } + + template + void nmtokens_pimpl:: + _xsd_parse_item (const ro_string& s) + { + parser_.pre (); + parser_._pre (); + parser_._characters (s); + parser_._post (); + seq_.push_back (parser_.post_nmtoken ()); + } + + // ncname + // + namespace bits + { + template + bool + valid_ncname (const C* s, typename ro_string::size_type size) + { + typedef typename ro_string::size_type size_type; + + // For now we are only checking the US-ASCII characters. + // + bool ok (size != 0); + + if (ok) + { + unsigned int c (static_cast (s[0])); + + ok = c >= 0x80 || + ((bits::char_table::table[c] & + bits::name_first_mask) && c != C (':')); + + if (ok) + { + for (size_type i (1); i < size; ++i) + { + c = static_cast (s[i]); + + if (c < 0x80 && + !(bits::char_table::table[c] & + bits::ncname_mask)) + { + ok = false; + break; + } + } + } + } + + return ok; + } + } + + template + void ncname_pimpl:: + _pre () + { + str_.clear (); + } + + template + void ncname_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + template + void ncname_pimpl:: + _post () + { + typedef typename ro_string::size_type size_type; + + ro_string tmp (str_); + size_type size (trim_right (tmp)); + + if (!bits::valid_ncname (tmp.data (), size)) + throw invalid_value (bits::ncname (), tmp); + + str_.resize (size); + } + + template + std::basic_string ncname_pimpl:: + post_ncname () + { + std::basic_string r; + r.swap (str_); + return r; + } + + // id + // + template + void id_pimpl:: + _pre () + { + str_.clear (); + } + + template + void id_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + template + void id_pimpl:: + _post () + { + typedef typename ro_string::size_type size_type; + + ro_string tmp (str_); + size_type size (trim_right (tmp)); + + if (!bits::valid_ncname (tmp.data (), size)) + throw invalid_value (bits::id (), tmp); + + str_.resize (size); + } + + template + std::basic_string id_pimpl:: + post_id () + { + std::basic_string r; + r.swap (str_); + return r; + } + + // idref + // + template + void idref_pimpl:: + _pre () + { + str_.clear (); + } + + template + void idref_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + template + void idref_pimpl:: + _post () + { + typedef typename ro_string::size_type size_type; + + ro_string tmp (str_); + size_type size (trim_right (tmp)); + + if (!bits::valid_ncname (tmp.data (), size)) + throw invalid_value (bits::idref (), tmp); + + str_.resize (size); + } + + template + std::basic_string idref_pimpl:: + post_idref () + { + std::basic_string r; + r.swap (str_); + return r; + } + + // idrefs + // + template + void idrefs_pimpl:: + _pre () + { + idrefs_pskel::_pre (); + seq_.clear (); + } + + template + void idrefs_pimpl:: + _post () + { + idrefs_pskel::_post (); + + // Should have at least one element. + // + if (seq_.size () < 1) + { + ro_string tmp; + throw invalid_value (bits::idrefs (), tmp); + } + } + + template + string_sequence idrefs_pimpl:: + post_idrefs () + { + string_sequence r; + r.swap (seq_); + return r; + } + + template + void idrefs_pimpl:: + _xsd_parse_item (const ro_string& s) + { + parser_.pre (); + parser_._pre (); + parser_._characters (s); + parser_._post (); + seq_.push_back (parser_.post_idref ()); + } + + // language + // + template + void language_pimpl:: + _pre () + { + str_.clear (); + } + + template + void language_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + template + void language_pimpl:: + _post () + { + typedef typename ro_string::size_type size_type; + + ro_string tmp (str_); + size_type size (trim_right (tmp)); + + // language := ALPHA{1,8} *(-(ALPHA | DIGIT){1,8}) + // + bool ok (true); + + for (size_type tag (0), i (0); ; ++tag) + { + size_type n (0); + + for (; i < size && n < 8; ++n, ++i) + { + C c (tmp[i]); + + if (!((c >= C ('a') && c <= C ('z')) || + (c >= C ('A') && c <= C ('Z')) || + (tag != 0 && c >= C ('0') && c <= C ('9')))) + break; + } + + if (n == 0) + { + ok = false; + break; + } + + if (i == size) + break; + + if (tmp[i++] != C ('-')) + { + ok = false; + break; + } + } + + if (!ok) + throw invalid_value (bits::language (), tmp); + + str_.resize (size); + } + + template + std::basic_string language_pimpl:: + post_language () + { + std::basic_string r; + r.swap (str_); + return r; + } + + // uri + // + template + void uri_pimpl:: + _pre () + { + str_.clear (); + } + + template + void uri_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + template + std::basic_string uri_pimpl:: + post_uri () + { + // According to Datatypes 3.2.17 and RFC2396 pretty much anything + // can be a URI and conforming processors do not need to figure + // out and verify particular URI schemes. + // + ro_string tmp (str_); + str_.resize (trim_right (tmp)); + + std::basic_string r; + r.swap (str_); + return r; + } + + // qname + // + template + void qname_pimpl:: + _pre () + { + str_.clear (); + } + + template + void qname_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + template + void qname_pimpl:: + _post () + { + typedef typename ro_string::size_type size_type; + + ro_string tmp (str_); + size_type size (trim_right (tmp)); + size_type pos (tmp.find (C (':'))); + + const C* s (tmp.data ()); + + if (pos != ro_string::npos) + { + if (!bits::valid_ncname (s, pos) || + !bits::valid_ncname (s + pos + 1, size - pos - 1)) + throw invalid_value (bits::qname (), tmp); + + prefix_.assign (s, pos); + name_.assign (s + pos + 1, size - pos - 1); + } + else + { + if (!bits::valid_ncname (s, size)) + throw invalid_value (bits::qname (), tmp); + + prefix_.clear (); + str_.resize (size); + name_.swap (str_); + } + } + + template + qname qname_pimpl:: + post_qname () + { + return prefix_.empty () + ? qname (name_) + : qname (prefix_, name_); + } + + // base64_binary + // + template + void base64_binary_pimpl:: + _pre () + { + str_.clear (); + } + + template + void base64_binary_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + namespace bits + { + template + inline unsigned char + base64_decode (C c) + { + unsigned char r (0xFF); + + if (c >= C('A') && c <= C ('Z')) + r = static_cast (c - C ('A')); + else if (c >= C('a') && c <= C ('z')) + r = static_cast (c - C ('a') + 26); + else if (c >= C('0') && c <= C ('9')) + r = static_cast (c - C ('0') + 52); + else if (c == C ('+')) + r = 62; + else if (c == C ('/')) + r = 63; + + return r; + } + } + + template + void base64_binary_pimpl:: + _post () + { + typedef typename std::basic_string::size_type size_type; + + size_type size (str_.size ()); + const C* src (str_.c_str ()); + + // Remove all whitespaces. + // + { + size_type j (0); + + bool subs (false); + + for (size_type i (0); i < size; ++i) + { + C c = str_[i]; + + if (c == C (0x20) || c == C (0x0A) || + c == C (0x0D) || c == C (0x09)) + { + subs = true; + } + else + { + if (subs) + subs = false; + + str_[j++] = c; + } + } + + size = j; + str_.resize (size); + } + + // Our length should be a multiple of four. + // + if (size == 0 || size % 4 != 0) + throw invalid_value (bits::base64_binary (), str_); + + size_type quad_count (size / 4); + size_type capacity (quad_count * 3 + 1); + + buf_.reset (new buffer (capacity, capacity)); + char* dst (buf_->data ()); + + size_type si (0), di (0); // Source and destination indexes. + + // Process all quads except the last one. + // + unsigned char b1, b2, b3, b4; + + for (size_type q (0); q < quad_count - 1; ++q) + { + b1 = bits::base64_decode (src[si++]); + b2 = bits::base64_decode (src[si++]); + b3 = bits::base64_decode (src[si++]); + b4 = bits::base64_decode (src[si++]); + + if (b1 == 0xFF || b2 == 0xFF || b3 == 0xFF || b4 == 0xFF) + throw invalid_value (bits::base64_binary (), str_); + + dst[di++] = (b1 << 2) | (b2 >> 4); + dst[di++] = (b2 << 4) | (b3 >> 2); + dst[di++] = (b3 << 6) | b4; + } + + // Process the last quad. The first two octets are always there. + // + b1 = bits::base64_decode (src[si++]); + b2 = bits::base64_decode (src[si++]); + + if (b1 == 0xFF || b2 == 0xFF) + throw invalid_value (bits::base64_binary (), str_); + + C e3 (src[si++]); + C e4 (src[si++]); + + if (e4 == C ('=')) + { + if (e3 == C ('=')) + { + // Two pads. Last 4 bits in b2 should be zero. + // + if ((b2 & 0x0F) != 0) + throw invalid_value (bits::base64_binary (), str_); + + dst[di++] = (b1 << 2) | (b2 >> 4); + } + else + { + // One pad. Last 2 bits in b3 should be zero. + // + b3 = bits::base64_decode (e3); + + if (b3 == 0xFF || (b3 & 0x03) != 0) + throw invalid_value (bits::base64_binary (), str_); + + dst[di++] = (b1 << 2) | (b2 >> 4); + dst[di++] = (b2 << 4) | (b3 >> 2); + } + } + else + { + // No pads. + // + b3 = bits::base64_decode (e3); + b4 = bits::base64_decode (e4); + + if (b3 == 0xFF || b4 == 0xFF) + throw invalid_value (bits::base64_binary (), str_); + + dst[di++] = (b1 << 2) | (b2 >> 4); + dst[di++] = (b2 << 4) | (b3 >> 2); + dst[di++] = (b3 << 6) | b4; + } + + // Set the real size. + // + buf_->size (di); + } + + template + std::auto_ptr base64_binary_pimpl:: + post_base64_binary () + { + return buf_; + } + + // hex_binary + // + template + void hex_binary_pimpl:: + _pre () + { + str_.clear (); + } + + template + void hex_binary_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + namespace bits + { + template + inline unsigned char + hex_decode (C c) + { + unsigned char r (0xFF); + + if (c >= C('0') && c <= C ('9')) + r = static_cast (c - C ('0')); + else if (c >= C ('A') && c <= C ('F')) + r = static_cast (10 + (c - C ('A'))); + else if (c >= C ('a') && c <= C ('f')) + r = static_cast (10 + (c - C ('a'))); + + return r; + } + } + + template + void hex_binary_pimpl:: + _post () + { + typedef typename ro_string::size_type size_type; + + ro_string tmp (str_); + size_type size (trim_right (tmp)); + + if (size % 2 != 0) + throw invalid_value (bits::hex_binary (), tmp); + + buffer::size_t n (size / 2); + buf_.reset (new buffer (n)); + + if (n != 0) + { + const C* src (tmp.data ()); + char* dst (buf_->data ()); + buffer::size_t i (0); + + for (; i < n; ++i) + { + unsigned char h (bits::hex_decode (src[2 * i])); + unsigned char l (bits::hex_decode (src[2 * i + 1])); + + if (h == 0xFF || l == 0xFF) + break; + + dst[i] = (h << 4) | l; + } + + if (i != n) + throw invalid_value (bits::hex_binary (), tmp); + } + } + + template + std::auto_ptr hex_binary_pimpl:: + post_hex_binary () + { + return buf_; + } + + // time_zone + // + namespace bits + { + // Datatypes 3.2.7.3. Return false if time zone is invalid. + // + template + bool + parse_tz (const C* s, + typename std::basic_string::size_type n, + short& h, short& m) + { + // time_zone := Z|(+|-)HH:MM + // + if (n == 0) + { + return false; + } + else if (s[0] == 'Z') + { + if (n != 1) + return false; + + h = 0; + m = 0; + } + else + { + if (n != 6 || (s[0] != '-' && s[0] != '+') || s[3] != ':') + return false; + + // Parse hours. + // + char d1 = s[1]; + char d2 = s[2]; + + if (d1 < '0' || d1 > '9' || d2 < '0' || d2 > '9') + return false; + + h = 10 * (d1 - '0') + (d2 - '0'); + + if (h > 14) + return false; + + // Parse minutes. + // + d1 = s[4]; + d2 = s[5]; + + if (d1 < '0' || d1 > '9' || d2 < '0' || d2 > '9') + return false; + + m = 10 * (d1 - '0') + (d2 - '0'); + + if (m > 59 || (h == 14 && m != 0)) + return false; + + if (s[0] == '-') + { + h = -h; + m = -m; + } + } + + return true; + } + } + + // gday + // + template + void gday_pimpl:: + _pre () + { + str_.clear (); + } + + template + void gday_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + template + void gday_pimpl:: + _post () + { + typedef typename ro_string::size_type size_type; + + ro_string tmp (str_); + size_type size (trim_right (tmp)); + const C* s (tmp.data ()); + + // gday := ---DD[Z|(+|-)HH:MM] + // + if (size < 5 || + s[0] != C ('-') || s[1] != C ('-') || s[2] != C ('-')) + throw invalid_value (bits::gday (), tmp); + + C d1 (s[3]), d2 (s[4]); + + if (d1 < '0' || d1 > '9' || d2 < '0' || d2 > '9') + throw invalid_value (bits::gday (), tmp); + + day_ = 10 * (d1 - '0') + (d2 - '0'); + + if (day_ < 1 || day_ > 31) + throw invalid_value (bits::gday (), tmp); + + if (size > 5) + { + if (!bits::parse_tz (s + 5, size - 5, zh_, zm_)) + throw invalid_value (bits::gday (), tmp); + + z_ = true; + } + else + z_ = false; + } + + template + gday gday_pimpl:: + post_gday () + { + return z_ ? gday (day_, zh_, zm_) : gday (day_); + } + + // gmonth + // + template + void gmonth_pimpl:: + _pre () + { + str_.clear (); + } + + template + void gmonth_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + template + void gmonth_pimpl:: + _post () + { + typedef typename ro_string::size_type size_type; + + ro_string tmp (str_); + size_type size (trim_right (tmp)); + const C* s (tmp.data ()); + + // gmonth := --MM[Z|(+|-)HH:MM] + // + if (size < 4 || s[0] != C ('-') || s[1] != C ('-')) + throw invalid_value (bits::gmonth (), tmp); + + C d1 (s[2]), d2 (s[3]); + + if (d1 < '0' || d1 > '9' || d2 < '0' || d2 > '9') + throw invalid_value (bits::gmonth (), tmp); + + month_ = 10 * (d1 - '0') + (d2 - '0'); + + if (month_ < 1 || month_ > 12) + throw invalid_value (bits::gmonth (), tmp); + + if (size > 4) + { + if (!bits::parse_tz (s + 4, size - 4, zh_, zm_)) + throw invalid_value (bits::gmonth (), tmp); + + z_ = true; + } + else + z_ = false; + } + + template + gmonth gmonth_pimpl:: + post_gmonth () + { + return z_ ? gmonth (month_, zh_, zm_) : gmonth (month_); + } + + // gyear + // + template + void gyear_pimpl:: + _pre () + { + str_.clear (); + } + + template + void gyear_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + template + void gyear_pimpl:: + _post () + { + typedef typename ro_string::size_type size_type; + + ro_string tmp (str_); + size_type size (trim_right (tmp)); + const C* s (tmp.data ()); + + // gyear := [-]CCYY[N]*[Z|(+|-)HH:MM] + // + + if (size < 4 || (s[0] == C ('-') && size < 5)) + throw invalid_value (bits::gyear (), tmp); + + // Find the end of the year token. + // + size_type pos (s[0] == C ('-') ? 5 : 4); + for (; pos < size; ++pos) + { + C c (s[pos]); + + if (c == C ('Z') || c == C ('+') || c == C ('-')) + break; + } + + ro_string year_fragment (s, pos); + zc_istream is (year_fragment); + + if (!(is >> year_ && is.exhausted () && year_ != 0)) + throw invalid_value (bits::gyear (), tmp); + + if (pos < size) + { + if (!bits::parse_tz (s + pos, size - pos, zh_, zm_)) + throw invalid_value (bits::gyear (), tmp); + + z_ = true; + } + else + z_ = false; + } + + template + gyear gyear_pimpl:: + post_gyear () + { + return z_ ? gyear (year_, zh_, zm_) : gyear (year_); + } + + // gmonth_day + // + template + void gmonth_day_pimpl:: + _pre () + { + str_.clear (); + } + + template + void gmonth_day_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + template + void gmonth_day_pimpl:: + _post () + { + typedef typename ro_string::size_type size_type; + + ro_string tmp (str_); + size_type size (trim_right (tmp)); + const C* s (tmp.data ()); + + // gmonth_day := --MM-DD[Z|(+|-)HH:MM] + // + if (size < 7 || + s[0] != C ('-') || s[1] != C ('-') || s[4] != C ('-')) + throw invalid_value (bits::gmonth_day (), tmp); + + // month + // + C d1 (s[2]), d2 (s[3]); + + if (d1 < '0' || d1 > '9' || d2 < '0' || d2 > '9') + throw invalid_value (bits::gmonth_day (), tmp); + + month_ = 10 * (d1 - '0') + (d2 - '0'); + + if (month_ < 1 || month_ > 12) + throw invalid_value (bits::gmonth_day (), tmp); + + // day + // + d1 = s[5]; + d2 = s[6]; + + if (d1 < '0' || d1 > '9' || d2 < '0' || d2 > '9') + throw invalid_value (bits::gmonth_day (), tmp); + + day_ = 10 * (d1 - '0') + (d2 - '0'); + + if (day_ < 1 || day_ > 31) + throw invalid_value (bits::gmonth_day (), tmp); + + // zone + // + if (size > 7) + { + if (!bits::parse_tz (s + 7, size - 7, zh_, zm_)) + throw invalid_value (bits::gmonth_day (), tmp); + + z_ = true; + } + else + z_ = false; + } + + template + gmonth_day gmonth_day_pimpl:: + post_gmonth_day () + { + return z_ + ? gmonth_day (month_, day_, zh_, zm_) + : gmonth_day (month_, day_); + } + + // gyear_month + // + template + void gyear_month_pimpl:: + _pre () + { + str_.clear (); + } + + template + void gyear_month_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + template + void gyear_month_pimpl:: + _post () + { + typedef typename ro_string::size_type size_type; + + ro_string tmp (str_); + size_type size (trim_right (tmp)); + const C* s (tmp.data ()); + + // gyear_month := [-]CCYY[N]*-MM[Z|(+|-)HH:MM] + // + + if (size < 7 || (s[0] == C ('-') && size < 8)) + throw invalid_value (bits::gyear_month (), tmp); + + // Find the end of the year token. + // + size_type pos (tmp.find (C ('-'), s[0] == C ('-') ? 5 : 4)); + + if (pos == ro_string::npos || (size - pos - 1) < 2) + throw invalid_value (bits::gyear_month (), tmp); + + ro_string year_fragment (s, pos); + zc_istream yis (year_fragment); + + if (!(yis >> year_ && yis.exhausted () && year_ != 0)) + throw invalid_value (bits::gyear_month (), tmp); + + // month + // + C d1 (s[pos + 1]), d2 (s[pos + 2]); + + if (d1 < '0' || d1 > '9' || d2 < '0' || d2 > '9') + throw invalid_value (bits::gyear_month (), tmp); + + month_ = 10 * (d1 - '0') + (d2 - '0'); + + if (month_ < 1 || month_ > 12) + throw invalid_value (bits::gyear_month (), tmp); + + // zone + // + pos += 3; + + if (pos < size) + { + if (!bits::parse_tz (s + pos, size - pos, zh_, zm_)) + throw invalid_value (bits::gyear_month (), tmp); + + z_ = true; + } + else + z_ = false; + } + + template + gyear_month gyear_month_pimpl:: + post_gyear_month () + { + return z_ + ? gyear_month (year_, month_, zh_, zm_) + : gyear_month (year_, month_); + } + + // date + // + template + void date_pimpl:: + _pre () + { + str_.clear (); + } + + template + void date_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + template + void date_pimpl:: + _post () + { + typedef typename ro_string::size_type size_type; + + ro_string tmp (str_); + size_type size (trim_right (tmp)); + const C* s (tmp.data ()); + + // date := [-]CCYY[N]*-MM-DD[Z|(+|-)HH:MM] + // + + if (size < 10 || (s[0] == C ('-') && size < 11)) + throw invalid_value (bits::date (), tmp); + + // Find the end of the year token. + // + size_type pos (tmp.find (C ('-'), s[0] == C ('-') ? 5 : 4)); + + if (pos == ro_string::npos + || (size - pos - 1) < 5 + || s[pos + 3] != C ('-')) + throw invalid_value (bits::date (), tmp); + + ro_string year_fragment (s, pos); + zc_istream yis (year_fragment); + + if (!(yis >> year_ && yis.exhausted () && year_ != 0)) + throw invalid_value (bits::date (), tmp); + + // month + // + C d1 (s[pos + 1]), d2 (s[pos + 2]); + + if (d1 < '0' || d1 > '9' || d2 < '0' || d2 > '9') + throw invalid_value (bits::date (), tmp); + + month_ = 10 * (d1 - '0') + (d2 - '0'); + + if (month_ < 1 || month_ > 12) + throw invalid_value (bits::date (), tmp); + + // day + // + d1 = s[pos + 4]; + d2 = s[pos + 5]; + + if (d1 < '0' || d1 > '9' || d2 < '0' || d2 > '9') + throw invalid_value (bits::date (), tmp); + + day_ = 10 * (d1 - '0') + (d2 - '0'); + + if (day_ < 1 || day_ > 31) + throw invalid_value (bits::date (), tmp); + + // zone + // + pos += 6; + + if (pos < size) + { + if (!bits::parse_tz (s + pos, size - pos, zh_, zm_)) + throw invalid_value (bits::date (), tmp); + + z_ = true; + } + else + z_ = false; + } + + template + date date_pimpl:: + post_date () + { + return z_ + ? date (year_, month_, day_, zh_, zm_) + : date (year_, month_, day_); + } + + // time + // + template + void time_pimpl:: + _pre () + { + str_.clear (); + } + + template + void time_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + template + void time_pimpl:: + _post () + { + typedef typename ro_string::size_type size_type; + + ro_string tmp (str_); + size_type size (trim_right (tmp)); + const C* s (tmp.data ()); + + // time := HH:MM:SS[.S+][Z|(+|-)HH:MM] + // + + if (size < 8 || s[2] != C (':') || s[5] != C (':')) + throw invalid_value (bits::time (), tmp); + + // hours + // + C d1 (s[0]), d2 (s[1]); + + if (d1 < '0' || d1 > '9' || d2 < '0' || d2 > '9') + throw invalid_value (bits::time (), tmp); + + hours_ = 10 * (d1 - '0') + (d2 - '0'); + + if (hours_ > 24) + throw invalid_value (bits::time (), tmp); + + // minutes + // + d1 = s[3]; + d2 = s[4]; + + if (d1 < '0' || d1 > '9' || d2 < '0' || d2 > '9') + throw invalid_value (bits::time (), tmp); + + minutes_ = 10 * (d1 - '0') + (d2 - '0'); + + if (minutes_ > 59) + throw invalid_value (bits::time (), tmp); + + // Find the end of the seconds fragment. + // + size_type pos (8); + for (; pos < size; ++pos) + { + C c (s[pos]); + + if (c == C ('Z') || c == C ('+') || c == C ('-')) + break; + } + + // At least one digit should follow the fraction point. + // + if ((pos - 6) == 3) + throw invalid_value (bits::time (), tmp); + + ro_string seconds_fragment (s + 6, pos - 6); + zc_istream sis (seconds_fragment); + + if (!(sis >> seconds_ && sis.exhausted () && seconds_ < 60.0)) + throw invalid_value (bits::time (), tmp); + + if (hours_ == 24 && (minutes_ != 0 || seconds_ != 0.0)) + throw invalid_value (bits::time (), tmp); + + // zone + // + if (pos < size) + { + if (!bits::parse_tz (s + pos, size - pos, zh_, zm_)) + throw invalid_value (bits::time (), tmp); + + z_ = true; + } + else + z_ = false; + } + + template + time time_pimpl:: + post_time () + { + return z_ + ? time (hours_, minutes_, seconds_, zh_, zm_) + : time (hours_, minutes_, seconds_); + } + + + // date_time + // + template + void date_time_pimpl:: + _pre () + { + str_.clear (); + } + + template + void date_time_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + template + void date_time_pimpl:: + _post () + { + typedef typename ro_string::size_type size_type; + + ro_string tmp (str_); + size_type size (trim_right (tmp)); + const C* s (tmp.data ()); + + // date_time := [-]CCYY[N]*-MM-DDTHH:MM:SS[.S+][Z|(+|-)HH:MM] + // + + if (size < 19 || (s[0] == C ('-') && size < 20)) + throw invalid_value (bits::date_time (), tmp); + + // Find the end of the year token. + // + size_type pos (tmp.find (C ('-'), s[0] == C ('-') ? 5 : 4)); + + if (pos == ro_string::npos || (size - pos - 1) < 14 + || s[pos + 3] != C ('-') || s[pos + 6] != C ('T') + || s[pos + 9] != C (':') || s[pos + 12] != C (':')) + throw invalid_value (bits::date_time (), tmp); + + // year + // + ro_string year_fragment (s, pos); + zc_istream yis (year_fragment); + + if (!(yis >> year_ && yis.exhausted () && year_ != 0)) + throw invalid_value (bits::date_time (), tmp); + + // month + // + C d1 (s[pos + 1]), d2 (s[pos + 2]); + + if (d1 < '0' || d1 > '9' || d2 < '0' || d2 > '9') + throw invalid_value (bits::date_time (), tmp); + + month_ = 10 * (d1 - '0') + (d2 - '0'); + + if (month_ < 1 || month_ > 12) + throw invalid_value (bits::date_time (), tmp); + + // day + // + d1 = s[pos + 4]; + d2 = s[pos + 5]; + + if (d1 < '0' || d1 > '9' || d2 < '0' || d2 > '9') + throw invalid_value (bits::date_time (), tmp); + + day_ = 10 * (d1 - '0') + (d2 - '0'); + + if (day_ < 1 || day_ > 31) + throw invalid_value (bits::date_time (), tmp); + + pos += 7; // Point to the first H. + + // hours + // + d1 = s[pos]; + d2 = s[pos + 1]; + + if (d1 < '0' || d1 > '9' || d2 < '0' || d2 > '9') + throw invalid_value (bits::date_time (), tmp); + + hours_ = 10 * (d1 - '0') + (d2 - '0'); + + if (hours_ > 24) + throw invalid_value (bits::date_time (), tmp); + + // minutes + // + d1 = s[pos + 3]; + d2 = s[pos + 4]; + + if (d1 < '0' || d1 > '9' || d2 < '0' || d2 > '9') + throw invalid_value (bits::date_time (), tmp); + + minutes_ = 10 * (d1 - '0') + (d2 - '0'); + + if (minutes_ > 59) + throw invalid_value (bits::date_time (), tmp); + + // Find the end of the seconds fragment. + // + pos += 6; // Point to the first S. + + size_type sec_end (pos + 2); + for (; sec_end < size; ++sec_end) + { + C c (s[sec_end]); + + if (c == C ('Z') || c == C ('+') || c == C ('-')) + break; + } + + // At least one digit should should follow the fraction point. + // + if ((sec_end - pos) == 3) + throw invalid_value (bits::date_time (), tmp); + + ro_string seconds_fragment (s + pos, sec_end - pos); + zc_istream sis (seconds_fragment); + + if (!(sis >> seconds_ && sis.exhausted () && seconds_ < 60.0)) + throw invalid_value (bits::date_time (), tmp); + + if (hours_ == 24 && (minutes_ != 0 || seconds_ != 0.0)) + throw invalid_value (bits::date_time (), tmp); + + // zone + // + if (sec_end < size) + { + if (!bits::parse_tz (s + sec_end, size - sec_end, zh_, zm_)) + throw invalid_value (bits::date_time (), tmp); + + z_ = true; + } + else + z_ = false; + } + + template + date_time date_time_pimpl:: + post_date_time () + { + return z_ + ? date_time (year_, month_, day_, hours_, minutes_, seconds_, + zh_, zm_) + : date_time (year_, month_, day_, hours_, minutes_, seconds_); + } + + // duration + // + template + void duration_pimpl:: + _pre () + { + str_.clear (); + } + + template + void duration_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + namespace bits + { + template + inline typename ro_string::size_type + duration_delim (const C* s, + typename ro_string::size_type pos, + typename ro_string::size_type size) + { + const C* p (s + pos); + for (; p < (s + size); ++p) + { + if (*p == C ('Y') || *p == C ('D') || *p == C ('M') || + *p == C ('H') || *p == C ('M') || *p == C ('S') || + *p == C ('T')) + break; + } + + return p - s; + } + } + + template + void duration_pimpl:: + _post () + { + typedef typename ro_string::size_type size_type; + + ro_string tmp (str_); + size_type size (trim_right (tmp)); + + negative_ = false; + years_ = 0; + months_ = 0; + days_ = 0; + hours_ = 0; + minutes_ = 0; + seconds_ = 0.0; + + // duration := [-]P[nY][nM][nD][TnHnMn[.n+]S] + // + const C* s (tmp.data ()); + + if (size < 3 || (s[0] == C ('-') && size < 4)) + throw invalid_value (bits::duration (), tmp); + + size_type pos (0); + + if (s[0] == C ('-')) + { + negative_ = true; + pos++; + } + + if (s[pos++] != C ('P')) + throw invalid_value (bits::duration (), tmp); + + size_type del (bits::duration_delim (s, pos, size)); + + // Duration should contain at least one component. + // + if (del == size) + throw invalid_value (bits::duration (), tmp); + + if (s[del] == C ('Y')) + { + ro_string fragment (s + pos, del - pos); + zc_istream is (fragment); + + if (!(is >> years_ && is.exhausted ())) + throw invalid_value (bits::duration (), tmp); + + pos = del + 1; + del = bits::duration_delim (s, pos, size); + } + + if (del != size && s[del] == C ('M')) + { + ro_string fragment (s + pos, del - pos); + zc_istream is (fragment); + + if (!(is >> months_ && is.exhausted ())) + throw invalid_value (bits::duration (), tmp); + + pos = del + 1; + del = bits::duration_delim (s, pos, size); + } + + if (del != size && s[del] == C ('D')) + { + ro_string fragment (s + pos, del - pos); + zc_istream is (fragment); + + if (!(is >> days_ && is.exhausted ())) + throw invalid_value (bits::duration (), tmp); + + pos = del + 1; + del = bits::duration_delim (s, pos, size); + } + + if (del != size && s[del] == C ('T')) + { + pos = del + 1; + del = bits::duration_delim (s, pos, size); + + // At least one time component should be present. + // + if (del == size) + throw invalid_value (bits::duration (), tmp); + + if (s[del] == C ('H')) + { + ro_string fragment (s + pos, del - pos); + zc_istream is (fragment); + + if (!(is >> hours_ && is.exhausted ())) + throw invalid_value (bits::duration (), tmp); + + pos = del + 1; + del = bits::duration_delim (s, pos, size); + } + + if (del != size && s[del] == C ('M')) + { + ro_string fragment (s + pos, del - pos); + zc_istream is (fragment); + + if (!(is >> minutes_ && is.exhausted ())) + throw invalid_value (bits::duration (), tmp); + + pos = del + 1; + del = bits::duration_delim (s, pos, size); + } + + if (del != size && s[del] == C ('S')) + { + ro_string fragment (s + pos, del - pos); + zc_istream is (fragment); + + if (!(is >> seconds_ && is.exhausted () && seconds_ >= 0.0)) + throw invalid_value (bits::duration (), tmp); + + pos = del + 1; + } + } + + // Something did not match or appeared in the wrong order. + // + if (pos != size) + throw invalid_value (bits::duration (), tmp); + } + + template + duration duration_pimpl:: + post_duration () + { + return duration ( + negative_, years_, months_, days_, hours_, minutes_, seconds_); + } + } + } + } +} diff --git a/libxsd/xsd/cxx/parser/validating/xml-schema-pskel.hxx b/libxsd/xsd/cxx/parser/validating/xml-schema-pskel.hxx new file mode 100644 index 0000000..0fca037 --- /dev/null +++ b/libxsd/xsd/cxx/parser/validating/xml-schema-pskel.hxx @@ -0,0 +1,647 @@ +// file : xsd/cxx/parser/validating/xml-schema-pskel.hxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_PARSER_VALIDATING_XML_SCHEMA_PSKEL_HXX +#define XSD_CXX_PARSER_VALIDATING_XML_SCHEMA_PSKEL_HXX + +#include +#include // auto_ptr + +#include +#include + +namespace xsd +{ + namespace cxx + { + namespace parser + { + namespace validating + { + // anyType and anySimpleType. All events are routed to the + // _any_* callbacks. + // + template + struct any_type_pskel: complex_content + { + virtual bool + _start_element_impl (const ro_string&, + const ro_string&, + const ro_string*); + + virtual bool + _end_element_impl (const ro_string&, + const ro_string&); + + virtual bool + _attribute_impl_phase_two (const ro_string&, + const ro_string&, + const ro_string&); + + virtual bool + _characters_impl (const ro_string&); + + virtual void + post_any_type () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct any_simple_type_pskel: simple_content + { + virtual bool + _characters_impl (const ro_string&); + + virtual void + post_any_simple_type () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + + // Boolean. + // + template + struct boolean_pskel: simple_content + { + virtual bool + post_boolean () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + + // 8-bit + // + template + struct byte_pskel: simple_content + { + virtual signed char + post_byte () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct unsigned_byte_pskel: simple_content + { + virtual unsigned char + post_unsigned_byte () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + + // 16-bit + // + template + struct short_pskel: simple_content + { + virtual short + post_short () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct unsigned_short_pskel: simple_content + { + virtual unsigned short + post_unsigned_short () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + + // 32-bit + // + template + struct int_pskel: simple_content + { + virtual int + post_int () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct unsigned_int_pskel: simple_content + { + virtual unsigned int + post_unsigned_int () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + + // 64-bit + // + template + struct long_pskel: simple_content + { + virtual long long + post_long () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct unsigned_long_pskel: simple_content + { + virtual unsigned long long + post_unsigned_long () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + + // Arbitrary-length integers. + // + template + struct integer_pskel: simple_content + { + virtual long long + post_integer () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct negative_integer_pskel: simple_content + { + virtual long long + post_negative_integer () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct non_positive_integer_pskel: simple_content + { + virtual long long + post_non_positive_integer () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct positive_integer_pskel: simple_content + { + virtual unsigned long long + post_positive_integer () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct non_negative_integer_pskel: simple_content + { + virtual unsigned long long + post_non_negative_integer () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + + // Floats. + // + template + struct float_pskel: simple_content + { + virtual float + post_float () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct double_pskel: simple_content + { + virtual double + post_double () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct decimal_pskel: simple_content + { + virtual double + post_decimal () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + + // Strings. + // + template + struct string_pskel: simple_content + { + virtual std::basic_string + post_string () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct normalized_string_pskel: simple_content + { + virtual std::basic_string + post_normalized_string () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct token_pskel: simple_content + { + virtual std::basic_string + post_token () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct name_pskel: simple_content + { + virtual std::basic_string + post_name () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct nmtoken_pskel: simple_content + { + virtual std::basic_string + post_nmtoken () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct nmtokens_pskel: list_base + { + virtual string_sequence + post_nmtokens () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct ncname_pskel: simple_content + { + virtual std::basic_string + post_ncname () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct id_pskel: simple_content + { + virtual std::basic_string + post_id () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct idref_pskel: simple_content + { + virtual std::basic_string + post_idref () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct idrefs_pskel: list_base + { + virtual string_sequence + post_idrefs () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + // Language. + // + template + struct language_pskel: simple_content + { + virtual std::basic_string + post_language () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + // URI. + // + template + struct uri_pskel: simple_content + { + virtual std::basic_string + post_uri () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + // QName. + // + template + struct qname_pskel: simple_content + { + virtual qname + post_qname () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + // Base64 and hex binaries. + // + template + struct base64_binary_pskel: simple_content + { + virtual std::auto_ptr + post_base64_binary () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct hex_binary_pskel: simple_content + { + virtual std::auto_ptr + post_hex_binary () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + // Time and date types. + // + template + struct gday_pskel: simple_content + { + virtual gday + post_gday () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct gmonth_pskel: simple_content + { + virtual gmonth + post_gmonth () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct gyear_pskel: simple_content + { + virtual gyear + post_gyear () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct gmonth_day_pskel: simple_content + { + virtual gmonth_day + post_gmonth_day () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct gyear_month_pskel: simple_content + { + virtual gyear_month + post_gyear_month () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct date_pskel: simple_content + { + virtual date + post_date () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct time_pskel: simple_content + { + virtual time + post_time () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct date_time_pskel: simple_content + { + virtual date_time + post_date_time () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct duration_pskel: simple_content + { + virtual duration + post_duration () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + } + } + } +} + +#include + +#endif // XSD_CXX_PARSER_VALIDATING_XML_SCHEMA_PSKEL_HXX + +#include diff --git a/libxsd/xsd/cxx/parser/validating/xml-schema-pskel.ixx b/libxsd/xsd/cxx/parser/validating/xml-schema-pskel.ixx new file mode 100644 index 0000000..7a9f5e5 --- /dev/null +++ b/libxsd/xsd/cxx/parser/validating/xml-schema-pskel.ixx @@ -0,0 +1,1249 @@ +// file : xsd/cxx/parser/validating/xml-schema-pskel.ixx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#if defined(XSD_CXX_PARSER_USE_CHAR) || !defined(XSD_CXX_PARSER_USE_WCHAR) + +#ifndef XSD_CXX_PARSER_VALIDATING_XML_SCHEMA_PSKEL_IXX_CHAR +#define XSD_CXX_PARSER_VALIDATING_XML_SCHEMA_PSKEL_IXX_CHAR + +namespace xsd +{ + namespace cxx + { + namespace parser + { + namespace validating + { + template<> + inline const char* any_type_pskel:: + _static_type () + { + return "anyType http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* any_type_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* any_simple_type_pskel:: + _static_type () + { + return "anySimpleType http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* any_simple_type_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* boolean_pskel:: + _static_type () + { + return "boolean http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* boolean_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* byte_pskel:: + _static_type () + { + return "byte http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* byte_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* unsigned_byte_pskel:: + _static_type () + { + return "unsignedByte http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* unsigned_byte_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* short_pskel:: + _static_type () + { + return "short http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* short_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* unsigned_short_pskel:: + _static_type () + { + return "unsignedShort http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* unsigned_short_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* int_pskel:: + _static_type () + { + return "int http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* int_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* unsigned_int_pskel:: + _static_type () + { + return "unsignedInt http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* unsigned_int_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* long_pskel:: + _static_type () + { + return "long http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* long_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* unsigned_long_pskel:: + _static_type () + { + return "unsignedLong http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* unsigned_long_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* integer_pskel:: + _static_type () + { + return "integer http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* integer_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* negative_integer_pskel:: + _static_type () + { + return "negativeInteger http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* negative_integer_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* non_positive_integer_pskel:: + _static_type () + { + return "nonPositiveInteger http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* non_positive_integer_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* positive_integer_pskel:: + _static_type () + { + return "positiveInteger http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* positive_integer_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* non_negative_integer_pskel:: + _static_type () + { + return "nonNegativeInteger http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* non_negative_integer_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* float_pskel:: + _static_type () + { + return "float http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* float_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* double_pskel:: + _static_type () + { + return "double http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* double_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* decimal_pskel:: + _static_type () + { + return "decimal http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* decimal_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* string_pskel:: + _static_type () + { + return "string http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* string_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* normalized_string_pskel:: + _static_type () + { + return "normalizedString http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* normalized_string_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* token_pskel:: + _static_type () + { + return "token http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* token_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* name_pskel:: + _static_type () + { + return "Name http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* name_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* nmtoken_pskel:: + _static_type () + { + return "NMTOKEN http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* nmtoken_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* nmtokens_pskel:: + _static_type () + { + return "NMTOKENS http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* nmtokens_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* ncname_pskel:: + _static_type () + { + return "NCName http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* ncname_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* id_pskel:: + _static_type () + { + return "ID http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* id_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* idref_pskel:: + _static_type () + { + return "IDREF http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* idref_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* idrefs_pskel:: + _static_type () + { + return "IDREFS http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* idrefs_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* language_pskel:: + _static_type () + { + return "language http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* language_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* uri_pskel:: + _static_type () + { + return "anyURI http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* uri_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* qname_pskel:: + _static_type () + { + return "QName http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* qname_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* base64_binary_pskel:: + _static_type () + { + return "base64Binary http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* base64_binary_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* hex_binary_pskel:: + _static_type () + { + return "hexBinary http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* hex_binary_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* gday_pskel:: + _static_type () + { + return "gDay http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* gday_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* gmonth_pskel:: + _static_type () + { + return "gMonth http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* gmonth_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* gyear_pskel:: + _static_type () + { + return "gYear http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* gyear_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* gmonth_day_pskel:: + _static_type () + { + return "gMonthDay http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* gmonth_day_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* gyear_month_pskel:: + _static_type () + { + return "gYearMonth http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* gyear_month_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* date_pskel:: + _static_type () + { + return "date http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* date_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* time_pskel:: + _static_type () + { + return "time http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* time_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* date_time_pskel:: + _static_type () + { + return "dateTime http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* date_time_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* duration_pskel:: + _static_type () + { + return "duration http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* duration_pskel:: + _dynamic_type () const + { + return _static_type (); + } + } + } + } +} + +#endif // XSD_CXX_PARSER_VALIDATING_XML_SCHEMA_PSKEL_IXX_CHAR +#endif // XSD_CXX_PARSER_USE_CHAR + + +#if defined(XSD_CXX_PARSER_USE_WCHAR) || !defined(XSD_CXX_PARSER_USE_CHAR) + +#ifndef XSD_CXX_PARSER_VALIDATING_XML_SCHEMA_PSKEL_IXX_WCHAR +#define XSD_CXX_PARSER_VALIDATING_XML_SCHEMA_PSKEL_IXX_WCHAR + +namespace xsd +{ + namespace cxx + { + namespace parser + { + namespace validating + { + template<> + inline const wchar_t* any_type_pskel:: + _static_type () + { + return L"anyType http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* any_type_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* any_simple_type_pskel:: + _static_type () + { + return L"anySimpleType http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* any_simple_type_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* boolean_pskel:: + _static_type () + { + return L"boolean http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* boolean_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* byte_pskel:: + _static_type () + { + return L"byte http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* byte_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* unsigned_byte_pskel:: + _static_type () + { + return L"unsignedByte http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* unsigned_byte_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* short_pskel:: + _static_type () + { + return L"short http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* short_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* unsigned_short_pskel:: + _static_type () + { + return L"unsignedShort http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* unsigned_short_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* int_pskel:: + _static_type () + { + return L"int http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* int_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* unsigned_int_pskel:: + _static_type () + { + return L"unsignedInt http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* unsigned_int_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* long_pskel:: + _static_type () + { + return L"long http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* long_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* unsigned_long_pskel:: + _static_type () + { + return L"unsignedLong http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* unsigned_long_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* integer_pskel:: + _static_type () + { + return L"integer http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* integer_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* negative_integer_pskel:: + _static_type () + { + return L"negativeInteger http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* negative_integer_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* non_positive_integer_pskel:: + _static_type () + { + return L"nonPositiveInteger http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* non_positive_integer_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* positive_integer_pskel:: + _static_type () + { + return L"positiveInteger http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* positive_integer_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* non_negative_integer_pskel:: + _static_type () + { + return L"nonNegativeInteger http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* non_negative_integer_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* float_pskel:: + _static_type () + { + return L"float http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* float_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* double_pskel:: + _static_type () + { + return L"double http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* double_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* decimal_pskel:: + _static_type () + { + return L"decimal http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* decimal_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* string_pskel:: + _static_type () + { + return L"string http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* string_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* normalized_string_pskel:: + _static_type () + { + return L"normalizedString http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* normalized_string_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* token_pskel:: + _static_type () + { + return L"token http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* token_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* name_pskel:: + _static_type () + { + return L"Name http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* name_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* nmtoken_pskel:: + _static_type () + { + return L"NMTOKEN http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* nmtoken_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* nmtokens_pskel:: + _static_type () + { + return L"NMTOKENS http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* nmtokens_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* ncname_pskel:: + _static_type () + { + return L"NCName http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* ncname_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* id_pskel:: + _static_type () + { + return L"ID http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* id_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* idref_pskel:: + _static_type () + { + return L"IDREF http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* idref_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* idrefs_pskel:: + _static_type () + { + return L"IDREFS http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* idrefs_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* language_pskel:: + _static_type () + { + return L"language http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* language_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* uri_pskel:: + _static_type () + { + return L"anyURI http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* uri_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* qname_pskel:: + _static_type () + { + return L"QName http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* qname_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* base64_binary_pskel:: + _static_type () + { + return L"base64Binary http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* base64_binary_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* hex_binary_pskel:: + _static_type () + { + return L"hexBinary http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* hex_binary_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* gday_pskel:: + _static_type () + { + return L"gDay http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* gday_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* gmonth_pskel:: + _static_type () + { + return L"gMonth http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* gmonth_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* gyear_pskel:: + _static_type () + { + return L"gYear http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* gyear_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* gmonth_day_pskel:: + _static_type () + { + return L"gMonthDay http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* gmonth_day_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* gyear_month_pskel:: + _static_type () + { + return L"gYearMonth http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* gyear_month_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* date_pskel:: + _static_type () + { + return L"date http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* date_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* time_pskel:: + _static_type () + { + return L"time http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* time_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* date_time_pskel:: + _static_type () + { + return L"dateTime http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* date_time_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* duration_pskel:: + _static_type () + { + return L"duration http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* duration_pskel:: + _dynamic_type () const + { + return _static_type (); + } + } + } + } +} + +#endif // XSD_CXX_PARSER_VALIDATING_XML_SCHEMA_PSKEL_IXX_WCHAR +#endif // XSD_CXX_PARSER_USE_WCHAR diff --git a/libxsd/xsd/cxx/parser/validating/xml-schema-pskel.txx b/libxsd/xsd/cxx/parser/validating/xml-schema-pskel.txx new file mode 100644 index 0000000..c5fe5ef --- /dev/null +++ b/libxsd/xsd/cxx/parser/validating/xml-schema-pskel.txx @@ -0,0 +1,69 @@ +// file : xsd/cxx/parser/validating/xml-schema-pskel.txx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsd +{ + namespace cxx + { + namespace parser + { + namespace validating + { + // any_type + // + + template + bool any_type_pskel:: + _start_element_impl (const ro_string& ns, + const ro_string& name, + const ro_string* type) + { + _start_any_element (ns, name, type); + this->complex_content::context_.top ().any_ = true; + return true; + } + + template + bool any_type_pskel:: + _end_element_impl (const ro_string& ns, const ro_string& name) + { + this->complex_content::context_.top ().any_ = false; + _end_any_element (ns, name); + return true; + } + + + template + bool any_type_pskel:: + _attribute_impl_phase_two (const ro_string& ns, + const ro_string& name, + const ro_string& value) + { + _any_attribute (ns, name, value); + return true; + } + + template + bool any_type_pskel:: + _characters_impl (const ro_string& s) + { + _any_characters (s); + return true; + } + + // any_simple_type + // + + template + bool any_simple_type_pskel:: + _characters_impl (const ro_string& s) + { + _any_characters (s); + return true; + } + } + } + } +} diff --git a/libxsd/xsd/cxx/parser/xerces/elements.hxx b/libxsd/xsd/cxx/parser/xerces/elements.hxx new file mode 100644 index 0000000..9d79e61 --- /dev/null +++ b/libxsd/xsd/cxx/parser/xerces/elements.hxx @@ -0,0 +1,462 @@ +// file : xsd/cxx/parser/xerces/elements.hxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_PARSER_XERCES_ELEMENTS_HXX +#define XSD_CXX_PARSER_XERCES_ELEMENTS_HXX + +#include // std::auto_ptr +#include +#include +#include + +#include +#include +#include +#include + +#include +#include + +#include +#include +#include + +namespace xsd +{ + namespace cxx + { + namespace parser + { + namespace xerces + { + // + // + struct flags + { + // Use the following flags to modify the default behavior + // of the parsing functions. + // + + // Do not try to validate instance documents. + // + static const unsigned long dont_validate = 0x00000001; + + // Do not initialize the Xerces-C++ runtime. + // + static const unsigned long dont_initialize = 0x00000002; + + // Disable handling of subsequent imports for the same namespace + // in Xerces-C++ 3-series. + // + static const unsigned long no_multiple_imports = 0x00000004; + + public: + flags (unsigned long x = 0) + : x_ (x) + { + } + + operator unsigned long () const + { + return x_; + } + + private: + unsigned long x_; + }; + + + // Parsing properties. Refer to xsd/cxx/xml/elements.hxx for + // XML-related properties. + // + template + class properties: public xml::properties + { + }; + + // + // + template + struct document: cxx::parser::document // VC 7.1 likes it qualified + { + public: + document (parser_base& root, + const C* root_element_name, + bool polymorphic = false); + + document (parser_base& root, + const std::basic_string& root_element_name, + bool polymorphic = false); + + document (parser_base& root, + const C* root_element_namespace, + const C* root_element_name, + bool polymorphic = false); + + document (parser_base& root, + const std::basic_string& root_element_namespace, + const std::basic_string& root_element_name, + bool polymorphic = false); + + protected: + explicit + document (bool polymorphic = false); + + public: + // Parse URI or a local file. We have to overload it for const C* + // bacause xercesc::InputSource has an implicit constructor that + // takes const char*. + // + void + parse (const std::basic_string& uri, + flags = 0, + const properties& = properties ()); + + void + parse (const C* uri, + flags = 0, + const properties& = properties ()); + + + // Parse URI or a local file with a user-provided error_handler + // object. + // + void + parse (const std::basic_string& uri, + xml::error_handler&, + flags = 0, + const properties& = properties ()); + + void + parse (const C* uri, + xml::error_handler&, + flags = 0, + const properties& = properties ()); + + + // Parse URI or a local file with a user-provided ErrorHandler + // object. Note that you must initialize the Xerces-C++ runtime + // before calling these functions. + // + void + parse (const std::basic_string& uri, + xercesc::ErrorHandler&, + flags = 0, + const properties& = properties ()); + + void + parse (const C* uri, + xercesc::ErrorHandler&, + flags = 0, + const properties& = properties ()); + + + // Parse URI or a local file using a user-provided SAX2XMLReader + // object. Note that you must initialize the Xerces-C++ runtime + // before calling these functions. + // + void + parse (const std::basic_string& uri, + xercesc::SAX2XMLReader&, + flags = 0, + const properties& = properties ()); + + void + parse (const C* uri, + xercesc::SAX2XMLReader&, + flags = 0, + const properties& = properties ()); + + + public: + // System id is a "system" identifier of the resources (e.g., + // URI or a full file path). Public id is a "public" identifier + // of the resource (e.g., an application-specific name or a + // relative file path). System id is used to resolve relative + // paths. In diagnostics messages system id is used if public + // id is not available. Otherwise public id is used. + // + + // Parse std::istream. + // + void + parse (std::istream&, + flags = 0, + const properties& = properties ()); + + + // Parse std::istream with a user-provided error_handler object. + // + void + parse (std::istream&, + xml::error_handler&, + flags = 0, + const properties& = properties ()); + + + // Parse std::istream with a user-provided ErrorHandler object. + // Note that you must initialize the Xerces-C++ runtime before + // calling this function. + // + void + parse (std::istream&, + xercesc::ErrorHandler&, + flags = 0, + const properties& = properties ()); + + + // Parse std::istream using a user-provided SAX2XMLReader object. + // Note that you must initialize the Xerces-C++ runtime before + // calling this function. + // + void + parse (std::istream&, + xercesc::SAX2XMLReader&, + flags = 0, + const properties& = properties ()); + + + public: + // Parse std::istream with a system id. + // + void + parse (std::istream&, + const std::basic_string& system_id, + flags = 0, + const properties& = properties ()); + + + // Parse std::istream with a system id and a user-provided + // error_handler object. + // + void + parse (std::istream&, + const std::basic_string& system_id, + xml::error_handler&, + flags = 0, + const properties& = properties ()); + + + // Parse std::istream with a system id and a user-provided + // ErrorHandler object. Note that you must initialize the + // Xerces-C++ runtime before calling this function. + // + void + parse (std::istream&, + const std::basic_string& system_id, + xercesc::ErrorHandler&, + flags = 0, + const properties& = properties ()); + + + // Parse std::istream with a system id using a user-provided + // SAX2XMLReader object. Note that you must initialize the + // Xerces-C++ runtime before calling this function. + // + void + parse (std::istream&, + const std::basic_string& system_id, + xercesc::SAX2XMLReader&, + flags = 0, + const properties& = properties ()); + + + + public: + // Parse std::istream with system and public ids. + // + void + parse (std::istream&, + const std::basic_string& system_id, + const std::basic_string& public_id, + flags = 0, + const properties& = properties ()); + + + // Parse std::istream with system and public ids and a user-provided + // error_handler object. + // + void + parse (std::istream&, + const std::basic_string& system_id, + const std::basic_string& public_id, + xml::error_handler&, + flags = 0, + const properties& = properties ()); + + + // Parse std::istream with system and public ids and a user-provided + // ErrorHandler object. Note that you must initialize the Xerces-C++ + // runtime before calling this function. + // + void + parse (std::istream&, + const std::basic_string& system_id, + const std::basic_string& public_id, + xercesc::ErrorHandler&, + flags = 0, + const properties& = properties ()); + + + // Parse std::istream with system and public ids using a user- + // provided SAX2XMLReader object. Note that you must initialize + // the Xerces-C++ runtime before calling this function. + // + void + parse (std::istream&, + const std::basic_string& system_id, + const std::basic_string& public_id, + xercesc::SAX2XMLReader&, + flags = 0, + const properties& = properties ()); + + + public: + // Parse InputSource. Note that you must initialize the Xerces-C++ + // runtime before calling this function. + // + void + parse (const xercesc::InputSource&, + flags = 0, + const properties& = properties ()); + + + // Parse InputSource with a user-provided error_handler object. + // Note that you must initialize the Xerces-C++ runtime before + // calling this function. + // + void + parse (const xercesc::InputSource&, + xml::error_handler&, + flags = 0, + const properties& = properties ()); + + + // Parse InputSource with a user-provided ErrorHandler object. + // Note that you must initialize the Xerces-C++ runtime before + // calling this function. + // + void + parse (const xercesc::InputSource&, + xercesc::ErrorHandler&, + flags = 0, + const properties& = properties ()); + + + // Parse InputSource using a user-provided SAX2XMLReader object. + // Note that you must initialize the Xerces-C++ runtime before + // calling this function. + // + void + parse (const xercesc::InputSource&, + xercesc::SAX2XMLReader&, + flags = 0, + const properties& = properties ()); + + private: + void + parse (const std::basic_string& uri, + xercesc::ErrorHandler&, + xercesc::SAX2XMLReader&, + flags, + const properties&); + + void + parse (const xercesc::InputSource&, + xercesc::ErrorHandler&, + xercesc::SAX2XMLReader&, + flags, + const properties&); + + private: + std::auto_ptr + create_sax_ (flags, const properties&); + + private: + bool polymorphic_; + }; + + // + // + template + struct event_router: xercesc::DefaultHandler + { + event_router (cxx::parser::document&, bool polymorphic); + + // I know, some of those consts are stupid. But that's what + // Xerces folks put into their interfaces and VC 7.1 thinks + // there are different signatures if one strips this fluff off. + // + virtual void + setDocumentLocator (const xercesc::Locator* const); + + virtual void + startElement (const XMLCh* const uri, + const XMLCh* const lname, + const XMLCh* const qname, + const xercesc::Attributes& attributes); + + virtual void + endElement (const XMLCh* const uri, + const XMLCh* const lname, + const XMLCh* const qname); + +#if _XERCES_VERSION >= 30000 + virtual void + characters (const XMLCh* const s, const XMLSize_t length); +#else + virtual void + characters (const XMLCh* const s, const unsigned int length); +#endif + + virtual void + startPrefixMapping (const XMLCh* const prefix, + const XMLCh* const uri); + + virtual void + endPrefixMapping (const XMLCh* const prefix); + + private: + void + set_location (schema_exception&); + + private: + const xercesc::Locator* loc_; + cxx::parser::document& consumer_; + bool polymorphic_; + + // Last element name cache. + // + bool last_valid_; + std::basic_string last_ns_; + std::basic_string last_name_; + + // Namespace-prefix mapping. Only maintained in the polymorphic + // case. + // + struct ns_decl + { + ns_decl (const std::basic_string& p, + const std::basic_string& n) + : prefix (p), ns (n) + { + } + + std::basic_string prefix; + std::basic_string ns; + }; + + typedef std::vector ns_decls; + + ns_decls ns_decls_; + }; + } + } + } +} + +#include + +#endif // XSD_CXX_PARSER_XERCES_ELEMENTS_HXX diff --git a/libxsd/xsd/cxx/parser/xerces/elements.txx b/libxsd/xsd/cxx/parser/xerces/elements.txx new file mode 100644 index 0000000..e09ffc5 --- /dev/null +++ b/libxsd/xsd/cxx/parser/xerces/elements.txx @@ -0,0 +1,964 @@ +// file : xsd/cxx/parser/xerces/elements.txx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include +#include // std::size_t +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include // xml::bits::{xml_prefix, etc} + +#include +#include + +namespace xsd +{ + namespace cxx + { + namespace parser + { + namespace xerces + { + + // document + // + + template + document:: + document (parser_base& parser, + const C* name, + bool polymorphic) + : cxx::parser::document (parser, std::basic_string (), name), + polymorphic_ (polymorphic) + { + } + + template + document:: + document (parser_base& parser, + const std::basic_string& name, + bool polymorphic) + : cxx::parser::document (parser, std::basic_string (), name), + polymorphic_ (polymorphic) + { + } + + template + document:: + document (parser_base& parser, + const C* ns, + const C* name, + bool polymorphic) + : cxx::parser::document (parser, ns, name), + polymorphic_ (polymorphic) + { + } + + template + document:: + document (parser_base& parser, + const std::basic_string& ns, + const std::basic_string& name, + bool polymorphic) + : cxx::parser::document (parser, ns, name), + polymorphic_ (polymorphic) + { + } + + template + document:: + document (bool polymorphic) + : polymorphic_ (polymorphic) + { + } + + // parse (uri) + // + template + void document:: + parse (const std::basic_string& uri, + flags f, + const properties& p) + { + xml::auto_initializer init ((f & flags::dont_initialize) == 0); + + error_handler eh; + xml::sax::bits::error_handler_proxy eh_proxy (eh); + std::auto_ptr sax (create_sax_ (f, p)); + + parse (uri, eh_proxy, *sax, f, p); + + eh.throw_if_failed (); + } + + template + void document:: + parse (const C* uri, + flags f, + const properties& p) + { + parse (std::basic_string (uri), f, p); + } + + // error_handler + // + + template + void document:: + parse (const std::basic_string& uri, + xml::error_handler& eh, + flags f, + const properties& p) + { + xml::auto_initializer init ((f & flags::dont_initialize) == 0); + + xml::sax::bits::error_handler_proxy eh_proxy (eh); + std::auto_ptr sax (create_sax_ (f, p)); + + parse (uri, eh_proxy, *sax, f, p); + + if (eh_proxy.failed ()) + throw parsing (); + } + + template + void document:: + parse (const C* uri, + xml::error_handler& eh, + flags f, + const properties& p) + { + parse (std::basic_string (uri), eh, f, p); + } + + // ErrorHandler + // + + template + void document:: + parse (const std::basic_string& uri, + xercesc::ErrorHandler& eh, + flags f, + const properties& p) + { + xml::sax::bits::error_handler_proxy eh_proxy (eh); + std::auto_ptr sax (create_sax_ (f, p)); + + parse (uri, eh_proxy, *sax, f, p); + + if (eh_proxy.failed ()) + throw parsing (); + } + + template + void document:: + parse (const C* uri, + xercesc::ErrorHandler& eh, + flags f, + const properties& p) + { + parse (std::basic_string (uri), eh, f, p); + } + + // SAX2XMLReader + // + + template + void document:: + parse (const std::basic_string& uri, + xercesc::SAX2XMLReader& sax, + flags f, + const properties& p) + { + // If there is no error handler, then fall back on the default + // implementation. + // + xercesc::ErrorHandler* eh (sax.getErrorHandler ()); + + if (eh) + { + xml::sax::bits::error_handler_proxy eh_proxy (*eh); + + parse (uri, eh_proxy, sax, f, p); + + if (eh_proxy.failed ()) + throw parsing (); + } + else + { + error_handler fallback_eh; + xml::sax::bits::error_handler_proxy eh_proxy (fallback_eh); + + parse (uri, eh_proxy, sax, f, p); + + fallback_eh.throw_if_failed (); + } + } + + template + void document:: + parse (const C* uri, + xercesc::SAX2XMLReader& sax, + flags f, + const properties& p) + { + parse (std::basic_string (uri), sax, f, p); + } + + // parse (istream) + // + + template + void document:: + parse (std::istream& is, + flags f, + const properties& p) + { + xml::auto_initializer init ((f & flags::dont_initialize) == 0); + + xml::sax::std_input_source isrc (is); + + parse (isrc, f, p); + } + + template + void document:: + parse (std::istream& is, + xml::error_handler& eh, + flags f, + const properties& p) + { + xml::auto_initializer init ((f & flags::dont_initialize) == 0); + xml::sax::std_input_source isrc (is); + parse (isrc, eh, f, p); + } + + template + void document:: + parse (std::istream& is, + xercesc::ErrorHandler& eh, + flags f, + const properties& p) + { + xml::sax::std_input_source isrc (is); + parse (isrc, eh, f, p); + } + + template + void document:: + parse (std::istream& is, + xercesc::SAX2XMLReader& sax, + flags f, + const properties& p) + { + xml::sax::std_input_source isrc (is); + parse (isrc, sax, f, p); + } + + + // parse (istream, system_id) + // + + + template + void document:: + parse (std::istream& is, + const std::basic_string& system_id, + flags f, + const properties& p) + { + xml::auto_initializer init ((f & flags::dont_initialize) == 0); + xml::sax::std_input_source isrc (is, system_id); + parse (isrc, f, p); + } + + template + void document:: + parse (std::istream& is, + const std::basic_string& system_id, + xml::error_handler& eh, + flags f, + const properties& p) + { + xml::auto_initializer init ((f & flags::dont_initialize) == 0); + xml::sax::std_input_source isrc (is, system_id); + parse (isrc, eh, f, p); + } + + template + void document:: + parse (std::istream& is, + const std::basic_string& system_id, + xercesc::ErrorHandler& eh, + flags f, + const properties& p) + { + xml::sax::std_input_source isrc (is, system_id); + parse (isrc, eh, f, p); + } + + template + void document:: + parse (std::istream& is, + const std::basic_string& system_id, + xercesc::SAX2XMLReader& sax, + flags f, + const properties& p) + { + xml::sax::std_input_source isrc (is, system_id); + parse (isrc, sax, f, p); + } + + + // parse (istream, system_id, public_id) + // + + template + void document:: + parse (std::istream& is, + const std::basic_string& system_id, + const std::basic_string& public_id, + flags f, + const properties& p) + { + xml::auto_initializer init ((f & flags::dont_initialize) == 0); + xml::sax::std_input_source isrc (is, system_id, public_id); + parse (isrc, f, p); + } + + template + void document:: + parse (std::istream& is, + const std::basic_string& system_id, + const std::basic_string& public_id, + xml::error_handler& eh, + flags f, + const properties& p) + { + xml::auto_initializer init ((f & flags::dont_initialize) == 0); + xml::sax::std_input_source isrc (is, system_id, public_id); + parse (isrc, eh, f, p); + } + + template + void document:: + parse (std::istream& is, + const std::basic_string& system_id, + const std::basic_string& public_id, + xercesc::ErrorHandler& eh, + flags f, + const properties& p) + { + xml::sax::std_input_source isrc (is, system_id, public_id); + parse (isrc, eh, f, p); + } + + template + void document:: + parse (std::istream& is, + const std::basic_string& system_id, + const std::basic_string& public_id, + xercesc::SAX2XMLReader& sax, + flags f, + const properties& p) + { + xml::sax::std_input_source isrc (is, system_id, public_id); + parse (isrc, sax, f, p); + } + + + // parse (InputSource) + // + + + template + void document:: + parse (const xercesc::InputSource& is, + flags f, + const properties& p) + { + error_handler eh; + xml::sax::bits::error_handler_proxy eh_proxy (eh); + std::auto_ptr sax (create_sax_ (f, p)); + + parse (is, eh_proxy, *sax, f, p); + + eh.throw_if_failed (); + } + + template + void document:: + parse (const xercesc::InputSource& is, + xml::error_handler& eh, + flags f, + const properties& p) + { + xml::sax::bits::error_handler_proxy eh_proxy (eh); + std::auto_ptr sax (create_sax_ (f, p)); + + parse (is, eh_proxy, *sax, f, p); + + if (eh_proxy.failed ()) + throw parsing (); + } + + template + void document:: + parse (const xercesc::InputSource& is, + xercesc::ErrorHandler& eh, + flags f, + const properties& p) + { + xml::sax::bits::error_handler_proxy eh_proxy (eh); + std::auto_ptr sax (create_sax_ (f, p)); + + parse (is, eh_proxy, *sax, f, p); + + if (eh_proxy.failed ()) + throw parsing (); + } + + + template + void document:: + parse (const xercesc::InputSource& is, + xercesc::SAX2XMLReader& sax, + flags f, + const properties& p) + { + // If there is no error handler, then fall back on the default + // implementation. + // + xercesc::ErrorHandler* eh (sax.getErrorHandler ()); + + if (eh) + { + xml::sax::bits::error_handler_proxy eh_proxy (*eh); + + parse (is, eh_proxy, sax, f, p); + + if (eh_proxy.failed ()) + throw parsing (); + } + else + { + error_handler fallback_eh; + xml::sax::bits::error_handler_proxy eh_proxy (fallback_eh); + + parse (is, eh_proxy, sax, f, p); + + fallback_eh.throw_if_failed (); + } + } + + namespace Bits + { + struct ErrorHandlingController + { + ErrorHandlingController (xercesc::SAX2XMLReader& sax, + xercesc::ErrorHandler& eh) + : sax_ (sax), eh_ (sax_.getErrorHandler ()) + { + sax_.setErrorHandler (&eh); + } + + ~ErrorHandlingController () + { + sax_.setErrorHandler (eh_); + } + + private: + xercesc::SAX2XMLReader& sax_; + xercesc::ErrorHandler* eh_; + }; + + struct ContentHandlingController + { + ContentHandlingController (xercesc::SAX2XMLReader& sax, + xercesc::ContentHandler& ch) + : sax_ (sax), ch_ (sax_.getContentHandler ()) + { + sax_.setContentHandler (&ch); + } + + ~ContentHandlingController () + { + sax_.setContentHandler (ch_); + } + + private: + xercesc::SAX2XMLReader& sax_; + xercesc::ContentHandler* ch_; + }; + }; + + template + void document:: + parse (const std::basic_string& uri, + xercesc::ErrorHandler& eh, + xercesc::SAX2XMLReader& sax, + flags, + const properties&) + { + event_router router (*this, polymorphic_); + + Bits::ErrorHandlingController ehc (sax, eh); + Bits::ContentHandlingController chc (sax, router); + + try + { + sax.parse (xml::string (uri).c_str ()); + } + catch (const schema_exception& e) + { + xml::string id (e.id ()); + + xercesc::SAXParseException se ( + xml::string (e.message ()).c_str (), + id.c_str (), + id.c_str (), +#if _XERCES_VERSION >= 30000 + static_cast (e.line ()), + static_cast (e.column ()) +#else + static_cast (e.line ()), + static_cast (e.column ()) +#endif + ); + + eh.fatalError (se); + } + } + + template + void document:: + parse (const xercesc::InputSource& is, + xercesc::ErrorHandler& eh, + xercesc::SAX2XMLReader& sax, + flags, + const properties&) + { + event_router router (*this, polymorphic_); + + Bits::ErrorHandlingController controller (sax, eh); + Bits::ContentHandlingController chc (sax, router); + + try + { + sax.parse (is); + } + catch (const schema_exception& e) + { + xml::string id (e.id ()); + + xercesc::SAXParseException se ( + xml::string (e.message ()).c_str (), + id.c_str (), + id.c_str (), +#if _XERCES_VERSION >= 30000 + static_cast (e.line ()), + static_cast (e.column ()) +#else + static_cast (e.line ()), + static_cast (e.column ()) +#endif + ); + + eh.fatalError (se); + } + } + + + template + std::auto_ptr document:: + create_sax_ (flags f, const properties& p) + { + // HP aCC cannot handle using namespace xercesc; + // + using xercesc::SAX2XMLReader; + using xercesc::XMLReaderFactory; + using xercesc::XMLUni; + + std::auto_ptr sax ( + XMLReaderFactory::createXMLReader ()); + + sax->setFeature (XMLUni::fgSAX2CoreNameSpaces, true); + sax->setFeature (XMLUni::fgSAX2CoreNameSpacePrefixes, true); + sax->setFeature (XMLUni::fgXercesValidationErrorAsFatal, true); + + if (f & flags::dont_validate) + { + sax->setFeature (XMLUni::fgSAX2CoreValidation, false); + sax->setFeature (XMLUni::fgXercesSchema, false); + sax->setFeature (XMLUni::fgXercesSchemaFullChecking, false); + } + else + { + sax->setFeature (XMLUni::fgSAX2CoreValidation, true); + sax->setFeature (XMLUni::fgXercesSchema, true); + +#if _XERCES_VERSION >= 30000 + if (!(f & flags::no_multiple_imports)) + sax->setFeature (XMLUni::fgXercesHandleMultipleImports, true); +#endif + // This feature checks the schema grammar for additional + // errors. We most likely do not need it when validating + // instances (assuming the schema is valid). + // + sax->setFeature (XMLUni::fgXercesSchemaFullChecking, false); + } + + // Transfer properies if any. + // + + if (!p.schema_location ().empty ()) + { + xml::string sl (p.schema_location ()); + const void* v (sl.c_str ()); + + sax->setProperty ( + XMLUni::fgXercesSchemaExternalSchemaLocation, + const_cast (v)); + } + + if (!p.no_namespace_schema_location ().empty ()) + { + xml::string sl (p.no_namespace_schema_location ()); + const void* v (sl.c_str ()); + + sax->setProperty ( + XMLUni::fgXercesSchemaExternalNoNameSpaceSchemaLocation, + const_cast (v)); + } + + return sax; + } + + // event_router + // + template + event_router:: + event_router (cxx::parser::document& consumer, bool polymorphic) + : loc_ (0), consumer_ (consumer), polymorphic_ (polymorphic) + { + } + + template + void event_router:: + setDocumentLocator (const xercesc::Locator* const loc) + { + loc_ = loc; + } + + template + void event_router:: + startElement(const XMLCh* const uri, + const XMLCh* const lname, + const XMLCh* const /*qname*/, + const xercesc::Attributes& attributes) + { + typedef std::basic_string string; + + { + last_valid_ = true; + last_ns_ = xml::transcode (uri); + last_name_ = xml::transcode (lname); + + // Without this explicit construction IBM XL C++ complains + // about ro_string's copy ctor being private even though the + // temporary has been eliminated. Note that we cannot + // eliminate ns, name and value since ro_string does not make + // a copy. + // + ro_string ro_ns (last_ns_); + ro_string ro_name (last_name_); + + if (!polymorphic_) + { + try + { + consumer_.start_element (ro_ns, ro_name, 0); + } + catch (schema_exception& e) + { + set_location (e); + throw; + } + } + else + { + // Search for the xsi:type attribute. + // + int i (attributes.getIndex ( + xercesc::SchemaSymbols::fgURI_XSI, + xercesc::SchemaSymbols::fgXSI_TYPE)); + + if (i == -1) + { + try + { + consumer_.start_element (ro_ns, ro_name, 0); + } + catch (schema_exception& e) + { + set_location (e); + throw; + } + } + else + { + try + { + // @@ Probably need proper QName validation. + // + // Get the qualified type name and try to resolve it. + // + string qn (xml::transcode (attributes.getValue (i))); + + ro_string tp, tn; + typename string::size_type pos (qn.find (C (':'))); + + if (pos != string::npos) + { + tp.assign (qn.c_str (), pos); + tn.assign (qn.c_str () + pos + 1); + + if (tp.empty ()) + throw dynamic_type (qn); + } + else + tn.assign (qn); + + if (tn.empty ()) + throw dynamic_type (qn); + + // Search our namespace declaration stack. Sun CC 5.7 + // blows if we use const_reverse_iterator. + // + ro_string tns; + for (typename ns_decls::reverse_iterator + it (ns_decls_.rbegin ()), e (ns_decls_.rend ()); + it != e; ++it) + { + if (it->prefix == tp) + { + tns.assign (it->ns); + break; + } + } + + if (!tp.empty () && tns.empty ()) + { + // The 'xml' prefix requires special handling. + // + if (tp == xml::bits::xml_prefix ()) + tns.assign (xml::bits::xml_namespace ()); + else + throw dynamic_type (qn); + } + + // Construct the compound type id. + // + string id (tn.data (), tn.size ()); + + if (!tns.empty ()) + { + id += C (' '); + id.append (tns.data (), tns.size ()); + } + + ro_string ro_id (id); + consumer_.start_element (ro_ns, ro_name, &ro_id); + } + catch (schema_exception& e) + { + set_location (e); + throw; + } + } + } + } + +#if _XERCES_VERSION >= 30000 + for (XMLSize_t i (0), end (attributes.getLength()); i < end; ++i) +#else + for (unsigned int i (0), end (attributes.getLength()); i < end; ++i) +#endif + { + string ns (xml::transcode (attributes.getURI (i))); + string name (xml::transcode (attributes.getLocalName (i))); + string value (xml::transcode (attributes.getValue (i))); + + // Without this explicit construction IBM XL C++ complains + // about ro_string's copy ctor being private even though the + // temporary has been eliminated. Note that we cannot + // eliminate ns, name and value since ro_string does not make + // a copy. + // + ro_string ro_ns (ns); + ro_string ro_name (name); + ro_string ro_value (value); + + try + { + consumer_.attribute (ro_ns, ro_name, ro_value); + } + catch (schema_exception& e) + { + set_location (e); + throw; + } + } + } + + template + void event_router:: + endElement(const XMLCh* const uri, + const XMLCh* const lname, + const XMLCh* const /*qname*/) + { + typedef std::basic_string string; + + try + { + // Without this explicit construction IBM XL C++ complains + // about ro_string's copy ctor being private even though the + // temporary has been eliminated. Note that we cannot + // eliminate ns, name and value since ro_string does not make + // a copy. + // + if (last_valid_) + { + last_valid_ = false; + ro_string ro_ns (last_ns_); + ro_string ro_name (last_name_); + + consumer_.end_element (ro_ns, ro_name); + } + else + { + string ns (xml::transcode (uri)); + string name (xml::transcode (lname)); + + ro_string ro_ns (ns); + ro_string ro_name (name); + + consumer_.end_element (ro_ns, ro_name); + } + } + catch (schema_exception& e) + { + set_location (e); + throw; + } + } + + template + void event_router:: +#if _XERCES_VERSION >= 30000 + characters (const XMLCh* const s, const XMLSize_t n) +#else + characters (const XMLCh* const s, const unsigned int n) +#endif + { + typedef std::basic_string string; + + if (n != 0) + { + string str (xml::transcode (s, n)); + + // Without this explicit construction IBM XL C++ complains + // about ro_string's copy ctor being private even though the + // temporary has been eliminated. Note that we cannot + // eliminate str since ro_string does not make a copy. + // + ro_string ro_str (str); + + try + { + consumer_.characters (ro_str); + } + catch (schema_exception& e) + { + set_location (e); + throw; + } + } + } + + template + void event_router:: + startPrefixMapping (const XMLCh* const prefix, + const XMLCh* const uri) + { + if (polymorphic_) + { + typedef std::basic_string string; + + string p (xml::transcode (prefix)); + string ns (xml::transcode (uri)); + + ns_decls_.push_back (ns_decl (p, ns)); + } + } + + template + void event_router:: + endPrefixMapping (const XMLCh* const prefix) + { + if (polymorphic_) + { + typedef std::basic_string string; + + string p (xml::transcode (prefix)); + + // Here we assume the prefixes are removed in the reverse + // order of them being added. This appears to how every + // sensible implementation works. + // + assert (ns_decls_.back ().prefix == p); + + ns_decls_.pop_back (); + } + } + + template + void event_router:: + set_location (schema_exception& e) + { + if (loc_ != 0) + { + const XMLCh* id (loc_->getPublicId ()); + + if (id == 0) + id = loc_->getSystemId (); + + if (id != 0) + e.id (xml::transcode (id)); + +#if _XERCES_VERSION >= 30000 + e.line (static_cast (loc_->getLineNumber ())); + e.column (static_cast (loc_->getColumnNumber ())); +#else + XMLSSize_t l (loc_->getLineNumber ()); + XMLSSize_t c (loc_->getColumnNumber ()); + + e.line (l == -1 ? 0 : static_cast (l)); + e.column (c == -1 ? 0: static_cast (c)); +#endif + } + } + } + } + } +} diff --git a/libxsd/xsd/cxx/parser/xml-schema.hxx b/libxsd/xsd/cxx/parser/xml-schema.hxx new file mode 100644 index 0000000..b6f9a1b --- /dev/null +++ b/libxsd/xsd/cxx/parser/xml-schema.hxx @@ -0,0 +1,572 @@ +// file : xsd/cxx/parser/xml-schema.hxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_PARSER_XML_SCHEMA_HXX +#define XSD_CXX_PARSER_XML_SCHEMA_HXX + +#include +#include +#include // std::size_t + +namespace xsd +{ + namespace cxx + { + namespace parser + { + // String sequence. Used for the NMTOKENS and IDREFS types. + // + template + class string_sequence: public std::vector > + { + public: + typedef std::basic_string value_type; + typedef std::vector base; + typedef typename base::size_type size_type; + + string_sequence (); + + explicit + string_sequence (size_type n, const value_type& x = value_type ()); + + template + string_sequence (const I& begin, const I& end); + }; + + template + bool + operator== (const string_sequence&, const string_sequence&); + + template + bool + operator!= (const string_sequence&, const string_sequence&); + + + // QName + // + template + class qname + { + public: + explicit + qname (const std::basic_string& name); + + qname (const std::basic_string& prefix, + const std::basic_string& name); + + void + swap (qname&); + + const std::basic_string& + prefix () const; + + std::basic_string& + prefix (); + + void + prefix (const std::basic_string&); + + const std::basic_string& + name () const; + + std::basic_string& + name (); + + void + name (const std::basic_string&); + + private: + std::basic_string prefix_; + std::basic_string name_; + }; + + template + bool + operator== (const qname&, const qname&); + + template + bool + operator!= (const qname&, const qname&); + + + // Binary buffer. Used for the base64Binary and hexBinary types. + // + class buffer + { + public: + typedef std::size_t size_t; + + class bounds {}; // Out of bounds exception. + + public: + ~buffer (); + + explicit + buffer (size_t size = 0); + buffer (size_t size, size_t capacity); + buffer (const void* data, size_t size); + buffer (const void* data, size_t size, size_t capacity); + + // If the assume_ownership argument is true, the buffer will + // assume the ownership of the data and will release the memory + // by calling operator delete (). + // + buffer (void* data, + size_t size, + size_t capacity, + bool assume_ownership); + + buffer (const buffer&); + + public: + buffer& + operator= (const buffer&); + + public: + size_t + capacity () const; + + // Returns true if the underlying buffer has moved. + // + bool + capacity (size_t); + + public: + size_t + size () const; + + // Returns true if the underlying buffer has moved. + // + bool + size (size_t); + + public: + const char* + data () const; + + char* + data (); + + const char* + begin () const; + + char* + begin (); + + const char* + end () const; + + char* + end (); + + public: + void + swap (buffer&); + + private: + bool + capacity (size_t capacity, bool copy); + + private: + char* data_; + size_t size_; + size_t capacity_; + }; + + bool + operator== (const buffer&, const buffer&); + + bool + operator!= (const buffer&, const buffer&); + + + // Time and date types. + // + + class time_zone + { + public: + time_zone (); + time_zone (short hours, short minutes); + + // Returns true if time zone is specified. + // + bool + zone_present () const; + + // Resets the time zone to the 'not specified' state. + // + void + zone_reset (); + + short + zone_hours () const; + + void + zone_hours (short); + + short + zone_minutes () const; + + void + zone_minutes (short); + + private: + bool present_; + short hours_; + short minutes_; + }; + + bool + operator== (const time_zone&, const time_zone&); + + bool + operator!= (const time_zone&, const time_zone&); + + + class gday: public time_zone + { + public: + explicit + gday (unsigned short day); + gday (unsigned short day, short zone_hours, short zone_minutes); + + unsigned short + day () const; + + void + day (unsigned short); + + private: + unsigned short day_; + }; + + bool + operator== (const gday&, const gday&); + + bool + operator!= (const gday&, const gday&); + + + class gmonth: public time_zone + { + public: + explicit + gmonth (unsigned short month); + gmonth (unsigned short month, short zone_hours, short zone_minutes); + + unsigned short + month () const; + + void + month (unsigned short); + + private: + unsigned short month_; + }; + + bool + operator== (const gmonth&, const gmonth&); + + bool + operator!= (const gmonth&, const gmonth&); + + + class gyear: public time_zone + { + public: + explicit + gyear (int year); + gyear (int year, short zone_hours, short zone_minutes); + + int + year () const; + + void + year (int); + + private: + int year_; + }; + + bool + operator== (const gyear&, const gyear&); + + bool + operator!= (const gyear&, const gyear&); + + + class gmonth_day: public time_zone + { + public: + gmonth_day (unsigned short month, unsigned short day); + gmonth_day (unsigned short month, unsigned short day, + short zone_hours, short zone_minutes); + + unsigned short + month () const; + + void + month (unsigned short); + + unsigned short + day () const; + + void + day (unsigned short); + + private: + unsigned short month_; + unsigned short day_; + }; + + bool + operator== (const gmonth_day&, const gmonth_day&); + + bool + operator!= (const gmonth_day&, const gmonth_day&); + + + class gyear_month: public time_zone + { + public: + gyear_month (int year, unsigned short month); + gyear_month (int year, unsigned short month, + short zone_hours, short zone_minutes); + + int + year () const; + + void + year (int); + + unsigned short + month () const; + + void + month (unsigned short); + + private: + int year_; + unsigned short month_; + }; + + bool + operator== (const gyear_month&, const gyear_month&); + + bool + operator!= (const gyear_month&, const gyear_month&); + + + class date: public time_zone + { + public: + date (int year, unsigned short month, unsigned short day); + date (int year, unsigned short month, unsigned short day, + short zone_hours, short zone_minutes); + + int + year () const; + + void + year (int); + + unsigned short + month () const; + + void + month (unsigned short); + + unsigned short + day () const; + + void + day (unsigned short); + + private: + int year_; + unsigned short month_; + unsigned short day_; + }; + + bool + operator== (const date&, const date&); + + bool + operator!= (const date&, const date&); + + + class time: public time_zone + { + public: + time (unsigned short hours, unsigned short minutes, double seconds); + time (unsigned short hours, unsigned short minutes, double seconds, + short zone_hours, short zone_minutes); + + unsigned short + hours () const; + + void + hours (unsigned short); + + unsigned short + minutes () const; + + void + minutes (unsigned short); + + double + seconds () const; + + void + seconds (double); + + private: + unsigned short hours_; + unsigned short minutes_; + double seconds_; + }; + + bool + operator== (const time&, const time&); + + bool + operator!= (const time&, const time&); + + + class date_time: public time_zone + { + public: + date_time (int year, unsigned short month, unsigned short day, + unsigned short hours, unsigned short minutes, double seconds); + + date_time (int year, unsigned short month, unsigned short day, + unsigned short hours, unsigned short minutes, double seconds, + short zone_hours, short zone_minutes); + + int + year () const; + + void + year (int); + + unsigned short + month () const; + + void + month (unsigned short); + + unsigned short + day () const; + + void + day (unsigned short); + + unsigned short + hours () const; + + void + hours (unsigned short); + + unsigned short + minutes () const; + + void + minutes (unsigned short); + + double + seconds () const; + + void + seconds (double); + + private: + int year_; + unsigned short month_; + unsigned short day_; + unsigned short hours_; + unsigned short minutes_; + double seconds_; + }; + + bool + operator== (const date_time&, const date_time&); + + bool + operator!= (const date_time&, const date_time&); + + + class duration + { + public: + duration (bool negative, + unsigned int years, unsigned int months, unsigned int days, + unsigned int hours, unsigned int minutes, double seconds); + + bool + negative () const; + + void + negative (bool); + + unsigned int + years () const; + + void + years (unsigned int); + + unsigned int + months () const; + + void + months (unsigned int); + + unsigned int + days () const; + + void + days (unsigned int); + + unsigned int + hours () const; + + void + hours (unsigned int); + + unsigned int + minutes () const; + + void + minutes (unsigned int); + + double + seconds () const; + + void + seconds (double); + + private: + bool negative_; + unsigned int years_; + unsigned int months_; + unsigned int days_; + unsigned int hours_; + unsigned int minutes_; + double seconds_; + }; + + bool + operator== (const duration&, const duration&); + + bool + operator!= (const duration&, const duration&); + } + } +} + +#include +#include + +#endif // XSD_CXX_PARSER_XML_SCHEMA_HXX diff --git a/libxsd/xsd/cxx/parser/xml-schema.ixx b/libxsd/xsd/cxx/parser/xml-schema.ixx new file mode 100644 index 0000000..5a0922b --- /dev/null +++ b/libxsd/xsd/cxx/parser/xml-schema.ixx @@ -0,0 +1,1022 @@ +// file : xsd/cxx/parser/xml-schema.ixx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include // operator new/delete +#include // std::memcpy, std::memcmp + +namespace xsd +{ + namespace cxx + { + namespace parser + { + // string_sequence + // + template + string_sequence:: + string_sequence () + { + } + + template + string_sequence:: + string_sequence (size_type n, const value_type& x) + : base (n, x) + { + } + + template + template + string_sequence:: + string_sequence (const I& begin, const I& end) + : base (begin, end) + { + } + + template + inline bool + operator!= (const string_sequence& a, const string_sequence& b) + { + return !(a == b); + } + + // qname + // + template + inline qname:: + qname (const std::basic_string& name) + : name_ (name) + { + } + + template + inline qname:: + qname (const std::basic_string& prefix, + const std::basic_string& name) + : prefix_ (prefix), name_ (name) + { + } + + template + void qname:: + swap (qname& x) + { + prefix_.swap (x.prefix_); + name_.swap (x.name_); + } + + template + inline const std::basic_string& qname:: + prefix () const + { + return prefix_; + } + + template + inline std::basic_string& qname:: + prefix () + { + return prefix_; + } + + template + inline void qname:: + prefix (const std::basic_string& prefix) + { + prefix_ = prefix; + } + + template + inline const std::basic_string& qname:: + name () const + { + return name_; + } + + template + inline std::basic_string& qname:: + name () + { + return name_; + } + + template + inline void qname:: + name (const std::basic_string& name) + { + name_ = name; + } + + template + inline bool + operator== (const qname& a, const qname& b) + { + return a.prefix () == b.prefix () && a.name () == b.name (); + } + + template + inline bool + operator!= (const qname& a, const qname& b) + { + return !(a == b); + } + + // buffer + // + inline buffer:: + ~buffer () + { + if (data_) + operator delete (data_); + } + + inline buffer:: + buffer (size_t size) + : data_ (0), size_ (0), capacity_ (0) + { + capacity (size); + size_ = size; + } + + inline buffer:: + buffer (size_t size, size_t cap) + : data_ (0), size_ (0), capacity_ (0) + { + if (size > cap) + throw bounds (); + + capacity (cap); + size_ = size; + } + + inline buffer:: + buffer (const void* data, size_t size) + : data_ (0), size_ (0), capacity_ (0) + { + capacity (size); + size_ = size; + + if (size_) + std::memcpy (data_, data, size_); + } + + inline buffer:: + buffer (const void* data, size_t size, size_t cap) + : data_ (0), size_ (0), capacity_ (0) + { + if (size > cap) + throw bounds (); + + capacity (cap); + size_ = size; + + if (size_) + std::memcpy (data_, data, size_); + } + + inline buffer:: + buffer (void* data, size_t size, size_t cap, bool own) + : data_ (0), size_ (0), capacity_ (0) + { + if (size > cap) + throw bounds (); + + if (own) + { + data_ = reinterpret_cast (data); + size_ = size; + capacity_ = cap; + } + else + { + capacity (cap); + size_ = size; + + if (size_) + std::memcpy (data_, data, size_); + } + } + + inline buffer:: + buffer (const buffer& other) + : data_ (0), size_ (0), capacity_ (0) + { + capacity (other.capacity_); + size_ = other.size_; + + if (size_) + std::memcpy (data_, other.data_, size_); + } + + inline buffer& buffer:: + operator= (const buffer& other) + { + if (this != &other) + { + capacity (other.capacity_, false); + size_ = other.size_; + + if (size_) + std::memcpy (data_, other.data_, size_); + } + + return *this; + } + + inline size_t buffer:: + capacity () const + { + return capacity_; + } + + inline bool buffer:: + capacity (size_t cap) + { + return capacity (cap, true); + } + + inline size_t buffer:: + size () const + { + return size_; + } + + inline bool buffer:: + size (size_t size) + { + bool r (false); + + if (size > capacity_) + r = capacity (size); + + size_ = size; + + return r; + } + + inline const char* buffer:: + data () const + { + return data_; + } + + inline char* buffer:: + data () + { + return data_; + } + + inline const char* buffer:: + begin () const + { + return data_; + } + + inline char* buffer:: + begin () + { + return data_; + } + + inline const char* buffer:: + end () const + { + return data_ + size_; + } + + inline char* buffer:: + end () + { + return data_ + size_; + } + + inline void buffer:: + swap (buffer& other) + { + char* tmp_data (data_); + size_t tmp_size (size_); + size_t tmp_capacity (capacity_); + + data_ = other.data_; + size_ = other.size_; + capacity_ = other.capacity_; + + other.data_ = tmp_data; + other.size_ = tmp_size; + other.capacity_ = tmp_capacity; + } + + inline bool buffer:: + capacity (size_t capacity, bool copy) + { + if (size_ > capacity) + throw bounds (); + + if (capacity <= capacity_) + { + return false; // Do nothing if shrinking is requested. + } + else + { + char* data (reinterpret_cast (operator new (capacity))); + + if (copy && size_ > 0) + std::memcpy (data, data_, size_); + + if (data_) + operator delete (data_); + + data_ = data; + capacity_ = capacity; + + return true; + } + } + + inline bool + operator== (const buffer& a, const buffer& b) + { + return a.size () == b.size () && + std::memcmp (a.data (), b.data (), a.size ()) == 0; + } + + inline bool + operator!= (const buffer& a, const buffer& b) + { + return !(a == b); + } + + // time_zone + // + inline time_zone:: + time_zone () + : present_ (false) + { + } + + inline time_zone:: + time_zone (short h, short m) + : present_ (true), hours_ (h), minutes_ (m) + { + } + + inline bool time_zone:: + zone_present () const + { + return present_; + } + + inline void time_zone:: + zone_reset () + { + present_ = false; + } + + inline short time_zone:: + zone_hours () const + { + return hours_; + } + + inline void time_zone:: + zone_hours (short h) + { + hours_ = h; + present_ = true; + } + + inline short time_zone:: + zone_minutes () const + { + return minutes_; + } + + inline void time_zone:: + zone_minutes (short m) + { + minutes_ = m; + present_ = true; + } + + inline bool + operator== (const time_zone& x, const time_zone& y) + { + return x.zone_present () + ? y.zone_present () && + x.zone_hours () == y.zone_hours () && + x.zone_minutes () == y.zone_minutes () + : !y.zone_present (); + } + + inline bool + operator!= (const time_zone& x, const time_zone& y) + { + return !(x == y); + } + + // gday + // + inline gday:: + gday (unsigned short day) + : day_ (day) + { + } + + inline gday:: + gday (unsigned short day, short zh, short zm) + : time_zone (zh, zm), day_ (day) + { + } + + inline unsigned short gday:: + day () const + { + return day_; + } + + inline void gday:: + day (unsigned short day) + { + day_ = day; + } + + inline bool + operator== (const gday& a, const gday& b) + { + const time_zone& az = a; + const time_zone& bz = b; + + return a.day () == b.day () && az == bz; + } + + inline bool + operator!= (const gday& a, const gday& b) + { + return !(a == b); + } + + // gmonth + // + inline gmonth:: + gmonth (unsigned short month) + : month_ (month) + { + } + + inline gmonth:: + gmonth (unsigned short month, short zh, short zm) + : time_zone (zh, zm), month_ (month) + { + } + + inline unsigned short gmonth:: + month () const + { + return month_; + } + + inline void gmonth:: + month (unsigned short month) + { + month_ = month; + } + + inline bool + operator== (const gmonth& a, const gmonth& b) + { + const time_zone& az = a; + const time_zone& bz = b; + + return a.month () == b.month () && az == bz; + } + + inline bool + operator!= (const gmonth& a, const gmonth& b) + { + return !(a == b); + } + + // gyear + // + inline gyear:: + gyear (int year) + : year_ (year) + { + } + + inline gyear:: + gyear (int year, short zh, short zm) + : time_zone (zh, zm), year_ (year) + { + } + + inline int gyear:: + year () const + { + return year_; + } + + inline void gyear:: + year (int year) + { + year_ = year; + } + + inline bool + operator== (const gyear& a, const gyear& b) + { + const time_zone& az = a; + const time_zone& bz = b; + + return a.year () == b.year () && az == bz; + } + + inline bool + operator!= (const gyear& a, const gyear& b) + { + return !(a == b); + } + + // gmonth_day + // + inline gmonth_day:: + gmonth_day (unsigned short month, unsigned short day) + : month_ (month), day_ (day) + { + } + + inline gmonth_day:: + gmonth_day (unsigned short month, + unsigned short day, + short zh, short zm) + : time_zone (zh, zm), month_ (month), day_ (day) + { + } + + inline unsigned short gmonth_day:: + month () const + { + return month_; + } + + inline void gmonth_day:: + month (unsigned short month) + { + month_ = month; + } + + inline unsigned short gmonth_day:: + day () const + { + return day_; + } + + inline void gmonth_day:: + day (unsigned short day) + { + day_ = day; + } + + inline bool + operator== (const gmonth_day& a, const gmonth_day& b) + { + const time_zone& az = a; + const time_zone& bz = b; + + return a.month () == b.month () && + a.day () == b.day () && + az == bz; + } + + inline bool + operator!= (const gmonth_day& a, const gmonth_day& b) + { + return !(a == b); + } + + // gyear_month + // + inline gyear_month:: + gyear_month (int year, unsigned short month) + : year_ (year), month_ (month) + { + } + + inline gyear_month:: + gyear_month (int year, unsigned short month, + short zh, short zm) + : time_zone (zh, zm), year_ (year), month_ (month) + { + } + + inline int gyear_month:: + year () const + { + return year_; + } + + inline void gyear_month:: + year (int year) + { + year_ = year; + } + + inline unsigned short gyear_month:: + month () const + { + return month_; + } + + inline void gyear_month:: + month (unsigned short month) + { + month_ = month; + } + + inline bool + operator== (const gyear_month& a, const gyear_month& b) + { + const time_zone& az = a; + const time_zone& bz = b; + + return a.year () == b.year () && + a.month () == b.month () && + az == bz; + } + + inline bool + operator!= (const gyear_month& a, const gyear_month& b) + { + return !(a == b); + } + + // date + // + inline date:: + date (int year, unsigned short month, unsigned short day) + : year_ (year), month_ (month), day_ (day) + { + } + + inline date:: + date (int year, unsigned short month, unsigned short day, + short zh, short zm) + : time_zone (zh, zm), year_ (year), month_ (month), day_ (day) + { + } + + inline int date:: + year () const + { + return year_; + } + + inline void date:: + year (int year) + { + year_ = year; + } + + inline unsigned short date:: + month () const + { + return month_; + } + + inline void date:: + month (unsigned short month) + { + month_ = month; + } + + inline unsigned short date:: + day () const + { + return day_; + } + + inline void date:: + day (unsigned short day) + { + day_ = day; + } + + inline bool + operator== (const date& a, const date& b) + { + const time_zone& az = a; + const time_zone& bz = b; + + return a.year () == b.year () && + a.month () == b.month () && + a.day () == b.day () && + az == bz; + } + + inline bool + operator!= (const date& a, const date& b) + { + return !(a == b); + } + + // time + // + inline time:: + time (unsigned short hours, unsigned short minutes, double seconds) + : hours_ (hours), minutes_ (minutes), seconds_ (seconds) + { + } + + inline time:: + time (unsigned short hours, unsigned short minutes, double seconds, + short zh, short zm) + : time_zone (zh, zm), + hours_ (hours), minutes_ (minutes), seconds_ (seconds) + { + } + + inline unsigned short time:: + hours () const + { + return hours_; + } + + inline void time:: + hours (unsigned short hours) + { + hours_ = hours; + } + + inline unsigned short time:: + minutes () const + { + return minutes_; + } + + inline void time:: + minutes (unsigned short minutes) + { + minutes_ = minutes; + } + + inline double time:: + seconds () const + { + return seconds_; + } + + inline void time:: + seconds (double seconds) + { + seconds_ = seconds; + } + + inline bool + operator== (const time& a, const time& b) + { + const time_zone& az = a; + const time_zone& bz = b; + + return a.hours () == b.hours () && + a.minutes () == b.minutes () && + a.seconds () == b.seconds () && + az == bz; + } + + inline bool + operator!= (const time& a, const time& b) + { + return !(a == b); + } + + // date_time + // + inline date_time:: + date_time (int year, unsigned short month, unsigned short day, + unsigned short hours, unsigned short minutes, double seconds) + : year_ (year), month_ (month), day_ (day), + hours_ (hours), minutes_ (minutes), seconds_ (seconds) + { + } + + inline date_time:: + date_time (int year, unsigned short month, unsigned short day, + unsigned short hours, unsigned short minutes, double seconds, + short zh, short zm) + : time_zone (zh, zm), + year_ (year), month_ (month), day_ (day), + hours_ (hours), minutes_ (minutes), seconds_ (seconds) + { + } + + inline int date_time:: + year () const + { + return year_; + } + + inline void date_time:: + year (int year) + { + year_ = year; + } + + inline unsigned short date_time:: + month () const + { + return month_; + } + + inline void date_time:: + month (unsigned short month) + { + month_ = month; + } + + inline unsigned short date_time:: + day () const + { + return day_; + } + + inline void date_time:: + day (unsigned short day) + { + day_ = day; + } + + inline unsigned short date_time:: + hours () const + { + return hours_; + } + + inline void date_time:: + hours (unsigned short hours) + { + hours_ = hours; + } + + inline unsigned short date_time:: + minutes () const + { + return minutes_; + } + + inline void date_time:: + minutes (unsigned short minutes) + { + minutes_ = minutes; + } + + inline double date_time:: + seconds () const + { + return seconds_; + } + + inline void date_time:: + seconds (double seconds) + { + seconds_ = seconds; + } + + inline bool + operator== (const date_time& a, const date_time& b) + { + const time_zone& az = a; + const time_zone& bz = b; + + return a.year () == b.year () && + a.month () == b.month () && + a.day () == b.day () && + a.hours () == b.hours () && + a.minutes () == b.minutes () && + a.seconds () == b.seconds () && + az == bz; + } + + inline bool + operator!= (const date_time& a, const date_time& b) + { + return !(a == b); + } + + // duration + // + inline duration:: + duration (bool negative, + unsigned int years, unsigned int months, unsigned int days, + unsigned int hours, unsigned int minutes, double seconds) + : negative_ (negative), + years_ (years), months_ (months), days_ (days), + hours_ (hours), minutes_ (minutes), seconds_ (seconds) + { + } + + inline bool duration:: + negative () const + { + return negative_; + } + + inline void duration:: + negative (bool negative) + { + negative_ = negative; + } + + inline unsigned int duration:: + years () const + { + return years_; + } + + inline void duration:: + years (unsigned int years) + { + years_ = years; + } + + inline unsigned int duration:: + months () const + { + return months_; + } + + inline void duration:: + months (unsigned int months) + { + months_ = months; + } + + inline unsigned int duration:: + days () const + { + return days_; + } + + inline void duration:: + days (unsigned int days) + { + days_ = days; + } + + inline unsigned int duration:: + hours () const + { + return hours_; + } + + inline void duration:: + hours (unsigned int hours) + { + hours_ = hours; + } + + inline unsigned int duration:: + minutes () const + { + return minutes_; + } + + inline void duration:: + minutes (unsigned int minutes) + { + minutes_ = minutes; + } + + inline double duration:: + seconds () const + { + return seconds_; + } + + inline void duration:: + seconds (double seconds) + { + seconds_ = seconds; + } + + inline bool + operator== (const duration& a, const duration& b) + { + return a.negative () == b.negative () && + a.years () == b.years () && + a.months () == b.months () && + a.days () == b.days () && + a.hours () == b.hours () && + a.minutes () == b.minutes () && + a.seconds () == b.seconds (); + } + + inline bool + operator!= (const duration& a, const duration& b) + { + return !(a == b); + } + } + } +} diff --git a/libxsd/xsd/cxx/parser/xml-schema.txx b/libxsd/xsd/cxx/parser/xml-schema.txx new file mode 100644 index 0000000..c0e2de9 --- /dev/null +++ b/libxsd/xsd/cxx/parser/xml-schema.txx @@ -0,0 +1,34 @@ +// file : xsd/cxx/parser/xml-schema.txx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsd +{ + namespace cxx + { + namespace parser + { + // string_sequence + // + template + bool + operator== (const string_sequence& a, const string_sequence& b) + { + if (a.size () != b.size ()) + return false; + + for (typename string_sequence::const_iterator + ai (a.begin ()), bi (b.begin ()), ae (a.end ()); + ai != ae; ++ai, ++bi) + { + if (*ai != *bi) + return false; + } + + return true; + } + } + } +} + diff --git a/libxsd/xsd/cxx/post.hxx b/libxsd/xsd/cxx/post.hxx new file mode 100644 index 0000000..839d473 --- /dev/null +++ b/libxsd/xsd/cxx/post.hxx @@ -0,0 +1,13 @@ +// file : xsd/cxx/post.hxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + + +#ifdef _MSC_VER +# if (_MSC_VER >= 1400) +# include +# elif (_MSC_VER >= 1300) +# include +# endif +#endif diff --git a/libxsd/xsd/cxx/pre.hxx b/libxsd/xsd/cxx/pre.hxx new file mode 100644 index 0000000..4d5bce7 --- /dev/null +++ b/libxsd/xsd/cxx/pre.hxx @@ -0,0 +1,15 @@ +// file : xsd/cxx/pre.hxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + + +#ifdef _MSC_VER +# if (_MSC_VER >= 1400) +# include +# elif (_MSC_VER >= 1300) +# include +# else +# error Microsoft Visual C++ 6 is not supported. +# endif +#endif diff --git a/libxsd/xsd/cxx/ro-string.hxx b/libxsd/xsd/cxx/ro-string.hxx new file mode 100644 index 0000000..33a70e6 --- /dev/null +++ b/libxsd/xsd/cxx/ro-string.hxx @@ -0,0 +1,430 @@ +// file : xsd/cxx/ro-string.hxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_RO_STRING_HXX +#define XSD_CXX_RO_STRING_HXX + +#include +#include // std::size_t +#include + +namespace xsd +{ + namespace cxx + { + // Read-only string class template. + // + template + class ro_string + { + public: + typedef std::char_traits traits_type; + typedef std::size_t size_type; + + static const size_type npos = ~(size_type (0)); + + public: + ro_string () + : data_ (0), size_ (0) + { + } + + ro_string (const C* s) + : data_ (s), size_ (traits_type::length (s)) + { + } + + ro_string (const C* s, size_type size) + : data_ (s), size_ (size) + { + } + + ro_string (const std::basic_string& s) + : data_ (s.data ()), size_ (s.size ()) + { + } + + operator std::basic_string () const + { + return std::basic_string (data (), size ()); + } + + private: + ro_string (const ro_string&); + + ro_string& + operator= (const ro_string&); + + public: + // The returned string is not necessarily terminated with '\0'. + // If size() returns 0, the returned pointer may be 0. + // + const C* + data () const + { + return data_; + } + + size_type + size () const + { + return size_; + } + + size_type + length () const + { + return size (); + } + + public: + bool + empty () const + { + return size () == 0; + } + + const C& + operator[] (size_type pos) const + { + return data ()[pos]; + } + + public: + void + assign (const C* s) + { + data_ = s; + size_ = traits_type::length (s); + } + + void + assign (const C* s, size_type size) + { + data_ = s; + size_ = size; + } + + void + assign (const std::basic_string& s) + { + data_ = s.c_str (); + size_ = s.size (); + } + + public: + int + compare (const ro_string& str) const + { + return compare (str.data (), str.size ()); + } + + int + compare (const std::basic_string& str) const + { + return compare (str.c_str (), str.size ()); + } + + int + compare (const C* str) const + { + return compare (str, traits_type::length (str)); + } + + int + compare (const C* str, size_type n) const + { + size_type s1 (size ()); + size_type s (s1 < n ? s1 : n); + + int r (s != 0 ? traits_type::compare (data (), str, s) : 0); + + if (!r && s1 != n) + r = s1 < n ? -1 : 1; + + return r; + } + + public: + size_type + find (C c, size_type pos = 0) const; + + private: + const C* data_; + size_type size_; + }; + + // operator== + // + template + inline bool + operator== (const ro_string& a, const ro_string& b) + { + return a.compare (b) == 0; + } + + template + inline bool + operator== (const ro_string& a, const std::basic_string& b) + { + return a.compare (b) == 0; + } + + template + inline bool + operator== (const std::basic_string& a, const ro_string& b) + { + return b.compare (a) == 0; + } + + template + inline bool + operator== (const ro_string& a, const C* b) + { + return a.compare (b) == 0; + } + + template + inline bool + operator== (const C* a, const ro_string& b) + { + return b.compare (a) == 0; + } + + // operator!= + // + template + inline bool + operator!= (const ro_string& a, const ro_string& b) + { + return a.compare (b) != 0; + } + + template + inline bool + operator!= (const ro_string& a, const std::basic_string& b) + { + return a.compare (b) != 0; + } + + template + inline bool + operator!= (const std::basic_string& a, const ro_string& b) + { + return b.compare (a) != 0; + } + + template + inline bool + operator!= (const ro_string& a, const C* b) + { + return a.compare (b) != 0; + } + + template + inline bool + operator!= (const C* a, const ro_string& b) + { + return b.compare (a) != 0; + } + + // operator< + // + template + inline bool + operator< (const ro_string& l, const ro_string& r) + { + return l.compare (r) < 0; + } + + template + inline bool + operator< (const ro_string& l, const std::basic_string& r) + { + return l.compare (r) < 0; + } + + template + inline bool + operator< (const std::basic_string& l, const ro_string& r) + { + return r.compare (l) > 0; + } + + template + inline bool + operator< (const ro_string& l, const C* r) + { + return l.compare (r) < 0; + } + + template + inline bool + operator< (const C* l, const ro_string& r) + { + return r.compare (l) > 0; + } + + + // operator> + // + template + inline bool + operator> (const ro_string& l, const ro_string& r) + { + return l.compare (r) > 0; + } + + template + inline bool + operator> (const ro_string& l, const std::basic_string& r) + { + return l.compare (r) > 0; + } + + template + inline bool + operator> (const std::basic_string& l, const ro_string& r) + { + return r.compare (l) < 0; + } + + template + inline bool + operator> (const ro_string& l, const C* r) + { + return l.compare (r) > 0; + } + + template + inline bool + operator> (const C* l, const ro_string& r) + { + return r.compare (l) < 0; + } + + // operator<= + // + template + inline bool + operator<= (const ro_string& l, const ro_string& r) + { + return l.compare (r) <= 0; + } + + template + inline bool + operator<= (const ro_string& l, const std::basic_string& r) + { + return l.compare (r) <= 0; + } + + template + inline bool + operator<= (const std::basic_string& l, const ro_string& r) + { + return r.compare (l) >= 0; + } + + template + inline bool + operator<= (const ro_string& l, const C* r) + { + return l.compare (r) <= 0; + } + + template + inline bool + operator<= (const C* l, const ro_string& r) + { + return r.compare (l) >= 0; + } + + + // operator>= + // + template + inline bool + operator>= (const ro_string& l, const ro_string& r) + { + return l.compare (r) >= 0; + } + + template + inline bool + operator>= (const ro_string& l, const std::basic_string& r) + { + return l.compare (r) >= 0; + } + + template + inline bool + operator>= (const std::basic_string& l, const ro_string& r) + { + return r.compare (l) <= 0; + } + + template + inline bool + operator>= (const ro_string& l, const C* r) + { + return l.compare (r) >= 0; + } + + template + inline bool + operator>= (const C* l, const ro_string& r) + { + return r.compare (l) <= 0; + } + + // operator<< + // + template + std::basic_ostream& + operator<< (std::basic_ostream& os, const ro_string& str) + { + if (str.size () != 0) + os.write (str.data (), static_cast (str.size ())); + + return os; + } + + // operator+= + // + template + std::basic_string& + operator+= (std::basic_string& l, const ro_string& r) + { + l.append (r.data (), r.size ()); + return l; + } + + // Trim leading and trailing XML whitespaces. Return the new + // string size. + // + template + typename ro_string::size_type + trim_left (ro_string&); + + template + typename ro_string::size_type + trim_right (ro_string&); + + template + typename ro_string::size_type + trim (ro_string&); + + // Trim leading and trailing XML whitespaces. + // + template + std::basic_string + trim (const std::basic_string&); + } +} + +#include + +#endif // XSD_CXX_RO_STRING_HXX diff --git a/libxsd/xsd/cxx/ro-string.txx b/libxsd/xsd/cxx/ro-string.txx new file mode 100644 index 0000000..6f4be14 --- /dev/null +++ b/libxsd/xsd/cxx/ro-string.txx @@ -0,0 +1,133 @@ +// file : xsd/cxx/ro-string.txx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsd +{ + namespace cxx + { + template + typename ro_string::size_type ro_string:: + find (C c, size_type pos) const + { + size_type r (npos); + + if (pos < size_) + { + if (const C* p = traits_type::find(data_ + pos, size_ - pos, c)) + r = p - data_; + } + + return r; + } + + template + typename ro_string::size_type + trim_left (ro_string& s) + { + typename ro_string::size_type size (s.size ()); + + if (size != 0) + { + const C* f (s.data ()); + const C* l (f + size); + const C* of (f); + + while (f < l && + (*f == C (0x20) || *f == C (0x0A) || + *f == C (0x0D) || *f == C (0x09))) + ++f; + + if (f != of) + { + size = f <= l ? l - f : 0; + s.assign ((f <= l ? f : 0), size); + } + } + + return size; + } + + template + typename ro_string::size_type + trim_right (ro_string& s) + { + typename ro_string::size_type size (s.size ()); + + if (size != 0) + { + const C* f (s.data ()); + const C* l (f + size - 1); + const C* ol (l); + + while (l > f && + (*l == C (0x20) || *l == C (0x0A) || + *l == C (0x0D) || *l == C (0x09))) + --l; + + if (l != ol) + { + size = f <= l ? l - f + 1 : 0; + s.assign ((f <= l ? f : 0), size); + } + } + + return size; + } + + template + typename ro_string::size_type + trim (ro_string& s) + { + typename ro_string::size_type size (s.size ()); + + if (size != 0) + { + const C* f (s.data ()); + const C* l (f + size); + + const C* of (f); + + while (f < l && + (*f == C (0x20) || *f == C (0x0A) || + *f == C (0x0D) || *f == C (0x09))) + ++f; + + --l; + + const C* ol (l); + + while (l > f && + (*l == C (0x20) || *l == C (0x0A) || + *l == C (0x0D) || *l == C (0x09))) + --l; + + if (f != of || l != ol) + { + size = f <= l ? l - f + 1 : 0; + s.assign ((f <= l ? f : 0), size); + } + } + + return size; + } + + template + std::basic_string + trim (const std::basic_string& s) + { + ro_string tmp (s); + typename ro_string::size_type size (tmp.size ()); + trim (tmp); + + // If we didn't change the string then return the original to help + // avoid copying for smart (ref counted) string implementations. + // + if (size == tmp.size ()) + return s; + else + return tmp; + } + } +} diff --git a/libxsd/xsd/cxx/tree/ace-cdr-stream-common.hxx b/libxsd/xsd/cxx/tree/ace-cdr-stream-common.hxx new file mode 100644 index 0000000..55f4547 --- /dev/null +++ b/libxsd/xsd/cxx/tree/ace-cdr-stream-common.hxx @@ -0,0 +1,26 @@ +// file : xsd/cxx/tree/ace-cdr-stream-common.hxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_TREE_ACE_CDR_STREAM_COMMON_HXX +#define XSD_CXX_TREE_ACE_CDR_STREAM_COMMON_HXX + +#include + +namespace xsd +{ + namespace cxx + { + namespace tree + { + // Base exception for ACE CDR insertion/extraction exceptions. + // + struct ace_cdr_stream_operation: xsd::cxx::exception + { + }; + } + } +} + +#endif // XSD_CXX_TREE_ACE_CDR_STREAM_COMMON_HXX diff --git a/libxsd/xsd/cxx/tree/ace-cdr-stream-extraction.hxx b/libxsd/xsd/cxx/tree/ace-cdr-stream-extraction.hxx new file mode 100644 index 0000000..8151507 --- /dev/null +++ b/libxsd/xsd/cxx/tree/ace-cdr-stream-extraction.hxx @@ -0,0 +1,334 @@ +// file : xsd/cxx/tree/ace-cdr-stream-extraction.hxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_TREE_ACE_CDR_STREAM_EXTRACTION_HXX +#define XSD_CXX_TREE_ACE_CDR_STREAM_EXTRACTION_HXX + +#include // std::size_t +#include + +#include // ACE::strdelete +#include + +#include + +#include +#include +#include + +namespace xsd +{ + namespace cxx + { + namespace tree + { + struct ace_cdr_stream_extraction: ace_cdr_stream_operation + { + virtual const char* + what () const throw () + { + return "ACE CDR stream extraction operation failed"; + } + }; + + + // as_size + // + +#ifdef XSD_CXX_TREE_USE_64_BIT_SIZE + template + inline istream& + operator>> (istream& s, + istream::as_size& x) + { + ACE_CDR::ULongLong r; + + if (!s.impl ().read_ulonglong (r) || + r > ~(T (0))) + throw ace_cdr_stream_extraction (); + + x.x_ = static_cast (r); + + return s; + } +#else + template + inline istream& + operator>> (istream& s, + istream::as_size& x) + { + ACE_CDR::ULong r; + + if (!s.impl ().read_ulong (r)) + throw ace_cdr_stream_extraction (); + + x.x_ = static_cast (r); + + return s; + } +#endif + + + // 8-bit + // + template + inline istream& + operator>> (istream& s, + istream::as_int8& x) + { + ACE_CDR::Octet r; + + if (!s.impl ().read_octet (r)) + throw ace_cdr_stream_extraction (); + + x.x_ = static_cast (r); + + return s; + } + + template + inline istream& + operator>> (istream& s, + istream::as_uint8& x) + { + ACE_CDR::Octet r; + + if (!s.impl ().read_octet (r)) + throw ace_cdr_stream_extraction (); + + x.x_ = static_cast (r); + + return s; + } + + + // 16-bit + // + template + inline istream& + operator>> (istream& s, + istream::as_int16& x) + { + ACE_CDR::Short r; + + if (!s.impl ().read_short (r)) + throw ace_cdr_stream_extraction (); + + x.x_ = static_cast (r); + + return s; + } + + template + inline istream& + operator>> (istream& s, + istream::as_uint16& x) + { + ACE_CDR::UShort r; + + if (!s.impl ().read_ushort (r)) + throw ace_cdr_stream_extraction (); + + x.x_ = static_cast (r); + + return s; + } + + + // 32-bit + // + template + inline istream& + operator>> (istream& s, + istream::as_int32& x) + { + ACE_CDR::Long r; + + if (!s.impl ().read_long (r)) + throw ace_cdr_stream_extraction (); + + x.x_ = static_cast (r); + + return s; + } + + template + inline istream& + operator>> (istream& s, + istream::as_uint32& x) + { + ACE_CDR::ULong r; + + if (!s.impl ().read_ulong (r)) + throw ace_cdr_stream_extraction (); + + x.x_ = static_cast (r); + + return s; + } + + + // 64-bit + // + template + inline istream& + operator>> (istream& s, + istream::as_int64& x) + { + ACE_CDR::LongLong r; + + if (!s.impl ().read_longlong (r)) + throw ace_cdr_stream_extraction (); + + x.x_ = static_cast (r); + + return s; + } + + template + inline istream& + operator>> (istream& s, + istream::as_uint64& x) + { + ACE_CDR::ULongLong r; + + if (!s.impl ().read_ulonglong (r)) + throw ace_cdr_stream_extraction (); + + x.x_ = static_cast (r); + + return s; + } + + + // Boolean + // + template + inline istream& + operator>> (istream& s, + istream::as_bool& x) + { + ACE_CDR::Boolean r; + + if (!s.impl ().read_boolean (r)) + throw ace_cdr_stream_extraction (); + + x.x_ = static_cast (r); + + return s; + } + + + // Floating-point + // + template + inline istream& + operator>> (istream& s, + istream::as_float32& x) + { + ACE_CDR::Float r; + + if (!s.impl ().read_float (r)) + throw ace_cdr_stream_extraction (); + + x.x_ = static_cast (r); + + return s; + } + + template + inline istream& + operator>> (istream& s, + istream::as_float64& x) + { + ACE_CDR::Double r; + + if (!s.impl ().read_double (r)) + throw ace_cdr_stream_extraction (); + + x.x_ = static_cast (r); + + return s; + } + + // Extraction of std::basic_string. + // + + namespace bits + { + template + struct ace_str_deallocator + { + void + deallocate (C* s) + { + ACE::strdelete (s); + } + }; + } + + inline istream& + operator>> (istream& s, std::basic_string& x) + { + typedef bits::ace_str_deallocator deallocator; + + deallocator d; + char* r; + + if (!s.impl ().read_string (r)) + throw ace_cdr_stream_extraction (); + + auto_array ar (r, d); + + x = r; + + return s; + } + +#ifdef ACE_HAS_WCHAR + inline istream& + operator>> (istream& s, std::basic_string& x) + { + typedef bits::ace_str_deallocator deallocator; + + deallocator d; + wchar_t* r; + + if (!s.impl ().read_wstring (r)) + throw ace_cdr_stream_extraction (); + + auto_array ar (r, d); + + x = r; + + return s; + } +#endif + + + // Extraction of a binary buffer. + // + template + istream& + operator>> (istream& s, buffer& x) + { + ACE_CDR::ULong size; + + if (!s.impl ().read_ulong (size)) + throw ace_cdr_stream_extraction (); + + x.size (size); + + if (!s.impl ().read_octet_array ( + reinterpret_cast (x.data ()), size)) + throw ace_cdr_stream_extraction (); + + return s; + } + } + } +} + +#endif // XSD_CXX_TREE_ACE_CDR_STREAM_EXTRACTION_HXX diff --git a/libxsd/xsd/cxx/tree/ace-cdr-stream-insertion.hxx b/libxsd/xsd/cxx/tree/ace-cdr-stream-insertion.hxx new file mode 100644 index 0000000..d9c4187 --- /dev/null +++ b/libxsd/xsd/cxx/tree/ace-cdr-stream-insertion.hxx @@ -0,0 +1,249 @@ +// file : xsd/cxx/tree/ace-cdr-stream-insertion.hxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_TREE_ACE_CDR_STREAM_INSERTION_HXX +#define XSD_CXX_TREE_ACE_CDR_STREAM_INSERTION_HXX + +#include // std::size_t +#include + +#include + +#include +#include +#include + +namespace xsd +{ + namespace cxx + { + namespace tree + { + struct ace_cdr_stream_insertion: ace_cdr_stream_operation + { + virtual const char* + what () const throw () + { + return "ACE CDR stream insertion operation failed"; + } + }; + + + // as_size + // + +#ifdef XSD_CXX_TREE_USE_64_BIT_SIZE + template + inline ostream& + operator<< (ostream& s, + ostream::as_size x) + { + if (!s.impl ().write_ulonglong ( + static_cast (x.x_))) + throw ace_cdr_stream_insertion (); + return s; + } +#else + template + inline ostream& + operator<< (ostream& s, + ostream::as_size x) + { + if (x.x_ > ~(ACE_CDR::ULong (0)) || + !s.impl ().write_ulong (static_cast (x.x_))) + throw ace_cdr_stream_insertion (); + + return s; + } +#endif + + + // 8-bit + // + template + inline ostream& + operator<< (ostream& s, + ostream::as_int8 x) + { + ACE_CDR::Octet r (static_cast (x.x_)); + + if (!s.impl ().write_octet (r)) + throw ace_cdr_stream_insertion (); + + return s; + } + + template + inline ostream& + operator<< (ostream& s, + ostream::as_uint8 x) + { + ACE_CDR::Octet r (static_cast (x.x_)); + + if (!s.impl ().write_octet (r)) + throw ace_cdr_stream_insertion (); + + return s; + } + + + // 16-bit + // + template + inline ostream& + operator<< (ostream& s, + ostream::as_int16 x) + { + if (!s.impl ().write_short (static_cast (x.x_))) + throw ace_cdr_stream_insertion (); + return s; + } + + template + inline ostream& + operator<< (ostream& s, + ostream::as_uint16 x) + { + if (!s.impl ().write_ushort (static_cast (x.x_))) + throw ace_cdr_stream_insertion (); + return s; + } + + + // 32-bit + // + template + inline ostream& + operator<< (ostream& s, + ostream::as_int32 x) + { + if (!s.impl ().write_long (static_cast (x.x_))) + throw ace_cdr_stream_insertion (); + return s; + } + + template + inline ostream& + operator<< (ostream& s, + ostream::as_uint32 x) + { + if (!s.impl ().write_ulong (static_cast (x.x_))) + throw ace_cdr_stream_insertion (); + return s; + } + + + // 64-bit + // + template + inline ostream& + operator<< (ostream& s, + ostream::as_int64 x) + { + if (!s.impl ().write_longlong (static_cast (x.x_))) + throw ace_cdr_stream_insertion (); + return s; + } + + template + inline ostream& + operator<< (ostream& s, + ostream::as_uint64 x) + { + if (!s.impl ().write_ulonglong ( + static_cast (x.x_))) + throw ace_cdr_stream_insertion (); + return s; + } + + + // Boolean + // + template + inline ostream& + operator<< (ostream& s, + ostream::as_bool x) + { + if (!s.impl ().write_boolean (static_cast (x.x_))) + throw ace_cdr_stream_insertion (); + return s; + } + + + // Floating-point + // + template + inline ostream& + operator<< (ostream& s, + ostream::as_float32 x) + { + if (!s.impl ().write_float (static_cast (x.x_))) + throw ace_cdr_stream_insertion (); + return s; + } + + template + inline ostream& + operator<< (ostream& s, + ostream::as_float64 x) + { + if (!s.impl ().write_double (static_cast (x.x_))) + throw ace_cdr_stream_insertion (); + return s; + } + + // Insertion of std::basic_string. + // + + inline ostream& + operator<< (ostream& s, const std::basic_string& x) + { + // ACE CDR strings are hard-wired with a 32 bit length. + // + if (x.length () > ~(ACE_CDR::ULong (0)) || + !s.impl ().write_string ( + static_cast (x.length ()), x.c_str ())) + throw ace_cdr_stream_insertion (); + return s; + } + +#ifdef ACE_HAS_WCHAR + inline ostream& + operator<< (ostream& s, + const std::basic_string& x) + { + // ACE CDR strings are hard-wired with a 32 bit length. + // + if (x.length () > ~(ACE_CDR::ULong (0)) || + !s.impl ().write_wstring ( + static_cast (x.length ()), x.c_str ())) + throw ace_cdr_stream_insertion (); + return s; + } +#endif + + // Insertion of a binary buffer. + // + template + ostream& + operator<< (ostream& s, const buffer& x) + { + std::size_t size (x.size ()); + + // It is not possible to write an array with a 64-bit size. + // + if (size > ~(ACE_CDR::ULong (0)) || + !s.impl ().write_ulong (static_cast (size)) || + !s.impl ().write_octet_array ( + reinterpret_cast (x.data ()), size)) + throw ace_cdr_stream_insertion (); + + return s; + } + } + } +} + +#endif // XSD_CXX_TREE_ACE_CDR_STREAM_INSERTION_HXX diff --git a/libxsd/xsd/cxx/tree/bits/literals.hxx b/libxsd/xsd/cxx/tree/bits/literals.hxx new file mode 100644 index 0000000..186e0dc --- /dev/null +++ b/libxsd/xsd/cxx/tree/bits/literals.hxx @@ -0,0 +1,183 @@ +// file : xsd/cxx/tree/bits/literals.hxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_TREE_BITS_LITERALS_HXX +#define XSD_CXX_TREE_BITS_LITERALS_HXX + +namespace xsd +{ + namespace cxx + { + namespace tree + { + namespace bits + { + // Boolean literals + // + template + const C* + true_ (); + + template + const C* + one (); + + // Float literals: INF -INF NaN. + // + template + const C* + positive_inf (); + + template + const C* + negative_inf (); + + template + const C* + nan (); + + // Optional "not present" literal. + // + template + const C* + not_present (); + + // XML Schema namespace + // + template + const C* + xml_schema (); + + // Built-in XML Schema type names. + // + template + const C* + any_type (); + + template + const C* + any_simple_type (); + + template + const C* + string (); + + template + const C* + normalized_string (); + + template + const C* + token (); + + template + const C* + name (); + + template + const C* + nmtoken (); + + template + const C* + nmtokens (); + + template + const C* + ncname (); + + template + const C* + language (); + + template + const C* + id (); + + template + const C* + idref (); + + template + const C* + idrefs (); + + template + const C* + any_uri (); + + template + const C* + qname (); + + template + const C* + base64_binary (); + + template + const C* + hex_binary (); + + template + const C* + date (); + + template + const C* + date_time (); + + template + const C* + duration (); + + template + const C* + gday (); + + template + const C* + gmonth (); + + template + const C* + gmonth_day (); + + template + const C* + gyear (); + + template + const C* + gyear_month (); + + template + const C* + time (); + + template + const C* + entity (); + + template + const C* + entities (); + + // gday ("---") and gmonth ("--") prefixes. + // + template + const C* + gday_prefix (); + + template + const C* + gmonth_prefix (); + } + } + } +} + +#endif // XSD_CXX_TREE_BITS_LITERALS_HXX + +#include diff --git a/libxsd/xsd/cxx/tree/bits/literals.ixx b/libxsd/xsd/cxx/tree/bits/literals.ixx new file mode 100644 index 0000000..d2620e6 --- /dev/null +++ b/libxsd/xsd/cxx/tree/bits/literals.ixx @@ -0,0 +1,606 @@ +// file : xsd/cxx/tree/bits/literals.ixx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_TREE_BITS_LITERALS_IXX +#define XSD_CXX_TREE_BITS_LITERALS_IXX + +// The char versions of the following literals are required even +// if we are using wchar_t as the character type. +// +namespace xsd +{ + namespace cxx + { + namespace tree + { + namespace bits + { + // + // + template<> + inline const char* + positive_inf () + { + return "INF"; + } + + template<> + inline const char* + negative_inf () + { + return "-INF"; + } + + template<> + inline const char* + nan () + { + return "NaN"; + } + } + } + } +} + +#endif // XSD_CXX_TREE_BITS_LITERALS_IXX + + +#if defined(XSD_CXX_TREE_USE_CHAR) || !defined(XSD_CXX_TREE_USE_WCHAR) + +#ifndef XSD_CXX_TREE_BITS_LITERALS_IXX_CHAR +#define XSD_CXX_TREE_BITS_LITERALS_IXX_CHAR + +namespace xsd +{ + namespace cxx + { + namespace tree + { + namespace bits + { + // + // + template<> + inline const char* + true_ () + { + return "true"; + } + + template<> + inline const char* + one () + { + return "1"; + } + + // + // + template<> + inline const char* + not_present () + { + return ""; + } + + // + // + template <> + inline const char* + xml_schema () + { + return "http://www.w3.org/2001/XMLSchema"; + } + + // + // + template <> + inline const char* + any_type () + { + return "anyType"; + } + + template <> + inline const char* + any_simple_type () + { + return "anySimpleType"; + } + + template <> + inline const char* + string () + { + return "string"; + } + + template <> + inline const char* + normalized_string () + { + return "normalizedString"; + } + + template <> + inline const char* + token () + { + return "token"; + } + + template <> + inline const char* + name () + { + return "Name"; + } + + template <> + inline const char* + nmtoken () + { + return "NMTOKEN"; + } + + template <> + inline const char* + nmtokens () + { + return "NMTOKENS"; + } + + template <> + inline const char* + ncname () + { + return "NCName"; + } + + template <> + inline const char* + language () + { + return "language"; + } + + + template <> + inline const char* + id () + { + return "ID"; + } + + template <> + inline const char* + idref () + { + return "IDREF"; + } + + template <> + inline const char* + idrefs () + { + return "IDREFS"; + } + + template <> + inline const char* + any_uri () + { + return "anyURI"; + } + + template <> + inline const char* + qname () + { + return "QName"; + } + + template <> + inline const char* + base64_binary () + { + return "base64Binary"; + } + + template <> + inline const char* + hex_binary () + { + return "hexBinary"; + } + + template <> + inline const char* + date () + { + return "date"; + } + + template <> + inline const char* + date_time () + { + return "dateTime"; + } + + template <> + inline const char* + duration () + { + return "duration"; + } + + template <> + inline const char* + gday () + { + return "gDay"; + } + + template <> + inline const char* + gmonth () + { + return "gMonth"; + } + + template <> + inline const char* + gmonth_day () + { + return "gMonthDay"; + } + + template <> + inline const char* + gyear () + { + return "gYear"; + } + + template <> + inline const char* + gyear_month () + { + return "gYearMonth"; + } + + template <> + inline const char* + time () + { + return "time"; + } + + template <> + inline const char* + entity () + { + return "ENTITY"; + } + + template <> + inline const char* + entities () + { + return "ENTITIES"; + } + + template <> + inline const char* + gday_prefix () + { + return "---"; + } + + template <> + inline const char* + gmonth_prefix () + { + return "--"; + } + } + } + } +} + +#endif // XSD_CXX_TREE_BITS_LITERALS_IXX_CHAR +#endif // XSD_CXX_TREE_USE_CHAR + + +#if defined(XSD_CXX_TREE_USE_WCHAR) || !defined(XSD_CXX_TREE_USE_CHAR) + +#ifndef XSD_CXX_TREE_BITS_LITERALS_IXX_WCHAR +#define XSD_CXX_TREE_BITS_LITERALS_IXX_WCHAR + +namespace xsd +{ + namespace cxx + { + namespace tree + { + namespace bits + { + // + // + template<> + inline const wchar_t* + true_ () + { + return L"true"; + } + + template<> + inline const wchar_t* + one () + { + return L"1"; + } + + // + // + template<> + inline const wchar_t* + positive_inf () + { + return L"INF"; + } + + template<> + inline const wchar_t* + negative_inf () + { + return L"-INF"; + } + + template<> + inline const wchar_t* + nan () + { + return L"NaN"; + } + + // + // + template<> + inline const wchar_t* + not_present () + { + return L""; + } + + // + // + template <> + inline const wchar_t* + xml_schema () + { + return L"http://www.w3.org/2001/XMLSchema"; + } + + // + // + template <> + inline const wchar_t* + any_type () + { + return L"anyType"; + } + + template <> + inline const wchar_t* + any_simple_type () + { + return L"anySimpleType"; + } + + template <> + inline const wchar_t* + string () + { + return L"string"; + } + + template <> + inline const wchar_t* + normalized_string () + { + return L"normalizedString"; + } + + template <> + inline const wchar_t* + token () + { + return L"token"; + } + + template <> + inline const wchar_t* + name () + { + return L"Name"; + } + + template <> + inline const wchar_t* + nmtoken () + { + return L"NMTOKEN"; + } + + template <> + inline const wchar_t* + nmtokens () + { + return L"NMTOKENS"; + } + + template <> + inline const wchar_t* + ncname () + { + return L"NCName"; + } + + template <> + inline const wchar_t* + language () + { + return L"language"; + } + + + template <> + inline const wchar_t* + id () + { + return L"ID"; + } + + template <> + inline const wchar_t* + idref () + { + return L"IDREF"; + } + + template <> + inline const wchar_t* + idrefs () + { + return L"IDREFS"; + } + + template <> + inline const wchar_t* + any_uri () + { + return L"anyURI"; + } + + template <> + inline const wchar_t* + qname () + { + return L"QName"; + } + + template <> + inline const wchar_t* + base64_binary () + { + return L"base64Binary"; + } + + template <> + inline const wchar_t* + hex_binary () + { + return L"hexBinary"; + } + + template <> + inline const wchar_t* + date () + { + return L"date"; + } + + template <> + inline const wchar_t* + date_time () + { + return L"dateTime"; + } + + template <> + inline const wchar_t* + duration () + { + return L"duration"; + } + + template <> + inline const wchar_t* + gday () + { + return L"gDay"; + } + + template <> + inline const wchar_t* + gmonth () + { + return L"gMonth"; + } + + template <> + inline const wchar_t* + gmonth_day () + { + return L"gMonthDay"; + } + + template <> + inline const wchar_t* + gyear () + { + return L"gYear"; + } + + template <> + inline const wchar_t* + gyear_month () + { + return L"gYearMonth"; + } + + template <> + inline const wchar_t* + time () + { + return L"time"; + } + + template <> + inline const wchar_t* + entity () + { + return L"ENTITY"; + } + + template <> + inline const wchar_t* + entities () + { + return L"ENTITIES"; + } + + template <> + inline const wchar_t* + gday_prefix () + { + return L"---"; + } + + template <> + inline const wchar_t* + gmonth_prefix () + { + return L"--"; + } + } + } + } +} + +#endif // XSD_CXX_TREE_BITS_LITERALS_IXX_WCHAR +#endif // XSD_CXX_TREE_USE_WCHAR diff --git a/libxsd/xsd/cxx/tree/buffer.hxx b/libxsd/xsd/cxx/tree/buffer.hxx new file mode 100644 index 0000000..f611fe6 --- /dev/null +++ b/libxsd/xsd/cxx/tree/buffer.hxx @@ -0,0 +1,336 @@ +// file : xsd/cxx/tree/buffer.hxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +/** + * @file + * + * @brief Contains a simple binary buffer abstraction that is used to + * implement the base64Binary and hexBinary XML Schema built-in types. + * + * This is an internal header and is included by the generated code. You + * normally should not include it directly. + * + */ + +#ifndef XSD_CXX_TREE_BUFFER_HXX +#define XSD_CXX_TREE_BUFFER_HXX + +#include // operator new/delete +#include // std::size_t +#include // std::memcpy, std::memcmp + +#include + +namespace xsd +{ + namespace cxx + { + /** + * @brief C++/Tree mapping runtime namespace. + * + * This is an internal namespace and normally should not be referenced + * directly. Instead you should use the aliases for types in this + * namespaces that are created in the generated code. + * + */ + namespace tree + { + //@cond + + class buffer_base + { + protected: + virtual + ~buffer_base () + { + if (data_) + operator delete (data_); + } + + buffer_base () + : data_ (0), size_ (0), capacity_ (0) + { + } + + protected: + char* data_; + size_t size_; + size_t capacity_; + }; + + //@endcond + + /** + * @brief Simple binary %buffer abstraction + * + * The %buffer class manages a continuous binary %buffer. The base + * concepts are data (actual memory region), size (the portion of + * the %buffer that contains useful information), and capacity (the + * actual size of the underlying memory region). The bounds + * %exception is thrown from the constructors and modifier functions + * if the (size <= capacity) constraint is violated. + * + * Note that the template parameter is only used to instantiate + * %exception types. The underlying %buffer type is always @c char. + * + * @nosubgrouping + */ + template + class buffer: protected buffer_base + { + public: + /** + * @brief Size type + */ + typedef std::size_t size_t; + + public: + /** + * @name Constructors + */ + //@{ + + /** + * @brief Allocate a %buffer of the specified size. + * + * The resulting %buffer has the same size and capacity. + * + * @param size A %buffer size in bytes. + */ + explicit + buffer (size_t size = 0); + + /** + * @brief Allocate a %buffer of the specified size and capacity. + * + * @param size A %buffer size in bytes. + * @param capacity A %buffer capacity in bytes. + * @throw bounds If @a size exceeds @a capacity + */ + buffer (size_t size, size_t capacity); + + /** + * @brief Allocate a %buffer of the specified size and copy + * the data. + * + * The resulting %buffer has the same size and capacity with + * @a size bytes copied from @a data. + * + * @param data A %buffer to copy the data from. + * @param size A %buffer size in bytes. + */ + buffer (const void* data, size_t size); + + /** + * @brief Allocate a %buffer of the specified size and capacity + * and copy the data. + * + * @a size bytes are copied from @a data to the resulting + * %buffer. + * + * @param data A %buffer to copy the data from. + * @param size A %buffer size in bytes. + * @param capacity A %buffer capacity in bytes. + * @throw bounds If @a size exceeds @a capacity + */ + buffer (const void* data, size_t size, size_t capacity); + + /** + * @brief Assume ownership of the specified %buffer. + * + * If the @a assume_ownership argument is true, the %buffer will + * assume ownership of @a data and will release the memory + * by calling @c operator @c delete(). + * + * @param data A %buffer to assume ownership of. + * @param size A %buffer size in bytes. + * @param capacity A %buffer capacity in bytes. + * @param assume_ownership A boolean value indication whether to + * assume ownership. + * @throw bounds If @a size exceeds @a capacity + */ + buffer (void* data, + size_t size, + size_t capacity, + bool assume_ownership); + + /** + * @brief Copy constructor. + * + * The copy constructor performs a deep copy of the underlying + * memory %buffer. + * + * @param x An instance to make a copy of. + */ + buffer (const buffer& x); + + //@} + + public: + /** + * @brief Copy assignment operator. + * + * The copy assignment operator changes the buffer's capacity + * to @c x.capacity() and copies @c x.size() bytes from @a x. + * + * @param x An instance to assign. + * @return A reference to the instance. + */ + buffer& + operator= (const buffer& x); + + public: + /** + * @brief Get buffer's capacity. + * + * @return A number of bytes that the %buffer can hold without + * reallocation. + */ + size_t + capacity () const + { + return capacity_; + } + + /** + * @brief Set buffer's capacity. + * + * @param c The new capacity in bytes. + * @return True if the underlying %buffer has moved, false otherwise. + */ + bool + capacity (size_t c) + { + return this->capacity (c, true); + } + + public: + /** + * @brief Get buffer's size. + * + * @return A number of bytes that the %buffer holds. + */ + size_t + size () const {return size_;} + + /** + * @brief Set buffer's size. + * + * @param s The new size in bytes. + * @return True if the underlying %buffer has moved, false otherwise. + */ + bool + size (size_t s) + { + bool r (false); + + if (s > capacity_) + r = capacity (s); + + size_ = s; + + return r; + } + + public: + /** + * @brief Get the underlying memory region. + * + * @return A constant pointer to the underlying memory region. + */ + const char* + data () const {return data_;} + + /** + * @brief Get the underlying memory region. + * + * @return A pointer to the underlying memory region. + */ + char* + data () {return data_;} + + /** + * @brief Get the beginning of the underlying memory region. + * + * @return A constant pointer to the first byte of the underlying + * memory region. + */ + const char* + begin () const {return data_;} + + /** + * @brief Get the beginning of the underlying memory region. + * + * @return A pointer to the first byte of the underlying memory + * region. + */ + char* + begin () {return data_;} + + /** + * @brief Get the end of the underlying memory region. + * + * @return A constant pointer to the one past last byte of the + * underlying memory region (that is @c %begin() @c + @c %size() ). + */ + const char* + end () const {return data_ + size_;} + + /** + * @brief Get the end of the underlying memory region. + * + * @return A pointer to the one past last byte of the underlying + * memory region (that is @c %begin() @c + @c %size() ). + */ + char* + end () {return data_ + size_;} + + public: + /** + * @brief Swap data with another %buffer. + * + * @param x A %buffer to swap with. + */ + void + swap (buffer& x); + + private: + bool + capacity (size_t capacity, bool copy); + }; + + /** + * @brief %buffer comparison operator. + * + * @return True if the buffers have the same sizes and the same + * data. + */ + template + inline bool + operator== (const buffer& a, const buffer& b) + { + return a.size () == b.size () && + std::memcmp (a.data (), b.data (), a.size ()) == 0; + } + + /** + * @brief %buffer comparison operator. + * + * @return True if the buffers have different sizes or different + * data. + */ + template + inline bool + operator!= (const buffer& a, const buffer& b) + { + return !(a == b); + } + } + } +} + +#include + +#endif // XSD_CXX_TREE_BUFFER_HXX diff --git a/libxsd/xsd/cxx/tree/buffer.txx b/libxsd/xsd/cxx/tree/buffer.txx new file mode 100644 index 0000000..6212e20 --- /dev/null +++ b/libxsd/xsd/cxx/tree/buffer.txx @@ -0,0 +1,153 @@ +// file : xsd/cxx/tree/buffer.txx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsd +{ + namespace cxx + { + namespace tree + { + template + buffer:: + buffer (size_t size) + { + capacity (size); + size_ = size; + } + + template + buffer:: + buffer (size_t size, size_t capacity) + { + if (size > capacity) + throw bounds (); + + this->capacity (capacity); + size_ = size; + } + + template + buffer:: + buffer (const void* data, size_t size) + { + capacity (size); + size_ = size; + + if (size_) + std::memcpy (data_, data, size_); + } + + template + buffer:: + buffer (const void* data, size_t size, size_t capacity) + { + if (size > capacity) + throw bounds (); + + this->capacity (capacity); + size_ = size; + + if (size_) + std::memcpy (data_, data, size_); + } + + template + buffer:: + buffer (void* data, size_t size, size_t capacity, bool own) + { + if (size > capacity) + throw bounds (); + + if (own) + { + data_ = reinterpret_cast (data); + size_ = size; + capacity_ = capacity; + } + else + { + this->capacity (capacity); + size_ = size; + + if (size_) + std::memcpy (data_, data, size_); + } + } + + template + buffer:: + buffer (const buffer& other) + : buffer_base () + { + capacity (other.capacity_); + size_ = other.size_; + + if (size_) + std::memcpy (data_, other.data_, size_); + } + + template + buffer& buffer:: + operator= (const buffer& other) + { + if (this != &other) + { + capacity (other.capacity_, false); + size_ = other.size_; + + if (size_) + std::memcpy (data_, other.data_, size_); + } + + return *this; + } + + template + void buffer:: + swap (buffer& other) + { + char* tmp_data (data_); + size_t tmp_size (size_); + size_t tmp_capacity (capacity_); + + data_ = other.data_; + size_ = other.size_; + capacity_ = other.capacity_; + + other.data_ = tmp_data; + other.size_ = tmp_size; + other.capacity_ = tmp_capacity; + } + + template + bool buffer:: + capacity (size_t capacity, bool copy) + { + if (size_ > capacity) + throw bounds (); + + if (capacity <= capacity_) + { + return false; // Do nothing if shrinking is requested. + } + else + { + char* data (reinterpret_cast (operator new (capacity))); + + if (copy && size_ > 0) + std::memcpy (data, data_, size_); + + if (data_) + operator delete (data_); + + data_ = data; + capacity_ = capacity; + + return true; + } + } + } + } +} diff --git a/libxsd/xsd/cxx/tree/comparison-map.hxx b/libxsd/xsd/cxx/tree/comparison-map.hxx new file mode 100644 index 0000000..f8461a0 --- /dev/null +++ b/libxsd/xsd/cxx/tree/comparison-map.hxx @@ -0,0 +1,109 @@ +// file : xsd/cxx/tree/comparison-map.hxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_TREE_COMPARISON_MAP_HXX +#define XSD_CXX_TREE_COMPARISON_MAP_HXX + +#include +#include // std::size_t +#include + +#include + +namespace xsd +{ + namespace cxx + { + namespace tree + { + template + struct comparison_map + { + typedef std::type_info type_id; + typedef bool (*comparator) (const type&, const type&); + + comparison_map (); + + void + register_type (const type_id&, comparator, bool override = true); + + bool + compare (const type&, const type&); + + public: + comparator + find (const type_id&) const; + + private: + struct type_id_comparator + { + bool + operator() (const type_id* x, const type_id* y) const + { + // XL C++ on AIX has buggy type_info::before() in that + // it returns true for two different type_info objects + // that happened to be for the same type. + // +#if defined(__xlC__) && defined(_AIX) + return *x != *y && x->before (*y); +#else + return x->before (*y); +#endif + } + }; + + typedef + std::map + type_map; + + type_map type_map_; + }; + + // + // + template + struct comparison_plate + { + static comparison_map* map; + static std::size_t count; + + comparison_plate (); + ~comparison_plate (); + }; + + template + comparison_map* comparison_plate::map = 0; + + template + std::size_t comparison_plate::count = 0; + + + // + // + template + inline comparison_map& + comparison_map_instance () + { + return *comparison_plate::map; + } + + // + // + template + bool + comparator_impl (const type&, const type&); + + template + struct comparison_initializer + { + comparison_initializer (); + }; + } + } +} + +#include + +#endif // XSD_CXX_TREE_COMPARISON_MAP_HXX diff --git a/libxsd/xsd/cxx/tree/comparison-map.txx b/libxsd/xsd/cxx/tree/comparison-map.txx new file mode 100644 index 0000000..38f215f --- /dev/null +++ b/libxsd/xsd/cxx/tree/comparison-map.txx @@ -0,0 +1,287 @@ +// file : xsd/cxx/tree/comparison-map.txx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include + +namespace xsd +{ + namespace cxx + { + namespace tree + { + // comparison_map + // + template + comparison_map:: + comparison_map () + { + // anyType and anySimpleType. + // + + //register_type ( + // typeid (type), + // &comparator_impl, + // false); + + typedef simple_type simple_type; + + //register_type ( + // typeid (simple_type), + // &comparator_impl, + // false); + + + // Strings + // + typedef string string; + register_type ( + typeid (string), + &comparator_impl, + false); + + typedef normalized_string normalized_string; + register_type ( + typeid (normalized_string), + &comparator_impl, + false); + + typedef token token; + register_type ( + typeid (token), + &comparator_impl, + false); + + typedef name name; + register_type ( + typeid (name), + &comparator_impl, + false); + + typedef nmtoken nmtoken; + register_type ( + typeid (nmtoken), + &comparator_impl, + false); + + typedef nmtokens nmtokens; + register_type ( + typeid (nmtokens), + &comparator_impl, + false); + + typedef ncname ncname; + register_type ( + typeid (ncname), + &comparator_impl, + false); + + typedef language language; + register_type ( + typeid (language), + &comparator_impl, + false); + + + // ID/IDREF. + // + typedef id id; + register_type ( + typeid (id), + &comparator_impl, + false); + + typedef idref idref; + register_type ( + typeid (idref), + &comparator_impl, + false); + + typedef idrefs idrefs; + register_type ( + typeid (idrefs), + &comparator_impl, + false); + + + // URI. + // + typedef uri uri; + register_type ( + typeid (uri), + &comparator_impl, + false); + + + // Qualified name. + // + typedef qname qname; + register_type ( + typeid (qname), + &comparator_impl, + false); + + + // Binary. + // + typedef base64_binary base64_binary; + register_type ( + typeid (base64_binary), + &comparator_impl, + false); + + typedef hex_binary hex_binary; + register_type ( + typeid (hex_binary), + &comparator_impl, + false); + + + // Date/time. + // + typedef gday gday; + register_type ( + typeid (gday), + &comparator_impl, + false); + + typedef gmonth gmonth; + register_type ( + typeid (gmonth), + &comparator_impl, + false); + + typedef gyear gyear; + register_type ( + typeid (gyear), + &comparator_impl, + false); + + typedef gmonth_day gmonth_day; + register_type ( + typeid (gmonth_day), + &comparator_impl, + false); + + typedef gyear_month gyear_month; + register_type ( + typeid (gyear_month), + &comparator_impl, + false); + + typedef date date; + register_type ( + typeid (date), + &comparator_impl, + false); + + typedef time time; + register_type ( + typeid (time), + &comparator_impl