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