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/auto-array.hxx | 22 ++-- libxsd/xsd/cxx/config.hxx | 35 +++++- 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 +-- libxsd/xsd/cxx/tree/ace-cdr-stream-extraction.hxx | 38 ++++-- libxsd/xsd/cxx/tree/containers.hxx | 33 +++--- libxsd/xsd/cxx/tree/containers.txx | 21 +++- libxsd/xsd/cxx/tree/element-map.hxx | 10 +- libxsd/xsd/cxx/tree/elements.hxx | 131 ++++++++++----------- libxsd/xsd/cxx/tree/istream.hxx | 6 +- libxsd/xsd/cxx/tree/ostream.hxx | 6 +- libxsd/xsd/cxx/tree/parsing.txx | 18 +-- libxsd/xsd/cxx/tree/parsing/element-map.txx | 6 +- libxsd/xsd/cxx/tree/stream-extraction-map.hxx | 10 +- libxsd/xsd/cxx/tree/stream-extraction-map.txx | 6 +- libxsd/xsd/cxx/tree/stream-extraction.hxx | 3 +- libxsd/xsd/cxx/tree/type-factory-map.hxx | 16 +-- libxsd/xsd/cxx/tree/type-factory-map.txx | 13 +- libxsd/xsd/cxx/tree/type-serializer-map.hxx | 3 +- libxsd/xsd/cxx/tree/type-serializer-map.txx | 2 +- libxsd/xsd/cxx/tree/types.txx | 20 +++- libxsd/xsd/cxx/xml/char-iso8859-1.txx | 15 ++- libxsd/xsd/cxx/xml/char-lcp.txx | 24 +++- libxsd/xsd/cxx/xml/char-utf8.txx | 15 ++- 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 +- libxsd/xsd/cxx/xml/std-memory-manager.hxx | 11 ++ libxsd/xsd/cxx/xml/string.hxx | 13 +- libxsd/xsd/cxx/xml/string.txx | 16 ++- 42 files changed, 497 insertions(+), 230 deletions(-) (limited to 'libxsd/xsd') diff --git a/libxsd/xsd/cxx/auto-array.hxx b/libxsd/xsd/cxx/auto-array.hxx index e309603..64c454a 100644 --- a/libxsd/xsd/cxx/auto-array.hxx +++ b/libxsd/xsd/cxx/auto-array.hxx @@ -6,6 +6,12 @@ #ifndef XSD_CXX_AUTO_ARRAY_HXX #define XSD_CXX_AUTO_ARRAY_HXX +#include // XSD_CXX11 + +#ifdef XSD_CXX11 +# error use std::unique_ptr instead of non-standard auto_array +#endif + #include // std::size_t namespace xsd @@ -13,20 +19,20 @@ namespace xsd namespace cxx { template - struct std_deallocator + struct std_array_deleter { void - deallocate (T* p) + operator() (T* p) const { delete[] p; } }; // Simple automatic array. The second template parameter is - // an optional deallocator type. If not specified, delete[] + // an optional deleter type. If not specified, delete[] // is used. // - template > + template > struct auto_array { auto_array (T a[]) @@ -34,7 +40,7 @@ namespace xsd { } - auto_array (T a[], D& d) + auto_array (T a[], const D& d) : a_ (a), d_ (&d) { } @@ -42,7 +48,7 @@ namespace xsd ~auto_array () { if (d_ != 0) - d_->deallocate (a_); + (*d_) (a_); else delete[] a_; } @@ -73,7 +79,7 @@ namespace xsd if (a_ != a) { if (d_ != 0) - d_->deallocate (a_); + (*d_) (a_); else delete[] a_; @@ -100,7 +106,7 @@ namespace xsd private: T* a_; - D* d_; + const D* d_; }; template diff --git a/libxsd/xsd/cxx/config.hxx b/libxsd/xsd/cxx/config.hxx index 1c214fc..e4d6a48 100644 --- a/libxsd/xsd/cxx/config.hxx +++ b/libxsd/xsd/cxx/config.hxx @@ -8,7 +8,40 @@ #include -// Macro to suppress unused variable warning. +// Available C++11 features. +// +#ifdef XSD_CXX11 +#ifdef _MSC_VER +# if _MSC_VER >= 1600 +# define XSD_CXX11_NULLPTR +# if _MSC_VER >= 1800 +# define XSD_CXX11_TEMPLATE_ALIAS +# endif +# endif +#else +# if defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L +# ifdef __GNUC__ +# if (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) || __GNUC__ > 4 +# define XSD_CXX11_NULLPTR +# endif +# if (__GNUC__ == 4 && __GNUC_MINOR__ >= 7) || __GNUC__ > 4 +# define XSD_CXX11_TEMPLATE_ALIAS +# endif +# else +# define XSD_CXX11_NULLPTR +# define XSD_CXX11_TEMPLATE_ALIAS +# endif +# endif +#endif +#endif // XSD_CXX11 + +#ifdef XSD_CXX11 +# define XSD_AUTO_PTR std::unique_ptr +#else +# define XSD_AUTO_PTR std::auto_ptr +#endif + +// Macro to suppress the unused variable warning. // #define XSD_UNUSED(x) (void)x 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); diff --git a/libxsd/xsd/cxx/tree/ace-cdr-stream-extraction.hxx b/libxsd/xsd/cxx/tree/ace-cdr-stream-extraction.hxx index 50c19d6..03e2409 100644 --- a/libxsd/xsd/cxx/tree/ace-cdr-stream-extraction.hxx +++ b/libxsd/xsd/cxx/tree/ace-cdr-stream-extraction.hxx @@ -12,7 +12,13 @@ #include // ACE::strdelete #include -#include +#include // XSD_CXX11 + +#ifdef XSD_CXX11 +# include // std::unique_ptr +#else +# include +#endif #include #include @@ -258,11 +264,11 @@ namespace xsd namespace bits { - template - struct ace_str_deallocator + template + struct ace_str_deleter { void - deallocate (C* s) + operator() (C* s) const { ACE::strdelete (s); } @@ -272,18 +278,22 @@ namespace xsd inline istream& operator>> (istream& s, std::basic_string& x) { - typedef bits::ace_str_deallocator deallocator; + typedef bits::ace_str_deleter deleter; - deallocator d; + deleter d; char* r; if (!s.impl ().read_string (r)) throw ace_cdr_stream_extraction (); - auto_array ar (r, d); +#ifdef XSD_CXX11 + std::unique_ptr ar ( +#else + auto_array ar ( +#endif + r, d); x = r; - return s; } @@ -291,18 +301,22 @@ namespace xsd inline istream& operator>> (istream& s, std::basic_string& x) { - typedef bits::ace_str_deallocator deallocator; + typedef bits::ace_str_deleter deleter; - deallocator d; + deleter d; wchar_t* r; if (!s.impl ().read_wstring (r)) throw ace_cdr_stream_extraction (); - auto_array ar (r, d); +#ifdef XSD_CXX11 + std::unique_ptr ar ( +#else + auto_array ar ( +#endif + r, d); x = r; - return s; } #endif diff --git a/libxsd/xsd/cxx/tree/containers.hxx b/libxsd/xsd/cxx/tree/containers.hxx index e6b9f88..1b959cb 100644 --- a/libxsd/xsd/cxx/tree/containers.hxx +++ b/libxsd/xsd/cxx/tree/containers.hxx @@ -9,11 +9,13 @@ #include // std::ptrdiff_t #include #include -#include // std::auto_ptr +#include // std::auto_ptr/unique_ptr #include // std::iterator_traits #include // std::equal, std::lexicographical_compare #include +#include // XSD_AUTO_PTR + #include namespace xsd @@ -136,7 +138,7 @@ namespace xsd one (const T&, container*); - one (std::auto_ptr, container*); + one (XSD_AUTO_PTR, container*); one (const one&, flags, container*); @@ -163,7 +165,7 @@ namespace xsd } void - set (std::auto_ptr); + set (XSD_AUTO_PTR); bool present () const @@ -171,13 +173,13 @@ namespace xsd return x_ != 0; } - std::auto_ptr + XSD_AUTO_PTR detach () { T* x (x_); x->_container (0); x_ = 0; - return std::auto_ptr (x); + return XSD_AUTO_PTR (x); } protected: @@ -268,7 +270,7 @@ namespace xsd optional (const T&, container* = 0); explicit - optional (std::auto_ptr, container* = 0); + optional (XSD_AUTO_PTR, container* = 0); optional (const optional&, flags = 0, container* = 0); @@ -341,18 +343,18 @@ namespace xsd } void - set (std::auto_ptr); + set (XSD_AUTO_PTR); void reset (); - std::auto_ptr + XSD_AUTO_PTR detach () { T* x (x_); x->_container (0); x_ = 0; - return std::auto_ptr (x); + return XSD_AUTO_PTR (x); } protected: @@ -1266,7 +1268,7 @@ namespace xsd } void - push_back (std::auto_ptr x) + push_back (XSD_AUTO_PTR x) { if (x->_container () != container_) x->_container (container_); @@ -1280,7 +1282,7 @@ namespace xsd v_.pop_back (); } - std::auto_ptr + XSD_AUTO_PTR detach_back (bool pop = true) { ptr& p (v_.back ()); @@ -1290,7 +1292,7 @@ namespace xsd if (pop) v_.pop_back (); - return std::auto_ptr (x); + return XSD_AUTO_PTR (x); } iterator @@ -1302,7 +1304,7 @@ namespace xsd } iterator - insert (iterator position, std::auto_ptr x) + insert (iterator position, XSD_AUTO_PTR x) { if (x->_container () != container_) x->_container (container_); @@ -1336,12 +1338,11 @@ namespace xsd } iterator - detach (iterator position, std::auto_ptr& r, bool erase = true) + detach (iterator position, XSD_AUTO_PTR& r, bool erase = true) { ptr& p (*position.base ()); p->_container (0); - std::auto_ptr tmp (static_cast (p.release ())); - r = tmp; + r.reset (static_cast (p.release ())); if (erase) return iterator (v_.erase (position.base ())); diff --git a/libxsd/xsd/cxx/tree/containers.txx b/libxsd/xsd/cxx/tree/containers.txx index a27af48..7e45a02 100644 --- a/libxsd/xsd/cxx/tree/containers.txx +++ b/libxsd/xsd/cxx/tree/containers.txx @@ -4,6 +4,11 @@ // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #include + +#ifdef XSD_CXX11 +# include // std::move +#endif + #include namespace xsd @@ -38,10 +43,14 @@ namespace xsd template one:: - one (std::auto_ptr x, container* c) + one (XSD_AUTO_PTR x, container* c) : x_ (0), container_ (c) { +#ifdef XSD_CXX11 + set (std::move (x)); +#else set (x); +#endif } template @@ -86,7 +95,7 @@ namespace xsd template void one:: - set (std::auto_ptr x) + set (XSD_AUTO_PTR x) { T* r (0); @@ -128,10 +137,14 @@ namespace xsd template optional:: - optional (std::auto_ptr x, container* c) + optional (XSD_AUTO_PTR x, container* c) : x_ (0), container_ (c) { +#ifdef XSD_CXX11 + set (std::move (x)); +#else set (x); +#endif } template @@ -185,7 +198,7 @@ namespace xsd template void optional:: - set (std::auto_ptr x) + set (XSD_AUTO_PTR x) { T* r (0); diff --git a/libxsd/xsd/cxx/tree/element-map.hxx b/libxsd/xsd/cxx/tree/element-map.hxx index debfaed..b00bdbd 100644 --- a/libxsd/xsd/cxx/tree/element-map.hxx +++ b/libxsd/xsd/cxx/tree/element-map.hxx @@ -7,10 +7,12 @@ #define XSD_CXX_TREE_ELEMENT_MAP_HXX #include -#include // std::auto_ptr +#include // std::auto_ptr/unique_ptr #include // std::size_t #include +#include // XSD_AUTO_PTR + #include #include @@ -44,7 +46,7 @@ namespace xsd * @param f Flags to create the new element object with. * @return An automatic pointer to the new element object. */ - static std::auto_ptr + static XSD_AUTO_PTR parse (const xercesc::DOMElement& e, flags f = 0); /** @@ -61,7 +63,7 @@ namespace xsd typedef xml::qualified_name qualified_name; - typedef std::auto_ptr + typedef XSD_AUTO_PTR (*parser) (const xercesc::DOMElement&, flags f); typedef void @@ -113,7 +115,7 @@ namespace xsd // // template - std::auto_ptr > + XSD_AUTO_PTR > parser_impl (const xercesc::DOMElement&, flags); template diff --git a/libxsd/xsd/cxx/tree/elements.hxx b/libxsd/xsd/cxx/tree/elements.hxx index 17ad70c..396e880 100644 --- a/libxsd/xsd/cxx/tree/elements.hxx +++ b/libxsd/xsd/cxx/tree/elements.hxx @@ -17,13 +17,19 @@ #ifndef XSD_CXX_TREE_ELEMENTS_HXX #define XSD_CXX_TREE_ELEMENTS_HXX +#include // XSD_AUTO_PTR, XSD_CXX11 + #include #include -#include // std::auto_ptr +#include // std::auto_ptr/unique_ptr #include #include #include +#ifdef XSD_CXX11 +# include // std::move +#endif + #include #include #include @@ -33,7 +39,7 @@ #include #include // xml::properties -#include // dom::auto_ptr +#include // dom::auto_ptr/unique_ptr #include #include @@ -83,7 +89,7 @@ namespace xsd * * This flag only makes sense together with the @c keep_dom * flag in the call to the %parsing function with the - * @c dom::auto_ptr argument. + * @c dom::auto_ptr/unique_ptr argument. * */ static const unsigned long own_dom = 0x00000200UL; @@ -386,11 +392,7 @@ namespace xsd { // Drop DOM association. // - if (dom_info_.get ()) - { - std::auto_ptr r (0); - dom_info_ = r; - } + dom_info_.reset (); } return *this; @@ -444,7 +446,7 @@ namespace xsd dr = c; } - std::auto_ptr& m (dr ? dr->map_ : map_); + XSD_AUTO_PTR& m (dr ? dr->map_ : map_); if (container_ == 0) { @@ -455,11 +457,16 @@ namespace xsd if (m.get () != 0) { m->insert (map_->begin (), map_->end ()); - std::auto_ptr tmp (0); - map_ = tmp; + map_.reset (); } else + { +#ifdef XSD_CXX11 + m = std::move (map_); +#else m = map_; +#endif + } } } else @@ -481,10 +488,7 @@ namespace xsd // Part of our subtree. // if (m.get () == 0) - { - std::auto_ptr tmp (new map); - m = tmp; - } + m.reset (new map); m->insert (*i); sr->map_->erase (i++); @@ -599,37 +603,31 @@ namespace xsd { if (container_ != 0) { - // @@ Should be a throw. - // assert (_root ()->_node () != 0); assert (_root ()->_node ()->getOwnerDocument () == n->getOwnerDocument ()); } - std::auto_ptr r ( + dom_info_ = dom_info_factory::create ( *static_cast (n), *this, - container_ == 0)); + container_ == 0); - dom_info_ = r; break; } case xercesc::DOMNode::ATTRIBUTE_NODE: { - //@@ Should be a throw. - // assert (container_ != 0); assert (_root ()->_node () != 0); assert (_root ()->_node ()->getOwnerDocument () == n->getOwnerDocument ()); - std::auto_ptr r ( + dom_info_ = dom_info_factory::create ( *static_cast (n), - *this)); + *this); - dom_info_ = r; break; } default: @@ -650,10 +648,7 @@ namespace xsd assert (container_ == 0); if (map_.get () == 0) - { - std::auto_ptr tmp (new map); - map_ = tmp; - } + map_.reset (new map); if (!map_->insert ( std::pair (&i, t)).second) @@ -714,7 +709,7 @@ namespace xsd { } - virtual std::auto_ptr + virtual XSD_AUTO_PTR clone (type& tree_node, container*) const = 0; virtual xercesc::DOMNode* @@ -731,32 +726,35 @@ namespace xsd struct dom_element_info: public dom_info { dom_element_info (xercesc::DOMElement& e, type& n, bool root) - : doc_ (0), e_ (e) + : e_ (e) { e_.setUserData (user_data_keys::node, &n, 0); if (root) { - // The caller should have associated a dom::auto_ptr object - // that owns this document with the document node using the - // xml_schema::dom::tree_node_key key. + // The caller should have associated a dom::auto/unique_ptr + // object that owns this document with the document node + // using the xml_schema::dom::tree_node_key key. // - xml::dom::auto_ptr* pd ( - reinterpret_cast*> ( + XSD_DOM_AUTO_PTR* pd ( + reinterpret_cast*> ( e.getOwnerDocument ()->getUserData (user_data_keys::node))); assert (pd != 0); assert (pd->get () == e.getOwnerDocument ()); - doc_ = *pd; // Transfer ownership. + // Transfer ownership. +#ifdef XSD_CXX11 + doc_ = std::move (*pd); +#else + doc_ = *pd; +#endif } } - virtual std::auto_ptr + virtual XSD_AUTO_PTR clone (type& tree_node, container* c) const { - using std::auto_ptr; - // Check if we are a document root. // if (c == 0) @@ -764,11 +762,10 @@ namespace xsd // We preserver DOM associations only in complete // copies from root. // - if (doc_.get () == 0) - return auto_ptr (0); - - return auto_ptr ( - new dom_element_info (*doc_, tree_node)); + return XSD_AUTO_PTR ( + doc_.get () == 0 + ? 0 + : new dom_element_info (*doc_, tree_node)); } // Check if our container does not have DOM association (e.g., @@ -779,8 +776,7 @@ namespace xsd DOMNode* cn (c->_node ()); if (cn == 0) - return auto_ptr (0); - + return XSD_AUTO_PTR (); // Now we are going to find the corresponding element in // the new tree. @@ -812,7 +808,7 @@ namespace xsd assert (dn->getNodeType () == DOMNode::ELEMENT_NODE); - return auto_ptr ( + return XSD_AUTO_PTR ( new dom_element_info (static_cast (*dn), tree_node, false)); @@ -835,7 +831,7 @@ namespace xsd } private: - xml::dom::auto_ptr doc_; + XSD_DOM_AUTO_PTR doc_; xercesc::DOMElement& e_; }; @@ -848,11 +844,9 @@ namespace xsd a_.setUserData (user_data_keys::node, &n, 0); } - virtual std::auto_ptr + virtual XSD_AUTO_PTR clone (type& tree_node, container* c) const { - using std::auto_ptr; - // Check if we are a document root. // if (c == 0) @@ -860,7 +854,7 @@ namespace xsd // We preserver DOM associations only in complete // copies from root. // - return auto_ptr (0); + return XSD_AUTO_PTR (); } // Check if our container does not have DOM association (e.g., @@ -871,7 +865,7 @@ namespace xsd DOMNode* cn (c->_node ()); if (cn == 0) - return auto_ptr (0); + return XSD_AUTO_PTR (); // We are going to find the corresponding attribute in // the new tree. @@ -898,7 +892,7 @@ namespace xsd DOMNode& n (*cn->getAttributes ()->item (i)); assert (n.getNodeType () == DOMNode::ATTRIBUTE_NODE); - return auto_ptr ( + return XSD_AUTO_PTR ( new dom_attribute_info (static_cast (n), tree_node)); } @@ -919,18 +913,18 @@ namespace xsd struct dom_info_factory { - static std::auto_ptr + static XSD_AUTO_PTR create (const xercesc::DOMElement& e, type& n, bool root) { - return std::auto_ptr ( + return XSD_AUTO_PTR ( new dom_element_info ( const_cast (e), n, root)); } - static std::auto_ptr + static XSD_AUTO_PTR create (const xercesc::DOMAttr& a, type& n) { - return std::auto_ptr ( + return XSD_AUTO_PTR ( new dom_attribute_info ( const_cast (a), n)); } @@ -938,7 +932,7 @@ namespace xsd //@endcond - std::auto_ptr dom_info_; + XSD_AUTO_PTR dom_info_; // ID/IDREF map. @@ -961,7 +955,7 @@ namespace xsd std::map map; - std::auto_ptr map_; + XSD_AUTO_PTR map_; private: container* container_; @@ -973,8 +967,7 @@ namespace xsd { if (x.dom_info_.get () != 0 && (f & flags::keep_dom)) { - std::auto_ptr r (x.dom_info_->clone (*this, c)); - dom_info_ = r; + dom_info_ = x.dom_info_->clone (*this, c); } } @@ -1183,25 +1176,25 @@ namespace xsd { typedef T type; - static std::auto_ptr + static XSD_AUTO_PTR create (const xercesc::DOMElement& e, flags f, container* c) { - return std::auto_ptr (new T (e, f, c)); + return XSD_AUTO_PTR (new T (e, f, c)); } - static std::auto_ptr + static XSD_AUTO_PTR create (const xercesc::DOMAttr& a, flags f, container* c) { - return std::auto_ptr (new T (a, f, c)); + return XSD_AUTO_PTR (new T (a, f, c)); } - static std::auto_ptr + static XSD_AUTO_PTR create (const std::basic_string& s, const xercesc::DOMElement* e, flags f, container* c) { - return std::auto_ptr (new T (s, e, f, c)); + return XSD_AUTO_PTR (new T (s, e, f, c)); } }; diff --git a/libxsd/xsd/cxx/tree/istream.hxx b/libxsd/xsd/cxx/tree/istream.hxx index b76fdcb..1ff2bd8 100644 --- a/libxsd/xsd/cxx/tree/istream.hxx +++ b/libxsd/xsd/cxx/tree/istream.hxx @@ -8,9 +8,11 @@ #include #include -#include // std::auto_ptr +#include // std::auto_ptr/unique_ptr #include // std::size_t +#include // XSD_AUTO_PTR + #include namespace xsd @@ -236,7 +238,7 @@ namespace xsd S& s_; std::size_t seq_; - std::auto_ptr pool_; + XSD_AUTO_PTR pool_; }; diff --git a/libxsd/xsd/cxx/tree/ostream.hxx b/libxsd/xsd/cxx/tree/ostream.hxx index 7d8711e..fde681e 100644 --- a/libxsd/xsd/cxx/tree/ostream.hxx +++ b/libxsd/xsd/cxx/tree/ostream.hxx @@ -8,9 +8,11 @@ #include #include -#include // std::auto_ptr +#include // std::auto_ptr/unique_ptr #include // std::size_t +#include // XSD_AUTO_PTR + namespace xsd { namespace cxx @@ -187,7 +189,7 @@ namespace xsd S& s_; std::size_t seq_; - std::auto_ptr pool_; + XSD_AUTO_PTR pool_; }; diff --git a/libxsd/xsd/cxx/tree/parsing.txx b/libxsd/xsd/cxx/tree/parsing.txx index e8bca99..14af025 100644 --- a/libxsd/xsd/cxx/tree/parsing.txx +++ b/libxsd/xsd/cxx/tree/parsing.txx @@ -35,25 +35,18 @@ namespace xsd // inline _type:: _type (const xercesc::DOMElement& e, flags f, container* c) - : dom_info_ (0), container_ (c) + : container_ (c) { if (f & flags::keep_dom) - { - std::auto_ptr r ( - dom_info_factory::create (e, *this, c == 0)); - dom_info_ = r; - } + dom_info_ = dom_info_factory::create (e, *this, c == 0); } inline _type:: _type (const xercesc::DOMAttr& a, flags f, container* c) - : dom_info_ (0), container_ (c) + : container_ (c) { if (f & flags::keep_dom) - { - std::auto_ptr r (dom_info_factory::create (a, *this)); - dom_info_ = r; - } + dom_info_ = dom_info_factory::create (a, *this); } template @@ -62,8 +55,7 @@ namespace xsd const xercesc::DOMElement*, flags, container* c) - : dom_info_ (0), // List elements don't have associated DOM nodes. - container_ (c) + : container_ (c) // List elements don't have associated DOM nodes. { } diff --git a/libxsd/xsd/cxx/tree/parsing/element-map.txx b/libxsd/xsd/cxx/tree/parsing/element-map.txx index 71f23a8..a284c39 100644 --- a/libxsd/xsd/cxx/tree/parsing/element-map.txx +++ b/libxsd/xsd/cxx/tree/parsing/element-map.txx @@ -17,7 +17,7 @@ namespace xsd namespace tree { template - std::auto_ptr > element_map:: + XSD_AUTO_PTR > element_map:: parse (const xercesc::DOMElement& e, flags f) { const qualified_name n (xml::dom::name (e)); @@ -30,10 +30,10 @@ namespace xsd } template - std::auto_ptr > + XSD_AUTO_PTR > parser_impl (const xercesc::DOMElement& e, flags f) { - return std::auto_ptr > (new T (e, f)); + return XSD_AUTO_PTR > (new T (e, f)); } } } diff --git a/libxsd/xsd/cxx/tree/stream-extraction-map.hxx b/libxsd/xsd/cxx/tree/stream-extraction-map.hxx index 1c18d51..245d786 100644 --- a/libxsd/xsd/cxx/tree/stream-extraction-map.hxx +++ b/libxsd/xsd/cxx/tree/stream-extraction-map.hxx @@ -7,9 +7,11 @@ #define XSD_CXX_TREE_STREAM_EXTRACTION_MAP_HXX #include -#include // std::auto_ptr +#include // std::auto_ptr/unique_ptr #include // std::size_t +#include // XSD_AUTO_PTR + #include #include #include @@ -24,7 +26,7 @@ namespace xsd struct stream_extraction_map { typedef xml::qualified_name qualified_name; - typedef std::auto_ptr (*extractor) ( + typedef XSD_AUTO_PTR (*extractor) ( istream&, flags, container*); public: @@ -38,7 +40,7 @@ namespace xsd void unregister_type (const qualified_name& name); - std::auto_ptr + XSD_AUTO_PTR extract (istream&, flags, container*); public: @@ -82,7 +84,7 @@ namespace xsd // // template - std::auto_ptr + XSD_AUTO_PTR extractor_impl (istream&, flags, container*); diff --git a/libxsd/xsd/cxx/tree/stream-extraction-map.txx b/libxsd/xsd/cxx/tree/stream-extraction-map.txx index 17b3fc5..156f9c0 100644 --- a/libxsd/xsd/cxx/tree/stream-extraction-map.txx +++ b/libxsd/xsd/cxx/tree/stream-extraction-map.txx @@ -233,7 +233,7 @@ namespace xsd } template - std::auto_ptr stream_extraction_map:: + XSD_AUTO_PTR stream_extraction_map:: extract (istream& s, flags f, container* c) { std::basic_string ns, name; @@ -303,10 +303,10 @@ namespace xsd // // template - std::auto_ptr + XSD_AUTO_PTR extractor_impl (istream& s, flags f, container* c) { - return std::auto_ptr (new T (s, f, c)); + return XSD_AUTO_PTR (new T (s, f, c)); } diff --git a/libxsd/xsd/cxx/tree/stream-extraction.hxx b/libxsd/xsd/cxx/tree/stream-extraction.hxx index eef60ca..e4a1740 100644 --- a/libxsd/xsd/cxx/tree/stream-extraction.hxx +++ b/libxsd/xsd/cxx/tree/stream-extraction.hxx @@ -67,8 +67,7 @@ namespace xsd while (size--) { - std::auto_ptr p (new T (s, f, c)); - this->push_back (p); + this->push_back (XSD_AUTO_PTR (new T (s, f, c))); } } } diff --git a/libxsd/xsd/cxx/tree/type-factory-map.hxx b/libxsd/xsd/cxx/tree/type-factory-map.hxx index a42ef96..ea173cc 100644 --- a/libxsd/xsd/cxx/tree/type-factory-map.hxx +++ b/libxsd/xsd/cxx/tree/type-factory-map.hxx @@ -8,11 +8,13 @@ #include #include -#include // std::auto_ptr +#include // std::auto_ptr/unique_ptr #include // std::size_t #include +#include // XSD_AUTO_PTR + #include #include @@ -26,9 +28,9 @@ namespace xsd struct type_factory_map { typedef xml::qualified_name qualified_name; - typedef std::auto_ptr (*factory) (const xercesc::DOMElement&, - flags, - container*); + typedef XSD_AUTO_PTR (*factory) (const xercesc::DOMElement&, + flags, + container*); public: type_factory_map (); @@ -49,7 +51,7 @@ namespace xsd unregister_element (const qualified_name& root, const qualified_name& subst); - std::auto_ptr + XSD_AUTO_PTR create (const C* name, // element name const C* ns, // element namespace factory static_type, @@ -66,7 +68,7 @@ namespace xsd private: template - static std::auto_ptr + static XSD_AUTO_PTR traits_adapter (const xercesc::DOMElement&, flags, container*); private: @@ -132,7 +134,7 @@ namespace xsd // // template - std::auto_ptr + XSD_AUTO_PTR factory_impl (const xercesc::DOMElement&, flags, container*); // diff --git a/libxsd/xsd/cxx/tree/type-factory-map.txx b/libxsd/xsd/cxx/tree/type-factory-map.txx index 998fb7b..174147c 100644 --- a/libxsd/xsd/cxx/tree/type-factory-map.txx +++ b/libxsd/xsd/cxx/tree/type-factory-map.txx @@ -273,7 +273,7 @@ namespace xsd } template - std::auto_ptr type_factory_map:: + XSD_AUTO_PTR type_factory_map:: create (const C* name, const C* ns, factory static_type, @@ -307,7 +307,7 @@ namespace xsd } if (f == 0) - return std::auto_ptr (0); // No match. + return XSD_AUTO_PTR (); // No match. // Check for xsi:type // @@ -326,11 +326,10 @@ namespace xsd template template - std::auto_ptr type_factory_map:: + XSD_AUTO_PTR type_factory_map:: traits_adapter (const xercesc::DOMElement& e, flags f, container* c) { - std::auto_ptr r (traits::create (e, f, c)); - return std::auto_ptr (r.release ()); + return XSD_AUTO_PTR (traits::create (e, f, c)); } template @@ -428,10 +427,10 @@ namespace xsd // // template - std::auto_ptr + XSD_AUTO_PTR factory_impl (const xercesc::DOMElement& e, flags f, container* c) { - return std::auto_ptr (new T (e, f, c)); + return XSD_AUTO_PTR (new T (e, f, c)); } // diff --git a/libxsd/xsd/cxx/tree/type-serializer-map.hxx b/libxsd/xsd/cxx/tree/type-serializer-map.hxx index 0ac9299..ca52129 100644 --- a/libxsd/xsd/cxx/tree/type-serializer-map.hxx +++ b/libxsd/xsd/cxx/tree/type-serializer-map.hxx @@ -16,6 +16,7 @@ #include #include +#include #include // namespace_infomap namespace xsd @@ -70,7 +71,7 @@ namespace xsd // Create DOMDocument with root element suitable for serializing // x into it. // - xml::dom::auto_ptr + XSD_DOM_AUTO_PTR serialize (const C* name, // element name const C* ns, // element namespace const xml::dom::namespace_infomap&, diff --git a/libxsd/xsd/cxx/tree/type-serializer-map.txx b/libxsd/xsd/cxx/tree/type-serializer-map.txx index 1dd1e52..454282e 100644 --- a/libxsd/xsd/cxx/tree/type-serializer-map.txx +++ b/libxsd/xsd/cxx/tree/type-serializer-map.txx @@ -399,7 +399,7 @@ namespace xsd } template - xml::dom::auto_ptr type_serializer_map:: + XSD_DOM_AUTO_PTR type_serializer_map:: serialize (const C* name, const C* ns, const xml::dom::namespace_infomap& m, diff --git a/libxsd/xsd/cxx/tree/types.txx b/libxsd/xsd/cxx/tree/types.txx index 98fcf81..61cb419 100644 --- a/libxsd/xsd/cxx/tree/types.txx +++ b/libxsd/xsd/cxx/tree/types.txx @@ -6,7 +6,13 @@ #include #include -#include +#include // XSD_CXX11 + +#ifdef XSD_CXX11 +# include // std::unique_ptr +#else +# include +#endif #include @@ -318,9 +324,13 @@ namespace xsd std::basic_string str; XMLSize_t n; - xml::std_memory_manager mm; + +#ifdef XSD_CXX11 + std::unique_ptr r ( +#else auto_array r ( +#endif Base64::encode ( reinterpret_cast (this->data ()), static_cast (this->size ()), @@ -353,9 +363,13 @@ namespace xsd xml::std_memory_manager mm; XMLSize_t size; +#ifdef XSD_CXX11 + std::unique_ptr data ( +#else auto_array data ( +#endif Base64::decodeToXMLByte (src, &size, &mm, Base64::Conf_RFC2045), - mm); + mm); if (data) { diff --git a/libxsd/xsd/cxx/xml/char-iso8859-1.txx b/libxsd/xsd/cxx/xml/char-iso8859-1.txx index ff82963..3ce88ad 100644 --- a/libxsd/xsd/cxx/xml/char-iso8859-1.txx +++ b/libxsd/xsd/cxx/xml/char-iso8859-1.txx @@ -3,7 +3,13 @@ // copyright : Copyright (c) 2005-2011 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file -#include +#include // XSD_CXX11 + +#ifdef XSD_CXX11 +# include // std::unique_ptr +#else +# include +#endif namespace xsd { @@ -87,7 +93,12 @@ namespace xsd { const C* end (s + len); - auto_array r (new XMLCh[len + 1]); +#ifdef XSD_CXX11 + std::unique_ptr r ( +#else + auto_array r ( +#endif + new XMLCh[len + 1]); XMLCh* ir (r.get ()); for (const C* p (s); p < end; ++p) diff --git a/libxsd/xsd/cxx/xml/char-lcp.txx b/libxsd/xsd/cxx/xml/char-lcp.txx index 7bd8862..21c85d0 100644 --- a/libxsd/xsd/cxx/xml/char-lcp.txx +++ b/libxsd/xsd/cxx/xml/char-lcp.txx @@ -7,7 +7,14 @@ #include -#include +#include // XSD_CXX11 + +#ifdef XSD_CXX11 +# include // std::unique_ptr +#else +# include +#endif + #include namespace xsd @@ -21,7 +28,11 @@ namespace xsd to (const XMLCh* s) { std_memory_manager mm; +#ifdef XSD_CXX11 + std::unique_ptr r ( +#else auto_array r ( +#endif xercesc::XMLString::transcode (s, &mm), mm); return std::basic_string (r.get ()); } @@ -30,12 +41,21 @@ namespace xsd std::basic_string char_lcp_transcoder:: to (const XMLCh* s, std::size_t len) { - auto_array tmp (new XMLCh[len + 1]); +#ifdef XSD_CXX11 + std::unique_ptr tmp ( +#else + auto_array tmp ( +#endif + new XMLCh[len + 1]); std::memcpy (tmp.get (), s, len * sizeof (XMLCh)); tmp[len] = XMLCh (0); std_memory_manager mm; +#ifdef XSD_CXX11 + std::unique_ptr r ( +#else auto_array r ( +#endif xercesc::XMLString::transcode (tmp.get (), &mm), mm); tmp.reset (); diff --git a/libxsd/xsd/cxx/xml/char-utf8.txx b/libxsd/xsd/cxx/xml/char-utf8.txx index ff3f9e0..7dc0ac9 100644 --- a/libxsd/xsd/cxx/xml/char-utf8.txx +++ b/libxsd/xsd/cxx/xml/char-utf8.txx @@ -3,7 +3,13 @@ // copyright : Copyright (c) 2005-2011 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file -#include +#include // XSD_CXX11 + +#ifdef XSD_CXX11 +# include // std::unique_ptr +#else +# include +#endif namespace xsd { @@ -184,7 +190,12 @@ namespace xsd if (!valid) throw invalid_utf8_string (); - auto_array r (new XMLCh[rl + 1]); +#ifdef XSD_CXX11 + std::unique_ptr r ( +#else + auto_array r ( +#endif + new XMLCh[rl + 1]); XMLCh* ir (r.get ()); unsigned int u (0); // Four byte UCS-4 char. 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 ()); } } diff --git a/libxsd/xsd/cxx/xml/std-memory-manager.hxx b/libxsd/xsd/cxx/xml/std-memory-manager.hxx index bd8fbab..00012fd 100644 --- a/libxsd/xsd/cxx/xml/std-memory-manager.hxx +++ b/libxsd/xsd/cxx/xml/std-memory-manager.hxx @@ -18,6 +18,8 @@ namespace xsd class std_memory_manager: public xercesc::MemoryManager { public: + // Xerces-C++ MemoryManager interface. + // virtual void* allocate(XMLSize_t size) { @@ -36,6 +38,15 @@ namespace xsd { return xercesc::XMLPlatformUtils::fgMemoryManager; } + + // Standard deleter interface. + // + void + operator() (void* p) const + { + if (p) + operator delete (p); + } }; } } diff --git a/libxsd/xsd/cxx/xml/string.hxx b/libxsd/xsd/cxx/xml/string.hxx index f1a907c..832e7ec 100644 --- a/libxsd/xsd/cxx/xml/string.hxx +++ b/libxsd/xsd/cxx/xml/string.hxx @@ -9,9 +9,16 @@ #include #include // std::size_t -#include #include // XMLCh +#include // XSD_CXX11 + +#ifdef XSD_CXX11 +# include // std::unique_ptr +#else +# include +#endif + namespace xsd { namespace cxx @@ -73,7 +80,11 @@ namespace xsd operator= (const string&); private: +#ifdef XSD_CXX11 + std::unique_ptr s_; +#else auto_array s_; +#endif }; } } diff --git a/libxsd/xsd/cxx/xml/string.txx b/libxsd/xsd/cxx/xml/string.txx index 830ed92..c6f1d20 100644 --- a/libxsd/xsd/cxx/xml/string.txx +++ b/libxsd/xsd/cxx/xml/string.txx @@ -47,7 +47,13 @@ namespace xsd XMLCh* wchar_transcoder:: from (const W* s, std::size_t length) { - auto_array r (new XMLCh[length + 1]); +#ifdef XSD_CXX11 + std::unique_ptr r ( +#else + auto_array r ( +#endif + new XMLCh[length + 1]); + XMLCh* ir (r.get ()); for (std::size_t i (0); i < length; ++ir, ++i) @@ -120,7 +126,13 @@ namespace xsd rl += (*p & 0xFFFF0000) ? 2 : 1; } - auto_array r (new XMLCh[rl + 1]); +#ifdef XSD_CXX11 + std::unique_ptr r ( +#else + auto_array r ( +#endif + new XMLCh[rl + 1]); + XMLCh* ir (r.get ()); for (const W* p (s); p < s + length; ++p) -- cgit v1.1