GeoModel - GeoModelCore
ArrayFunction.cpp
1 //==========================================================================//
2 // Imported from the QAT library (qat.pitt.edu) by the copyright holder //
3 // Joe Boudreau. Software licensed under the terms and conditions of the //
4 // GNU Lesser Public License v3. //
5 //==========================================================================//
6 #include "GeoGenericFunctions/ArrayFunction.h"
7 #include "GeoGenericFunctions/FixedConstant.h"
8 
9 namespace GeoGenfun {
10 
11 FUNCTION_OBJECT_IMP(ArrayFunction)
12 
13 // Constructor
14 ArrayFunction::ArrayFunction(const double *begin, const double *end) :
15 _values(begin,end) {}
16 
17 // Initializer list constructor:
18  ArrayFunction::ArrayFunction(std::initializer_list<double> values):
19  _values(values)
20  {
21  }
22 
23 // Destructor
24 ArrayFunction::~ArrayFunction(){}
25 
26 // Copy constructor
27 ArrayFunction::ArrayFunction(const ArrayFunction &right):
28  AbsFunction(right), _values(right._values) {}
29 
30  // Retreive function value
31 double ArrayFunction::operator ()(double argument) const {
32  int i = int (argument+0.5);
33  if (i<0 || i>=int(_values.size())) return 0;
34  else return _values[i];
35 }
36 Derivative ArrayFunction::partial(unsigned int index) const {
37  if (index!=0) throw std::range_error("ArrayFunction: partial derivative index out of range");
38  FixedConstant fPrime(0.0);
39  return Derivative(&fPrime);
40 }
41 
42 }
Definition: Abs.h:15