MPQC 2.3.1
autovec.h
1
2// This code is based on bits/std_memory.h from GCC.
3// The copyright and license information from the
4// original code is below.
5
6// Copyright (C) 2001 Free Software Foundation, Inc.
7//
8// This file is part of the GNU ISO C++ Library. This library is free
9// software; you can redistribute it and/or modify it under the
10// terms of the GNU General Public License as published by the
11// Free Software Foundation; either version 2, or (at your option)
12// any later version.
13
14// This library is distributed in the hope that it will be useful,
15// but WITHOUT ANY WARRANTY; without even the implied warranty of
16// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17// GNU General Public License for more details.
18
19// You should have received a copy of the GNU General Public License along
20// with this library; see the file COPYING. If not, write to the Free
21// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
22// USA.
23
24// As a special exception, you may use this file as part of a free software
25// library without restriction. Specifically, if other files instantiate
26// templates or use macros or inline functions from this file, or you compile
27// this file and link it with other files to produce an executable, this
28// file does not by itself cause the resulting executable to be covered by
29// the GNU General Public License. This exception does not however
30// invalidate any other reasons why the executable file might be covered by
31// the GNU General Public License.
32
33/*
34 * Copyright (c) 1997-1999
35 * Silicon Graphics Computer Systems, Inc.
36 *
37 * Permission to use, copy, modify, distribute and sell this software
38 * and its documentation for any purpose is hereby granted without fee,
39 * provided that the above copyright notice appear in all copies and
40 * that both that copyright notice and this permission notice appear
41 * in supporting documentation. Silicon Graphics makes no
42 * representations about the suitability of this software for any
43 * purpose. It is provided "as is" without express or implied warranty.
44 *
45 */
46
47#ifndef _util_misc_autovec_h
48#define _util_misc_autovec_h
49
50#include <stddef.h>
51
52namespace sc {
53
57template <class T>
58class auto_vec {
59 T* d_;
60 public:
61 typedef T element_type;
62
66 explicit auto_vec(T*d = 0) throw(): d_(d) {}
67
69 auto_vec(auto_vec &av) throw(): d_(av.release()) {}
70
72 ~auto_vec() throw() { delete[] d_; }
73
76 reset(av.release());
77 return *this;
78 }
79
81 T* get() const throw() { return d_; }
82
84 T &operator[](size_t i) throw() { return d_[i]; }
85
87 T* release() throw() {
88 T *r = d_;
89 d_ = 0;
90 return r;
91 }
92
94 void reset(T*d=0) throw() {
95 if (d != d_) {
96 delete[] d_;
97 d_ = d;
98 }
99 }
100
101};
102
103}
104
105#endif // _util_misc_autovec_h
106
void reset(T *d=0)
Assign to a new value.
Definition autovec.h:94
~auto_vec()
This will delete the vector.
Definition autovec.h:72
T * release()
Release ownership.
Definition autovec.h:87
auto_vec(auto_vec &av)
Create a auto_vec, transferring the storage from another.
Definition autovec.h:69
T & operator[](size_t i)
Returns the i'th element.
Definition autovec.h:84
auto_vec & operator=(auto_vec &av)
This member transfers the data from av to this.
Definition autovec.h:75
T * get() const
Returns the pointer.
Definition autovec.h:81
auto_vec(T *d=0)
Creates a new auto_vec for a vector, d, of type T.
Definition autovec.h:66

Generated at Mon Apr 28 2025 00:00:00 for MPQC 2.3.1 using the documentation package Doxygen 1.13.2.