#ifndef _F77AUTO_PTR_
#define _F77AUTO_PTR_

#ifdef  _MSC_VER
#pragma pack(push,8)
#endif  /* _MSC_VER */

namespace freddy77
{

// TEMPLATE CLASS auto_ptr
template<class _Ty>
class hp_auto_ptr {
public:
	typedef _Ty element_type;
	explicit hp_auto_ptr(_Ty *P = 0)
		: _Owns(P != 0), _Ptr(P) {;}
	hp_auto_ptr(const hp_auto_ptr<_Ty>& _Y)
		: _Owns(_Y._Owns), _Ptr(_Y.release()) {;}
	hp_auto_ptr<_Ty>& operator=(const hp_auto_ptr<_Ty>& _Y)
		{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); }
	~hp_auto_ptr()
		{if (_Owns)
			delete _Ptr; }
	_Ty& operator*() const
		{return (*get()); }
	_Ty *operator->() const
		{return (get()); }
	_Ty *get() const
		{return (_Ptr); }
	_Ty *release() const
		{ this->_Owns = false;
		return (_Ptr); }
private:
	mutable bool _Owns;
	_Ty *_Ptr;
};

// TEMPLATE CLASS auto_delete_ptr
// simile a auto_ptr ma cancella solo
template<class _Ty>
class auto_delete_ptr {
public:
	typedef _Ty element_type;
	explicit auto_delete_ptr(_Ty *P = 0)
		: _Ptr(P) {}
	auto_delete_ptr<_Ty>& operator=(_Ty *P)
		{ delete _Ptr; _Ptr = P; return *this; }
	~auto_delete_ptr()
		{ delete _Ptr; }
	_Ty& operator*() const
		{ return (*get()); }
	_Ty *operator->() const
		{ return (get()); }
	_Ty *get() const 
		{ return (_Ptr); }
	_Ty *release() 
		{ _Ty* tmp = _Ptr; _Ptr = 0; return tmp; }
private:
	_Ty *_Ptr;
	// not implemented
	auto_delete_ptr(const auto_delete_ptr<_Ty>& _Y);
	auto_delete_ptr<_Ty>& operator=(const auto_delete_ptr<_Ty>& _Y);
};


} // end namespace freddy77

#ifdef  _MSC_VER
#pragma pack(pop)
#endif  /* _MSC_VER */

#endif /* _F77AUTO_PTR_ */

/*
 * Copyright (c) 1995 by P.J. Plauger.  ALL RIGHTS RESERVED. 
 * Consult your license regarding permissions and restrictions.
 */

/*
 * This file is derived from software bearing the following
 * restrictions:
 *
 * Copyright (c) 1994
 * Hewlett-Packard Company
 *
 * Permission to use, copy, modify, distribute and sell this
 * software and its documentation for any purpose is hereby
 * granted without fee, provided that the above copyright notice
 * appear in all copies and that both that copyright notice and
 * this permission notice appear in supporting documentation.
 * Hewlett-Packard Company makes no representations about the
 * suitability of this software for any purpose. It is provided
 * "as is" without express or implied warranty.
 */
