Main Page | Class Hierarchy | Class List | File List | Class Members | Related Pages

autovec.h

00001 
00002 // This code is based on bits/std_memory.h from GCC.
00003 // The copyright and license information from the
00004 // original code is below.
00005 
00006 // Copyright (C) 2001 Free Software Foundation, Inc.
00007 //
00008 // This file is part of the GNU ISO C++ Library.  This library is free
00009 // software; you can redistribute it and/or modify it under the
00010 // terms of the GNU General Public License as published by the
00011 // Free Software Foundation; either version 2, or (at your option)
00012 // any later version.
00013 
00014 // This library is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 // GNU General Public License for more details.
00018 
00019 // You should have received a copy of the GNU General Public License along
00020 // with this library; see the file COPYING.  If not, write to the Free
00021 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
00022 // USA.
00023 
00024 // As a special exception, you may use this file as part of a free software
00025 // library without restriction.  Specifically, if other files instantiate
00026 // templates or use macros or inline functions from this file, or you compile
00027 // this file and link it with other files to produce an executable, this
00028 // file does not by itself cause the resulting executable to be covered by
00029 // the GNU General Public License.  This exception does not however
00030 // invalidate any other reasons why the executable file might be covered by
00031 // the GNU General Public License.
00032 
00033 /*
00034  * Copyright (c) 1997-1999
00035  * Silicon Graphics Computer Systems, Inc.
00036  *
00037  * Permission to use, copy, modify, distribute and sell this software
00038  * and its documentation for any purpose is hereby granted without fee,
00039  * provided that the above copyright notice appear in all copies and
00040  * that both that copyright notice and this permission notice appear
00041  * in supporting documentation.  Silicon Graphics makes no
00042  * representations about the suitability of this software for any
00043  * purpose.  It is provided "as is" without express or implied warranty.
00044  *
00045  */
00046 
00047 #ifndef _autovec_h
00048 #define _autovec_h
00049 
00050 namespace sc {
00051 
00055 template <class T>
00056 class auto_vec {
00057     T* d_;
00058   public:
00059     typedef T element_type;
00060 
00064     explicit auto_vec(T*d) throw(): d_(d) {}
00065 
00067     auto_vec(auto_vec &av) throw(): d_(av.release()) {}
00068 
00070     ~auto_vec() throw() { delete[] d_; }
00071 
00073     auto_vec &operator = (auto_vec &av) throw() {
00074       reset(av.release());
00075       return *this;
00076     }
00077 
00079     T* get() const throw() { return d_; }
00080 
00082     T* release() throw() {
00083       T *r = d_;
00084       d_ = 0;
00085       return r;
00086     }
00087 
00089     void reset(T*d=0) throw() {
00090       if (d != d_) {
00091           delete[] d_;
00092           d_ = d;
00093         }
00094     }
00095       
00096 };
00097 
00098 }
00099 
00100 #endif // _autovec_h
00101 

Generated at Fri Mar 19 10:48:12 2004 for MPQC 2.2.1 using the documentation package Doxygen 1.3.5.