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 --- .../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 +++++++++++++++++++++ 3 files changed, 344 insertions(+) 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 (limited to 'libxsd/xsd/cxx/xml/sax') diff --git a/libxsd/xsd/cxx/xml/sax/bits/error-handler-proxy.hxx b/libxsd/xsd/cxx/xml/sax/bits/error-handler-proxy.hxx new file mode 100644 index 0000000..7eca35b --- /dev/null +++ b/libxsd/xsd/cxx/xml/sax/bits/error-handler-proxy.hxx @@ -0,0 +1,81 @@ +// file : xsd/cxx/xml/sax/bits/error-handler-proxy.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_XML_SAX_ERROR_HANDLER_PROXY_HXX +#define XSD_CXX_XML_SAX_ERROR_HANDLER_PROXY_HXX + +#include +#include + +#include + +namespace xsd +{ + namespace cxx + { + namespace xml + { + namespace sax + { + namespace bits + { + template + class error_handler_proxy: public xercesc::ErrorHandler + { + public: + error_handler_proxy (error_handler& eh) + : failed_ (false), eh_ (&eh), native_eh_ (0) + { + } + + error_handler_proxy (xercesc::ErrorHandler& eh) + : failed_ (false), eh_ (0), native_eh_ (&eh) + { + } + + public: + virtual void + warning (const xercesc::SAXParseException& e); + + virtual void + error (const xercesc::SAXParseException& e); + + virtual void + fatalError (const xercesc::SAXParseException& e); + + public: + bool + failed () const + { + return failed_; + } + + virtual void + resetErrors() + { + failed_ = false; + } + + private: + typedef typename error_handler::severity severity; + + void + handle (const xercesc::SAXParseException&, severity); + + private: + bool failed_; + error_handler* eh_; + xercesc::ErrorHandler* native_eh_; + }; + } + } + } + } +} + +#include + +#endif // XSD_CXX_XML_SAX_ERROR_HANDLER_PROXY_HXX + diff --git a/libxsd/xsd/cxx/xml/sax/bits/error-handler-proxy.txx b/libxsd/xsd/cxx/xml/sax/bits/error-handler-proxy.txx new file mode 100644 index 0000000..dcf2091 --- /dev/null +++ b/libxsd/xsd/cxx/xml/sax/bits/error-handler-proxy.txx @@ -0,0 +1,89 @@ +// file : xsd/cxx/xml/sax/bits/error-handler-proxy.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 xml + { + namespace sax + { + namespace bits + { + template + void error_handler_proxy:: + warning (const xercesc::SAXParseException& e) + { + if (native_eh_) + native_eh_->warning (e); + else + handle (e, severity::warning); + } + + + template + void error_handler_proxy:: + error (const xercesc::SAXParseException& e) + { + failed_ = true; + + if (native_eh_) + native_eh_->error (e); + else + handle (e, severity::error); + } + + + template + void error_handler_proxy:: + fatalError (const xercesc::SAXParseException& e) + { + failed_ = true; + + if (native_eh_) + native_eh_->fatalError (e); + else + handle (e, severity::fatal); + } + + + template + void error_handler_proxy:: + handle (const xercesc::SAXParseException& e, severity s) + { + //@@ I do not honor return values from the handler. This + // is not too bad at the moment because I set + // all-errors-are-fatal flag on the parser. + // + const XMLCh* id (e.getPublicId ()); + + if (id == 0) + id = e.getSystemId (); + +#if _XERCES_VERSION >= 30000 + eh_->handle (transcode (id), + static_cast (e.getLineNumber ()), + static_cast (e.getColumnNumber ()), + s, + transcode (e.getMessage ())); +#else + XMLSSize_t l (e.getLineNumber ()); + XMLSSize_t c (e.getColumnNumber ()); + + eh_->handle (transcode (id), + (l == -1 ? 0 : static_cast (l)), + (c == -1 ? 0 : static_cast (c)), + s, + transcode (e.getMessage ())); +#endif + } + } + } + } + } +} diff --git a/libxsd/xsd/cxx/xml/sax/std-input-source.hxx b/libxsd/xsd/cxx/xml/sax/std-input-source.hxx new file mode 100644 index 0000000..f97d2c7 --- /dev/null +++ b/libxsd/xsd/cxx/xml/sax/std-input-source.hxx @@ -0,0 +1,174 @@ +// file : xsd/cxx/xml/std-sax-input-source.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_XML_SAX_STD_INPUT_SOURCE_HXX +#define XSD_CXX_XML_SAX_STD_INPUT_SOURCE_HXX + +#include + +#include + +#include +#include + +namespace xsd +{ + namespace cxx + { + namespace xml + { + namespace sax + { + class std_input_stream: public xercesc::BinInputStream + { + public : + std_input_stream (std::istream& is) + : is_ (is) + { + } + +#if _XERCES_VERSION >= 30000 + virtual XMLFilePos + curPos () const + { + return static_cast (is_.tellg ()); + } +#else + virtual unsigned int + curPos () const + { + return static_cast (is_.tellg ()); + } +#endif + +#if _XERCES_VERSION >= 30000 + virtual XMLSize_t + readBytes (XMLByte* const buf, const XMLSize_t size) +#else + virtual unsigned int + readBytes (XMLByte* const buf, const unsigned int size) +#endif + { + // Some implementations don't clear gcount if you + // call read() on a stream that is in the eof state. + // + if (is_.eof ()) + return 0; + + // Unset the exception failbit while we are working + // with the stream. + // + std::ios_base::iostate old (is_.exceptions ()); + is_.exceptions (old & ~std::ios_base::failbit); + + is_.read (reinterpret_cast (buf), + static_cast (size)); + + // Clear the fail bit if it was caused by eof and restore + // the original exception state. If there are any pending + // errors then the exception will be thrown now. + // + if (is_.fail () && is_.eof ()) + is_.clear (is_.rdstate () & ~std::ios_base::failbit); + + is_.exceptions (old); + + // Make sure that if we failed, readBytes won't be called + // again. + // + if (!(is_.bad () || is_.fail ())) + { +#if _XERCES_VERSION >= 30000 + return static_cast (is_.gcount ()); +#else + return static_cast (is_.gcount ()); +#endif + } + else + return 0; + } + +#if _XERCES_VERSION >= 30000 + virtual const XMLCh* + getContentType () const + { + return 0; + } +#endif + private : + std::istream& is_; + }; + + + class std_input_source: public xercesc::InputSource + { + public : + std_input_source (std::istream& is) + : is_ (&is) + { + } + + template + std_input_source (std::istream& is, const C* system_id) + : xercesc::InputSource (xml::string (system_id).c_str ()), + is_ (&is) + { + } + + template + std_input_source (std::istream& is, + const std::basic_string& system_id) + : xercesc::InputSource (xml::string (system_id).c_str ()), + is_ (&is) + { + } + + template + std_input_source (std::istream& is, + const C* system_id, + const C* public_id) + : xercesc::InputSource (xml::string (system_id).c_str (), + xml::string (public_id).c_str ()), + is_ (&is) + { + } + + template + std_input_source (std::istream& is, + const std::basic_string& system_id, + const std::basic_string& public_id) + : xercesc::InputSource (xml::string (system_id).c_str (), + xml::string (public_id).c_str ()), + is_ (&is) + { + } + + struct copy {}; + + // Throws the copy exception if this function is called more + // than once. + // + virtual xercesc::BinInputStream* + makeStream () const + { + if (is_ == 0) + throw copy (); + + std::istream& is (*is_); + + is_ = 0; + + return new std_input_stream (is); + } + + private : + mutable std::istream* is_; + }; + } + } + } +} + +#endif // XSD_CXX_XML_SAX_STD_INPUT_SOURCE_HXX -- cgit v1.1