ADMB Documentation  11.2.2828
 All Classes Files Functions Variables Typedefs Friends Defines
i5arr.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: i5arr.cpp 1921 2014-04-23 18:47:05Z 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 (i < indexmin() || i > indexmax())
00204       {
00205         ADMB_ARRAY_BOUNDS_ERROR("Index out of bounds",
00206         "i4_array& i5_array::operator ( ) (int i)", indexmin(), indexmax(), i);
00207       }
00208       return t[i];
00209     }
00210 
00215     i4_array& i5_array::operator [] (int i)
00216     {
00217       if (i < indexmin() || i > indexmax())
00218       {
00219         ADMB_ARRAY_BOUNDS_ERROR("Index out of bounds",
00220         "i4_array& i5_array::operator [] (int i)", indexmin(), indexmax(), i);
00221       }
00222       return t[i];
00223     }
00224 
00229     i3_array& i5_array::operator ( ) (int i ,int j)
00230     {
00231       return ((*this)(i))(j);
00232     }
00233 
00238     imatrix& i5_array::operator ( ) (int i,int j,int k)
00239     {
00240       return (((*this)(i,j))(k));
00241     }
00242 
00247     ivector& i5_array::operator ( ) (int i,int j,int k,int l)
00248     {
00249       return ( ((*this)(i,j,k))(l));
00250     }
00251 
00256     int& i5_array::operator ( ) (int i,int j,int k,int l,int ll)
00257     {
00258       return ( ((*this)(i,j,k))(l,ll));
00259     }
00260 
00265 const i4_array& i5_array::operator()(int i) const
00266     {
00267       if (i<indexmin() || i>indexmax())
00268       {
00269         cerr << "Index out of bounds in i5_array::operator () (int)"
00270              << endl;
00271         ad_exit(1);
00272       }
00273       return t[i];
00274     }
00275 
00280 const i4_array& i5_array::operator[](int i) const
00281     {
00282       if (i<indexmin() || i>indexmax())
00283       {
00284         cerr << "Index out of bounds in i5_array::operator () (int)"
00285              << endl;
00286         ad_exit(1);
00287       }
00288       return t[i];
00289     }
00290 
00295 const i3_array& i5_array::operator()(int i, int j) const
00296     {
00297       return ((*this)(i))(j);
00298     }
00299 
00304 const imatrix& i5_array::operator()(int i, int j, int k) const
00305     {
00306       return (((*this)(i,j))(k));
00307     }
00308 
00313 const ivector& i5_array::operator()(int i, int j, int k, int l) const
00314     {
00315       return ( ((*this)(i,j,k))(l));
00316     }
00317 
00322 const int& i5_array::operator()(int i, int j, int k, int l, int ll) const
00323     {
00324       return ( ((*this)(i,j,k))(l,ll));
00325     }
00326 #endif