From 2615896faa646e5830abf2c269150e1165c66515 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Fri, 18 Dec 2020 18:48:46 +0300 Subject: Switch to build2 --- libxsd/libxsd/cxx/xml/dom/auto-ptr.hxx | 232 +++++++++++++++++++++++++++++++++ 1 file changed, 232 insertions(+) create mode 100644 libxsd/libxsd/cxx/xml/dom/auto-ptr.hxx (limited to 'libxsd/libxsd/cxx/xml/dom/auto-ptr.hxx') diff --git a/libxsd/libxsd/cxx/xml/dom/auto-ptr.hxx b/libxsd/libxsd/cxx/xml/dom/auto-ptr.hxx new file mode 100644 index 0000000..4e19547 --- /dev/null +++ b/libxsd/libxsd/cxx/xml/dom/auto-ptr.hxx @@ -0,0 +1,232 @@ +// file : libxsd/cxx/xml/dom/auto-ptr.hxx +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef LIBXSD_CXX_XML_DOM_AUTO_PTR_HXX +#define LIBXSD_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 + { + namespace xml + { + namespace dom + { +#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 + { + typedef T r; + }; + + template + struct remove_c + { + typedef T r; + }; + + template + struct auto_ptr_ref + { + T* x_; + + explicit + auto_ptr_ref (T* x) + : x_ (x) + { + } + }; + + template + struct auto_ptr + { + ~auto_ptr () + { + reset (); + } + + explicit + auto_ptr (T* x = 0) + : x_ (x) + { + } + + auto_ptr (auto_ptr& y) + : x_ (y.release ()) + { + } + + template + auto_ptr (auto_ptr& y) + : x_ (y.release ()) + { + } + + auto_ptr (auto_ptr_ref r) + : x_ (r.x_) + { + } + + auto_ptr& + operator= (auto_ptr& y) + { + if (x_ != y.x_) + reset (y.release ()); + + return *this; + } + + template + auto_ptr& + operator= (auto_ptr& y) + { + if (x_ != y.x_) + reset (y.release ()); + + return *this; + } + + auto_ptr& + operator= (auto_ptr_ref r) + { + if (r.x_ != x_) + reset (r.x_); + + return *this; + } + + template + operator auto_ptr_ref () + { + return auto_ptr_ref (release ()); + } + + template + operator auto_ptr () + { + return auto_ptr (release ()); + } + + public: + T& + operator* () const + { + return *x_; + } + + T* + operator-> () const + { + return x_; + } + + T* + get () const + { + return x_; + } + + T* + release () + { + T* x (x_); + x_ = 0; + return x; + } + + void + reset (T* x = 0) + { + if (x_) + const_cast::r*> (x_)->release (); + + x_ = x; + } + + private: + T* x_; + }; + +#define XSD_DOM_AUTO_PTR xsd::cxx::xml::dom::auto_ptr + +#endif // XSD_CXX11 + } + } + } +} + +#endif // LIBXSD_CXX_XML_DOM_AUTO_PTR_HXX -- cgit v1.1