Salome HOME
f7f83e9b79c769a420dc52977b96589c2dcd6384
[tools/medcoupling.git] / src / INTERP_KERNEL / ExprEval / InterpKernelFunction.hxx
1 // Copyright (C) 2007-2015  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Author : Anthony Geay (CEA/DEN)
20
21 #ifndef __INTERPKERNELFUNCTION_HXX__
22 #define __INTERPKERNELFUNCTION_HXX__
23
24 #include "INTERPKERNELDefines.hxx"
25 #include "InterpKernelException.hxx"
26
27 #include <vector>
28
29 namespace INTERP_KERNEL
30 {
31   class Value;
32   class Function;
33
34   class INTERPKERNEL_EXPORT FunctionsFactory
35   {
36   public:
37     static Function *buildFuncFromString(const char *type, int nbOfParams);
38     static Function *buildUnaryFuncFromString(const char *type);
39     //static Function *buildUnaryFuncFromString(char type);
40     static Function *buildBinaryFuncFromString(const char *type);
41     static Function *buildBinaryFuncFromString(char type);
42     static Function *buildTernaryFuncFromString(const char *type);
43   };
44
45   class INTERPKERNEL_EXPORT Function
46   {
47   public:
48     virtual ~Function();
49     virtual int getNbInputParams() const = 0;
50     virtual void operate(std::vector<Value *>& stck) const = 0;
51     virtual void operateX86(std::vector<std::string>& asmb) const = 0;
52     virtual void operateStackOfDouble(std::vector<double>& stck) const = 0;
53     virtual void operateStackOfDoubleSafe(std::vector<double>& stck) const { operateStackOfDouble(stck); }
54     virtual const char *getRepr() const = 0;
55     virtual bool isACall() const = 0;
56     virtual Function *deepCopy() const = 0;
57   };
58
59   class INTERPKERNEL_EXPORT UnaryFunction : public Function
60   { 
61   public:
62     int getNbInputParams() const;
63   };
64
65   class INTERPKERNEL_EXPORT IdentityFunction : public UnaryFunction
66   {
67   public:
68     ~IdentityFunction();
69     void operate(std::vector<Value *>& stck) const;
70     void operateX86(std::vector<std::string>& asmb) const;
71     void operateStackOfDouble(std::vector<double>& stck) const;
72     const char *getRepr() const;
73     bool isACall() const;
74     IdentityFunction *deepCopy() const { return new IdentityFunction; }
75   public:
76     static const char REPR[];
77   };
78
79   class INTERPKERNEL_EXPORT PositiveFunction : public UnaryFunction
80   {
81   public:
82     ~PositiveFunction();
83     void operate(std::vector<Value *>& stck) const;
84     void operateX86(std::vector<std::string>& asmb) const;
85     void operateStackOfDouble(std::vector<double>& stck) const;
86     const char *getRepr() const;
87     bool isACall() const;
88     PositiveFunction *deepCopy() const { return new PositiveFunction; }
89   public:
90     static const char REPR[];
91   };
92
93   class INTERPKERNEL_EXPORT NegateFunction : public UnaryFunction
94   {
95   public:
96     ~NegateFunction();
97     void operate(std::vector<Value *>& stck) const;
98     void operateX86(std::vector<std::string>& asmb) const;
99     void operateStackOfDouble(std::vector<double>& stck) const;
100     const char *getRepr() const;
101     bool isACall() const;
102     NegateFunction *deepCopy() const { return new NegateFunction; }
103   public:
104     static const char REPR[];
105   };
106
107   class INTERPKERNEL_EXPORT CosFunction : public UnaryFunction
108   {
109   public:
110     ~CosFunction();
111     void operate(std::vector<Value *>& stck) const;
112     void operateX86(std::vector<std::string>& asmb) const;
113     void operateStackOfDouble(std::vector<double>& stck) const;
114     const char *getRepr() const;
115     bool isACall() const;
116     CosFunction *deepCopy() const { return new CosFunction; }
117   public:
118     static const char REPR[];
119   };
120
121   class INTERPKERNEL_EXPORT SinFunction : public UnaryFunction
122   {
123   public:
124     ~SinFunction();
125     void operate(std::vector<Value *>& stck) const;
126     void operateX86(std::vector<std::string>& asmb) const;
127     void operateStackOfDouble(std::vector<double>& stck) const;
128     const char *getRepr() const;
129     bool isACall() const;
130     SinFunction *deepCopy() const { return new SinFunction; }
131   public:
132     static const char REPR[];
133   };
134
135   class INTERPKERNEL_EXPORT TanFunction : public UnaryFunction
136   {
137   public:
138     ~TanFunction();
139     void operate(std::vector<Value *>& stck) const;
140     void operateX86(std::vector<std::string>& asmb) const;
141     void operateStackOfDouble(std::vector<double>& stck) const;
142     const char *getRepr() const;
143     bool isACall() const;
144     TanFunction *deepCopy() const { return new TanFunction; }
145   public:
146     static const char REPR[];
147   };
148
149   class INTERPKERNEL_EXPORT ACosFunction : public UnaryFunction
150   {
151   public:
152     ~ACosFunction();
153     void operate(std::vector<Value *>& stck) const;
154     void operateX86(std::vector<std::string>& asmb) const;
155     void operateStackOfDouble(std::vector<double>& stck) const;
156     void operateStackOfDoubleSafe(std::vector<double>& stck) const;
157     const char *getRepr() const;
158     bool isACall() const;
159     ACosFunction *deepCopy() const { return new ACosFunction; }
160   public:
161     static const char REPR[];
162   };
163
164   class INTERPKERNEL_EXPORT ASinFunction : public UnaryFunction
165   {
166   public:
167     ~ASinFunction();
168     void operate(std::vector<Value *>& stck) const;
169     void operateX86(std::vector<std::string>& asmb) const;
170     void operateStackOfDouble(std::vector<double>& stck) const;
171     void operateStackOfDoubleSafe(std::vector<double>& stck) const;
172     const char *getRepr() const;
173     bool isACall() const;
174     ASinFunction *deepCopy() const { return new ASinFunction; }
175   public:
176     static const char REPR[];
177   };
178
179   class INTERPKERNEL_EXPORT ATanFunction : public UnaryFunction
180   {
181   public:
182     ~ATanFunction();
183     void operate(std::vector<Value *>& stck) const;
184     void operateX86(std::vector<std::string>& asmb) const;
185     void operateStackOfDouble(std::vector<double>& stck) const;
186     const char *getRepr() const;
187     bool isACall() const;
188     ATanFunction *deepCopy() const { return new ATanFunction; }
189   public:
190     static const char REPR[];
191   };
192
193   class INTERPKERNEL_EXPORT CoshFunction : public UnaryFunction
194   {
195   public:
196     ~CoshFunction();
197     void operate(std::vector<Value *>& stck) const;
198     void operateX86(std::vector<std::string>& asmb) const;
199     void operateStackOfDouble(std::vector<double>& stck) const;
200     const char *getRepr() const;
201     bool isACall() const;
202     CoshFunction *deepCopy() const { return new CoshFunction; }
203   public:
204     static const char REPR[];
205   };
206
207   class INTERPKERNEL_EXPORT SinhFunction : public UnaryFunction
208   {
209   public:
210     ~SinhFunction();
211     void operate(std::vector<Value *>& stck) const;
212     void operateX86(std::vector<std::string>& asmb) const;
213     void operateStackOfDouble(std::vector<double>& stck) const;
214     const char *getRepr() const;
215     bool isACall() const;
216     SinhFunction *deepCopy() const { return new SinhFunction; }
217   public:
218     static const char REPR[];
219   };
220
221   class INTERPKERNEL_EXPORT TanhFunction : public UnaryFunction
222   {
223   public:
224     ~TanhFunction();
225     void operate(std::vector<Value *>& stck) const;
226     void operateX86(std::vector<std::string>& asmb) const;
227     void operateStackOfDouble(std::vector<double>& stck) const;
228     const char *getRepr() const;
229     bool isACall() const;
230     TanhFunction *deepCopy() const { return new TanhFunction; }
231   public:
232     static const char REPR[];
233   };
234
235   class INTERPKERNEL_EXPORT SqrtFunction : public UnaryFunction
236   {
237   public:
238     ~SqrtFunction();
239     void operateX86(std::vector<std::string>& asmb) const;
240     void operate(std::vector<Value *>& stck) const;
241     void operateStackOfDouble(std::vector<double>& stck) const;
242     void operateStackOfDoubleSafe(std::vector<double>& stck) const;
243     const char *getRepr() const;
244     bool isACall() const;
245     SqrtFunction *deepCopy() const { return new SqrtFunction; }
246   public:
247     static const char REPR[];
248   };
249
250   class INTERPKERNEL_EXPORT AbsFunction : public UnaryFunction
251   {
252   public:
253     ~AbsFunction();
254     void operate(std::vector<Value *>& stck) const;
255     void operateX86(std::vector<std::string>& asmb) const;
256     void operateStackOfDouble(std::vector<double>& stck) const;
257     const char *getRepr() const;
258     bool isACall() const;
259     AbsFunction *deepCopy() const { return new AbsFunction; }
260   public:
261     static const char REPR[];
262   };
263
264   class INTERPKERNEL_EXPORT ExpFunction : public UnaryFunction
265   {
266   public:
267     ~ExpFunction();
268     void operate(std::vector<Value *>& stck) const;
269     void operateX86(std::vector<std::string>& asmb) const;
270     void operateStackOfDouble(std::vector<double>& stck) const;
271     const char *getRepr() const;
272     bool isACall() const;
273     ExpFunction *deepCopy() const { return new ExpFunction; }
274   public:
275     static const char REPR[];
276   };
277
278   class INTERPKERNEL_EXPORT LnFunction : public UnaryFunction
279   {
280   public:
281     ~LnFunction();
282     void operate(std::vector<Value *>& stck) const;
283     void operateX86(std::vector<std::string>& asmb) const;
284     void operateStackOfDouble(std::vector<double>& stck) const;
285     void operateStackOfDoubleSafe(std::vector<double>& stck) const;
286     const char *getRepr() const;
287     bool isACall() const;
288     LnFunction *deepCopy() const { return new LnFunction; }
289   public:
290     static const char REPR[];
291   };
292
293   class INTERPKERNEL_EXPORT LogFunction : public UnaryFunction
294   {
295   public:
296     ~LogFunction();
297     void operate(std::vector<Value *>& stck) const;
298     void operateX86(std::vector<std::string>& asmb) const;
299     void operateStackOfDouble(std::vector<double>& stck) const;
300     void operateStackOfDoubleSafe(std::vector<double>& stck) const;
301     const char *getRepr() const;
302     bool isACall() const;
303     LogFunction *deepCopy() const { return new LogFunction; }
304   public:
305     static const char REPR[];
306   };
307
308   class INTERPKERNEL_EXPORT Log10Function : public UnaryFunction
309   {
310   public:
311     ~Log10Function();
312     void operate(std::vector<Value *>& stck) const;
313     void operateX86(std::vector<std::string>& asmb) const;
314     void operateStackOfDouble(std::vector<double>& stck) const;
315     void operateStackOfDoubleSafe(std::vector<double>& stck) const;
316     const char *getRepr() const;
317     bool isACall() const;
318     Log10Function *deepCopy() const { return new Log10Function; }
319   public:
320     static const char REPR[];
321   };
322
323   class INTERPKERNEL_EXPORT BinaryFunction : public Function
324   {
325   public:
326     int getNbInputParams() const;
327   };
328
329   class PlusFunction : public BinaryFunction
330   {
331   public:
332     ~PlusFunction();
333     void operate(std::vector<Value *>& stck) const;
334     void operateX86(std::vector<std::string>& asmb) const;
335     void operateStackOfDouble(std::vector<double>& stck) const;
336     const char *getRepr() const;
337     bool isACall() const;
338     PlusFunction *deepCopy() const { return new PlusFunction; }
339   public:
340     static const char REPR[];
341   };
342
343   class INTERPKERNEL_EXPORT MinusFunction : public BinaryFunction
344   {
345   public:
346     ~MinusFunction();
347     void operate(std::vector<Value *>& stck) const;
348     void operateX86(std::vector<std::string>& asmb) const;
349     void operateStackOfDouble(std::vector<double>& stck) const;
350     const char *getRepr() const;
351     bool isACall() const;
352     MinusFunction *deepCopy() const { return new MinusFunction; }
353   public:
354     static const char REPR[];
355   };
356
357   class INTERPKERNEL_EXPORT MultFunction : public BinaryFunction
358   {
359   public:
360     ~MultFunction();
361     void operate(std::vector<Value *>& stck) const;
362     void operateX86(std::vector<std::string>& asmb) const;
363     void operateStackOfDouble(std::vector<double>& stck) const;
364     const char *getRepr() const;
365     bool isACall() const;
366     MultFunction *deepCopy() const { return new MultFunction; }
367   public:
368     static const char REPR[];
369   };
370   
371   class INTERPKERNEL_EXPORT DivFunction : public BinaryFunction
372   {
373   public:
374     ~DivFunction();
375     void operate(std::vector<Value *>& stck) const;
376     void operateX86(std::vector<std::string>& asmb) const;
377     void operateStackOfDouble(std::vector<double>& stck) const;
378     void operateStackOfDoubleSafe(std::vector<double>& stck) const;
379     const char *getRepr() const;
380     bool isACall() const;
381     DivFunction *deepCopy() const { return new DivFunction; }
382   public:
383     static const char REPR[];
384   };
385
386   class INTERPKERNEL_EXPORT PowFunction : public BinaryFunction
387   {
388   public:
389     ~PowFunction();
390     void operate(std::vector<Value *>& stck) const;
391     void operateX86(std::vector<std::string>& asmb) const;
392     void operateStackOfDouble(std::vector<double>& stck) const;
393     void operateStackOfDoubleSafe(std::vector<double>& stck) const;
394     const char *getRepr() const;
395     bool isACall() const;
396     PowFunction *deepCopy() const { return new PowFunction; }
397   public:
398     static const char REPR[];
399   };
400
401   class INTERPKERNEL_EXPORT MaxFunction : public BinaryFunction
402   {
403   public:
404     ~MaxFunction();
405     void operate(std::vector<Value *>& stck) const;
406     void operateX86(std::vector<std::string>& asmb) const;
407     void operateStackOfDouble(std::vector<double>& stck) const;
408     const char *getRepr() const;
409     bool isACall() const;
410     MaxFunction *deepCopy() const { return new MaxFunction; }
411   public:
412     static const char REPR[];
413   };
414
415   class INTERPKERNEL_EXPORT MinFunction : public BinaryFunction
416   {
417   public:
418     ~MinFunction();
419     void operate(std::vector<Value *>& stck) const;
420     void operateX86(std::vector<std::string>& asmb) const;
421     void operateStackOfDouble(std::vector<double>& stck) const;
422     const char *getRepr() const;
423     bool isACall() const;
424     MinFunction *deepCopy() const { return new MinFunction; }
425   public:
426     static const char REPR[];
427   };
428
429   class INTERPKERNEL_EXPORT GreaterThanFunction : public BinaryFunction
430   {
431   public:
432     ~GreaterThanFunction();
433     void operate(std::vector<Value *>& stck) const;
434     void operateX86(std::vector<std::string>& asmb) const;
435     void operateStackOfDouble(std::vector<double>& stck) const;
436     const char *getRepr() const;
437     bool isACall() const;
438     GreaterThanFunction *deepCopy() const { return new GreaterThanFunction; }
439   public:
440     static const char REPR[];
441   };
442
443   class INTERPKERNEL_EXPORT LowerThanFunction : public BinaryFunction
444   {
445   public:
446     ~LowerThanFunction();
447     void operate(std::vector<Value *>& stck) const;
448     void operateX86(std::vector<std::string>& asmb) const;
449     void operateStackOfDouble(std::vector<double>& stck) const;
450     const char *getRepr() const;
451     bool isACall() const;
452     LowerThanFunction *deepCopy() const { return new LowerThanFunction; }
453   public:
454     static const char REPR[];
455   };
456
457   class INTERPKERNEL_EXPORT TernaryFunction : public Function
458   {
459   public:
460     int getNbInputParams() const;
461   };
462
463   class INTERPKERNEL_EXPORT IfFunction : public TernaryFunction
464   {
465   public:
466     ~IfFunction();
467     void operate(std::vector<Value *>& stck) const;
468     void operateX86(std::vector<std::string>& asmb) const;
469     void operateStackOfDouble(std::vector<double>& stck) const;
470     void operateStackOfDoubleSafe(std::vector<double>& stck) const;
471     const char *getRepr() const;
472     bool isACall() const;
473     IfFunction *deepCopy() const { return new IfFunction; }
474   public:
475     static const char REPR[];
476   };
477 }
478
479 #endif