AbstractFunction.h 5.17 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/******************************************************************************
 *
 * AMDiS - Adaptive multidimensional simulations
 *
 * Copyright (C) 2013 Dresden University of Technology. All Rights Reserved.
 * Web: https://fusionforge.zih.tu-dresden.de/projects/amdis
 *
 * Authors: 
 * Simon Vey, Thomas Witkowski, Andreas Naumann, Simon Praetorius, et al.
 *
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 *
 *
 * This file is part of AMDiS
 *
 * See also license.opensource.txt in the distribution.
 * 
 ******************************************************************************/
20
21


22
23
24
25
26
27
28
29

/** \file AbstractFunction.h */

#ifndef AMDIS_ABSTRACTFUNCTION_H
#define AMDIS_ABSTRACTFUNCTION_H

#include "Global.h"

Praetorius, Simon's avatar
Praetorius, Simon committed
30
31
32
33
#include <boost/preprocessor/arithmetic/inc.hpp>
#include <boost/preprocessor/repetition/enum_params.hpp>
#include <boost/preprocessor/repetition/repeat.hpp>

34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
namespace AMDiS {

  /** 
   * \ingroup Common
   * 
   * \brief
   * An AbstractFunction object represents a function 
   * f : ArgumentType -> ReturnType. 
   *
   * AbstractFunction is a pure virtual class interface class.
   * To create your own function you have to derive AbstractFunction and
   * overload operator(). 
   */
  template<typename ReturnType, typename ArgumentType>
  class AbstractFunction
  {
  public:
51
    /// Constructor.
52
53
    AbstractFunction(int degree = 0) : 
      degree_(degree) 
Thomas Witkowski's avatar
Thomas Witkowski committed
54
    {}
55

Thomas Witkowski's avatar
Thomas Witkowski committed
56
    virtual ~AbstractFunction() {}
57

58
    /// Returns \ref degree_.
Thomas Witkowski's avatar
Thomas Witkowski committed
59
60
    inline int getDegree() const 
    { 
61
      return degree_; 
Thomas Witkowski's avatar
Thomas Witkowski committed
62
    }
63

64
    /// Deligates the evaluation to overriden method f.
65
    virtual ReturnType operator()(const ArgumentType& x) const = 0;
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82

  protected:
    int degree_;
  };

  /**
   * \ingroup Common
   *
   * \brief
   * Interface for binary functions. 
   */
  template<typename ReturnType, 
	   typename ArgumentType1, 
	   typename ArgumentType2>
  class BinaryAbstractFunction
  {
  public:
83
    /// Constructor.
84
85
    BinaryAbstractFunction(int degree = 0) : 
      degree_(degree) 
86
    {}
87

88
    virtual ~BinaryAbstractFunction() {}
89

90
    /// Returns \ref degree_.
Thomas Witkowski's avatar
Thomas Witkowski committed
91
92
    inline int getDegree() const 
    { 
93
      return degree_; 
94
    }
95

96
    /// Deligates the evaluation to overriden method f.
97
98
    virtual ReturnType operator()(const ArgumentType1& x,
				  const ArgumentType2& y) const = 0;
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116

  protected:
    int degree_;
  };

  /**
   * \ingroup Common
   *
   * \brief
   * Interface for tertiary functions. 
   */
  template<typename ReturnType, 
	   typename ArgumentType1, 
	   typename ArgumentType2,
	   typename ArgumentType3>
  class TertiaryAbstractFunction
  {
  public:
117
    /// Constructor.
118
119
    TertiaryAbstractFunction(int degree = 0) : 
      degree_(degree) 
120
    {}
121

122
    virtual ~TertiaryAbstractFunction() {}
123

124
    /// Returns \ref degree_.
Thomas Witkowski's avatar
Thomas Witkowski committed
125
126
    inline int getDegree() const 
    { 
127
      return degree_; 
128
    }
129

130
    /// function evaluation.
131
132
133
    virtual ReturnType operator()(const ArgumentType1& x,
				  const ArgumentType2& y,
				  const ArgumentType3& z) const = 0;
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152

  protected:
    int degree_;
  };

  /**
   * \ingroup Common
   *
   * \brief
   * Interface for quart functions. 
   */
  template<typename ReturnType, 
	   typename ArgumentType1, 
	   typename ArgumentType2, 
	   typename ArgumentType3,
	   typename ArgumentType4>
  class QuartAbstractFunction
  {
  public:
153
    /// Constructor.
154
155
    QuartAbstractFunction(int degree = 0) : 
      degree_(degree) 
156
    {}
157

158
    virtual ~QuartAbstractFunction() {}
159

160
    /// Returns \ref degree_.
Thomas Witkowski's avatar
Thomas Witkowski committed
161
162
    inline int getDegree() const 
    { 
163
      return degree_; 
164
    }
165

166
    /// function evaluation.
167
168
169
170
    virtual ReturnType operator()(const ArgumentType1& x,
				  const ArgumentType2& y,
				  const ArgumentType3& z,
				  const ArgumentType4& u) const = 0;
171
172
173
174
175
176

  protected:
    int degree_;
  };


Praetorius, Simon's avatar
Praetorius, Simon committed
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
  ///////////////////////////////////////////////////////////////
  // test of AbstractFunction with arbitrary number of arguments
  
  #define ABSTRACT_FUNCTION_MACRO(z, n, _) \
   template< typename ReturnType, \
      BOOST_PP_ENUM_PARAMS_Z(z, n, typename T) \
   > class AbstractFunction ## n { \
    AbstractFunction ## n (int degree = 0) : \
      degree_(degree) \
    {} \
    virtual ~AbstractFunction ## n () {} \
    inline int getDegree() const \
    { \
      return degree_; \
    } \
    virtual ReturnType operator()(BOOST_PP_ENUM_BINARY_PARAMS_Z(z, n, const T, &t)) const = 0; \
    \
  protected: \
    int degree_; \
   }; \
   
//   template< typename ReturnType,
//     BOOST_PP_ENUM_PARAMS(N, typename T) // expands to typename T0, typename T1, typename T2...
//     >
//   class CONCAT_STR(AbstractFunction,N)
//   {
//   public:
//     CONCAT_STR(AbstractFunction,N)(int degree = 0) : 
//       degree_(degree) 
//     {}
// 
//     virtual ~CONCAT_STR(AbstractFunction,N)() {}
// 
//     /// Returns \ref degree_.
//     inline int getDegree() const 
//     { 
//       return degree_; 
//     }
// 
//     /// function evaluation.
//     virtual ReturnType operator()(BOOST_PP_ENUM_BINARY_PARAMS(N, const T, &t)) const = 0;
// 
//   protected:
//     int degree_;
//   };
  
  BOOST_PP_REPEAT_FROM_TO(1, 11, ABSTRACT_FUNCTION_MACRO, nil)
224
225
226
227
228


}

#endif // AMDIS_ABSTRACTFUNCTION_H