Jpp  17.3.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 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
JConstantFunction1D & mul(const double value)
Scale contents.
Interface for binary output.
result_type getY() const
Function value.
JConstantFunction1D & sub(const JConstantFunction1D &function)
Subtract function.
functional_type::argument_type argument_type
Definition: JFunctional.hh:323
friend JWriter & operator<<(JWriter &out, const JConstantFunction1D &function)
Write function to output.
JConstantFunction1D & add(const JConstantFunction1D &function)
Add function.
JConstantFunction1D & div(const double value)
Scale contents.
virtual void do_compile() override
Function compilation.
JConstantFunction1D(const result_type y)
Constructor.
friend JReader & operator>>(JReader &in, JConstantFunction1D &function)
Read function from input.
JConstantFunction1D & sub(typename JLANG::JClass< result_type >::argument_type value)
Subtract offset.
JConstantFunction1D & add(typename JLANG::JClass< result_type >::argument_type value)
Add offset.
Template definition of function object interface in one dimension.
Definition: JFunctional.hh:317
JArgument< T >::argument_type argument_type
Definition: JClass.hh:82
JConstantFunction1D(const JMATH::JZero &y)
Constructor.
Template implementation of function object in one dimension returning a constant value.
Auxiliary class to assign zero value.
Definition: JZero.hh:81
JFunction1D< JArgument_t, JResult_t > function_type
functional_type::result_type result_type
Definition: JFunctional.hh:324
Interface for binary input.
function_type::argument_type argument_type
virtual result_type evaluate(const argument_type *pX) const override
Function value evaluation.
function_type::result_type result_type
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Definition: JCanberra.sh:46
JConstantFunction1D()
Default constructor.