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