Jpp 19.3.0-rc.2
the software that should make you happy
Loading...
Searching...
No Matches
JConstantFunction1D.hh
Go to the documentation of this file.
1#ifndef __JCONSTANTFUNCTION1D__
2#define __JCONSTANTFUNCTION1D__
3
6
7
8/**
9 * \author mdejong
10 */
11
12namespace JTOOLS {}
13namespace JPP { using namespace JTOOLS; }
14
15namespace 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 */
43
44
45 /**
46 * Constructor.
47 *
48 * \param y value
49 */
52 __y(y)
53 {}
54
55
56 /**
57 * Constructor.
58 *
59 * \param y zero
60 */
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 */
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 override
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() override
199 {}
200
201 private:
203 };
204}
205
206#endif
Interface for binary input.
Interface for binary output.
Template implementation of function object in one dimension returning a constant value.
result_type getY() const
Function value.
JConstantFunction1D & mul(const double value)
Scale contents.
function_type::result_type result_type
virtual result_type evaluate(const argument_type *pX) const override
Function value evaluation.
function_type::argument_type argument_type
JConstantFunction1D & div(const double value)
Scale contents.
virtual void do_compile() override
Function compilation.
friend JReader & operator>>(JReader &in, JConstantFunction1D &function)
Read function from input.
JConstantFunction1D()
Default constructor.
friend JWriter & operator<<(JWriter &out, const JConstantFunction1D &function)
Write function to output.
JConstantFunction1D(const JMATH::JZero &y)
Constructor.
JConstantFunction1D & sub(typename JLANG::JClass< result_type >::argument_type value)
Subtract offset.
JConstantFunction1D & sub(const JConstantFunction1D &function)
Subtract function.
JFunction1D< JArgument_t, JResult_t > function_type
JConstantFunction1D & add(const JConstantFunction1D &function)
Add function.
JConstantFunction1D & add(typename JLANG::JClass< result_type >::argument_type value)
Add offset.
JConstantFunction1D(const result_type y)
Constructor.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary classes and methods for multi-dimensional interpolations and histograms.
JArgument< T >::argument_type argument_type
Definition JClass.hh:82
Auxiliary class to assign zero value.
Definition JZero.hh:81
Template definition of function object interface in one dimension.
functional_type::result_type result_type
functional_type::argument_type argument_type