From 0fdf19714613a82a184f4f6e75fb9a4f9b62f18a Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sun, 19 Jan 2014 10:05:08 +0200 Subject: Use std::unique_ptr instead of std::auto_ptr in C++11 mode --- libxsd/xsd/cxx/parser/expat/elements.hxx | 25 +++++++++++++++++++--- libxsd/xsd/cxx/parser/expat/elements.txx | 8 +++---- .../cxx/parser/non-validating/xml-schema-pimpl.hxx | 6 ++++-- .../cxx/parser/non-validating/xml-schema-pimpl.txx | 8 +++---- .../cxx/parser/non-validating/xml-schema-pskel.hxx | 8 ++++--- .../xsd/cxx/parser/validating/xml-schema-pimpl.hxx | 10 +++++---- .../xsd/cxx/parser/validating/xml-schema-pimpl.txx | 16 ++++++++++++-- .../xsd/cxx/parser/validating/xml-schema-pskel.hxx | 8 ++++--- libxsd/xsd/cxx/parser/xerces/elements.hxx | 6 ++++-- libxsd/xsd/cxx/parser/xerces/elements.txx | 16 +++++++------- 10 files changed, 76 insertions(+), 35 deletions(-) (limited to 'libxsd/xsd/cxx/parser') diff --git a/libxsd/xsd/cxx/parser/expat/elements.hxx b/libxsd/xsd/cxx/parser/expat/elements.hxx index 706b6a3..d47106b 100644 --- a/libxsd/xsd/cxx/parser/expat/elements.hxx +++ b/libxsd/xsd/cxx/parser/expat/elements.hxx @@ -6,11 +6,17 @@ #ifndef XSD_CXX_PARSER_EXPAT_ELEMENTS_HXX #define XSD_CXX_PARSER_EXPAT_ELEMENTS_HXX +#include // XSD_CXX11 + #include #include #include // std::size_t #include +#ifdef XSD_CXX11 +# include // std::unique_ptr +#endif + #include // We only support UTF-8 expat for now. @@ -35,6 +41,19 @@ namespace xsd { namespace expat { +#ifdef XSD_CXX11 + struct parser_deleter + { + void + operator() (XML_Parser p) const + { + if (p != 0) + XML_ParserFree (p); + } + }; + + typedef std::unique_ptr parser_auto_ptr; +#else // Simple auto pointer for Expat's XML_Parser object. // struct parser_auto_ptr @@ -61,8 +80,8 @@ namespace xsd return *this; } - public: - operator XML_Parser () + XML_Parser + get () const { return parser_; } @@ -76,7 +95,7 @@ namespace xsd private: XML_Parser parser_; }; - +#endif // XSD_CXX11 // // diff --git a/libxsd/xsd/cxx/parser/expat/elements.txx b/libxsd/xsd/cxx/parser/expat/elements.txx index 21dff58..f3df667 100644 --- a/libxsd/xsd/cxx/parser/expat/elements.txx +++ b/libxsd/xsd/cxx/parser/expat/elements.txx @@ -334,18 +334,18 @@ namespace xsd { // First call. // - if (auto_xml_parser_ == 0) + if (auto_xml_parser_.get () == 0) { auto_xml_parser_ = XML_ParserCreateNS (0, XML_Char (' ')); - if (auto_xml_parser_ == 0) + if (auto_xml_parser_.get () == 0) throw std::bad_alloc (); if (system_id || public_id) - parse_begin (auto_xml_parser_, + parse_begin (auto_xml_parser_.get (), system_id ? *system_id : *public_id, eh); else - parse_begin (auto_xml_parser_, eh); + parse_begin (auto_xml_parser_.get (), eh); } bool r (XML_Parse (xml_parser_, diff --git a/libxsd/xsd/cxx/parser/non-validating/xml-schema-pimpl.hxx b/libxsd/xsd/cxx/parser/non-validating/xml-schema-pimpl.hxx index 26c77a6..0e05e42 100644 --- a/libxsd/xsd/cxx/parser/non-validating/xml-schema-pimpl.hxx +++ b/libxsd/xsd/cxx/parser/non-validating/xml-schema-pimpl.hxx @@ -8,6 +8,8 @@ #include +#include // XSD_AUTO_PTR + #include namespace xsd @@ -564,7 +566,7 @@ namespace xsd virtual void _characters (const ro_string&); - virtual std::auto_ptr + virtual XSD_AUTO_PTR post_base64_binary (); protected: @@ -582,7 +584,7 @@ namespace xsd virtual void _characters (const ro_string&); - virtual std::auto_ptr + virtual XSD_AUTO_PTR post_hex_binary (); protected: diff --git a/libxsd/xsd/cxx/parser/non-validating/xml-schema-pimpl.txx b/libxsd/xsd/cxx/parser/non-validating/xml-schema-pimpl.txx index 2c46874..77b1423 100644 --- a/libxsd/xsd/cxx/parser/non-validating/xml-schema-pimpl.txx +++ b/libxsd/xsd/cxx/parser/non-validating/xml-schema-pimpl.txx @@ -1157,7 +1157,7 @@ namespace xsd } template - std::auto_ptr base64_binary_pimpl:: + XSD_AUTO_PTR base64_binary_pimpl:: post_base64_binary () { typedef typename std::basic_string::size_type size_type; @@ -1199,7 +1199,7 @@ namespace xsd size_type quad_count (size / 4); size_type capacity (quad_count * 3 + 1); - std::auto_ptr buf (new buffer (capacity, capacity)); + XSD_AUTO_PTR buf (new buffer (capacity, capacity)); char* dst (buf->data ()); size_type si (0), di (0); // Source and destination indexes. @@ -1309,7 +1309,7 @@ namespace xsd } template - std::auto_ptr hex_binary_pimpl:: + XSD_AUTO_PTR hex_binary_pimpl:: post_hex_binary () { typedef typename ro_string::size_type size_type; @@ -1318,7 +1318,7 @@ namespace xsd size_type size (trim_right (tmp)); buffer::size_t n (size / 2); - std::auto_ptr buf (new buffer (n)); + XSD_AUTO_PTR buf (new buffer (n)); const C* src (tmp.data ()); char* dst (buf->data ()); diff --git a/libxsd/xsd/cxx/parser/non-validating/xml-schema-pskel.hxx b/libxsd/xsd/cxx/parser/non-validating/xml-schema-pskel.hxx index 7d0dd00..aae157e 100644 --- a/libxsd/xsd/cxx/parser/non-validating/xml-schema-pskel.hxx +++ b/libxsd/xsd/cxx/parser/non-validating/xml-schema-pskel.hxx @@ -7,7 +7,9 @@ #define XSD_CXX_PARSER_NON_VALIDATING_XML_SCHEMA_PSKEL_HXX #include -#include // auto_ptr +#include // std::auto_ptr/unique_ptr + +#include // XSD_AUTO_PTR #include #include @@ -494,7 +496,7 @@ namespace xsd template struct base64_binary_pskel: simple_content { - virtual std::auto_ptr + virtual XSD_AUTO_PTR post_base64_binary () = 0; static const C* @@ -507,7 +509,7 @@ namespace xsd template struct hex_binary_pskel: simple_content { - virtual std::auto_ptr + virtual XSD_AUTO_PTR post_hex_binary () = 0; static const C* diff --git a/libxsd/xsd/cxx/parser/validating/xml-schema-pimpl.hxx b/libxsd/xsd/cxx/parser/validating/xml-schema-pimpl.hxx index 0df1c4f..09194e4 100644 --- a/libxsd/xsd/cxx/parser/validating/xml-schema-pimpl.hxx +++ b/libxsd/xsd/cxx/parser/validating/xml-schema-pimpl.hxx @@ -8,6 +8,8 @@ #include +#include // XSD_AUTO_PTR + #include namespace xsd @@ -664,12 +666,12 @@ namespace xsd virtual void _post (); - virtual std::auto_ptr + virtual XSD_AUTO_PTR post_base64_binary (); protected: std::basic_string str_; - std::auto_ptr buf_; + XSD_AUTO_PTR buf_; }; // hexBinary @@ -686,12 +688,12 @@ namespace xsd virtual void _post (); - virtual std::auto_ptr + virtual XSD_AUTO_PTR post_hex_binary (); protected: std::basic_string str_; - std::auto_ptr buf_; + XSD_AUTO_PTR buf_; }; // gday diff --git a/libxsd/xsd/cxx/parser/validating/xml-schema-pimpl.txx b/libxsd/xsd/cxx/parser/validating/xml-schema-pimpl.txx index 021cca8..6631dd2 100644 --- a/libxsd/xsd/cxx/parser/validating/xml-schema-pimpl.txx +++ b/libxsd/xsd/cxx/parser/validating/xml-schema-pimpl.txx @@ -6,6 +6,10 @@ #include #include +#ifdef XSD_CXX11 +# include // std::move +#endif + #include #include @@ -1634,10 +1638,14 @@ namespace xsd } template - std::auto_ptr base64_binary_pimpl:: + XSD_AUTO_PTR base64_binary_pimpl:: post_base64_binary () { +#ifdef XSD_CXX11 + return std::move (buf_); +#else return buf_; +#endif } // hex_binary @@ -1721,10 +1729,14 @@ namespace xsd } template - std::auto_ptr hex_binary_pimpl:: + XSD_AUTO_PTR hex_binary_pimpl:: post_hex_binary () { +#ifdef XSD_CXX11 + return std::move (buf_); +#else return buf_; +#endif } // time_zone diff --git a/libxsd/xsd/cxx/parser/validating/xml-schema-pskel.hxx b/libxsd/xsd/cxx/parser/validating/xml-schema-pskel.hxx index 4641fe9..88cc3ab 100644 --- a/libxsd/xsd/cxx/parser/validating/xml-schema-pskel.hxx +++ b/libxsd/xsd/cxx/parser/validating/xml-schema-pskel.hxx @@ -7,7 +7,9 @@ #define XSD_CXX_PARSER_VALIDATING_XML_SCHEMA_PSKEL_HXX #include -#include // auto_ptr +#include // std::auto_ptr/unique_ptr + +#include // XSD_AUTO_PTR #include #include @@ -494,7 +496,7 @@ namespace xsd template struct base64_binary_pskel: simple_content { - virtual std::auto_ptr + virtual XSD_AUTO_PTR post_base64_binary () = 0; static const C* @@ -507,7 +509,7 @@ namespace xsd template struct hex_binary_pskel: simple_content { - virtual std::auto_ptr + virtual XSD_AUTO_PTR post_hex_binary () = 0; static const C* diff --git a/libxsd/xsd/cxx/parser/xerces/elements.hxx b/libxsd/xsd/cxx/parser/xerces/elements.hxx index 5fe3688..35920a4 100644 --- a/libxsd/xsd/cxx/parser/xerces/elements.hxx +++ b/libxsd/xsd/cxx/parser/xerces/elements.hxx @@ -6,7 +6,7 @@ #ifndef XSD_CXX_PARSER_XERCES_ELEMENTS_HXX #define XSD_CXX_PARSER_XERCES_ELEMENTS_HXX -#include // std::auto_ptr +#include // std::auto_ptr/unique_ptr #include #include #include @@ -18,6 +18,8 @@ #include +#include // XSD_AUTO_PTR + #include #include @@ -377,7 +379,7 @@ namespace xsd const properties&); private: - std::auto_ptr + XSD_AUTO_PTR create_sax_ (flags, const properties&); private: diff --git a/libxsd/xsd/cxx/parser/xerces/elements.txx b/libxsd/xsd/cxx/parser/xerces/elements.txx index 60b6c6d..2324b0c 100644 --- a/libxsd/xsd/cxx/parser/xerces/elements.txx +++ b/libxsd/xsd/cxx/parser/xerces/elements.txx @@ -95,7 +95,7 @@ namespace xsd error_handler eh; xml::sax::bits::error_handler_proxy eh_proxy (eh); - std::auto_ptr sax (create_sax_ (f, p)); + XSD_AUTO_PTR sax (create_sax_ (f, p)); parse (uri, eh_proxy, *sax, f, p); @@ -124,7 +124,7 @@ namespace xsd 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)); + XSD_AUTO_PTR sax (create_sax_ (f, p)); parse (uri, eh_proxy, *sax, f, p); @@ -153,7 +153,7 @@ namespace xsd const properties& p) { xml::sax::bits::error_handler_proxy eh_proxy (eh); - std::auto_ptr sax (create_sax_ (f, p)); + XSD_AUTO_PTR sax (create_sax_ (f, p)); parse (uri, eh_proxy, *sax, f, p); @@ -390,7 +390,7 @@ namespace xsd { error_handler eh; xml::sax::bits::error_handler_proxy eh_proxy (eh); - std::auto_ptr sax (create_sax_ (f, p)); + XSD_AUTO_PTR sax (create_sax_ (f, p)); parse (is, eh_proxy, *sax, f, p); @@ -405,7 +405,7 @@ namespace xsd const properties& p) { xml::sax::bits::error_handler_proxy eh_proxy (eh); - std::auto_ptr sax (create_sax_ (f, p)); + XSD_AUTO_PTR sax (create_sax_ (f, p)); parse (is, eh_proxy, *sax, f, p); @@ -421,7 +421,7 @@ namespace xsd const properties& p) { xml::sax::bits::error_handler_proxy eh_proxy (eh); - std::auto_ptr sax (create_sax_ (f, p)); + XSD_AUTO_PTR sax (create_sax_ (f, p)); parse (is, eh_proxy, *sax, f, p); @@ -569,12 +569,12 @@ namespace xsd template - std::auto_ptr document:: + XSD_AUTO_PTR document:: create_sax_ (flags f, const properties& p) { using namespace xercesc; - std::auto_ptr sax ( + XSD_AUTO_PTR sax ( XMLReaderFactory::createXMLReader ()); sax->setFeature (XMLUni::fgSAX2CoreNameSpaces, true); -- cgit v1.1