ADMB Documentation  11.2.2817
 All Classes Files Functions Variables Typedefs Friends Defines
ivec7.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: ivec7.cpp 2793 2014-12-12 21:45:05Z 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 #include <stdexcept>
00025 
00026 #ifndef OPT_LIB
00027 
00031 int& ivector::operator[](int i)
00032 {
00033   if (!v)
00034   {
00035     cerr << "\nattempting to acces non-allocated ivector in "
00036        "ivector::operator[]\n";
00037     throw std::bad_alloc();
00038   }
00039   else if (i > indexmax())
00040   {
00041      ADMB_ARRAY_BOUNDS_ERROR("array bound exceeded -- index too high",
00042      "int& ivector::operator[] (int i)", indexmin(), indexmax(), i);
00043      throw std::out_of_range("array bound exceeded -- index too high");
00044   }
00045   else if (i<indexmin())
00046   {
00047      ADMB_ARRAY_BOUNDS_ERROR("array bound exceeded -- index too low",
00048      "int& ivector::operator[] (int i)", indexmin(), indexmax(), i);
00049      throw std::out_of_range("array bound exceeded -- index too low");
00050   }
00051   else
00052   {
00053     return *(v+i);
00054   }
00055 }
00056 
00061 int& ivector::operator()(int i)
00062 {
00063   if (!v)
00064   {
00065     cerr << "\nattempting to acces non-allocated ivector in "
00066      "ivector::operator()\n";
00067     throw std::bad_alloc();
00068   }
00069   else if (i > indexmax())
00070   {
00071      ADMB_ARRAY_BOUNDS_ERROR("array bound exceeded -- index too high",
00072      "int& ivector::operator() (int i)", indexmin(), indexmax(), i);
00073      throw std::out_of_range("array bound exceeded -- index too high");
00074   }
00075   else if (i < indexmin())
00076   {
00077      ADMB_ARRAY_BOUNDS_ERROR("array bound exceeded -- index too low",
00078      "int& ivector::operator() (int i)", indexmin(), indexmax(), i);
00079      throw std::out_of_range("array bound exceeded -- index too low");
00080   }
00081   else
00082   {
00083     return *(v+i);
00084   }
00085 }
00086 
00091 const int& ivector::operator[](int i) const
00092 {
00093   if (!v)
00094   {
00095     cerr << "\nattempting to acces non-allocated ivector in "
00096        "ivector::operator[]\n";
00097     throw std::bad_alloc();
00098   }
00099   else if (i > indexmax())
00100   {
00101     cerr << "\narray bound exceeded -- index too high in "
00102        "ivector::operator[]";
00103     cerr << "index value " << i << " max value " << indexmax() << endl;
00104     cerr << endl;
00105     throw std::out_of_range("array bound exceeded -- index too high");
00106   }
00107   else if (i < indexmin())
00108   {
00109     cerr << "\narray bound exceeded -- index too low in ivector::operator[]";
00110     cerr << endl;
00111     throw std::out_of_range("array bound exceeded -- index too low");
00112   }
00113   else
00114   {
00115     return *(v+i);
00116   }
00117 }
00118 
00123 const int& ivector::operator()(int i) const
00124 {
00125   if (!v)
00126   {
00127     cerr << "\nattempting to acces non-allocated ivector in "
00128        "ivector::operator()\n";
00129     throw std::bad_alloc();
00130   }
00131   else if (i>indexmax())
00132   {
00133     cerr << "\narray bound exceeded -- index too high in "
00134        "ivector::operator()";
00135     cerr << "index value " << i << " max value " << indexmax() << endl;
00136     throw std::out_of_range("array bound exceeded -- index too high");
00137   }
00138   else if (i<indexmin())
00139   {
00140     cerr << "\narray bound exceeded -- index too low in ivector::operator[]";
00141     cerr << endl;
00142     throw std::out_of_range("array bound exceeded -- index too low");
00143   }
00144   else
00145   {
00146     return *(v+i);
00147   }
00148 }
00149 #endif