The Original CHomP Software
autoarray.h
Go to the documentation of this file.
1
3
16
17// Copyright (C) 1997-2020 by Pawel Pilarczyk.
18//
19// This file is part of my research software package. This is free software:
20// you can redistribute it and/or modify it under the terms of the GNU
21// General Public License as published by the Free Software Foundation,
22// either version 3 of the License, or (at your option) any later version.
23//
24// This software is distributed in the hope that it will be useful,
25// but WITHOUT ANY WARRANTY; without even the implied warranty of
26// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27// GNU General Public License for more details.
28//
29// You should have received a copy of the GNU General Public License
30// along with this software; see the file "license.txt". If not,
31// please, see <https://www.gnu.org/licenses/>.
32
33// Started on April 10, 2011. Last revision: April 10, 2011.
34
35
36#ifndef _CHOMP_STRUCT_AUTOARRAY_H_
37#define _CHOMP_STRUCT_AUTOARRAY_H_
38
39
40namespace chomp {
41namespace homology {
42
43
44// --------------------------------------------------
45// ------------------- auto_array -------------------
46// --------------------------------------------------
47
52template <typename T>
54{
55private:
56 T *ptr;
57
58public:
60 typedef T element_type;
61
63 explicit auto_array (element_type *p = 0) throw (): ptr (p) {}
64
66 auto_array (auto_array &a) throw (): ptr (a. release ()) {}
67
70 {
71 reset (a. release ());
72 return *this;
73 }
74
77 {
78 if (ptr)
79 delete [] ptr;
80 return;
81 }
82
84 element_type *get () const throw ()
85 {
86 return ptr;
87 }
88
90 element_type *release () throw ()
91 {
92 element_type *tmp = ptr;
93 ptr = 0;
94 return tmp;
95 }
96
98 void reset (element_type *p = 0) throw ()
99 {
100 if (p != ptr)
101 {
102 if (ptr)
103 delete [] ptr;
104 ptr = p;
105 }
106 }
107
108}; /* class auto_array */
109
110
111} // namespace homology
112} // namespace chomp
113
114#endif // _CHOMP_STRUCT_AUTOARRAY_H_
115
117
An auto_array template that mimics selected behaviors of the std::auto_ptr template,...
Definition: autoarray.h:54
~auto_array()
The destructor.
Definition: autoarray.h:76
void reset(element_type *p=0)
Resets the object to hold another pointer.
Definition: autoarray.h:98
auto_array & operator=(auto_array &a)
Assignment operator.
Definition: autoarray.h:69
auto_array(element_type *p=0)
The constructor.
Definition: autoarray.h:63
T element_type
The type of the elements in the array.
Definition: autoarray.h:60
element_type * release()
Releases the pointer and returns it.
Definition: autoarray.h:90
auto_array(auto_array &a)
Copy constructor.
Definition: autoarray.h:66
element_type * get() const
Returns the internally stored pointer to an array.
Definition: autoarray.h:84
This namespace contains the entire CHomP library interface.
Definition: bitmaps.h:51