00001
00002
00003
00004
00005
00006
00011 #include <fvar.hpp>
00012 #include "admb_messages.h"
00013
00018 void i4_array::allocate(void)
00019 {
00020 t=0;
00021 shape=0;
00022 }
00023
00028 void i4_array::initialize(void)
00029 {
00030 if (allocated(*this))
00031 {
00032 int mmin=indexmin();
00033 int mmax=indexmax();
00034 for (int i=mmin;i<=mmax;i++)
00035 {
00036 (*this)(i).initialize();
00037 }
00038 }
00039 }
00040
00045 i4_array::i4_array(void)
00046 {
00047 allocate();
00048 }
00049
00054 i4_array::i4_array(int hsl,int hsu)
00055 {
00056 allocate(hsl,hsu);
00057 }
00058
00063 void i4_array::allocate(int hsl,int hsu)
00064 {
00065 int ss=hsu-hsl+1;
00066 if (ss>0)
00067 {
00068 if ( (t = new i3_array[ss]) == 0)
00069 {
00070 cerr << " Error allocating memory in i4_array contructor\n";
00071 ad_exit(21);
00072 }
00073 if ( (shape=new vector_shapex(hsl,hsu,t)) == 0)
00074 {
00075 cerr << " Error allocating memory in i4_array contructor\n";
00076 ad_exit(21);
00077 }
00078 t -= indexmin();
00079 for (int i=hsl; i<=hsu; i++)
00080 {
00081 (*this)(i).allocate();
00082 }
00083 }
00084 else
00085 {
00086 t=0;
00087 shape=0;
00088 }
00089 }
00090
00095 i4_array::i4_array(int hsl, int hsu, int sl, const ivector& sh, int nrl,
00096 const imatrix& nrh, int ncl, const i3_array& nch)
00097 {
00098 allocate(hsl,hsu,sl,sh,nrl,nrh,ncl,nch);
00099 }
00100
00105 void i4_array::allocate(int hsl,int hsu,int sl,int sh,int nrl,
00106 int nrh,int ncl,int nch)
00107 {
00108 int ss=hsu-hsl+1;
00109 if (ss>0)
00110 {
00111 if ( (t = new i3_array[ss]) == 0)
00112 {
00113 cerr << " Error allocating memory in i4_array contructor\n";
00114 ad_exit(21);
00115 }
00116 if ( (shape=new vector_shapex(hsl,hsu,t)) == 0)
00117 {
00118 cerr << " Error allocating memory in i4_array contructor\n";
00119 ad_exit(21);
00120 }
00121 t -= indexmin();
00122 for (int i=hsl; i<=hsu; i++)
00123 {
00124 (*this)(i).allocate(sl,sh,nrl,nrh,ncl,nch);
00125 }
00126 }
00127 else
00128 {
00129 t=0;
00130 shape=0;
00131 }
00132 }
00133
00138 void i4_array::allocate(const ad_integer& hsl,const ad_integer& hsu,
00139 const index_type& sl,const index_type& sh,const index_type& nrl,
00140 const index_type& nrh,const index_type& ncl,const index_type& nch)
00141 {
00142 int ss=hsu-hsl+1;
00143 if (ss>0)
00144 {
00145 if ( (t = new i3_array[ss]) == 0)
00146 {
00147 cerr << " Error allocating memory in i4_array contructor\n";
00148 ad_exit(21);
00149 }
00150 if ( (shape=new vector_shapex(hsl,hsu,t)) == 0)
00151 {
00152 cerr << " Error allocating memory in i4_array contructor\n";
00153 ad_exit(21);
00154 }
00155 t -= indexmin();
00156 for (int i=hsl; i<=hsu; i++)
00157 {
00158 (*this)(i).allocate(ad_integer(sl(i)),ad_integer(sh(i)),nrl(i),nrh(i),
00159 ncl(i),nch(i));
00160 }
00161 }
00162 else
00163 {
00164 t=0;
00165 shape=0;
00166 }
00167 }
00168
00173 i4_array::i4_array(const i4_array& m2)
00174 {
00175 if (m2.shape)
00176 {
00177 shape=m2.shape;
00178 (shape->ncopies)++;
00179 t = m2.t;
00180 }
00181 else
00182 {
00183 shape=NULL;
00184 t=NULL;
00185 }
00186 }
00187
00192 i4_array::~i4_array()
00193 {
00194 deallocate();
00195 }
00196
00201 void i4_array::deallocate()
00202 {
00203 if (shape)
00204 {
00205 if (shape->ncopies)
00206 {
00207 (shape->ncopies)--;
00208 }
00209 else
00210 {
00211 t= (i3_array*) (shape->get_truepointer());
00212 delete [] t;
00213 t=NULL;
00214 delete shape;
00215 shape=NULL;
00216 }
00217 }
00218 }
00219
00220 #if !defined (OPT_LIB)
00221
00226 i3_array& i4_array::operator ( ) (int i)
00227 {
00228 if (i < indexmin() || i > indexmax())
00229 {
00230 ADMB_ARRAY_BOUNDS_ERROR("Index out of bounds",
00231 "i3_array& i4_array::operator ( ) (int i)", indexmin(), indexmax(), i);
00232 }
00233 return t[i];
00234 }
00235
00240 i3_array& i4_array::operator [] (int i)
00241 {
00242 if (i < indexmin() || i > indexmax())
00243 {
00244 ADMB_ARRAY_BOUNDS_ERROR("Index out of bounds",
00245 "i3_array& i4_array::operator [] (int i)", indexmin(), indexmax(), i);
00246 }
00247 return t[i];
00248 }
00249
00254 imatrix& i4_array::operator ( ) (int i ,int j)
00255 {
00256 return ((*this)(i))(j);
00257 }
00258
00263 ivector& i4_array::operator ( ) (int i,int j,int k)
00264 {
00265 return (((*this)(i,j))(k));
00266 }
00267
00272 int& i4_array::operator ( ) (int i,int j,int k,int l)
00273 {
00274 return ( ((*this)(i,j,k))(l));
00275 }
00276
00281 const i3_array& i4_array::operator()(int i) const
00282 {
00283 if (i<indexmin() || i>indexmax())
00284 {
00285 cerr << "Index out of bounds in i4_array::operator () (int)"
00286 << endl;
00287 ad_exit(1);
00288 }
00289 return t[i];
00290 }
00291
00296 const i3_array& i4_array::operator[](int i) const
00297 {
00298 if (i<indexmin() || i>indexmax())
00299 {
00300 cerr << "Index out of bounds in i4_array::operator () (int)"
00301 << endl;
00302 ad_exit(1);
00303 }
00304 return t[i];
00305 }
00306
00311 const imatrix& i4_array::operator()(int i, int j) const
00312 {
00313 return ((*this)(i))(j);
00314 }
00315
00320 const ivector& i4_array::operator()(int i, int j, int k) const
00321 {
00322 return (((*this)(i,j))(k));
00323 }
00324
00329 const int& i4_array::operator()(int i, int j, int k, int l) const
00330 {
00331 return ( ((*this)(i,j,k))(l));
00332 }
00333 #endif