ADMB Documentation  11.1.1916
 All Classes Files Functions Variables Typedefs Friends Defines
xdoublind.h
Go to the documentation of this file.
00001 /*
00002  * $Id: xdoublind.h 1112 2013-07-12 21:41:41Z johnoel $
00003  *
00004  * Author: David Fournier
00005  * Copyright (c) 2008-2012 Regents of the University of California
00006  *
00007  * ADModelbuilder and associated libraries and documentations are
00008  * provided under the general terms of the "BSD" license.
00009  *
00010  * License:
00011  *
00012  * Redistribution and use in source and binary forms, with or without
00013  * modification, are permitted provided that the following conditions are
00014  * met:
00015  *
00016  * 1. Redistributions of source code must retain the above copyright
00017  * notice, this list of conditions and the following disclaimer.
00018  *
00019  * 2.  Redistributions in binary form must reproduce the above copyright
00020  * notice, this list of conditions and the following disclaimer in the
00021  * documentation and/or other materials provided with the distribution.
00022  *
00023  * 3.  Neither the name of the  University of California, Otter Research,
00024  * nor the ADMB Foundation nor the names of its contributors may be used
00025  * to endorse or promote products derived from this software without
00026  * specific prior written permission.
00027  *
00028  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00029  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00030  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00031  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00032  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00033  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00034  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00035  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00036  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00037  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00038  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00039  *
00040  */
00045 #if !defined(_DOUBLE_IND_)
00046 #define _DOUBLE_IND_
00047   class double_index_guts;
00048   class double_index_type;
00049   class double_number_index;
00050   class double_vector_index;
00051   class double_matrix_index;
00052   class double_i3_index;
00053 
00058   class pre_double_index_type
00059   {
00060     const double_index_type * a;
00061     int i;
00062   public:
00063     pre_double_index_type( const double_index_type * _a,int _i) : a(_a),i(_i){}
00064     friend class double_index_type;
00065   };
00066 
00071   class ad_double
00072   {
00073   protected:
00074     double d;
00075   public:
00076     operator double () const { return d;}
00077     ad_double(const double& _d, const adkludge& k) : d(_d) {}
00078     ad_double(double _d) : d(_d) {}
00079     ad_double(const double_index_type& it);
00080     ad_double make_ad_double(double _d) {adkludge adk; return ad_double(d,adk);}
00081     ad_double& operator = (const ad_double&);
00082   };
00083 
00088   class double_index_guts
00089   {
00090     friend class ad_double;
00091   protected:
00092     int * ncopies;
00093   public:
00094     virtual double_index_guts * operator [] (int) = 0;
00095     virtual int  isdouble(void) const { return 1;}
00096     virtual operator double () { cerr << "Error in index_type"
00097      " -- object not dereferenced enough" << endl; exit(1); return 1;}
00098     virtual int indexmin(void)=0;
00099     virtual int indexmax(void)=0;
00100     double_index_guts();
00101     double_index_guts(const double_index_guts& ig);
00102     virtual ~double_index_guts();
00103     friend class double_index_type;
00104   };
00105 
00110   class double_index_type
00111   {
00112     double_index_guts * p;
00113   public:
00114     double ddouble(void) const;
00115     int isdouble(void) const { return p->isdouble();}
00116     double_index_type(double x);
00117     //index_type(const data_int& x);
00118     double_index_type(const dvector& x);
00119     double_index_type(const dmatrix& x);
00120     double_index_type(const d3_array& x);
00121     double_index_type(const pre_double_index_type& pit);
00122     double_index_type(const double_index_type& pit);
00123     //index_type (i4_array& x) { p = new i4_index(x);}
00124     ~double_index_type ();
00125     double_index_type operator [] (int i);
00126     double_index_type operator () (int i);
00127     double_index_type operator [] (int i) const;
00128     double_index_type operator () (int i) const;
00129     int indexmin(void) const { return p->indexmin();}
00130     int indexmax(void) const { return p->indexmax();}
00131     friend class ad_integer;
00132   };
00133 
00138   class double_index : public ad_double, public double_index_guts
00139   {
00140   private:
00141     virtual int  isdouble_(void) const { return 0;}
00142     virtual double_index_guts * operator [] (int i);
00143     virtual int indexmin(void){return 1;}
00144     virtual int indexmax(void){return 1;}
00145   public:
00146     virtual ~double_index() {}
00147     double_index(double i) : ad_double(i) {}
00148     // only overload this for number_index ... will fail for other classes
00149     virtual operator double () { return d;}
00150     friend class double_index_type;
00151   };
00152 
00157   class dvector_index : public dvector, public double_index_guts
00158   {
00159     virtual double_index_guts * operator [] (int i)
00160     {
00161       return new double_index(dvector::operator [](i));
00162     }
00163   public:
00164     //vector_index(const ivector& v) : ivector(v){}
00165     dvector_index(const dvector& v);
00166     virtual ~dvector_index();
00167     virtual int indexmin(void){return dvector::indexmin();}
00168     virtual int indexmax(void){return dvector::indexmax();}
00169     friend class double_index_type;
00170   };
00171 
00176   class dmatrix_index : public dmatrix, public double_index_guts
00177   {
00178   private:
00179     virtual double_index_guts * operator [] (int i);
00180     //{
00181       //return new dvector_index(dmatrix::operator [](i));
00182     //}
00183   public:
00184     virtual ~dmatrix_index();
00185     dmatrix_index(const dmatrix& v) : dmatrix(v){}
00186     virtual int indexmin(void){return dmatrix::rowmin();}
00187     virtual int indexmax(void){return dmatrix::rowmax();}
00188     friend class double_index_type;
00189   };
00190 
00195   class d3_index : public d3_array, public double_index_guts
00196   {
00197     virtual double_index_guts * operator [] (int i)
00198     {
00199       return new dmatrix_index(d3_array::operator [](i));
00200     }
00201   public:
00202     d3_index(d3_array& v) : d3_array(v){}
00203     virtual int indexmin(void){return d3_array::slicemin();}
00204     virtual int indexmax(void){return d3_array::slicemax();}
00205     friend class index_type;
00206   };
00207 #endif