Jpp
JConstantFunction1D.hh
Go to the documentation of this file.
1 #ifndef __JCONSTANTFUNCTION1D__
2 #define __JCONSTANTFUNCTION1D__
3 
4 #include "JIO/JSerialisable.hh"
5 #include "JTools/JFunctional.hh"
6 
7 
8 /**
9  * \author mdejong
10  */
11 
12 namespace JTOOLS {}
13 namespace JPP { using namespace JTOOLS; }
14 
15 namespace JTOOLS {
16 
17  using JIO::JReader;
18  using JIO::JWriter;
19 
20  /**
21  * Template implementation of function object in one dimension returning a constant value.
22  *
23  * This class implements the JFunction1D interface.
24  */
25  template<class JArgument_t, class JResult_t>
27  public JFunction1D<JArgument_t, JResult_t>
28  {
29  public:
30 
34 
35 
36  /**
37  * Default constructor.
38  */
40  function_type(),
41  __y()
42  {}
43 
44 
45  /**
46  * Constructor.
47  *
48  * \param y value
49  */
51  function_type(),
52  __y(y)
53  {}
54 
55 
56  /**
57  * Constructor.
58  *
59  * \param y zero
60  */
62  function_type(),
63  __y(y)
64  {}
65 
66 
67  /**
68  * Add offset.
69  *
70  * \param value offset
71  */
73  {
74  __y += value;
75 
76  return *this;
77  }
78 
79 
80  /**
81  * Subtract offset.
82  *
83  * \param value offset
84  */
86  {
87  __y -= value;
88 
89  return *this;
90  }
91 
92 
93  /**
94  * Scale contents.
95  *
96  * \param value multiplication factor
97  */
98  JConstantFunction1D& mul(const double value)
99  {
100  __y *= value;
101 
102  return *this;
103  }
104 
105 
106  /**
107  * Scale contents.
108  *
109  * \param value division factor
110  */
111  JConstantFunction1D& div(const double value)
112  {
113  __y /= value;
114 
115  return *this;
116  }
117 
118 
119  /**
120  * Add function.
121  *
122  * \param function function
123  */
125  {
126  __y += function.getY();
127 
128  return *this;
129  }
130 
131 
132  /**
133  * Subtract function.
134  *
135  * \param function function
136  */
138  {
139  __y -= function.getY();
140 
141  return *this;
142  }
143 
144 
145  /**
146  * Function value.
147  *
148  * \return function value
149  */
150  result_type getY() const
151  {
152  return __y;
153  }
154 
155 
156  /**
157  * Function value evaluation.
158  *
159  * \param pX pointer to abscissa values
160  * \return function value
161  */
162  virtual result_type evaluate(const argument_type* pX) const
163  {
164  return __y;
165  }
166 
167 
168  /**
169  * Read function from input.
170  *
171  * \param in reader
172  * \param function function
173  * \return reader
174  */
175  friend inline JReader& operator>>(JReader& in, JConstantFunction1D& function)
176  {
177  return in >> function.__y;
178  }
179 
180 
181  /**
182  * Write function to output.
183  *
184  * \param out writer
185  * \param function function
186  * \return writer
187  */
188  friend inline JWriter& operator<<(JWriter& out, const JConstantFunction1D& function)
189  {
190  return out << function.__y;
191  }
192 
193 
194  protected:
195  /**
196  * Function compilation.
197  */
198  virtual void do_compile()
199  {}
200 
201  private:
203  };
204 }
205 
206 #endif
JIO::JReader
Interface for binary input.
Definition: JSerialisable.hh:62
JTOOLS::JConstantFunction1D::div
JConstantFunction1D & div(const double value)
Scale contents.
Definition: JConstantFunction1D.hh:111
JTOOLS::pX
pX
Definition: JPolint.hh:625
JTOOLS::JConstantFunction1D::sub
JConstantFunction1D & sub(typename JLANG::JClass< result_type >::argument_type value)
Subtract offset.
Definition: JConstantFunction1D.hh:85
JTOOLS::JConstantFunction1D
Template implementation of function object in one dimension returning a constant value.
Definition: JConstantFunction1D.hh:26
JTOOLS::JConstantFunction1D::__y
result_type __y
Definition: JConstantFunction1D.hh:202
JLANG::JClass::argument_type
JArgument< T >::argument_type argument_type
Definition: JClass.hh:82
JTOOLS::JConstantFunction1D::do_compile
virtual void do_compile()
Function compilation.
Definition: JConstantFunction1D.hh:198
JTOOLS::JConstantFunction1D::operator>>
friend JReader & operator>>(JReader &in, JConstantFunction1D &function)
Read function from input.
Definition: JConstantFunction1D.hh:175
JTOOLS::JConstantFunction1D::JConstantFunction1D
JConstantFunction1D(const JMATH::JZero &y)
Constructor.
Definition: JConstantFunction1D.hh:61
JTOOLS::JConstantFunction1D::argument_type
function_type::argument_type argument_type
Definition: JConstantFunction1D.hh:32
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JTOOLS::JFunction1D
Template definition of function object interface in one dimension.
Definition: JFunctional.hh:317
JSerialisable.hh
JTOOLS::JConstantFunction1D::result_type
function_type::result_type result_type
Definition: JConstantFunction1D.hh:33
JTOOLS::JConstantFunction1D::evaluate
virtual result_type evaluate(const argument_type *pX) const
Function value evaluation.
Definition: JConstantFunction1D.hh:162
JIO::JWriter
Interface for binary output.
Definition: JSerialisable.hh:131
JTOOLS::JConstantFunction1D::mul
JConstantFunction1D & mul(const double value)
Scale contents.
Definition: JConstantFunction1D.hh:98
JTOOLS::JConstantFunction1D::sub
JConstantFunction1D & sub(const JConstantFunction1D &function)
Subtract function.
Definition: JConstantFunction1D.hh:137
JTOOLS::JConstantFunction1D::JConstantFunction1D
JConstantFunction1D()
Default constructor.
Definition: JConstantFunction1D.hh:39
JTOOLS::JConstantFunction1D::JConstantFunction1D
JConstantFunction1D(const result_type y)
Constructor.
Definition: JConstantFunction1D.hh:50
JMATH::JZero
Auxiliary class to assign zero value.
Definition: JZero.hh:70
JTOOLS::JConstantFunction1D::operator<<
friend JWriter & operator<<(JWriter &out, const JConstantFunction1D &function)
Write function to output.
Definition: JConstantFunction1D.hh:188
JTOOLS::JConstantFunction1D::add
JConstantFunction1D & add(typename JLANG::JClass< result_type >::argument_type value)
Add offset.
Definition: JConstantFunction1D.hh:72
JFunctional.hh
JTOOLS::JConstantFunction1D::add
JConstantFunction1D & add(const JConstantFunction1D &function)
Add function.
Definition: JConstantFunction1D.hh:124
JTOOLS
Auxiliary classes and methods for multi-dimensional interpolations and histograms.
Definition: JAbstractCollection.hh:9
JTOOLS::JFunction1D::argument_type
functional_type::argument_type argument_type
Definition: JFunctional.hh:323
JTOOLS::JFunction1D::result_type
functional_type::result_type result_type
Definition: JFunctional.hh:324
JTOOLS::JConstantFunction1D::getY
result_type getY() const
Function value.
Definition: JConstantFunction1D.hh:150
JTOOLS::JConstantFunction1D::function_type
JFunction1D< JArgument_t, JResult_t > function_type
Definition: JConstantFunction1D.hh:31