|
// auto_array_ptr.h
//
// Author : David Shepherd
// Copyright (c) 2002, DaeDoe-Software
//
/////////////////////////////////////////////////////////////////////////////
#if !defined(AFX_AUTO_ARRAY_PTR_H__571358A1_15C3_11D6_B6A6_80A09D5B1F45__INCLUDED_)
#define AFX_AUTO_ARRAY_PTR_H__571358A1_15C3_11D6_B6A6_80A09D5B1F45__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
/////////////////////////////////////////////////////////////////////////////
// auto_array_ptr
template<class _Ty>
class auto_array_ptr {
public:
typedef _Ty element_type;
explicit auto_array_ptr(_Ty *_P = 0) _THROW0()
: _Owns(_P != 0), _Ptr(_P) {}
auto_array_ptr(const auto_array_ptr<_Ty>& _Y) _THROW0()
: _Owns(_Y._Owns), _Ptr(_Y.release()) {}
auto_array_ptr<_Ty>& operator=(const auto_array_ptr<_Ty>& _Y) _THROW0()
{if (this != &_Y)
{if (_Ptr != _Y.get())
{if (_Owns)
delete [] _Ptr;
_Owns = _Y._Owns; }
else if (_Y._Owns)
_Owns = true;
_Ptr = _Y.release(); }
return (*this); }
~auto_array_ptr()
{if (_Owns)
delete [] _Ptr; }
_Ty& operator*() const _THROW0()
{return (*get()); }
_Ty *operator->() const _THROW0()
{return (get()); }
_Ty *get() const _THROW0()
{return (_Ptr); }
_Ty *release() const _THROW0()
{((auto_array_ptr<_Ty> *)this)->_Owns = false;
return (_Ptr); }
private:
bool _Owns;
_Ty *_Ptr;
};
#endif // !defined(AFX_AUTO_ARRAY_PTR_H__571358A1_15C3_11D6_B6A6_80A09D5B1F45__INCLUDED_)
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.