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/xml/dom/auto-ptr.hxx | 80 ++++++++++++++++++++++++- libxsd/xsd/cxx/xml/dom/parsing-source.hxx | 9 ++- libxsd/xsd/cxx/xml/dom/parsing-source.txx | 16 ++--- libxsd/xsd/cxx/xml/dom/serialization-source.hxx | 4 +- libxsd/xsd/cxx/xml/dom/serialization-source.txx | 8 +-- libxsd/xsd/cxx/xml/dom/wildcard-source.hxx | 2 +- libxsd/xsd/cxx/xml/dom/wildcard-source.txx | 4 +- 7 files changed, 99 insertions(+), 24 deletions(-) (limited to 'libxsd/xsd/cxx/xml/dom') diff --git a/libxsd/xsd/cxx/xml/dom/auto-ptr.hxx b/libxsd/xsd/cxx/xml/dom/auto-ptr.hxx index d94ba13..b8c9aa3 100644 --- a/libxsd/xsd/cxx/xml/dom/auto-ptr.hxx +++ b/libxsd/xsd/cxx/xml/dom/auto-ptr.hxx @@ -6,6 +6,14 @@ #ifndef XSD_CXX_XML_DOM_AUTO_PTR_HXX #define XSD_CXX_XML_DOM_AUTO_PTR_HXX +#include // XSD_CXX11_* + +#ifdef XSD_CXX11 +# include // std::unique_ptr +# include // std::move +# include // std::remove_const +#endif + namespace xsd { namespace cxx @@ -14,9 +22,73 @@ namespace xsd { namespace dom { - // Simple auto_ptr version that calls release() instead of delete. - // +#ifdef XSD_CXX11 + template + struct deleter + { + void + operator() (T* p) const + { + if (p != 0) + const_cast::type*> (p)->release (); + } + }; + +#ifdef XSD_CXX11_TEMPLATE_ALIAS + template + using unique_ptr = std::unique_ptr>; +#else + template + class unique_ptr: public std::unique_ptr> + { + public: + typedef std::unique_ptr> base; + + typedef typename base::pointer pointer; + typedef T element_type; + typedef deleter deleter_type; + + unique_ptr (): base () {} + explicit unique_ptr (pointer p): base (p) {} + unique_ptr (pointer p, const deleter_type& d): base (p, d) {} + unique_ptr (pointer p, deleter_type&& d): base (p, std::move (d)) {} + unique_ptr (unique_ptr&& p): base (std::move (p)) {} + template + unique_ptr (unique_ptr&& p): base (std::move (p)) {} + template + unique_ptr (std::auto_ptr&& p): base (std::move (p)) {} + + unique_ptr& operator= (unique_ptr&& p) + { + static_cast (*this) = std::move (p); + return *this; + } + template + unique_ptr& operator= (unique_ptr&& p) + { + static_cast (*this) = std::move (p); + return *this; + } + +#ifdef XSD_CXX11_NULLPTR + unique_ptr (std::nullptr_t p): base (p) {} + + unique_ptr& operator= (std::nullptr_t p) + { + static_cast (*this) = p; + return *this; + } +#endif + }; +#endif // XSD_CXX11_TEMPLATE_ALIAS + +#define XSD_DOM_AUTO_PTR xsd::cxx::xml::dom::unique_ptr + +#else + // Simple auto_ptr version for C++98 that calls release() instead + // of delete. + // template struct remove_c { @@ -150,6 +222,10 @@ namespace xsd private: T* x_; }; + +#define XSD_DOM_AUTO_PTR xsd::cxx::xml::dom::auto_ptr + +#endif // XSD_CXX11 } } } diff --git a/libxsd/xsd/cxx/xml/dom/parsing-source.hxx b/libxsd/xsd/cxx/xml/dom/parsing-source.hxx index f35f99d..1daac34 100644 --- a/libxsd/xsd/cxx/xml/dom/parsing-source.hxx +++ b/libxsd/xsd/cxx/xml/dom/parsing-source.hxx @@ -19,7 +19,6 @@ #include // properies #include - #include #include // name #include @@ -102,28 +101,28 @@ namespace xsd const unsigned long no_muliple_imports = 0x00000800UL; template - xml::dom::auto_ptr + XSD_DOM_AUTO_PTR parse (xercesc::InputSource&, error_handler&, const properties&, unsigned long flags); template - xml::dom::auto_ptr + XSD_DOM_AUTO_PTR parse (xercesc::InputSource&, xercesc::DOMErrorHandler&, const properties&, unsigned long flags); template - xml::dom::auto_ptr + XSD_DOM_AUTO_PTR parse (const std::basic_string& uri, error_handler&, const properties&, unsigned long flags); template - xml::dom::auto_ptr + XSD_DOM_AUTO_PTR parse (const std::basic_string& uri, xercesc::DOMErrorHandler&, const properties&, diff --git a/libxsd/xsd/cxx/xml/dom/parsing-source.txx b/libxsd/xsd/cxx/xml/dom/parsing-source.txx index d2152ac..352114d 100644 --- a/libxsd/xsd/cxx/xml/dom/parsing-source.txx +++ b/libxsd/xsd/cxx/xml/dom/parsing-source.txx @@ -68,7 +68,7 @@ namespace xsd // parse() // template - xml::dom::auto_ptr + XSD_DOM_AUTO_PTR parse (xercesc::InputSource& is, error_handler& eh, const properties& prop, @@ -79,7 +79,7 @@ namespace xsd } template - auto_ptr + XSD_DOM_AUTO_PTR parse (xercesc::InputSource& is, xercesc::DOMErrorHandler& eh, const properties& prop, @@ -98,7 +98,7 @@ namespace xsd DOMImplementation* impl ( DOMImplementationRegistry::getDOMImplementation (ls_id)); - auto_ptr parser ( + XSD_DOM_AUTO_PTR parser ( impl->createLSParser (DOMImplementationLS::MODE_SYNCHRONOUS, 0)); DOMConfiguration* conf (parser->getDomConfig ()); @@ -196,7 +196,7 @@ namespace xsd xercesc::Wrapper4InputSource wrap (&is, false); - auto_ptr doc; + XSD_DOM_AUTO_PTR doc; try { doc.reset (parser->parse (&wrap)); @@ -212,7 +212,7 @@ namespace xsd } template - xml::dom::auto_ptr + XSD_DOM_AUTO_PTR parse (const std::basic_string& uri, error_handler& eh, const properties& prop, @@ -223,7 +223,7 @@ namespace xsd } template - auto_ptr + XSD_DOM_AUTO_PTR parse (const std::basic_string& uri, xercesc::DOMErrorHandler& eh, const properties& prop, @@ -242,7 +242,7 @@ namespace xsd DOMImplementation* impl ( DOMImplementationRegistry::getDOMImplementation (ls_id)); - auto_ptr parser ( + XSD_DOM_AUTO_PTR parser ( impl->createLSParser(DOMImplementationLS::MODE_SYNCHRONOUS, 0)); DOMConfiguration* conf (parser->getDomConfig ()); @@ -339,7 +339,7 @@ namespace xsd bits::error_handler_proxy ehp (eh); conf->setParameter (XMLUni::fgDOMErrorHandler, &ehp); - auto_ptr doc; + XSD_DOM_AUTO_PTR doc; try { doc.reset (parser->parseURI (string (uri).c_str ())); diff --git a/libxsd/xsd/cxx/xml/dom/serialization-source.hxx b/libxsd/xsd/cxx/xml/dom/serialization-source.hxx index 9bfd27b..3b23220 100644 --- a/libxsd/xsd/cxx/xml/dom/serialization-source.hxx +++ b/libxsd/xsd/cxx/xml/dom/serialization-source.hxx @@ -53,7 +53,7 @@ namespace xsd const unsigned long dont_pretty_print = 0x00020000UL; template - xml::dom::auto_ptr + XSD_DOM_AUTO_PTR serialize (const std::basic_string& root_element, const std::basic_string& root_element_namespace, const namespace_infomap& map, @@ -62,7 +62,7 @@ namespace xsd // This one helps Sun C++ to overcome its fears. // template - inline xml::dom::auto_ptr + inline XSD_DOM_AUTO_PTR serialize (const C* root_element, const C* root_element_namespace, const namespace_infomap& map, diff --git a/libxsd/xsd/cxx/xml/dom/serialization-source.txx b/libxsd/xsd/cxx/xml/dom/serialization-source.txx index 7de5ca0..efd4141 100644 --- a/libxsd/xsd/cxx/xml/dom/serialization-source.txx +++ b/libxsd/xsd/cxx/xml/dom/serialization-source.txx @@ -110,7 +110,7 @@ namespace xsd // // template - auto_ptr + XSD_DOM_AUTO_PTR serialize (const std::basic_string& el, const std::basic_string& ns, const namespace_infomap& map, @@ -153,7 +153,7 @@ namespace xsd DOMImplementation* impl ( DOMImplementationRegistry::getDOMImplementation (ls)); - auto_ptr doc ( + XSD_DOM_AUTO_PTR doc ( impl->createDocument ( (ns.empty () ? 0 : xml::string (ns).c_str ()), xml::string ((prefix.empty () @@ -295,7 +295,7 @@ namespace xsd bits::error_handler_proxy ehp (eh); - xml::dom::auto_ptr writer ( + XSD_DOM_AUTO_PTR writer ( impl->createLSSerializer ()); DOMConfiguration* conf (writer->getDomConfig ()); @@ -318,7 +318,7 @@ namespace xsd conf->canSetParameter (XMLUni::fgDOMXMLDeclaration, false)) conf->setParameter (XMLUni::fgDOMXMLDeclaration, false); - xml::dom::auto_ptr out (impl->createLSOutput ()); + XSD_DOM_AUTO_PTR out (impl->createLSOutput ()); out->setEncoding (xml::string (encoding).c_str ()); out->setByteStream (&target); diff --git a/libxsd/xsd/cxx/xml/dom/wildcard-source.hxx b/libxsd/xsd/cxx/xml/dom/wildcard-source.hxx index 55d083b..225f5df 100644 --- a/libxsd/xsd/cxx/xml/dom/wildcard-source.hxx +++ b/libxsd/xsd/cxx/xml/dom/wildcard-source.hxx @@ -19,7 +19,7 @@ namespace xsd namespace dom { template - xml::dom::auto_ptr + XSD_DOM_AUTO_PTR create_document (); } } diff --git a/libxsd/xsd/cxx/xml/dom/wildcard-source.txx b/libxsd/xsd/cxx/xml/dom/wildcard-source.txx index 7feb937..bd2817f 100644 --- a/libxsd/xsd/cxx/xml/dom/wildcard-source.txx +++ b/libxsd/xsd/cxx/xml/dom/wildcard-source.txx @@ -17,7 +17,7 @@ namespace xsd namespace dom { template - xml::dom::auto_ptr + XSD_DOM_AUTO_PTR create_document () { const XMLCh ls[] = {xercesc::chLatin_L, @@ -29,7 +29,7 @@ namespace xsd xercesc::DOMImplementation* impl ( xercesc::DOMImplementationRegistry::getDOMImplementation (ls)); - return xml::dom::auto_ptr ( + return XSD_DOM_AUTO_PTR ( impl->createDocument ()); } } -- cgit v1.1