Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JMultiMapTransformer.hh
Go to the documentation of this file.
1 #ifndef __JTOOLS__JMULTIMAPTRANSFORMER__
2 #define __JTOOLS__JMULTIMAPTRANSFORMER__
3 
4 #include <stdarg.h>
5 
6 #include "JLang/JClonable.hh"
7 #include "JIO/JSerialisable.hh"
8 #include "JTools/JArray.hh"
9 #include "JTools/JTransformer.hh"
10 
11 
12 /**
13  * \author mdejong
14  */
15 
16 namespace JTOOLS {}
17 namespace JPP { using namespace JTOOLS; }
18 
19 namespace JTOOLS {
20 
21  using JLANG::JClonable;
22  using JIO::JSerialisable;
23  using JIO::JReader;
24  using JIO::JWriter;
25 
26 
27  /**
28  * Interface for weight application and coordinate transformation of function.
29  *
30  * The template parameters refer to the dimension of the map and the data type of the argument, respectively.
31  *
32  * This class extends the JClonable and JSerialisable interfacea.
33  */
34  template<unsigned int N, class JArgument_t>
36  public JClonable< JMultiMapTransformer<N, JArgument_t> >,
37  public JSerialisable
38  {
39  public:
40 
42 
44  typedef JArgument_t argument_type;
47 
48 
49  /**
50  * Evaluate xn value as a function of {x0, ..., xn-1}
51  *
52  * \param buffer x0 - xn-1 values
53  * \param xn xn value
54  * \return xn value
55  */
56  virtual argument_type putXn(const_array_type& buffer, const argument_type xn) const = 0;
57 
58 
59  /**
60  * Evaluate xn value as a function of {x0, ..., xn-1}
61  *
62  * \param buffer x0 - xn-1 values
63  * \param xn xn value
64  * \return xn value
65  */
66  virtual argument_type getXn(const_array_type& buffer, const argument_type xn) const = 0;
67 
68 
69  /**
70  * Weight function.
71  *
72  * \param buffer x0 - xn-1 values
73  * \return weight
74  */
75  virtual double getWeight(const_array_type& buffer) const = 0;
76 
77 
78  /**
79  * Weight function.
80  *
81  * \param x comma seperated list of abscissa values
82  * \return weight
83  */
84  double getWeight(const argument_type x, ...) const
85  {
86  va_start(ap, x);
87 
88  buffer[0] = x;
89 
90  for (int i = 1; i != N; ++i) {
91  buffer[i] = va_arg(ap, argument_type);
92  }
93 
94  va_end(ap);
95 
96  return getWeight(buffer);
97  }
98 
99 
100  /**
101  * Default implementation of weight application and coordinate transformation of function.
102  */
103  class JMultiMapDefaultTransformer;
104 
105 
106  /**
107  * Get default transformer.
108  *
109  * \return default transformer
110  */
112  {
113  static const JMultiMapDefaultTransformer transformer;
114 
115  return transformer;
116  }
117 
118 
119  /**
120  * Get clone of default transformer.
121  *
122  * \return pointer to newly created transformer
123  */
125  {
126  return new JMultiMapDefaultTransformer();
127  }
128 
129 
130  private:
131  mutable va_list ap;
133  };
134 
135 
136  /**
137  * Default implementation of weight application and coordinate transformation of function.
138  *
139  * The coordiniate transformation has no effect and the weight is equal to one.
140  *
141  * This class implements the JMultiMapTransformer, JClonable and JSerialisable interfaces.
142  */
143  template<unsigned int N, class JArgument_t>
145  public JMultiMapTransformer<N, JArgument_t>
146  {
147  public:
148 
149  /**
150  * Default constructor.
151  */
153  {}
154 
155 
156  /**
157  * Clone object.
158  *
159  * \return pointer to newly created transformer
160  */
161  virtual clone_type clone() const
162  {
163  return new JMultiMapDefaultTransformer(*this);
164  }
165 
166 
167  /**
168  * Evaluate xn value as a function of {x0, ..., xn-1}
169  *
170  * \param buffer x0 - xn-1 values
171  * \param xn xn value
172  * \return xn value
173  */
175  {
176  return xn;
177  }
178 
179 
180  /**
181  * Evaluate xn value as a function of {x0, ..., xn-1}
182  *
183  * \param buffer x0 - xn-1 values
184  * \param xn xn value
185  * \return xn value
186  */
188  {
189  return xn;
190  }
191 
192 
193  /**
194  * Weight function.
195  *
196  * \param buffer x0 - xn-1 values
197  * \return weight
198  */
199  virtual double getWeight(const_array_type& buffer) const
200  {
201  return 1.0;
202  }
203 
204 
205  /**
206  * Read from input.
207  *
208  * This method reads nothing.
209  *
210  * \param in reader
211  * \return reader
212  */
213  virtual JReader& read(JReader& in)
214  {
215  return in;
216  }
217 
218 
219  /**
220  * Write to output.
221  *
222  * This method writes nothing.
223  *
224  * \param out writer
225  * \return writer
226  */
227  virtual JWriter& write(JWriter& out) const
228  {
229  return out;
230  }
231  };
232 
233 
234  /**
235  * Auxiliary class to convert JMultiMapTransformer to JCollectionElementTransformer.
236  *
237  * This class implements the JCollectionElementTransformer interface.
238  */
239  template<unsigned int N, class JElement_t>
241  public JCollectionElementTransformer<JElement_t>
242  {
243  public:
244 
245  typedef typename JElement_t::abscissa_type abscissa_type;
246  typedef typename JElement_t::ordinate_type ordinate_type;
247 
249 
251 
252 
253  /**
254  * Constructor.
255  *
256  * \param __transformer multidimensional map transformer
257  * \param __buffer x0 - xn-1 values
258  */
260  const_array_type& __buffer) :
261  transformer(__transformer),
262  buffer (__buffer),
263  W(transformer.getWeight(buffer))
264  {}
265 
266 
267  /**
268  * Transform element.
269  *
270  * \param element input element
271  * \return output element
272  */
273  virtual JElement_t operator()(const JElement_t& element) const
274  {
275  return JElement_t(transformer.putXn(buffer, element.getX()), element.getY() / W);
276  }
277 
278  private:
281  const double W;
282  };
283 
284 
285  /**
286  * Auxiliary class to convert JMultiMapTransformer to JCollectionElementTransformer.
287  *
288  * This class implements the JCollectionElementTransformer interface.
289  */
290  template<unsigned int N, class JElement_t>
292  public JCollectionElementTransformer<JElement_t>
293  {
294  public:
295 
296  typedef typename JElement_t::abscissa_type abscissa_type;
297  typedef typename JElement_t::ordinate_type ordinate_type;
298 
300 
302 
303 
304  /**
305  * Constructor.
306  *
307  * \param __transformer multidimensional map transformer
308  * \param __buffer x0 - xn-1 values
309  */
311  const_array_type& __buffer) :
312  transformer(__transformer),
313  buffer (__buffer),
314  W(transformer.getWeight(buffer))
315  {}
316 
317 
318  /**
319  * Transform element.
320  *
321  * \param element input element
322  * \return output element
323  */
324  virtual JElement_t operator()(const JElement_t& element) const
325  {
326  return JElement_t(transformer.getXn(buffer, element.getX()), element.getY() * W);
327  }
328 
329  private:
332  const double W;
333  };
334 
335 
336  /**
337  * Abstract interface for transformable multidimensional map.
338  *
339  * The template parameters refer to the dimension of the map and the data type of the argument, respectively.
340  */
341  template<unsigned int N, class JArgument_t>
343  {
344  typedef JArgument_t argument_type;
346 
347  /**
348  * Application of transformation.
349  *
350  * \param transformer function transformer
351  */
352  virtual void transform(const transformer_type& transformer) = 0;
353  };
354 }
355 
356 #endif
virtual argument_type putXn(const_array_type &buffer, const argument_type xn) const
Evaluate xn value as a function of {x0, ..., xn-1}.
transformer_type::const_array_type const_array_type
Interface for binary output.
JMultiMapTransformer< N, JArgument_t > multimaptransformer_type
JMultiMapTransformer< N, abscissa_type > transformer_type
JClonable< multimaptransformer_type >::clone_type clone_type
Auxiliary class to convert JMultiMapTransformer to JCollectionElementTransformer. ...
virtual argument_type getXn(const_array_type &buffer, const argument_type xn) const
Evaluate xn value as a function of {x0, ..., xn-1}.
virtual JReader & read(JReader &in)
Read from input.
virtual void transform(const transformer_type &transformer)=0
Application of transformation.
transformer_type::const_array_type const_array_type
Forward declaration of binary output.
double getWeight(const argument_type x,...) const
Weight function.
const transformer_type & transformer
JArray< N, argument_type > array_type
virtual double getWeight(const_array_type &buffer) const =0
Weight function.
const transformer_type & transformer
Abstract interface for transformable multidimensional map.
JElement_t::abscissa_type abscissa_type
virtual JElement_t operator()(const JElement_t &element) const
Transform element.
JMultiMapTransformer< N, argument_type > transformer_type
const JArray< N, const argument_type > const_array_type
static JMultiMapTransformer * getClone()
Get clone of default transformer.
Template interface class for object cloning.
Definition: JClonable.hh:19
Interface for binary input.
Default implementation of weight application and coordinate transformation of function.
Interface for transformation of collection of elements.
Definition: JTransformer.hh:18
JMultiMapPutTransformer(const transformer_type &__transformer, const_array_type &__buffer)
Constructor.
virtual JWriter & write(JWriter &out) const
Write to output.
JClass_t * clone_type
Type definition of return value of method clone().
Definition: JClonable.hh:25
JMultiMapGetTransformer(const transformer_type &__transformer, const_array_type &__buffer)
Constructor.
JElement_t::ordinate_type ordinate_type
Interface for weight application and coordinate transformation of function.
virtual argument_type getXn(const_array_type &buffer, const argument_type xn) const =0
Evaluate xn value as a function of {x0, ..., xn-1}.
virtual double getWeight(const_array_type &buffer) const
Weight function.
Auxiliary class to convert JMultiMapTransformer to JCollectionElementTransformer. ...
JElement_t::ordinate_type ordinate_type
virtual argument_type putXn(const_array_type &buffer, const argument_type xn) const =0
Evaluate xn value as a function of {x0, ..., xn-1}.
JArray< N, argument_type > buffer
JMultiMapTransformer< N, abscissa_type > transformer_type
virtual JElement_t operator()(const JElement_t &element) const
Transform element.
JElement_t::abscissa_type abscissa_type
static const JMultiMapTransformer & getDefaultTransformer()
Get default transformer.