MPQC  3.0.0-alpha
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 #include <util/misc/exception.h>
52 
53 namespace sc {
54 
58 template <class T>
59 class auto_vec {
60  T* d_;
61  public:
62  typedef T element_type;
63 
67  explicit auto_vec(T*d = 0) MPQC__NOEXCEPT: d_(d) {}
68 
70  auto_vec(auto_vec &av) MPQC__NOEXCEPT: d_(av.release()) {}
71 
73  ~auto_vec() MPQC__NOEXCEPT { delete[] d_; }
74 
76  auto_vec &operator = (auto_vec &av) MPQC__NOEXCEPT {
77  reset(av.release());
78  return *this;
79  }
80 
82  T* get() const MPQC__NOEXCEPT { return d_; }
83 
85  T &operator[](size_t i) MPQC__NOEXCEPT { return d_[i]; }
86 
88  const T &operator[](size_t i) const MPQC__NOEXCEPT { return d_[i]; }
89 
91  T* release() MPQC__NOEXCEPT {
92  T *r = d_;
93  d_ = 0;
94  return r;
95  }
96 
98  void reset(T*d=0) MPQC__NOEXCEPT {
99  if (d != d_) {
100  delete[] d_;
101  d_ = d;
102  }
103  }
104 
105 };
106 
107 }
108 
109 #endif // _util_misc_autovec_h
110 
sc::auto_vec::release
T * release() MPQC__NOEXCEPT
Release ownership.
Definition: autovec.h:91
sc::auto_vec::get
T * get() const MPQC__NOEXCEPT
Returns the pointer.
Definition: autovec.h:82
sc::auto_vec::reset
void reset(T *d=0) MPQC__NOEXCEPT
Assign to a new value.
Definition: autovec.h:98
sc::auto_vec
The auto_vec class functions much like auto_ptr, except it contains references to arrays.
Definition: autovec.h:59
sc::auto_vec::operator=
auto_vec & operator=(auto_vec &av) MPQC__NOEXCEPT
This member transfers the data from av to this.
Definition: autovec.h:76
sc::auto_vec::operator[]
const T & operator[](size_t i) const MPQC__NOEXCEPT
Returns the i'th element.
Definition: autovec.h:88
sc::auto_vec::auto_vec
auto_vec(auto_vec &av) MPQC__NOEXCEPT
Create a auto_vec, transferring the storage from another.
Definition: autovec.h:70
sc::auto_vec::~auto_vec
~auto_vec() MPQC__NOEXCEPT
This will delete the vector.
Definition: autovec.h:73
sc::auto_vec::auto_vec
auto_vec(T *d=0) MPQC__NOEXCEPT
Creates a new auto_vec for a vector, d, of type T.
Definition: autovec.h:67
sc
Contains all MPQC code up to version 3.
Definition: mpqcin.h:14
sc::auto_vec::operator[]
T & operator[](size_t i) MPQC__NOEXCEPT
Returns the i'th element.
Definition: autovec.h:85

Generated at Sun Jan 26 2020 23:24:01 for MPQC 3.0.0-alpha using the documentation package Doxygen 1.8.16.