ADMB Documentation  11.1.1916
 All Classes Files Functions Variables Typedefs Friends Defines
i5arr.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: i5arr.cpp 1714 2014-03-01 00:45:28Z johnoel $
00003  *
00004  * Author: David Fournier
00005  * Copyright (c) 2008-2012 Regents of the University of California
00006  */
00011 #include <fvar.hpp>
00012 #include "admb_messages.h"
00013 
00018 void i5_array::allocate(void)
00019 {
00020   t=0;
00021   shape=0;
00022 }
00023 
00028 i5_array::i5_array(void)
00029 {
00030   allocate();
00031 }
00032 
00037 i5_array::i5_array(int hsl,int hsu)
00038 {
00039   allocate(hsl,hsu);
00040 }
00041 
00046 void i5_array::allocate(int hsl,int hsu)
00047 {
00048   int ss=hsu-hsl+1;
00049   if (ss>0)
00050   {
00051     if ( (t = new i4_array[ss]) == 0)
00052     {
00053       cerr << " Error allocating memory in i5_array contructor\n";
00054       ad_exit(21);
00055     }
00056     if ( (shape=new vector_shapex(hsl,hsu,t)) == 0)
00057     {
00058       cerr << " Error allocating memory in i5_array contructor\n";
00059       ad_exit(21);
00060     }
00061     t -= indexmin();
00062     for (int i=hsl; i<=hsu; i++)
00063     {
00064       (*this)(i).allocate();
00065     }
00066   }
00067   else
00068   {
00069     t=0;
00070     shape=0;
00071   }
00072 }
00073 
00078 void i5_array::allocate(int hsl,int hsu,int sl,int sh,int nrl,
00079    int nrh,int ncl,int nch,int aa,int bb)
00080  {
00081    int ss=hsu-hsl+1;
00082    if (ss>0)
00083    {
00084      if ( (t = new i4_array[ss]) == 0)
00085      {
00086        cerr << " Error allocating memory in i5_array contructor\n";
00087        ad_exit(21);
00088      }
00089      if ( (shape=new vector_shapex(hsl,hsu,t)) == 0)
00090      {
00091        cerr << " Error allocating memory in i5_array contructor\n";
00092        ad_exit(21);
00093      }
00094      t -= indexmin();
00095      for (int i=hsl; i<=hsu; i++)
00096      {
00097        (*this)(i).allocate(sl,sh,nrl,nrh,ncl,nch,aa,bb);
00098      }
00099    }
00100    else
00101    {
00102      t=0;
00103      shape=0;
00104    }
00105  }
00106 
00111  void i5_array::allocate(const ad_integer& hsl,const ad_integer& hsu,
00112    const index_type& sl,const index_type& sh,
00113    const index_type& nrl,const index_type& nrh,
00114    const index_type& ncl,const index_type& nch,
00115    const index_type& aa,const index_type& bb)
00116  {
00117    int ss=hsu-hsl+1;
00118    if (ss>0)
00119    {
00120      if ( (t = new i4_array[ss]) == 0)
00121      {
00122        cerr << " Error allocating memory in i5_array contructor\n";
00123        ad_exit(21);
00124      }
00125      if ( (shape=new vector_shapex(hsl,hsu,t)) == 0)
00126      {
00127        cerr << " Error allocating memory in i5_array contructor\n";
00128        ad_exit(21);
00129      }
00130      t -= indexmin();
00131      for (int i=hsl; i<=hsu; i++)
00132      {
00133        (*this)(i).allocate(ad_integer(sl),ad_integer(sh),nrl(i),nrh(i),
00134          ncl(i),nch(i),aa(i),bb(i));
00135      }
00136    }
00137    else
00138    {
00139      t=0;
00140      shape=0;
00141    }
00142  }
00143 
00148 i5_array::i5_array(const i5_array& m2)
00149  {
00150    if (m2.shape)
00151    {
00152      shape=m2.shape;
00153      (shape->ncopies)++;
00154      t = m2.t;
00155    }
00156    else
00157    {
00158      shape=NULL;
00159      t=NULL;
00160    }
00161  }
00162 
00167  i5_array::~i5_array()
00168  {
00169    deallocate();
00170  }
00171 
00176  void i5_array::deallocate()
00177  {
00178    if (shape)
00179    {
00180      if (shape->ncopies)
00181      {
00182        (shape->ncopies)--;
00183      }
00184      else
00185      {
00186        t= (i4_array*) (shape->get_truepointer());
00187        delete [] t;
00188        t=NULL;
00189        delete shape;
00190        shape=NULL;
00191      }
00192    }
00193  }
00194 
00195 #if !defined (OPT_LIB)
00196 
00201     i4_array& i5_array::operator ( ) (int i)
00202     {
00203 #     if defined(SAFE_ARRAYS)
00204       if (i < indexmin() || i > indexmax())
00205       {
00206         ADMB_ARRAY_BOUNDS_ERROR("Index out of bounds",
00207         "i4_array& i5_array::operator ( ) (int i)", indexmin(), indexmax(), i);
00208       }
00209 #     endif
00210       return t[i];
00211     }
00212 
00217     i4_array& i5_array::operator [] (int i)
00218     {
00219 #     if defined(SAFE_ARRAYS)
00220       if (i < indexmin() || i > indexmax())
00221       {
00222         ADMB_ARRAY_BOUNDS_ERROR("Index out of bounds",
00223         "i4_array& i5_array::operator [] (int i)", indexmin(), indexmax(), i);
00224       }
00225 #     endif
00226       return t[i];
00227     }
00228 
00233     i3_array& i5_array::operator ( ) (int i ,int j)
00234     {
00235       return ((*this)(i))(j);
00236     }
00237 
00242     imatrix& i5_array::operator ( ) (int i,int j,int k)
00243     {
00244       return (((*this)(i,j))(k));
00245     }
00246 
00251     ivector& i5_array::operator ( ) (int i,int j,int k,int l)
00252     {
00253       return ( ((*this)(i,j,k))(l));
00254     }
00255 
00260     int& i5_array::operator ( ) (int i,int j,int k,int l,int ll)
00261     {
00262       return ( ((*this)(i,j,k))(l,ll));
00263     }
00264 
00269 const i4_array& i5_array::operator()(int i) const
00270     {
00271 #     if defined(SAFE_ARRAYS)
00272       if (i<indexmin() || i>indexmax())
00273       {
00274         cerr << "Index out of bounds in i5_array::operator () (int)"
00275              << endl;
00276         ad_exit(1);
00277       }
00278 #     endif
00279       return t[i];
00280     }
00281 
00286 const i4_array& i5_array::operator[](int i) const
00287     {
00288 #     if defined(SAFE_ARRAYS)
00289       if (i<indexmin() || i>indexmax())
00290       {
00291         cerr << "Index out of bounds in i5_array::operator () (int)"
00292              << endl;
00293         ad_exit(1);
00294       }
00295 #     endif
00296       return t[i];
00297     }
00298 
00303 const i3_array& i5_array::operator()(int i, int j) const
00304     {
00305       return ((*this)(i))(j);
00306     }
00307 
00312 const imatrix& i5_array::operator()(int i, int j, int k) const
00313     {
00314       return (((*this)(i,j))(k));
00315     }
00316 
00321 const ivector& i5_array::operator()(int i, int j, int k, int l) const
00322     {
00323       return ( ((*this)(i,j,k))(l));
00324     }
00325 
00330 const int& i5_array::operator()(int i, int j, int k, int l, int ll) const
00331     {
00332       return ( ((*this)(i,j,k))(l,ll));
00333     }
00334 #endif