ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
string5.cpp
Go to the documentation of this file.
1 
8 #include <fvar.hpp>
9 #include <stdlib.h>
10 
11 #ifndef OPT_LIB
12  #include <cassert>
13 #endif
14 
19  shape(NULL),
20  ptr(NULL)
21 {
22 }
27 {
28  shape=sa.shape;
29  ptr=sa.ptr;
30 }
32 {
33  allocate(min,max);
34 }
39 {
40  if (ptr)
41  {
42  if (next==this)
43  {
44  int min=indexmin();
45  int max=indexmax();
46  for(int i=min;i<=max;i++)
47  {
48  if (ptr[i])
49  {
50  delete ptr[i];
51  ptr[i] = 0;
52  }
53  }
54  ptr+=indexmin();
55 
56  delete [] ptr;
57  ptr = 0;
58 
59  delete shape;
60  shape = 0;
61  }
62  }
63 }
64 
66  { return shape ? shape->indexmax() - shape->indexmin() + 1 : 0; }
67 
69  { return shape ? shape->indexmin() : 0;}
70 
72  { return shape ? shape->indexmax() : 0;}
73 
81 {
82  if (min > max)
83  {
84  cerr << " Error in adstring_array(int min,int max) --"
85  << " max must be >= min" << endl;
86  ad_exit(1);
87  }
88  shape = new vector_shape(min, max);
89  if (!shape)
90  {
91  cerr << "Error allocating memory in adstring_array" << endl;
92  }
93  unsigned int size = static_cast<unsigned int>(max - min + 1);
94  ptr = new adstring*[size];
95  if (!ptr)
96  {
97  cerr << "Error allocating memory in adstring_array" << endl;
98  }
99  ptr-=indexmin();
100  for (int i=min;i<=max;i++)
101  {
102  ptr[i]=new adstring;
103  }
104 }
111 {
112  if (!shape)
113  {
114  cerr << "Error -- trying to access unallocated adstring array" << endl;
115  ad_exit(1);
116  }
117 
118 #ifndef OPT_LIB
119  assert(indexmin() <= i && i <= indexmax());
120 #endif
121 
122  return *(ptr[i]);
123 }
130 {
131  if (!shape)
132  {
133  cerr << "Error -- trying to access unallocated adstring array" << endl;
134  ad_exit(1);
135  }
136 
137 #ifndef OPT_LIB
138  assert(indexmin() <= i && i <= indexmax());
139 #endif
140 
141  return *(ptr[i]);
142 }
149 {
150  if (!shape)
151  {
152  cerr << "Error -- trying to access unallocated adstring array" << endl;
153  ad_exit(1);
154  }
155 
156 #ifndef OPT_LIB
157  assert(indexmin() <= i && i <= indexmax());
158 #endif
159 
160  return *(ptr[i]);
161 }
168 {
169  if (!shape)
170  {
171  cerr << "Error -- trying to access unallocated adstring array" << endl;
172  ad_exit(1);
173  }
174 
175 #ifndef OPT_LIB
176  assert(indexmin() <= i && i <= indexmax());
177 #endif
178 
179  return *(ptr[i]);
180 }
adstring ** ptr
Definition: adstring.hpp:201
int indexmin(void) const
Definition: string5.cpp:68
Description not yet available.
Definition: fvar.hpp:509
int indexmin() const
Definition: fvar.hpp:553
vector_shape * shape
Definition: adstring.hpp:200
exitptr ad_exit
Definition: gradstrc.cpp:53
~adstring_array()
Destructor.
Definition: string5.cpp:38
void allocate()
Definition: adstring.hpp:210
prnstream & endl(prnstream &)
const adstring & operator[](int i) const
Returns a reference to the element at specified index i.
Definition: string5.cpp:148
#define min(a, b)
Definition: cbivnorm.cpp:188
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
const adstring & operator()(int i) const
Returns a reference to the element at specified index i.
Definition: string5.cpp:167
int indexmax() const
Definition: fvar.hpp:557
adstring_array(void)
Default constructor.
Definition: string5.cpp:18
int size() const
Definition: string5.cpp:65
Definition: clist.h:43
int indexmax(void) const
Definition: string5.cpp:71
clist * next
Definition: clist.h:48
#define max(a, b)
Definition: cbivnorm.cpp:189