SumRule.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/SumRule.h
10 
11 #ifndef __SumRule_H
12 #define __SumRule_H
13 
14 #include "MEAL/GroupRule.h"
15 
16 namespace MEAL {
17 
19  template<class T>
20  class SumRule : 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 "SumRule<" + std::string(T::Name)+ ">"; }
39 
40  protected:
41 
42  // ///////////////////////////////////////////////////////////////////
43  //
44  // GroupRule implementation
45  //
46  // ///////////////////////////////////////////////////////////////////
47 
49  const Result get_identity () const { return 0.0; }
50 
52  void operate (Result& total, const Result& element) { total += element; }
53 
55  const Result partial (const Result& element) const { return 0; }
56 
57  };
58 
59  template<class T>
60  SumRule<T>* sum (T* A, T* B)
61  {
63  result->add_model (A);
64  result->add_model (B);
65  return result.release();
66  }
67 
68  template<class T>
69  SumRule<T>* sum (Reference::To<T>& A, T* B)
70  { return sum (A.get(), B); }
71 
72  template<class T>
73  SumRule<T>* sum (T* A, Reference::To<T>& B)
74  { return sum (A, B.get()); }
75 
76  template<class T>
77  SumRule<T>* sum (Reference::To<T>& A, Reference::To<T>& B)
78  { return sum (A.get(), B.get()); }
79 }
80 
81 
82 #endif
83 
void operate(Result &total, const Result &element)
Add the element to the total.
Definition: SumRule.h:62
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
std::string get_name() const
Return the name of the class.
Definition: SumRule.h:47
const Result partial(const Result &element) const
Neighbouring terms do not affect each other's partial derivatives.
Definition: SumRule.h:65
Represents a sum of models.
Definition: SumRule.h:25
void operator+=(T *model)
Add the model to the sum.
Definition: SumRule.h:38
const Result get_identity() const
Return the identity of the addition group (zero)
Definition: SumRule.h:59

Generated using doxygen 1.8.17