Univariate.h
1 //-*-C++-*-
2 /***************************************************************************
3  *
4  * Copyright (C) 2004 by Willem van Straten
5  * Licensed under the Academic Free License version 2.1
6  *
7  ***************************************************************************/
8 
9 // psrchive/More/MEAL/MEAL/Univariate.h
10 
11 #ifndef __MEAL_Univariate_H
12 #define __MEAL_Univariate_H
13 
14 #include "MEAL/UnivariatePolicy.h"
15 #include "Reference.h"
16 
17 namespace MEAL {
18 
20  template<class T>
21  class Univariate : public T {
22 
23  public:
24 
27  { set_univariate_policy ( new UnivariatePolicy (this) ); }
28 
30  Univariate (const Univariate& copy) : T (copy) { }
31 
33  Univariate& operator = (const Univariate& copy);
34 
36  Univariate<T>* clone () const
37  { throw Error (InvalidState, "Univariate<T>::clone", "not implemented"); }
38 
40  virtual void set_abscissa (double value)
41  { univariate_policy->set_abscissa(value); }
42 
44  double get_abscissa () const
45  { return univariate_policy->get_abscissa (); }
46 
48  typename T::Result compute (double x)
49  { set_abscissa (x); return this->evaluate (); }
50 
51  protected:
52 
53  template <class U>
54  friend class FunctionPolicyTraits;
55 
56  void set_univariate_policy (UnivariatePolicy* policy)
57  { this->argument_policy = univariate_policy = policy; }
58 
59  UnivariatePolicy* get_univariate_policy () const
60  { return univariate_policy; }
61 
63  void copy_univariate_policy (const Univariate* other)
64  { set_univariate_policy (other->get_univariate_policy()); }
65 
66  private:
67 
69  Reference::To<UnivariatePolicy> univariate_policy;
70 
71  };
72 
73  template<class T>
74  class FunctionPolicyTraits< Univariate<T> >
75  {
76  public:
77  static void composite_component (Univariate<T>* composite,
78  Univariate<T>* component)
79  {
80  component->copy_univariate_policy (composite);
81  }
82  };
83 }
84 
85 template<class T>
87 {
88  if (&copy != this) {
89  set_abscissa( copy.get_abscissa() );
90  T::operator=( copy );
91  }
92  return *this;
93 }
94 
95 #endif
96 
T::Result compute(double x)
Evaluate the function.
Definition: Univariate.h:58
Abstract template base class of univariate Function implementations.
Definition: Univariate.h:26
Univariate< T > * clone() const
Clone.
Definition: Univariate.h:46
void copy_univariate_policy(const Univariate *other)
Copy the parameter policy of another instance.
Definition: Univariate.h:73
A function of one scalar variable.
Definition: UnivariatePolicy.h:24
Namespace in which all modeling and calibration related code is declared.
Definition: ExampleComplex2.h:16
virtual void set_abscissa(double value)
Set the abscissa value.
Definition: Univariate.h:50
Univariate & operator=(const Univariate &copy)
Assignment operator.
Definition: Univariate.h:86
Univariate()
Default constructor.
Definition: Univariate.h:36
double get_abscissa() const
Get the abscissa value.
Definition: Univariate.h:54

Generated using doxygen 1.8.17