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 ++++---- 2 files changed, 26 insertions(+), 7 deletions(-) (limited to 'libxsd/xsd/cxx/parser/expat') 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_, -- cgit v1.1