// file : xsd/cxx/xml/dom/serialization-source.hxx // copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #ifndef XSD_CXX_XML_DOM_SERIALIZATION_SOURCE_HXX #define XSD_CXX_XML_DOM_SERIALIZATION_SOURCE_HXX #include #include // std::memcpy #include #include #include #include #include #include // XMLFormatTarget, XMLFormatter #include #include #include // name #include namespace xsd { namespace cxx { namespace xml { namespace dom { // // template xercesc::DOMAttr& create_attribute (const C* name, xercesc::DOMElement&); template xercesc::DOMAttr& create_attribute (const C* name, const C* ns, xercesc::DOMElement&); template xercesc::DOMElement& create_element (const C* name, xercesc::DOMElement&); template xercesc::DOMElement& create_element (const C* name, const C* ns, xercesc::DOMElement&); // Add namespace declarations and schema locations. // template void add_namespaces (xercesc::DOMElement&, const namespace_infomap&); // Serialization flags. // const unsigned long no_xml_declaration = 0x00010000UL; const unsigned long dont_pretty_print = 0x00020000UL; template XSD_DOM_AUTO_PTR serialize (const std::basic_string& root_element, const std::basic_string& root_element_namespace, const namespace_infomap& map, unsigned long flags); // This one helps Sun C++ to overcome its fears. // template inline XSD_DOM_AUTO_PTR serialize (const C* root_element, const C* root_element_namespace, const namespace_infomap& map, unsigned long flags) { return serialize (std::basic_string (root_element), std::basic_string (root_element_namespace), map, flags); } // // template bool serialize (xercesc::XMLFormatTarget& target, const xercesc::DOMDocument& doc, const std::basic_string& enconding, error_handler& eh, unsigned long flags); template bool serialize (xercesc::XMLFormatTarget& target, const xercesc::DOMDocument& doc, const std::basic_string& enconding, xercesc::DOMErrorHandler& eh, unsigned long flags); class ostream_format_target: public xercesc::XMLFormatTarget { public: ostream_format_target (std::ostream& os) : n_ (0), os_ (os) { } public: // I know, some of those consts are stupid. But that's what // Xerces folks put into their interfaces and VC thinks there // are different signatures if one strips this fluff off. // virtual void writeChars (const XMLByte* const buf, const XMLSize_t size, xercesc::XMLFormatter* const) { // Ignore the write request if there was a stream failure and the // stream is not using exceptions. // if (os_.fail ()) return; // Flush the buffer if the block is too large or if we don't have // any space left. // if ((size >= buf_size_ / 8 || n_ + size > buf_size_) && n_ != 0) { os_.write (buf_, static_cast (n_)); n_ = 0; if (os_.fail ()) return; } if (size < buf_size_ / 8) { std::memcpy (buf_ + n_, reinterpret_cast (buf), size); n_ += size; } else os_.write (reinterpret_cast (buf), static_cast (size)); } virtual void flush () { // Ignore the flush request if there was a stream failure // and the stream is not using exceptions. // if (!os_.fail ()) { if (n_ != 0) { os_.write (buf_, static_cast (n_)); n_ = 0; if (os_.fail ()) return; } os_.flush (); } } private: static const std::size_t buf_size_ = 1024; char buf_[buf_size_]; std::size_t n_; std::ostream& os_; }; } } } } #include #endif // XSD_CXX_XML_DOM_SERIALIZATION_SOURCE_HXX