00001
00002
00003
00004
00005
00006
00011 #include <df1b2fun.h>
00012 #include "admb_messages.h"
00013
00017 df1b2_init_bounded_number_vector::df1b2_init_bounded_number_vector():
00018 v(NULL),
00019 index_min(1),
00020 index_max(0),
00021 it(NULL)
00022 {
00023 }
00024
00025 #if !defined(OPT_LIB)
00026
00030 df1b2_init_bounded_number& df1b2_init_bounded_number_vector::operator[](int i)
00031 {
00032 if (i < indexmin() || i > indexmax())
00033 {
00034 ADMB_ARRAY_BOUNDS_ERROR("Index out of range",
00035 "df1b2_init_bounded_number_vector::operator [] (int i)",
00036 indexmin(), indexmax(), i);
00037 }
00038 return v[i];
00039 }
00040
00045 df1b2_init_bounded_number& df1b2_init_bounded_number_vector::operator()(int i)
00046 {
00047 if (i < indexmin() || i > indexmax())
00048 {
00049 ADMB_ARRAY_BOUNDS_ERROR("Index out of range",
00050 "df1b2_init_bounded_number_vector::operator () (int i)",
00051 indexmin(), indexmax(), i);
00052 }
00053 return v[i];
00054 }
00055 #endif
00056
00061 df1b2_init_bounded_number_vector::~df1b2_init_bounded_number_vector()
00062 {
00063 deallocate();
00064 }
00065
00070 void df1b2_init_bounded_number_vector::deallocate(void)
00071 {
00072 if(it)
00073 {
00074 delete it;
00075 it=NULL;
00076 }
00077 if (v)
00078 {
00079 v+=indexmin();
00080 delete [] v;
00081 v=NULL;
00082 }
00083 }
00084
00089 void df1b2_init_bounded_number_vector::allocate(int min1,int max1,
00090 const double_index_type & bmin,const double_index_type & bmax,const char * s)
00091 {
00092 allocate(min1,max1,bmin,bmax,1,s);
00093 }
00094
00099 void df1b2_init_bounded_number_vector::allocate(int min1,int max1,
00100 const double_index_type & bmin,const double_index_type & bmax,
00101 const index_type& phase_start,const char * s)
00102 {
00103 index_min=min1;
00104 index_max=max1;
00105 int size=indexmax()-indexmin()+1;
00106 if (size>0)
00107 {
00108 v = new df1b2_init_bounded_number[size];
00109 if (!v)
00110 {
00111 cerr << " error trying to allocate memory in "
00112 "df1b2_init_bounded_number_vector " << endl;
00113 exit(1);
00114 }
00115 v-=indexmin();
00116 for (int i=indexmin();i<=indexmax();i++)
00117 {
00118
00119 adstring ss=s + adstring("[") + str(i) + adstring("]");
00120 v[i].allocate(ad_double(bmin[i]),ad_double(bmax[i]),
00121 ad_integer(phase_start[i]),(char*)(ss) );
00122 }
00123 }
00124 else
00125 v=NULL;
00126 }
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211 #if !defined(OPT_LIB)
00212
00216 df1b2_init_number& df1b2_init_number_vector::operator [] (int i)
00217 {
00218 if (i < indexmin() || i > indexmax())
00219 {
00220 ADMB_ARRAY_BOUNDS_ERROR("Index out of range",
00221 "df1b2_init_number_vector::operator [] (int i)",
00222 indexmin(), indexmax(), i);
00223 }
00224 return v[i];
00225 }
00226
00231 df1b2_init_number& df1b2_init_number_vector::operator () (int i)
00232 {
00233 if (i < indexmin() || i > indexmax())
00234 {
00235 ADMB_ARRAY_BOUNDS_ERROR("Index out of range",
00236 "df1b2_init_number_vector::operator () (int i)",
00237 indexmin(), indexmax(), i);
00238 }
00239 return v[i];
00240 }
00241 #endif
00242
00246 df1b2_init_number_vector::df1b2_init_number_vector():
00247 v(NULL),
00248 index_min(0),
00249 index_max(-1),
00250 it(NULL)
00251 {
00252 }
00256 df1b2_init_number_vector::~df1b2_init_number_vector()
00257 {
00258 deallocate();
00259 }
00260
00265 void df1b2_init_number_vector::deallocate(void)
00266 {
00267 if(it)
00268 {
00269 delete it;
00270 it=NULL;
00271 }
00272 if (v)
00273 {
00274 v+=indexmin();
00275 delete [] v;
00276 v=NULL;
00277 }
00278 }
00279
00284 void df1b2_init_number_vector::allocate(int min1,int max1,
00285 const char * s)
00286 {
00287 allocate(min1,max1,1,s);
00288 }
00289
00294 void df1b2_init_number_vector::allocate(int min1,int max1,
00295 const index_type& phase_start,const char * s)
00296 {
00297 index_min=min1;
00298 index_max=max1;
00299 int size=indexmax()-indexmin()+1;
00300 if (size>0)
00301 {
00302 v = new df1b2_init_number[size];
00303 if (!v)
00304 {
00305 cerr << " error trying to allocate memory in "
00306 "df1b2_init_number_vector " << endl;
00307 exit(1);
00308 }
00309 v-=indexmin();
00310 for (int i=indexmin();i<=indexmax();i++)
00311 {
00312
00313 adstring ss=s + adstring("[") + str(i) + adstring("]");
00314 v[i].allocate(ad_integer(phase_start[i]),(char*)(ss) );
00315 }
00316 }
00317 else
00318 v=NULL;
00319 }