source: ThirdParty/mpqc_open/src/lib/util/misc/autovec.h@ 860145

Action_Thermostats Add_AtomRandomPerturbation Add_RotateAroundBondAction Add_SelectAtomByNameAction Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_StructOpt_integration_tests Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_ChronosMutex Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion GeometryObjects Gui_displays_atomic_force_velocity IndependentFragmentGrids_IntegrationTest JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks RotateToPrincipalAxisSystem_UndoRedo StoppableMakroAction Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg ThirdParty_MPQC_rebuilt_buildsystem TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps Ubuntu_1604_changes stable
Last change on this file since 860145 was 860145, checked in by Frederik Heber <heber@…>, 8 years ago

Merge commit '0b990dfaa8c6007a996d030163a25f7f5fc8a7e7' as 'ThirdParty/mpqc_open'

  • Property mode set to 100644
File size: 3.4 KB
Line 
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
54/** The auto_vec class functions much like auto_ptr, except
55 it contains references to arrays. The delete[] operator will be used
56 to deallocate data. */
57template <class T>
58class auto_vec {
59 T* d_;
60 public:
61 typedef T element_type;
62
63 /** Creates a new auto_vec for a vector, d, of type T.
64 The d argument must be created with the vector new
65 operator: new T[...]. */
66 explicit auto_vec(T*d = 0) throw(): d_(d) {}
67
68 /** Create a auto_vec, transferring the storage from another. */
69 auto_vec(auto_vec &av) throw(): d_(av.release()) {}
70
71 /** This will delete the vector. */
72 ~auto_vec() throw() { delete[] d_; }
73
74 /** This member transfers the data from av to this. */
75 auto_vec &operator = (auto_vec &av) throw() {
76 reset(av.release());
77 return *this;
78 }
79
80 /** Returns the pointer. */
81 T* get() const throw() { return d_; }
82
83 /** Returns the i'th element. */
84 T &operator[](size_t i) throw() { return d_[i]; }
85
86 /** Release ownership. */
87 T* release() throw() {
88 T *r = d_;
89 d_ = 0;
90 return r;
91 }
92
93 /** Assign to a new value. */
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
Note: See TracBrowser for help on using the repository browser.