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 
16 namespace 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  {
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 
Represents a product of models.
Definition: ProductRule.h:25
const Result get_identity() const
Return the identity of the multiplication group (one)
Definition: ProductRule.h:59
Type * release()
Type * get() const
Namespace in which all modeling and calibration related code is declared.
Definition: ExampleComplex2.h:16
void add_model(T *model)
Add an element to the result.
Definition: GroupRule.h:185
const Result partial(const Result &element) const
Neighbouring terms stay in each other's partial derivatives.
Definition: ProductRule.h:66
void operate(Result &total, const Result &element)
Multiply the total by the element.
Definition: ProductRule.h:62
void operator*=(T *model)
Add the model to the product.
Definition: ProductRule.h:38
std::string get_name() const
Return the name of the class.
Definition: ProductRule.h:47
std::complex< double > Result
The return type of the evaluate method.
Definition: Evaluable.h:40

Generated using doxygen 1.8.17