From 26e36b3a9d7b49d46ecfa69b447482251acba8ac Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Wed, 24 Jan 2024 16:53:38 +0300 Subject: Turn libodb repository into package for muti-package repository --- libodb/odb/details/unique-ptr.hxx | 95 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 libodb/odb/details/unique-ptr.hxx (limited to 'libodb/odb/details/unique-ptr.hxx') diff --git a/libodb/odb/details/unique-ptr.hxx b/libodb/odb/details/unique-ptr.hxx new file mode 100644 index 0000000..06b2c76 --- /dev/null +++ b/libodb/odb/details/unique-ptr.hxx @@ -0,0 +1,95 @@ +// file : odb/details/unique-ptr.hxx +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef ODB_DETAILS_UNIQUE_PTR_HXX +#define ODB_DETAILS_UNIQUE_PTR_HXX + +#include + +#include + +namespace odb +{ + namespace details + { + template + class unique_ptr + { + public: + typedef T element_type; + + explicit unique_ptr (T* p = 0): p_ (p) {} + ~unique_ptr () {delete p_;} + +#ifdef ODB_CXX11 + unique_ptr (unique_ptr&& p) noexcept: p_ (p.p_) {p.p_ = 0;} + unique_ptr& operator= (unique_ptr&& p) noexcept + { + if (this != &p) + { + delete p_; + p_ = p.p_; + p.p_ = 0; + } + return *this; + } +#endif + + private: + unique_ptr (const unique_ptr&); + unique_ptr& operator= (const unique_ptr&); + + public: + T* + operator-> () const {return p_;} + + T& + operator* () const {return *p_;} + + typedef T* unique_ptr::*unspecified_bool_type; + operator unspecified_bool_type () const + { + return p_ != 0 ? &unique_ptr::p_ : 0; + } + + T* + get () const {return p_;} + + void + reset (T* p = 0) + { + delete p_; + p_ = p; + } + + T* + release () + { + T* r (p_); + p_ = 0; + return r; + } + + private: + T* p_; + }; + + template + inline bool + operator== (const unique_ptr& a, const unique_ptr& b) + { + return a.get () == b.get (); + } + + template + inline bool + operator!= (const unique_ptr& a, const unique_ptr& b) + { + return a.get () != b.get (); + } + } +} + +#include + +#endif // ODB_DETAILS_UNIQUE_PTR_HXX -- cgit v1.1