Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

f77auto_ptr

Go to the documentation of this file.
00001 #ifndef _F77AUTO_PTR_
00002 #define _F77AUTO_PTR_
00003 
00004 #ifdef  _MSC_VER
00005 #pragma pack(push,8)
00006 #endif  /* _MSC_VER */
00007 
00008 namespace freddy77
00009 {
00010 
00011 // TEMPLATE CLASS auto_ptr
00012 template<class _Ty>
00013 class hp_auto_ptr {
00014 public:
00015         typedef _Ty element_type;
00016         explicit hp_auto_ptr(_Ty *P = 0)
00017                 : _Owns(P != 0), _Ptr(P) {;}
00018         hp_auto_ptr(const hp_auto_ptr<_Ty>& _Y)
00019                 : _Owns(_Y._Owns), _Ptr(_Y.release()) {;}
00020         hp_auto_ptr<_Ty>& operator=(const hp_auto_ptr<_Ty>& _Y)
00021                 {if (this != &_Y)
00022                         {if (_Ptr != _Y.get())
00023                                 {if (_Owns)
00024                                         delete _Ptr;
00025                                 _Owns = _Y._Owns; }
00026                         else if (_Y._Owns)
00027                                 _Owns = true;
00028                         _Ptr = _Y.release(); }
00029                 return (*this); }
00030         ~hp_auto_ptr()
00031                 {if (_Owns)
00032                         delete _Ptr; }
00033         _Ty& operator*() const
00034                 {return (*get()); }
00035         _Ty *operator->() const
00036                 {return (get()); }
00037         _Ty *get() const
00038                 {return (_Ptr); }
00039         _Ty *release() const
00040                 { this->_Owns = false;
00041                 return (_Ptr); }
00042 private:
00043         mutable bool _Owns;
00044         _Ty *_Ptr;
00045 };
00046 
00047 // TEMPLATE CLASS auto_delete_ptr
00048 // simile a auto_ptr ma cancella solo
00049 template<class _Ty>
00050 class auto_delete_ptr {
00051 public:
00052         typedef _Ty element_type;
00053         explicit auto_delete_ptr(_Ty *P = 0)
00054                 : _Ptr(P) {}
00055         auto_delete_ptr<_Ty>& operator=(_Ty *P)
00056                 { delete _Ptr; _Ptr = P; return *this; }
00057         ~auto_delete_ptr()
00058                 { delete _Ptr; }
00059         _Ty& operator*() const
00060                 { return (*get()); }
00061         _Ty *operator->() const
00062                 { return (get()); }
00063         _Ty *get() const 
00064                 { return (_Ptr); }
00065         _Ty *release() 
00066                 { _Ty* tmp = _Ptr; _Ptr = 0; return tmp; }
00067 private:
00068         _Ty *_Ptr;
00069         // not implemented
00070         auto_delete_ptr(const auto_delete_ptr<_Ty>& _Y);
00071         auto_delete_ptr<_Ty>& operator=(const auto_delete_ptr<_Ty>& _Y);
00072 };
00073 
00074 
00075 } // end namespace freddy77
00076 
00077 #ifdef  _MSC_VER
00078 #pragma pack(pop)
00079 #endif  /* _MSC_VER */
00080 
00081 #endif /* _F77AUTO_PTR_ */
00082 
00083 /*
00084  * Copyright (c) 1995 by P.J. Plauger.  ALL RIGHTS RESERVED. 
00085  * Consult your license regarding permissions and restrictions.
00086  */
00087 
00088 /*
00089  * This file is derived from software bearing the following
00090  * restrictions:
00091  *
00092  * Copyright (c) 1994
00093  * Hewlett-Packard Company
00094  *
00095  * Permission to use, copy, modify, distribute and sell this
00096  * software and its documentation for any purpose is hereby
00097  * granted without fee, provided that the above copyright notice
00098  * appear in all copies and that both that copyright notice and
00099  * this permission notice appear in supporting documentation.
00100  * Hewlett-Packard Company makes no representations about the
00101  * suitability of this software for any purpose. It is provided
00102  * "as is" without express or implied warranty.
00103  */

Generated on Mon Jan 13 22:20:34 2003 for perdr by doxygen1.2.15