ADMB Documentation  11.1.2453
 All Classes Files Functions Variables Typedefs Friends Defines
fvar_ar1.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: fvar_ar1.cpp 1919 2014-04-22 22:02:01Z johnoel $
00003  *
00004  * Author: David Fournier
00005  * Copyright (c) 2008-2012 Regents of the University of California
00006  */
00007 #include "fvar.hpp"
00008 
00014  dvar_vector::~dvar_vector()
00015  {
00016    deallocate();
00017  }
00018 
00023  void dvar_vector::deallocate()
00024  {
00025    if (shape)
00026    {
00027 #ifdef DIAG
00028      cout << " Deallocating dvar_vector with ptr_address\n  "
00029           << &ptr << "  pointing at  " << (ptr+indexmin()) << "\n";
00030 #endif
00031      if (shape->ncopies)
00032      {
00033        (shape->ncopies)--;
00034      }
00035      else
00036      {
00037        va = (double_and_int*) shape->trueptr;
00038        * (arr_link **) va = link_ptr;
00039        arr_free(va);
00040        delete shape;
00041      }
00042      va=NULL;
00043      shape=NULL;
00044    }
00045  }
00046 
00051 dvar_vector::dvar_vector(const dvar_vector& t)
00052  {
00053    index_min=t.index_min;
00054    index_max=t.index_max;
00055    shape=t.shape;
00056    link_ptr=t.link_ptr;
00057    if (shape) (shape->ncopies)++;
00058    va = t.va;
00059    #ifdef DIAG
00060      cout << " Making copy for dvar_vector with ptr_address\n  "
00061            << &va << "  pointing at  " << (va+indexmin()) << "\n";
00062    #endif
00063  }
00064 
00069  void dvar_vector::shallow_copy(const dvar_vector& t)
00070  {
00071    index_min=t.index_min;
00072    index_max=t.index_max;
00073    shape=t.shape;
00074    link_ptr=t.link_ptr;
00075    if (shape) (shape->ncopies)++;
00076    va = t.va;
00077    #ifdef DIAG
00078      cout << " Making copy for dvar_vector with ptr_address\n  "
00079            << &va << "  pointing at  " << (va+indexmin()) << "\n";
00080    #endif
00081  }
00082 
00087 dvar_vector::dvar_vector(const predvar_vector& pdv)
00088  {
00089 #ifndef OPT_LIB
00090    if (pdv.ub<pdv.lb)
00091    {
00092      cerr << "lower index greater than upper index in dvar_vector::"
00093        " dvar-vector(const predvar_vector&) " << endl;
00094      ad_exit (1);
00095    }
00096    if ((pdv.lb<pdv.p->indexmin()) || (pdv.lb>pdv.p->indexmax()))
00097    {
00098      cerr << "lower index out of bounds in dvar_vector::"
00099        " operator(int lb,int ub) " << endl;
00100      ad_exit (1);
00101    }
00102 
00103    if ((pdv.ub<pdv.p->indexmin()) || (pdv.ub>pdv.p->indexmax()))
00104    {
00105      cerr << " upper index out of bounds in dvar_vector::"
00106        " operator(int lb,int ub) " << endl;
00107      ad_exit (1);
00108    }
00109 #endif
00110    index_min=pdv.lb;
00111    index_max=pdv.ub;
00112    shape=pdv.p->shape;
00113    link_ptr=pdv.p->link_ptr;
00114    (shape->ncopies)++;
00115    va = pdv.p->va;
00116    #ifdef DIAG
00117      cout << " Making copy for dvar_vector with ptr_address\n  "
00118            << &va << "  pointing at  " << (va+indexmin()) << "\n";
00119    #endif
00120  }
00121 
00122 /*
00123 dvar_vector::dvar_vector(const dvar_vector& t, int lb, int ub)
00124  {
00125 #ifndef OPT_LIB
00126    if (ub<lb)
00127    {
00128      cerr << "lower index greater than upper index in dvar_vector::"
00129        " operator(int lb,int ub) " << endl;
00130      ad_exit (1);
00131    }
00132    if ((lb<t.indexmin()) || (lb>t.indexmax()))
00133    {
00134      cerr << "lower index out of bounds in dvar_vector::"
00135        " operator(int lb,int ub) " << endl;
00136      ad_exit (1);
00137    }
00138 
00139    if ((ub<t.indexmin()) || (ub>t.indexmax()))
00140    {
00141      cerr << " upper index out of bounds in dvar_vector::"
00142        " operator(int lb,int ub) " << endl;
00143      ad_exit (1);
00144    }
00145 #endif
00146 
00147    index_min=lb;
00148    index_max=ub;
00149    shape=t.shape;
00150    link_ptr=t.link_ptr;
00151    (shape->ncopies)++;
00152    va = t.va;
00153    #ifdef DIAG
00154      cout << " Making copy for dvar_vector with ptr_address\n  "
00155            << &va << "  pointing at  " << (va+indexmin()) << "\n";
00156    #endif
00157  }
00158 */
00159