ProductRule.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/ProductRule.h
10
11#ifndef __MEAL_ProductRule_H
12#define __MEAL_ProductRule_H
13
14#include "MEAL/GroupRule.h"
15
16namespace MEAL {
17
19 template<class T>
20 class ProductRule : public GroupRule<T>
21 {
22
23 public:
24
25 typedef typename T::Result Result;
26
28 void operator *= (T* model) { this->add_model (model); }
29
30 // ///////////////////////////////////////////////////////////////////
31 //
32 // Function implementation
33 //
34 // ///////////////////////////////////////////////////////////////////
35
37 std::string get_name () const
38 { return "ProductRule<" + std::string(T::Name)+ ">"; }
39
40 protected:
41
42 // ///////////////////////////////////////////////////////////////////
43 //
44 // GroupRule implementation
45 //
46 // ///////////////////////////////////////////////////////////////////
47
49 const Result get_identity() const { return 1.0; }
50
52 void operate (Result& total, const Result& element)
53 { total = total * element; }
54
56 const Result partial (const Result& element) const { return element; }
57
58 };
59
60 template<class T>
61 ProductRule<T>* product (T* A, T* B)
62 {
63 Reference::To< ProductRule<T> > result = new ProductRule<T>;
64 result->add_model (A);
65 result->add_model (B);
66 return result.release();
67 }
68
69 template<class T>
70 ProductRule<T>* product (Reference::To<T>& A, T* B)
71 { return product (A.get(), B); }
72
73 template<class T>
74 ProductRule<T>* product (T* A, Reference::To<T>& B)
75 { return product (A, B.get()); }
76
77 template<class T>
78 ProductRule<T>* product (Reference::To<T>& A, Reference::To<T>& B)
79 { return product (A.get(), B.get()); }
80}
81
82
83
84
85
86#endif
87
void add_model(T *model)
Add an element to the result.
Definition GroupRule.h:185
GroupRule()
Default constructor.
Definition GroupRule.h:37
Represents a product of models.
Definition ProductRule.h:21
void operator*=(T *model)
Add the model to the product.
Definition ProductRule.h:28
std::string get_name() const
Return the name of the class.
Definition ProductRule.h:37
void operate(Result &total, const Result &element)
Multiply the total by the element.
Definition ProductRule.h:52
const Result get_identity() const
Return the identity of the multiplication group (one)
Definition ProductRule.h:49
const Result partial(const Result &element) const
Neighbouring terms stay in each other's partial derivatives.
Definition ProductRule.h:56
Type * get() const
Type * release()
Namespace in which all modeling and calibration related code is declared.
Definition ExampleComplex2.h:16

Generated using doxygen 1.14.0