1 // Copyright (C) 2007-2014 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Anthony Geay (CEA/DEN)
21 #include "InterpKernelFunction.hxx"
22 #include "InterpKernelValue.hxx"
26 using namespace INTERP_KERNEL;
28 const char IdentityFunction::REPR[]="Id";
30 const char PositiveFunction::REPR[]="+";
32 const char NegateFunction::REPR[]="-";
34 const char CosFunction::REPR[]="cos";
36 const char SinFunction::REPR[]="sin";
38 const char TanFunction::REPR[]="tan";
40 const char ACosFunction::REPR[]="acos";
42 const char ASinFunction::REPR[]="asin";
44 const char ATanFunction::REPR[]="atan";
46 const char CoshFunction::REPR[]="cosh";
48 const char SinhFunction::REPR[]="sinh";
50 const char TanhFunction::REPR[]="tanh";
52 const char SqrtFunction::REPR[]="sqrt";
54 const char AbsFunction::REPR[]="abs";
56 const char PlusFunction::REPR[]="+";
58 const char MinusFunction::REPR[]="-";
60 const char MultFunction::REPR[]="*";
62 const char DivFunction::REPR[]="/";
64 const char PowFunction::REPR[]="^";
66 const char ExpFunction::REPR[]="exp";
68 const char LnFunction::REPR[]="ln";
70 const char LogFunction::REPR[]="log";
72 const char Log10Function::REPR[]="log10";
74 const char MaxFunction::REPR[]="max";
76 const char MinFunction::REPR[]="min";
78 const char GreaterThanFunction::REPR[]=">";
80 const char LowerThanFunction::REPR[]="<";
82 const char IfFunction::REPR[]="if";
84 Function *FunctionsFactory::buildFuncFromString(const char *type, int nbOfParams)
89 return buildUnaryFuncFromString(type);
91 return buildBinaryFuncFromString(type);
93 return buildTernaryFuncFromString(type);
95 throw INTERP_KERNEL::Exception("Invalid number of params detected : limited to 2 !");
99 Function *FunctionsFactory::buildUnaryFuncFromString(const char *type)
101 std::string tmp(type);
103 return new IdentityFunction;
104 if(tmp==CosFunction::REPR)
105 return new CosFunction;
106 if(tmp==SinFunction::REPR)
107 return new SinFunction;
108 if(tmp==TanFunction::REPR)
109 return new TanFunction;
110 if(tmp==ACosFunction::REPR)
111 return new ACosFunction;
112 if(tmp==ASinFunction::REPR)
113 return new ASinFunction;
114 if(tmp==ATanFunction::REPR)
115 return new ATanFunction;
116 if(tmp==CoshFunction::REPR)
117 return new CoshFunction;
118 if(tmp==SinhFunction::REPR)
119 return new SinhFunction;
120 if(tmp==TanhFunction::REPR)
121 return new TanhFunction;
122 if(tmp==SqrtFunction::REPR)
123 return new SqrtFunction;
124 if(tmp==AbsFunction::REPR)
125 return new AbsFunction;
126 if(tmp==PositiveFunction::REPR)
127 return new PositiveFunction;
128 if(tmp==NegateFunction::REPR)
129 return new NegateFunction;
130 if(tmp==ExpFunction::REPR)
131 return new ExpFunction;
132 if(tmp==LnFunction::REPR)
133 return new LnFunction;
134 if(tmp==LogFunction::REPR)
135 return new LogFunction;
136 if(tmp==Log10Function::REPR)
137 return new Log10Function;
139 std::string msg("Invalid unary function detected : \"");
140 msg+=type; msg+="\"";
141 throw INTERP_KERNEL::Exception(msg.c_str());
144 Function *FunctionsFactory::buildBinaryFuncFromString(const char *type)
146 std::string tmp(type);
147 if(tmp==PositiveFunction::REPR)
148 return new PlusFunction;
149 if(tmp==NegateFunction::REPR)
150 return new MinusFunction;
151 if(tmp==MultFunction::REPR)
152 return new MultFunction;
153 if(tmp==DivFunction::REPR)
154 return new DivFunction;
155 if(tmp==PowFunction::REPR)
156 return new PowFunction;
157 if(tmp==MaxFunction::REPR)
158 return new MaxFunction;
159 if(tmp==MinFunction::REPR)
160 return new MinFunction;
161 if(tmp==GreaterThanFunction::REPR)
162 return new GreaterThanFunction;
163 if(tmp==LowerThanFunction::REPR)
164 return new LowerThanFunction;
165 std::string msg("Invalid binary function detected : \"");
166 msg+=type; msg+="\"";
167 throw INTERP_KERNEL::Exception(msg.c_str());
170 Function *FunctionsFactory::buildTernaryFuncFromString(const char *type)
172 std::string tmp(type);
173 if(tmp==IfFunction::REPR)
174 return new IfFunction();
175 std::string msg("Invalid ternary function detected : \"");
176 msg+=type; msg+="\"";
177 throw INTERP_KERNEL::Exception(msg.c_str());
180 Function *FunctionsFactory::buildBinaryFuncFromString(char type)
182 char tmp[2]; tmp[0]=type; tmp[1]='\0';
183 return buildBinaryFuncFromString(tmp);
186 Function::~Function()
190 IdentityFunction::~IdentityFunction()
194 void IdentityFunction::operate(std::vector<Value *>& stack) const
198 void IdentityFunction::operateX86(std::vector<std::string>& asmb) const
202 const char *IdentityFunction::getRepr() const
207 bool IdentityFunction::isACall() const
212 PositiveFunction::~PositiveFunction()
216 int UnaryFunction::getNbInputParams() const
221 void PositiveFunction::operate(std::vector<Value *>& stack) const
225 void PositiveFunction::operateX86(std::vector<std::string>& asmb) const
229 const char *PositiveFunction::getRepr() const
234 bool PositiveFunction::isACall() const
239 NegateFunction::~NegateFunction()
243 void NegateFunction::operate(std::vector<Value *>& stack) const
245 Value *val=stack.back();
249 void NegateFunction::operateX86(std::vector<std::string>& asmb) const
251 asmb.push_back("fchs");
254 const char *NegateFunction::getRepr() const
259 bool NegateFunction::isACall() const
264 CosFunction::~CosFunction()
268 void CosFunction::operate(std::vector<Value *>& stack) const
270 Value *val=stack.back();
274 void CosFunction::operateX86(std::vector<std::string>& asmb) const
276 asmb.push_back("fcos");
279 const char *CosFunction::getRepr() const
284 bool CosFunction::isACall() const
289 SinFunction::~SinFunction()
293 void SinFunction::operate(std::vector<Value *>& stack) const
295 Value *val=stack.back();
299 void SinFunction::operateX86(std::vector<std::string>& asmb) const
301 asmb.push_back("fsin");
304 const char *SinFunction::getRepr() const
309 bool SinFunction::isACall() const
314 TanFunction::~TanFunction()
318 void TanFunction::operate(std::vector<Value *>& stack) const
320 Value *val=stack.back();
324 void TanFunction::operateX86(std::vector<std::string>& asmb) const
326 throw INTERP_KERNEL::Exception("Assembly Not implemented yet !");
329 const char *TanFunction::getRepr() const
334 bool TanFunction::isACall() const
339 ACosFunction::~ACosFunction()
343 void ACosFunction::operate(std::vector<Value *>& stack) const
345 Value *val=stack.back();
349 void ACosFunction::operateX86(std::vector<std::string>& asmb) const
351 throw INTERP_KERNEL::Exception("Assembly Not implemented yet !");
354 const char *ACosFunction::getRepr() const
359 bool ACosFunction::isACall() const
364 ASinFunction::~ASinFunction()
368 void ASinFunction::operate(std::vector<Value *>& stack) const
370 Value *val=stack.back();
374 void ASinFunction::operateX86(std::vector<std::string>& asmb) const
376 throw INTERP_KERNEL::Exception("Assembly Not implemented yet !");
379 const char *ASinFunction::getRepr() const
384 bool ASinFunction::isACall() const
389 ATanFunction::~ATanFunction()
393 void ATanFunction::operate(std::vector<Value *>& stack) const
395 Value *val=stack.back();
399 void ATanFunction::operateX86(std::vector<std::string>& asmb) const
401 throw INTERP_KERNEL::Exception("Assembly Not implemented yet !");
404 const char *ATanFunction::getRepr() const
409 bool ATanFunction::isACall() const
414 CoshFunction::~CoshFunction()
418 void CoshFunction::operate(std::vector<Value *>& stack) const
420 Value *val=stack.back();
424 void CoshFunction::operateX86(std::vector<std::string>& asmb) const
426 throw INTERP_KERNEL::Exception("Assembly Not implemented yet !");
429 const char *CoshFunction::getRepr() const
434 bool CoshFunction::isACall() const
439 SinhFunction::~SinhFunction()
443 void SinhFunction::operate(std::vector<Value *>& stack) const
445 Value *val=stack.back();
449 void SinhFunction::operateX86(std::vector<std::string>& asmb) const
451 throw INTERP_KERNEL::Exception("Assembly Not implemented yet !");
454 const char *SinhFunction::getRepr() const
459 bool SinhFunction::isACall() const
464 TanhFunction::~TanhFunction()
468 void TanhFunction::operate(std::vector<Value *>& stack) const
470 Value *val=stack.back();
474 void TanhFunction::operateX86(std::vector<std::string>& asmb) const
476 throw INTERP_KERNEL::Exception("Assembly Not implemented yet !");
479 const char *TanhFunction::getRepr() const
484 bool TanhFunction::isACall() const
489 SqrtFunction::~SqrtFunction()
493 void SqrtFunction::operate(std::vector<Value *>& stack) const
495 Value *val=stack.back();
499 void SqrtFunction::operateX86(std::vector<std::string>& asmb) const
501 asmb.push_back("fsqrt");
504 const char *SqrtFunction::getRepr() const
509 bool SqrtFunction::isACall() const
514 AbsFunction::~AbsFunction()
518 void AbsFunction::operate(std::vector<Value *>& stack) const
520 Value *val=stack.back();
524 void AbsFunction::operateX86(std::vector<std::string>& asmb) const
526 asmb.push_back("fabs");
529 const char *AbsFunction::getRepr() const
534 bool AbsFunction::isACall() const
539 void ExpFunction::operate(std::vector<Value *>& stack) const
541 Value *val=stack.back();
545 void ExpFunction::operateX86(std::vector<std::string>& asmb) const
547 throw INTERP_KERNEL::Exception("Assembly Not implemented yet !");
550 const char *ExpFunction::getRepr() const
555 bool ExpFunction::isACall() const
560 LnFunction::~LnFunction()
564 void LnFunction::operate(std::vector<Value *>& stack) const
566 Value *val=stack.back();
570 void LnFunction::operateX86(std::vector<std::string>& asmb) const
572 throw INTERP_KERNEL::Exception("Assembly Not implemented yet !");
575 const char *LnFunction::getRepr() const
580 bool LnFunction::isACall() const
585 LogFunction::~LogFunction()
589 void LogFunction::operate(std::vector<Value *>& stack) const
591 Value *val=stack.back();
595 void LogFunction::operateX86(std::vector<std::string>& asmb) const
597 throw INTERP_KERNEL::Exception("Assembly for log Not implemented yet !");
600 const char *LogFunction::getRepr() const
605 bool LogFunction::isACall() const
610 Log10Function::~Log10Function()
614 void Log10Function::operate(std::vector<Value *>& stack) const
616 Value *val=stack.back();
620 void Log10Function::operateX86(std::vector<std::string>& asmb) const
622 throw INTERP_KERNEL::Exception("Assembly for log Not implemented yet !");
625 const char *Log10Function::getRepr() const
630 bool Log10Function::isACall() const
635 int BinaryFunction::getNbInputParams() const
640 PlusFunction::~PlusFunction()
644 void PlusFunction::operate(std::vector<Value *>& stack) const
646 Value *val1=stack.back();
648 Value *& val2=stack.back();
652 val3=val1->plus(val2);
654 catch(INTERP_KERNEL::Exception& e)
664 void PlusFunction::operateX86(std::vector<std::string>& asmb) const
666 asmb.push_back("faddp st1");
669 const char *PlusFunction::getRepr() const
674 bool PlusFunction::isACall() const
679 MinusFunction::~MinusFunction()
683 void MinusFunction::operate(std::vector<Value *>& stack) const
685 Value *val1=stack.back();
687 Value *& val2=stack.back();
691 val3=val1->minus(val2);
693 catch(INTERP_KERNEL::Exception& e)
703 void MinusFunction::operateX86(std::vector<std::string>& asmb) const
705 asmb.push_back("fsubp st1");
708 const char *MinusFunction::getRepr() const
713 bool MinusFunction::isACall() const
718 MultFunction::~MultFunction()
722 void MultFunction::operate(std::vector<Value *>& stack) const
724 Value *val1=stack.back();
726 Value *& val2=stack.back();
727 Value *val3=val1->mult(val2);
733 void MultFunction::operateX86(std::vector<std::string>& asmb) const
735 asmb.push_back("fmulp st1");
738 const char *MultFunction::getRepr() const
743 bool MultFunction::isACall() const
748 DivFunction::~DivFunction()
752 void DivFunction::operate(std::vector<Value *>& stack) const
754 Value *val1=stack.back();
756 Value *& val2=stack.back();
760 val3=val1->div(val2);
762 catch(INTERP_KERNEL::Exception& e)
772 void DivFunction::operateX86(std::vector<std::string>& asmb) const
774 asmb.push_back("fdivp st1");
777 const char *DivFunction::getRepr() const
782 bool DivFunction::isACall() const
787 PowFunction::~PowFunction()
791 void PowFunction::operate(std::vector<Value *>& stack) const
793 Value *val1=stack.back();
795 Value *& val2=stack.back();
799 val3=val1->pow(val2);
801 catch(INTERP_KERNEL::Exception& e)
811 void PowFunction::operateX86(std::vector<std::string>& asmb) const
813 throw INTERP_KERNEL::Exception("Assembly Not implemented yet !");
816 const char *PowFunction::getRepr() const
821 bool PowFunction::isACall() const
826 ExpFunction::~ExpFunction()
830 MaxFunction::~MaxFunction()
834 void MaxFunction::operate(std::vector<Value *>& stack) const
836 Value *val1=stack.back();
838 Value *& val2=stack.back();
842 val3=val1->max(val2);
844 catch(INTERP_KERNEL::Exception& e)
854 void MaxFunction::operateX86(std::vector<std::string>& asmb) const
856 throw INTERP_KERNEL::Exception("Assembly Not implemented yet !");
859 const char *MaxFunction::getRepr() const
864 bool MaxFunction::isACall() const
869 MinFunction::~MinFunction()
873 void MinFunction::operate(std::vector<Value *>& stack) const
875 Value *val1=stack.back();
877 Value *& val2=stack.back();
881 val3=val1->min(val2);
883 catch(INTERP_KERNEL::Exception& e)
893 void MinFunction::operateX86(std::vector<std::string>& asmb) const
895 throw INTERP_KERNEL::Exception("Assembly Not implemented yet !");
898 const char *MinFunction::getRepr() const
903 bool MinFunction::isACall() const
908 GreaterThanFunction::~GreaterThanFunction()
912 void GreaterThanFunction::operate(std::vector<Value *>& stack) const
914 Value *val1=stack.back();
916 Value *& val2=stack.back();
920 val3=val1->greaterThan(val2);
922 catch(INTERP_KERNEL::Exception& e)
932 void GreaterThanFunction::operateX86(std::vector<std::string>& asmb) const
934 throw INTERP_KERNEL::Exception("Assembly Not implemented yet !");
937 const char *GreaterThanFunction::getRepr() const
942 bool GreaterThanFunction::isACall() const
947 LowerThanFunction::~LowerThanFunction()
951 void LowerThanFunction::operate(std::vector<Value *>& stack) const
953 Value *val1=stack.back();
955 Value *& val2=stack.back();
959 val3=val1->lowerThan(val2);
961 catch(INTERP_KERNEL::Exception& e)
971 void LowerThanFunction::operateX86(std::vector<std::string>& asmb) const
973 throw INTERP_KERNEL::Exception("Assembly Not implemented yet !");
976 const char *LowerThanFunction::getRepr() const
981 bool LowerThanFunction::isACall() const
986 int TernaryFunction::getNbInputParams() const
991 IfFunction::~IfFunction()
995 void IfFunction::operate(std::vector<Value *>& stack) const
997 Value *val1=stack.back();
999 Value *val2=stack.back();
1001 Value *&val3=stack.back();
1005 val4=val1->ifFunc(val2,val3);
1007 catch(INTERP_KERNEL::Exception& e)
1019 void IfFunction::operateX86(std::vector<std::string>& asmb) const
1021 throw INTERP_KERNEL::Exception("Assembly Not implemented yet !");
1024 const char *IfFunction::getRepr() const
1029 bool IfFunction::isACall() const