ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
i4arr.cpp
Go to the documentation of this file.
1 
5 #include <fvar.hpp>
6 #include "admb_messages.h"
7 
10 {
11  t = nullptr;
12  shape = nullptr;
13 }
16 {
17  for (int i = hslicemin(); i <= hslicemax(); ++i)
18  {
19  if (allocated(elem(i)))
20  {
21  elem(i).initialize();
22  }
23  }
24 }
27 {
28  allocate();
29 }
37 i4_array::i4_array(int hsl, int hsu)
38 {
39  allocate(hsl, hsu);
40 }
48 void i4_array::allocate(int hsl, int hsu)
49 {
50  if (hsl > hsu)
51  {
52  return allocate();
53  }
54  if ((t = new i3_array[static_cast<unsigned int>(hsu - hsl + 1)]) == 0)
55  {
56  cerr << " Error: i4_array unable to allocate t in "
57  << "i4_array::allocate(int, int).\n";
58  ad_exit(1);
59  }
60  if ((shape=new vector_shapex(hsl, hsu, t)) == 0)
61  {
62  cerr << " Error: i4_array unable to allocate shape in "
63  << "i4_array::allocate(int, int).\n";
64  ad_exit(1);
65  }
66  t -= indexmin();
67  for (int i = hsl; i <= hsu; ++i)
68  {
69  elem(i).allocate();
70  }
71 }
77  int hsl, int hsu,
78  int sl, const ivector& sh,
79  int nrl, const imatrix& nrh,
80  int ncl, const i3_array& nch)
81 {
82  allocate(hsl,hsu,sl,sh,nrl,nrh,ncl,nch);
83 }
98  int hsl, int hsu,
99  int sl, int sh,
100  int nrl, int nrh,
101  int ncl, int nch)
102 {
103  allocate(hsl, hsu, sl, sh, nrl, nrh, ncl, nch);
104 }
119  int hsl, int hsu,
120  int sl, int sh,
121  int nrl, int nrh,
122  int ncl, int nch)
123 {
124  if (hsl > hsu)
125  {
126  return allocate();
127  }
128  allocate(hsl, hsu);
129  for (int i = hslicemin(); i <= hslicemax(); ++i)
130  {
131  elem(i).allocate(sl, sh, nrl, nrh, ncl, nch);
132  }
133 }
148  const ad_integer& hsl, const ad_integer& hsu,
149  const index_type& sl, const index_type& sh,
150  const index_type& nrl, const index_type& nrh,
151  const index_type& ncl, const index_type& nch)
152 {
153  unsigned int ss =
154  static_cast<unsigned int>(hsu < hsl ? 0 : hsu - hsl + 1);
155  if (ss > 0)
156  {
157  if ((t = new i3_array[ss]) == 0)
158  {
159  cerr << " Error: i4_array unable to allocate memory in "
160  << __FILE__ << ':' << __LINE__ << '\n';
161  ad_exit(1);
162  }
163  if ((shape = new vector_shapex(hsl, hsu, t)) == 0)
164  {
165  cerr << " Error: i4_array unable to allocate memory in "
166  << __FILE__ << ':' << __LINE__ << '\n';
167  ad_exit(1);
168  }
169  t -= indexmin();
170  for (int i = hsl; i <= hsu; ++i)
171  {
172  (*this)(i).allocate(
173  ad_integer(sl(i)), ad_integer(sh(i)),
174  nrl(i), nrh(i),
175  ncl(i), nch(i));
176  }
177  }
178  else
179  {
180  t = 0;
181  shape = 0;
182  }
183 }
186 {
187  shallow_copy(other);
188 }
195 {
196  if (other.shape)
197  {
198  shape = other.shape;
199  ++(shape->ncopies);
200  t = other.t;
201  }
202  else
203  {
204 #ifdef DEBUG
205  cerr << "Warning -- Unable to shallow copy an unallocated i4_array.\n";
206 #endif
207  allocate();
208  }
209 }
212 {
213  deallocate();
214 }
217 {
218  if (shape)
219  {
220  if (shape->ncopies > 0)
221  {
222  --(shape->ncopies);
223  }
224  else
225  {
226  t = static_cast<i3_array*>(shape->get_truepointer());
227  delete [] t;
228  delete shape;
229  }
230  allocate();
231  }
232 #if defined(DIAG)
233  else
234  {
235  cerr << "Warning -- Unable to deallocate an unallocated i4_array.\n";
236  }
237 #endif
238 }
i3_array * t
Definition: fvar.hpp:5772
Uses polymorphism to get index information from various data types to be used in constructing and all...
Definition: fvar.hpp:7731
int indexmin() const
Definition: fvar.hpp:5893
Description not yet available.
Definition: imatrix.h:69
i3_array & elem(int i)
Definition: fvar.hpp:5959
int allocated(const ivector &v)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Definition: fvar_a59.cpp:13
~i4_array()
Destructor.
Definition: i4arr.cpp:211
exitptr ad_exit
Definition: gradstrc.cpp:53
void * get_truepointer(void)
Returns address of first element in the vector.
Definition: vector_shapex.h:64
void allocate(int sl, int sh, int nrl, int nrh, const ivector &nc)
Description not yet available.
Definition: fvar.hpp:5769
void deallocate(void)
Deallocate i4_array memory.
Definition: i4arr.cpp:216
Array of integers(int) with indexes from index_min to indexmax.
Definition: ivector.h:50
void shallow_copy(const i4_array &)
Shallow copy other data structure pointers.
Definition: i4arr.cpp:194
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
vector_shapex * shape
Definition: fvar.hpp:5771
int hslicemax() const
Definition: fvar.hpp:5905
i4_array()
Default constructor.
Definition: i4arr.cpp:26
unsigned int ncopies
Copy counter to enable shallow copies.
Definition: vector_shapex.h:79
void allocate(void)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Definition: i4arr.cpp:9
Holds &quot;shape&quot; information for vector objects.
Definition: vector_shapex.h:46
void initialize(int sl, int sh, int nrl, const ivector &nrh, int ncl, const ivector &nch)
int hslicemin() const
Definition: fvar.hpp:5901
void initialize()
Initializes elements of i4_array to zero.
Definition: i4arr.cpp:15
Stores integer.
Definition: fvar.hpp:7654
Description not yet available.
Definition: fvar.hpp:3944