ADMB Documentation  11.1x.2730
 All Classes Files Functions Variables Typedefs Friends Defines
ivec7.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: ivec7.cpp 2558 2014-11-05 18:38:53Z johnoel $
00003  *
00004  * Author: David Fournier
00005  * Copyright (c) 2008-2012 Regents of the University of California
00006  */
00011 #include "fvar.hpp"
00012 
00013 #ifdef __TURBOC__
00014   #pragma hdrstop
00015   #include <iostream.h>
00016 #endif
00017 
00018 #ifdef __ZTC__
00019   #include <iostream.hpp>
00020 #endif
00021 
00022 #include <stdlib.h>
00023 #include "admb_messages.h"
00024 
00025 #ifndef OPT_LIB
00026 
00030  int& ivector::operator[] (int i)
00031  {
00032    if (!v)
00033    {
00034        cerr << "\nattempting to acces non-allocated ivector in "
00035        "ivector::operator[]\n";
00036        ad_exit(1);
00037    }
00038    if (i > indexmax())
00039    {
00040      ADMB_ARRAY_BOUNDS_ERROR("array bound exceeded -- index too high",
00041      "int& ivector::operator[] (int i)", indexmin(), indexmax(), i);
00042    }
00043    if (i<indexmin())
00044    {
00045      ADMB_ARRAY_BOUNDS_ERROR("array bound exceeded -- index too low",
00046      "int& ivector::operator[] (int i)", indexmin(), indexmax(), i);
00047    }
00048    return(*(v+i));
00049  }
00050 
00055  int& ivector::operator() (int i)
00056  {
00057    if (!v)
00058    {
00059      cerr << "\nattempting to acces non-allocated ivector in "
00060      "ivector::operator()\n";
00061      ad_exit(1);
00062    }
00063    if (i > indexmax())
00064    {
00065      ADMB_ARRAY_BOUNDS_ERROR("array bound exceeded -- index too high",
00066      "int& ivector::operator() (int i)", indexmin(), indexmax(), i);
00067    }
00068    if (i < indexmin())
00069    {
00070      ADMB_ARRAY_BOUNDS_ERROR("array bound exceeded -- index too low",
00071      "int& ivector::operator() (int i)", indexmin(), indexmax(), i);
00072    }
00073    return(*(v+i));
00074  }
00075 
00080 const int& ivector::operator[](int i) const
00081  {
00082      if (!v)
00083      {
00084        cerr << "\nattempting to acces non-allocated ivector in "
00085        "ivector::operator[]\n";
00086        ad_exit(1);
00087      }
00088      if (i>indexmax())
00089      {
00090        cerr << "\narray bound exceeded -- index too high in "
00091        "ivector::operator[]";
00092        cerr << "index value " << i << " max value " << indexmax() << endl;
00093        cerr << endl;
00094        ad_exit(1);
00095      }
00096 
00097      if (i<indexmin())
00098      {
00099        cerr << "\narray bound exceeded -- index too low in ivector::operator[]";
00100        cerr << endl;
00101        ad_exit(1);
00102      }
00103    return(*(v+i));
00104  }
00105 
00110 const int& ivector::operator()(int i) const
00111  {
00112      if (!v)
00113      {
00114        cerr << "\nattempting to acces non-allocated ivector in "
00115        "ivector::operator()\n";
00116        ad_exit(1);
00117      }
00118      if (i>indexmax())
00119      {
00120        cerr << "\narray bound exceeded -- index too high in "
00121        "ivector::operator()";
00122        cerr << "index value " << i << " max value " << indexmax() << endl;
00123        ad_exit(1);
00124      }
00125 
00126      if (i<indexmin())
00127      {
00128        cerr << "\narray bound exceeded -- index too low in ivector::operator[]";
00129        cerr << endl;
00130        ad_exit(1);
00131      }
00132    return(*(v+i));
00133  }
00134 #endif