Whole document tree
    

Whole document tree

std_memory.h Source File
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

std_memory.h

Go to the documentation of this file.
00001 // <memory> -*- C++ -*-
00002 
00003 // Copyright (C) 2001 Free Software Foundation, Inc.
00004 //
00005 // This file is part of the GNU ISO C++ Library.  This library is free
00006 // software; you can redistribute it and/or modify it under the
00007 // terms of the GNU General Public License as published by the
00008 // Free Software Foundation; either version 2, or (at your option)
00009 // any later version.
00010 
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU General Public License for more details.
00015 
00016 // You should have received a copy of the GNU General Public License along
00017 // with this library; see the file COPYING.  If not, write to the Free
00018 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
00019 // USA.
00020 
00021 // As a special exception, you may use this file as part of a free software
00022 // library without restriction.  Specifically, if other files instantiate
00023 // templates or use macros or inline functions from this file, or you compile
00024 // this file and link it with other files to produce an executable, this
00025 // file does not by itself cause the resulting executable to be covered by
00026 // the GNU General Public License.  This exception does not however
00027 // invalidate any other reasons why the executable file might be covered by
00028 // the GNU General Public License.
00029 
00030 /*
00031  * Copyright (c) 1997-1999
00032  * Silicon Graphics Computer Systems, Inc.
00033  *
00034  * Permission to use, copy, modify, distribute and sell this software
00035  * and its documentation for any purpose is hereby granted without fee,
00036  * provided that the above copyright notice appear in all copies and
00037  * that both that copyright notice and this permission notice appear
00038  * in supporting documentation.  Silicon Graphics makes no
00039  * representations about the suitability of this software for any
00040  * purpose.  It is provided "as is" without express or implied warranty.
00041  *
00042  */
00043 
00044 #ifndef _CPP_MEMORY
00045 #define _CPP_MEMORY 1
00046 
00047 #pragma GCC system_header
00048 
00049 #include <bits/stl_algobase.h>
00050 #include <bits/stl_alloc.h>
00051 #include <bits/stl_construct.h>
00052 #include <bits/stl_iterator_base_types.h> //for iterator_traits
00053 #include <bits/stl_tempbuf.h>
00054 #include <bits/stl_uninitialized.h>
00055 #include <bits/stl_raw_storage_iter.h>
00056 
00057 namespace std
00058 {
00059 
00060  template<class _Tp1> struct auto_ptr_ref {
00061    _Tp1* _M_ptr;
00062    auto_ptr_ref(_Tp1* __p) : _M_ptr(__p) {}
00063 };
00064 
00065 template <class _Tp> class auto_ptr {
00066 private:
00067   _Tp* _M_ptr;
00068 
00069 public:
00070   typedef _Tp element_type;
00071 
00072   explicit auto_ptr(_Tp* __p = 0) __STL_NOTHROW : _M_ptr(__p) {}
00073   auto_ptr(auto_ptr& __a) __STL_NOTHROW : _M_ptr(__a.release()) {}
00074 
00075   template <class _Tp1> auto_ptr(auto_ptr<_Tp1>& __a) __STL_NOTHROW
00076     : _M_ptr(__a.release()) {}
00077 
00078   auto_ptr& operator=(auto_ptr& __a) __STL_NOTHROW {
00079     reset(__a.release());
00080     return *this;
00081   }
00082 
00083   template <class _Tp1>
00084   auto_ptr& operator=(auto_ptr<_Tp1>& __a) __STL_NOTHROW {
00085     reset(__a.release());
00086     return *this;
00087   }
00088   
00089   // Note: The C++ standard says there is supposed to be an empty throw
00090   // specification here, but omitting it is standard conforming.  Its 
00091   // presence can be detected only if _Tp::~_Tp() throws, but (17.4.3.6/2)
00092   // this is prohibited.
00093   ~auto_ptr() { delete _M_ptr; }
00094  
00095   _Tp& operator*() const __STL_NOTHROW {
00096     return *_M_ptr;
00097   }
00098   _Tp* operator->() const __STL_NOTHROW {
00099     return _M_ptr;
00100   }
00101   _Tp* get() const __STL_NOTHROW {
00102     return _M_ptr;
00103   }
00104   _Tp* release() __STL_NOTHROW {
00105     _Tp* __tmp = _M_ptr;
00106     _M_ptr = 0;
00107     return __tmp;
00108   }
00109   void reset(_Tp* __p = 0) __STL_NOTHROW {
00110     if (__p != _M_ptr) {
00111       delete _M_ptr;
00112       _M_ptr = __p;
00113     }    
00114   }
00115 
00116   // According to the C++ standard, these conversions are required.  Most
00117   // present-day compilers, however, do not enforce that requirement---and, 
00118   // in fact, most present-day compilers do not support the language 
00119   // features that these conversions rely on.
00120 public:
00121   auto_ptr(auto_ptr_ref<_Tp> __ref) __STL_NOTHROW
00122     : _M_ptr(__ref._M_ptr) {}
00123 
00124   auto_ptr& operator=(auto_ptr_ref<_Tp> __ref) __STL_NOTHROW {
00125     if (__ref._M_ptr != this->get()) {
00126       delete _M_ptr;
00127       _M_ptr = __ref._M_ptr;
00128     }
00129     return *this;
00130   }
00131 
00132   template <class _Tp1> operator auto_ptr_ref<_Tp1>() __STL_NOTHROW 
00133     { return auto_ptr_ref<_Tp>(this->release()); }
00134   template <class _Tp1> operator auto_ptr<_Tp1>() __STL_NOTHROW
00135     { return auto_ptr<_Tp1>(this->release()); }
00136 };
00137 
00138 } // namespace std
00139 
00140 #endif /* _CPP_MEMORY */
00141 
00142 
00143 // Local Variables:
00144 // mode:C++
00145 // End:

Generated on Mon Apr 8 03:11:34 2002 for libstdc++-v3 Source by doxygen1.2.15