Salome HOME
Copyright update 2020
[tools/medcoupling.git] / src / INTERP_KERNEL / ExprEval / InterpKernelValue.hxx
1 // Copyright (C) 2007-2020  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 __INTERPKERNELVALUE_HXX__
22 #define __INTERPKERNELVALUE_HXX__
23
24 #include "INTERPKERNELDefines.hxx"
25 #include "InterpKernelException.hxx"
26 #include "InterpKernelUnit.hxx"
27
28 namespace INTERP_KERNEL
29 {
30   class INTERPKERNEL_EXPORT Value
31   {
32   public:
33     virtual Value *newInstance() const = 0;
34     virtual ~Value() { }
35     virtual void setDouble(double val) = 0;
36     virtual void setVarname(int fastPos, const std::string& var) = 0;
37     //unary
38     virtual void positive() = 0;
39     virtual void negate() = 0;
40     virtual void sqrt() = 0;
41     virtual void cos() = 0;
42     virtual void sin() = 0;
43     virtual void tan() = 0;
44     virtual void acos() = 0;
45     virtual void asin() = 0;
46     virtual void atan() = 0;
47     virtual void cosh() = 0;
48     virtual void sinh() = 0;
49     virtual void tanh() = 0;
50     virtual void abs() = 0;
51     virtual void exp() = 0;
52     virtual void ln() = 0;
53     virtual void log10() = 0;
54     //binary
55     virtual Value *plus(const Value *other) const = 0;
56     virtual Value *minus(const Value *other) const = 0;
57     virtual Value *mult(const Value *other) const = 0;
58     virtual Value *div(const Value *other) const = 0;
59     virtual Value *pow(const Value *other) const = 0;
60     virtual Value *max(const Value *other) const = 0;
61     virtual Value *min(const Value *other) const = 0;
62     virtual Value *greaterThan(const Value *other) const = 0;
63     virtual Value *lowerThan(const Value *other) const = 0;
64     //ternary
65     virtual Value *ifFunc(const Value *the, const Value *els) const = 0;
66   };
67
68   class INTERPKERNEL_EXPORT ValueDouble : public Value
69   {
70   public:
71     ValueDouble();
72     Value *newInstance() const;
73     void setDouble(double val);
74     void setVarname(int fastPos, const std::string& var);
75     //
76     double getData() const { return _data; }
77     void positive();
78     void negate();
79     void sqrt();
80     void cos();
81     void sin();
82     void tan();
83     void acos();
84     void asin();
85     void atan();
86     void cosh();
87     void sinh();
88     void tanh();
89     void abs();
90     void exp();
91     void ln();
92     void log10();
93     //
94     Value *plus(const Value *other) const;
95     Value *minus(const Value *other) const;
96     Value *mult(const Value *other) const;
97     Value *div(const Value *other) const;
98     Value *pow(const Value *other) const;
99     Value *max(const Value *other) const;
100     Value *min(const Value *other) const;
101     Value *greaterThan(const Value *other) const;
102     Value *lowerThan(const Value *other) const;
103     //
104     Value *ifFunc(const Value *the, const Value *els) const;
105   private:
106     ValueDouble(double val);
107     static const ValueDouble *checkSameType(const Value *val);
108   private:
109     double _data;
110   };
111
112   class ValueUnit : public Value
113   {
114   public:
115     INTERPKERNEL_EXPORT ValueUnit();
116     INTERPKERNEL_EXPORT Value *newInstance() const;
117     INTERPKERNEL_EXPORT void setDouble(double val);
118     INTERPKERNEL_EXPORT void setVarname(int fastPos, const std::string& var);
119     //
120     INTERPKERNEL_EXPORT DecompositionInUnitBase getData() const { return _data; }
121     INTERPKERNEL_EXPORT void positive();
122     INTERPKERNEL_EXPORT void negate();
123     INTERPKERNEL_EXPORT void sqrt();
124     INTERPKERNEL_EXPORT void cos();
125     INTERPKERNEL_EXPORT void sin();
126     INTERPKERNEL_EXPORT void tan();
127     INTERPKERNEL_EXPORT void acos();
128     INTERPKERNEL_EXPORT void asin();
129     INTERPKERNEL_EXPORT void atan();
130     INTERPKERNEL_EXPORT void cosh();
131     INTERPKERNEL_EXPORT void sinh();
132     INTERPKERNEL_EXPORT void tanh();
133     INTERPKERNEL_EXPORT void abs();
134     INTERPKERNEL_EXPORT void exp();
135     INTERPKERNEL_EXPORT void ln();
136     INTERPKERNEL_EXPORT void log10();
137     //
138     INTERPKERNEL_EXPORT Value *plus(const Value *other) const;
139     INTERPKERNEL_EXPORT Value *minus(const Value *other) const;
140     INTERPKERNEL_EXPORT Value *mult(const Value *other) const;
141     INTERPKERNEL_EXPORT Value *div(const Value *other) const;
142     INTERPKERNEL_EXPORT Value *pow(const Value *other) const;
143     INTERPKERNEL_EXPORT Value *max(const Value *other) const;
144     INTERPKERNEL_EXPORT Value *min(const Value *other) const;
145     INTERPKERNEL_EXPORT Value *greaterThan(const Value *other) const;
146     INTERPKERNEL_EXPORT Value *lowerThan(const Value *other) const;
147     //
148     INTERPKERNEL_EXPORT Value *ifFunc(const Value *the, const Value *els) const;
149   private:
150     ValueUnit(const DecompositionInUnitBase& unit);
151     static void unsupportedOp(const char *type);
152     static const ValueUnit *checkSameType(const Value *val);
153   private:
154     DecompositionInUnitBase _data;
155   };
156
157   class INTERPKERNEL_EXPORT ValueDoubleExpr : public Value
158   {
159   public:
160     ValueDoubleExpr(int szDestData, const double *srcData);
161     ~ValueDoubleExpr();
162     double *getData() const { return _dest_data; }
163     Value *newInstance() const;
164     void setDouble(double val);
165     void setVarname(int fastPos, const std::string& var);
166     //
167     void positive();
168     void negate();
169     void sqrt();
170     void cos();
171     void sin();
172     void tan();
173     void acos();
174     void asin();
175     void atan();
176     void cosh();
177     void sinh();
178     void tanh();
179     void abs();
180     void exp();
181     void ln();
182     void log10();
183     //
184     Value *plus(const Value *other) const;
185     Value *minus(const Value *other) const;
186     Value *mult(const Value *other) const;
187     Value *div(const Value *other) const;
188     Value *pow(const Value *other) const;
189     Value *max(const Value *other) const;
190     Value *min(const Value *other) const;
191     Value *greaterThan(const Value *other) const;
192     Value *lowerThan(const Value *other) const;
193     //
194     Value *ifFunc(const Value *the, const Value *els) const;
195   private:
196     int _sz_dest_data;
197     double *_dest_data;
198     const double *_src_data;
199   };
200 }
201
202 #endif