ADMB Documentation  11.5.3197
 All Classes Files Functions Variables Typedefs Friends Defines
fvar2.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id$
00003  *
00004  * Author: David Fournier
00005  * Copyright (c) 2008-2012 Regents of the University of California
00006  */
00011 // file fvar.cpp
00012 // constructors, destructors and misc functions involving class prevariable
00013 #include "fvar.hpp"
00014 
00015 #ifdef __TURBOC__
00016   #pragma hdrstop
00017   #include <iostream.h>
00018 #endif
00019 
00020 #ifdef __ZTC__
00021   #include <iostream.hpp>
00022 #endif
00023 
00024 #include <stdio.h>
00025 #ifndef __SUN__
00026 #endif
00027 #include <math.h>
00028 
00033 double_and_int* gradnew()
00034 {
00035 #if !defined(OPT_LIB)
00036   if (!gradient_structure::instances)
00037   {
00038     cerr << "Error -- you are trying to create a dvariable object"
00039             " when there is " << endl << "no object of type"
00040             " gradient_structure in scope " << endl;
00041     ad_exit(1);
00042   }
00043 #endif
00044   dlink* tmp = gradient_structure::GRAD_LIST->last_remove();
00045   if (!tmp)
00046   {
00047     tmp = gradient_structure::GRAD_LIST->create();
00048   }
00049   //  cout << "In gradnew the address of the double * ptr is "
00050   //       << _farptr_tolong(tmp) << "\n";
00051   return (double_and_int*)tmp;
00052 }
00057 void gradfree(dlink* v)
00058 {
00059   if (gradient_structure::GRAD_LIST)
00060   {
00061     if (gradient_structure::instances)
00062     {
00063       gradient_structure::GRAD_LIST->append(v);
00064     }
00065     else
00066     {
00067       delete (double_and_int*)v;
00068       v = NULL;
00069     }
00070   }
00071 }
00072 //prevariable::prevariable(const prevariable& t)
00073 //  {
00074 //     v=t.v;
00075 //     (*v).nc++;
00076 //  }
00082 dvariable::dvariable(const prevariable& t)
00083 {
00084   v=gradnew();
00085   //(*v).nc=0;
00086   v->x=t.v->x;
00087   gradient_structure::GRAD_STACK1->
00088     set_gradient_stack(default_evaluation1,&(v->x),&(t.v->x));
00089 }
00095 dvariable::dvariable(const dvariable& t): prevariable()
00096 {
00097   v=gradnew();
00098   v->x=t.v->x;
00099   gradient_structure::GRAD_STACK1->
00100     set_gradient_stack(default_evaluation1,&(v->x),&(t.v->x));
00101 }
00107 dvariable::dvariable()
00108 {
00109   v=gradnew();
00110   //(*v).nc=0;
00111 #ifdef SAFE_INITIALIZE
00112   (*v).x = 0;
00113   gradient_structure::GRAD_STACK1->set_gradient_stack0(
00114     default_evaluation0,&((*v).x));
00115 #endif
00116 }
00121 dvariable::dvariable(kkludge_object)
00122 {
00123   v = gradnew();
00124   //(*v).nc=0;
00125 }
00129 dvariable::~dvariable()
00130 {
00131   gradfree((dlink*)v);
00132 }
00139 dvariable::dvariable(const double t)
00140 {
00141   v = gradnew();
00142   v->x = t;
00143   //(*v).nc=0;
00144   gradient_structure::GRAD_STACK1->set_gradient_stack0(default_evaluation0,
00145     &(v->x));
00146 }
00153 dvariable::dvariable(const int& t)
00154 {
00155   v = gradnew();
00156   v->x = t;
00157   //(*v).nc=0;
00158   gradient_structure::GRAD_STACK1->set_gradient_stack0(default_evaluation0,
00159     &(v->x) );
00160 }