ADMB Documentation  11.4.2893
 All Classes Files Functions Variables Typedefs Friends Defines
dvec_acc.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 #include "fvar.hpp"
00012 #include <cassert>
00013 
00014 
00020 bool dvector::is_valid_index(const int i) const
00021 {
00022   bool valid = index_min <= i && i <= index_max;
00023   if (!valid)
00024   {
00025 #if defined(USE_EXCEPTIONS)
00026     throw vector_range_exception(i, index_min, index_max);
00027 #else
00028     cerr << "Error: Used invalid i = " << i << " for dvector bounded by ["
00029          << index_min << ", " << index_max << "].\n";
00030 #endif
00031   }
00032   return valid;
00033 }
00034 #if !defined(OPT_LIB)
00035 
00040 double& dvector::operator[](int i)
00041 {
00042   assert((index_min <= i && i <= index_max) || is_valid_index(i));
00043 
00044   return *(v + i);
00045 }
00051 double& dvector::operator()(int i)
00052 {
00053   assert((index_min <= i && i <= index_max) || is_valid_index(i));
00054 
00055   return *(v + i);
00056 }
00062 const double& dvector::operator[](int i) const
00063 {
00064   assert((index_min <= i && i <= index_max) || is_valid_index(i));
00065 
00066   return *(v + i);
00067 }
00073 const double& dvector::operator()(int i) const
00074 {
00075   assert((index_min <= i && i <= index_max) || is_valid_index(i));
00076 
00077   return *(v + i);
00078 }
00079 #endif