13c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#ifndef _DEUNIQUEPTR_HPP 23c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#define _DEUNIQUEPTR_HPP 33c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*------------------------------------------------------------------------- 43c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * drawElements C++ Base Library 53c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * ----------------------------- 63c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 73c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Copyright 2014 The Android Open Source Project 83c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 93c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Licensed under the Apache License, Version 2.0 (the "License"); 103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * you may not use this file except in compliance with the License. 113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * You may obtain a copy of the License at 123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * http://www.apache.org/licenses/LICENSE-2.0 143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Unless required by applicable law or agreed to in writing, software 163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * distributed under the License is distributed on an "AS IS" BASIS, 173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * See the License for the specific language governing permissions and 193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * limitations under the License. 203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*! 223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \file 233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Unique pointer. 243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/ 253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deDefs.hpp" 273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 283c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace de 293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry//! Unique pointer self-test. 323c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid UniquePtr_selfTest (void); 333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// Hide implementation-private types in a details namespace. 353c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace details 363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry//! Auxiliary struct used to pass references between unique pointers. To 393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry//! ensure that managed pointers are deleted exactly once, this type should 403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry//! not appear in user code. 413c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<typename T, class D> 423c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct PtrData 433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry PtrData (T* p, D d) : ptr(p), deleter(d) {} 453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry template <typename T2, class D2> 473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry PtrData (const PtrData<T2, D2>& d) : ptr(d.ptr), deleter(d.deleter) {} 483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry T* ptr; 503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry D deleter; 513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 533c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<typename T, class D> 543c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass UniqueBase 553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 563c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry typedef T element_type; 583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry typedef D deleter_type; 593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry T* get (void) const throw() { return m_data.ptr; } //!< Get stored pointer. 613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry D getDeleter (void) const throw() { return m_data.deleter; } 623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry T* operator-> (void) const throw() { return get(); } //!< Get stored pointer. 633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry T& operator* (void) const throw() { return *get(); } //!< De-reference stored pointer. 643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry operator bool (void) const throw() { return !!get(); } 653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 663c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprotected: 673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry UniqueBase (T* ptr, D deleter) : m_data(ptr, deleter) {} 683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry UniqueBase (PtrData<T, D> data) : m_data(data) {} 693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ~UniqueBase (void); 703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void reset (void); //!< Delete previous pointer, set to null. 723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry PtrData<T, D> releaseData (void) throw(); //!< Relinquish ownership, return pointer data. 733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void assignData (PtrData<T, D> data); //!< Set new pointer, delete previous pointer. 743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 753c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate: 763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry PtrData<T, D> m_data; 773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 793c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename T, class D> 803c827367444ee418f129b2c238299f49d3264554Jarkko PoyryUniqueBase<T, D>::~UniqueBase (void) 813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry reset(); 833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 853c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename T, class D> 863c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid UniqueBase<T, D>::reset (void) 873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_data.ptr != DE_NULL) 893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_data.deleter(m_data.ptr); 913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_data.ptr = DE_NULL; 923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 953c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename T, class D> 963c827367444ee418f129b2c238299f49d3264554Jarkko PoyryPtrData<T, D> UniqueBase<T, D>::releaseData (void) throw() 973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry PtrData<T, D> data = m_data; 993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_data.ptr = DE_NULL; 1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return data; 1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename T, class D> 1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid UniqueBase<T, D>::assignData (PtrData<T, D> data) 1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (data.ptr != m_data.ptr) 1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry reset(); 1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_data = data; 1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*--------------------------------------------------------------------*//*! 1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Movable unique pointer 1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * A MovePtr is smart pointer that retains sole ownership of a pointer and 1173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * destroys it when it is destroyed (for example when it goes out of scope). 1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * A MovePtr can be copied and assigned to. The pointer ownership is moved to 1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * the newly constructer or assigned-to MovePtr. Upon assignment to a 1213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * MovePtr, the previously managed pointer is deleted. 1223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 1233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/ 1243c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<typename T, class Deleter = DefaultDeleter<T> > 1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass MovePtr : public UniqueBase<T, Deleter> 1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1273c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 1283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry MovePtr (void) : UniqueBase<T, Deleter> (DE_NULL, Deleter()) {} 1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry explicit MovePtr (T* ptr, Deleter deleter = Deleter()) : UniqueBase<T, Deleter> (ptr, deleter) {} 1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry MovePtr (MovePtr<T, Deleter>& other) : UniqueBase<T, Deleter> (other.releaseData()) {} 1313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry MovePtr& operator= (MovePtr<T, Deleter>& other); 1333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry T* release (void) throw(); 1343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void clear (void) { this->reset(); } 1353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // These implicit by-value conversions to and from a PtrData are used to 1373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // allow copying a MovePtr by value when returning from a function. To 1383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // ensure that the managed pointer gets deleted exactly once, the PtrData 1393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // should only exist as a temporary conversion step between two MovePtrs. 1403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry MovePtr (PtrData<T, Deleter> data) : UniqueBase<T, Deleter> (data) {} 1413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry MovePtr& operator= (PtrData<T, Deleter> data); 1423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry template<typename U, class Del2> 1443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry operator PtrData<U, Del2> (void) { return this->releaseData(); } 1453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 1463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1473c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<typename T, class D> 1483c827367444ee418f129b2c238299f49d3264554Jarkko PoyryMovePtr<T, D>& MovePtr<T,D>::operator= (PtrData<T, D> data) 1493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry this->assignData(data); 1513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return *this; 1523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1543c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<typename T, class D> 1553c827367444ee418f129b2c238299f49d3264554Jarkko PoyryMovePtr<T, D>& MovePtr<T,D>::operator= (MovePtr<T, D>& other) 1563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return (*this = other.releaseData()); 1583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry//! Steal the managed pointer. The caller is responsible for explicitly 1613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry//! deleting the returned pointer. 1623c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<typename T, class D> 1633c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline T* MovePtr<T,D>::release (void) throw() 1643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return this->releaseData().ptr; 1663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry//! Construct a MovePtr from a pointer. 1693c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<typename T> 1703c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline MovePtr<T> movePtr (T* ptr) { return MovePtr<T>(ptr); } 1713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry//! Allocate and construct an object and return its address as a MovePtr. 1733c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<typename T> 1743c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline MovePtr<T> newMovePtr (void) { return MovePtr<T>(new T()); } 1753c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<typename T, typename P0> 1763c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline MovePtr<T> newMovePtr (P0 p0) { return MovePtr<T>(new T(p0)); } 1773c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<typename T, typename P0, typename P1> 1783c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline MovePtr<T> newMovePtr (P0 p0, P1 p1) { return MovePtr<T>(new T(p0, p1)); } 1793c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<typename T, typename P0, typename P1, typename P2> 1803c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline MovePtr<T> newMovePtr (P0 p0, P1 p1, P2 p2) { return MovePtr<T>(new T(p0, p1, p2)); } 1813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*--------------------------------------------------------------------*//*! 1833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Unique pointer 1843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 1853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * UniquePtr is smart pointer that retains sole ownership of a pointer 1863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * and destroys it when UniquePtr is destroyed (for example when UniquePtr 1873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * goes out of scope). 1883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 1893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * UniquePtr is not copyable or assignable. Pointer ownership can be transferred 1903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * from a UniquePtr only explicitly with the move() member function. 1913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 1923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * A UniquePtr can be constructed from a MovePtr. In this case it assumes 1933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * ownership of the pointer from the MovePtr. Because a UniquePtr cannot be 1943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * copied, direct initialization syntax must be used, i.e.: 1953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 1963fdee359c9eee4d6c1d823b23f7f64631b5945f8Jarkko Pöyry * MovePtr<Foo> createFoo (void); 1973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * UniquePtr<Foo> fooPtr(createFoo()); // NOT fooPtr = createFoo(); 1983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 1993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/ 2003c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<typename T, class Deleter = DefaultDeleter<T> > 2013c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass UniquePtr : public UniqueBase<T, Deleter> 2023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2033c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 2043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry explicit UniquePtr (T* ptr, Deleter deleter = Deleter()); 2053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry UniquePtr (PtrData<T, Deleter> data); 2063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry MovePtr<T, Deleter> move (void); 2073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2083c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate: 2093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry UniquePtr (const UniquePtr<T>& other); // Not allowed! 2103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry UniquePtr operator= (const UniquePtr<T>& other); // Not allowed! 2113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 2123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*--------------------------------------------------------------------*//*! 2143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Construct unique pointer. 2153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \param ptr Pointer to be managed. 2163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 2173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Pointer ownership is transferred to the UniquePtr. 2183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/ 2193c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<typename T, class Deleter> 2203c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline UniquePtr<T, Deleter>::UniquePtr (T* ptr, Deleter deleter) 2213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : UniqueBase<T, Deleter> (ptr, deleter) 2223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 2243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2253c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<typename T, class Deleter> 2263c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline UniquePtr<T, Deleter>::UniquePtr (PtrData<T, Deleter> data) 2273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : UniqueBase<T, Deleter> (data) 2283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 2303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*--------------------------------------------------------------------*//*! 2323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Relinquish ownership of pointer. 2333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 2343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * This method returns a MovePtr that now owns the pointer. The pointer in 2353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * the UniquePtr is set to null. 2363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/ 2373c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<typename T, class Deleter> 2383c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline MovePtr<T, Deleter> UniquePtr<T, Deleter>::move (void) 2393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return MovePtr<T, Deleter>(this->releaseData()); 2413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 2423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // details 2443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2453c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing details::UniquePtr; 2463c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing details::MovePtr; 2473c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing details::newMovePtr; 2483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // de 2503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#endif // _DEUNIQUEPTR_HPP 252