CLHEP VERSION Reference Documentation
   
CLHEP Home Page     CLHEP Documentation     CLHEP Bug Reports

GenericFunctions/AbsFunction.hh
Go to the documentation of this file.
1// -*- C++ -*-
2// $Id: AbsFunction.hh,v 1.3 2007/01/21 20:20:40 boudreau Exp $
3//------------------------AbsFunction-----------------------------------//
4// //
5// AbsFunction, base class for function objects //
6// Joe Boudreau, Petar Maksimovic //
7// Nov 1999 //
8// //
9//----------------------------------------------------------------------//
10#ifndef AbsFunction_h
11#define AbsFunction_h 1
13
14namespace Genfun {
15
16 class AbsParameter;
17
18 //-----------------------------------------------------------------------//
19 // Exact return type of arithmentic operations. To the user, the return //
20 // type is GENFUNCTION, or const AbsFunction &. //
21 //-----------------------------------------------------------------------//
22
23 class FunctionProduct;
24 class FunctionSum;
25 class FunctionDifference;
26 class FunctionQuotient;
27 class FunctionNegation;
28 class FunctionConvolution;
29 class FunctionDirectProduct;
30 class FunctionComposition;
31 class ConstPlusFunction;
32 class ConstTimesFunction;
33 class ConstMinusFunction;
34 class ConstOverFunction;
35 class FunctionPlusParameter;
36 class FunctionTimesParameter;
37 class FunctionNumDeriv;
38 class Variable;
39 class FunctionNoop;
40 class ParameterComposition;
41
42 typedef FunctionNoop Derivative;
43
49
50 public:
51
52 // Default Constructor
54
55 // Copy Constructor:
56 AbsFunction(const AbsFunction &right);
57
58 // Destructor
59 virtual ~AbsFunction();
60
61 // Function value: N-dimensional functions must override these:
62 virtual unsigned int dimensionality() const ; // returns 1;
63
64 // Function value
65 virtual double operator() (double argument) const=0;
66 virtual double operator() (const Argument &argument) const=0;
67
68 // Every function must override this:
69 virtual AbsFunction * clone() const=0;
70
71 // Function composition. Do not attempt to override:
73
74 // Parameter composition. Do not attempt to override:
76
77 // Derivative, (All functions) (do not override)
79
80 // Derivative (1D functions only) (do not override)
82
83 // Does this function have an analytic derivative?
84 virtual bool hasAnalyticDerivative() const {return false;}
85
86 // Derivative. Overriders may be provided, numerical method by default!
87 virtual Derivative partial(unsigned int) const;
88
89 private:
90
91 // It is illegal to assign a function.
92 const AbsFunction & operator=(const AbsFunction &right);
93
94 };
95
97FunctionSum operator + (const AbsFunction &op1, const AbsFunction &op2);
101
102ConstTimesFunction operator * (double c, const AbsFunction &op2);
103ConstPlusFunction operator + (double c, const AbsFunction &op2);
104ConstMinusFunction operator - (double c, const AbsFunction &op2);
105ConstOverFunction operator / (double c, const AbsFunction &op2);
106
107ConstTimesFunction operator * (const AbsFunction &op2, double c);
108ConstPlusFunction operator + (const AbsFunction &op2, double c);
109ConstPlusFunction operator - (const AbsFunction &op2, double c);
110ConstTimesFunction operator / (const AbsFunction &op2, double c);
111
116
121
122FunctionConvolution convolve (const AbsFunction &op1, const AbsFunction &op2, double x0, double x1);
124
125typedef const AbsFunction & GENFUNCTION;
126
127} // namespace Genfun
128
129
130//----------------------------------------------------------------------------
131//
132// This macro does all the ugly boilerplate. For reference I will lis what
133// it is doing:
134//
135// 1). It uses the base class function composition operator. It would be
136// nice to just use the
137//
138// using AbsFunction::operator();
139//
140// directive but unfortunately this is compiler-dependent!
141//
142
143
144#define FUNCTION_OBJECT_DEF(classname) \
145public: \
146 virtual FunctionComposition operator()(const AbsFunction &function) const; \
147 virtual ParameterComposition operator()(const AbsParameter &p) const; \
148 virtual classname *clone() const; \
149private:
150
151//----------------------------------------------------------------------------
152//
153// This macro implements the ugly boilerplate
154//
155
156#define FUNCTION_OBJECT_IMP(classname) \
157inline FunctionComposition classname::operator()(const AbsFunction & function) const\
158{ \
159 return AbsFunction::operator() (function); \
160} \
161inline ParameterComposition classname::operator()(const AbsParameter & p) const\
162{ \
163 return AbsFunction::operator() (p); \
164} \
165inline classname *classname::clone() const \
166{ \
167 return new classname(*this); \
168}
169
170
171//----------------------------------------------------------------------------
172
173
190
191#endif
AbsFunction(const AbsFunction &right)
virtual bool hasAnalyticDerivative() const
virtual AbsFunction * clone() const =0
virtual ~AbsFunction()
Derivative derivative(const Variable &v) const
virtual Derivative partial(unsigned int) const
virtual unsigned int dimensionality() const
Derivative prime() const
virtual double operator()(double argument) const =0
void f(void g())
FunctionQuotient operator/(const AbsFunction &op1, const AbsFunction &op2)
FunctionDirectProduct operator%(const AbsFunction &op1, const AbsFunction &op2)
FunctionSum operator+(const AbsFunction &op1, const AbsFunction &op2)
FunctionProduct operator*(const AbsFunction &op1, const AbsFunction &op2)
const AbsFunction & GENFUNCTION
FunctionConvolution convolve(const AbsFunction &op1, const AbsFunction &op2, double x0, double x1)
FunctionDifference operator-(const AbsFunction &op1, const AbsFunction &op2)