]> SALOME platform Git repositories - tools/medcoupling.git/blobdiff - src/INTERP_KERNEL/ExprEval/InterpKernelExprParser.hxx
Salome HOME
Missing wrap of appendFieldProfileFlatly
[tools/medcoupling.git] / src / INTERP_KERNEL / ExprEval / InterpKernelExprParser.hxx
index a5730415b5e0beea227e8365036532bcc358f6f1..b103645cc4f775c2aab0dd14a83dd08f186037a7 100644 (file)
@@ -1,9 +1,9 @@
-// Copyright (C) 2007-2013  CEA/DEN, EDF R&D
+// Copyright (C) 2007-2016  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -39,10 +39,12 @@ namespace INTERP_KERNEL
   {
   public:
     INTERPKERNEL_EXPORT virtual ~LeafExpr();
+    INTERPKERNEL_EXPORT virtual double getDoubleValue() const = 0;
     INTERPKERNEL_EXPORT virtual void fillValue(Value *val) const = 0;
     INTERPKERNEL_EXPORT virtual void compileX86(std::vector<std::string>& ass) const = 0;
     INTERPKERNEL_EXPORT virtual void compileX86_64(std::vector<std::string>& ass) const = 0;
     INTERPKERNEL_EXPORT virtual void replaceValues(const std::vector<double>& valuesInExpr) = 0;
+    INTERPKERNEL_EXPORT virtual LeafExpr *deepCopy() const = 0;
     INTERPKERNEL_EXPORT static LeafExpr *buildInstanceFrom(const std::string& expr);
   };
 
@@ -51,10 +53,12 @@ namespace INTERP_KERNEL
   public:
     INTERPKERNEL_EXPORT LeafExprVal(double value);
     INTERPKERNEL_EXPORT ~LeafExprVal();
+    INTERPKERNEL_EXPORT double getDoubleValue() const;
     INTERPKERNEL_EXPORT void compileX86(std::vector<std::string>& ass) const;
     INTERPKERNEL_EXPORT void compileX86_64(std::vector<std::string>& ass) const;
     INTERPKERNEL_EXPORT void fillValue(Value *val) const;
     INTERPKERNEL_EXPORT void replaceValues(const std::vector<double>& valuesInExpr);
+    INTERPKERNEL_EXPORT LeafExprVal *deepCopy() const;
   private:
     double _value;
   };
@@ -62,26 +66,69 @@ namespace INTERP_KERNEL
   class LeafExprVar : public LeafExpr
   {
   public:
+    INTERPKERNEL_EXPORT LeafExprVar(const LeafExprVar& other):_fast_pos(other._fast_pos),_ref_pos(other._ref_pos),_var_name(other._var_name),_val(other._val) { }
     INTERPKERNEL_EXPORT LeafExprVar(const std::string& var);
     INTERPKERNEL_EXPORT ~LeafExprVar();
+    INTERPKERNEL_EXPORT double getDoubleValue() const;
     INTERPKERNEL_EXPORT void compileX86(std::vector<std::string>& ass) const;
     INTERPKERNEL_EXPORT void compileX86_64(std::vector<std::string>& ass) const;
     INTERPKERNEL_EXPORT void fillValue(Value *val) const;
     INTERPKERNEL_EXPORT std::string getVar() const { return _var_name; }
     INTERPKERNEL_EXPORT void prepareExprEvaluation(const std::vector<std::string>& vars, int nbOfCompo, int targetNbOfCompo) const;
+    INTERPKERNEL_EXPORT void prepareExprEvaluationDouble(const std::vector<std::string>& vars, int nbOfCompo, int targetNbOfCompo, int refPos, const double *ptOfInputStart, const double *ptOfInputEnd) const;
     INTERPKERNEL_EXPORT void prepareExprEvaluationVec() const;
     INTERPKERNEL_EXPORT void replaceValues(const std::vector<double>& valuesInExpr);
     INTERPKERNEL_EXPORT static bool isRecognizedKeyVar(const std::string& var, int& pos);
+    INTERPKERNEL_EXPORT LeafExprVar *deepCopy() const;
   public:
     static const char END_OF_RECOGNIZED_VAR[];
   private:
     mutable int _fast_pos;
+    mutable int _ref_pos;
     std::string _var_name;
+    mutable const double *_val;
+  };
+
+  class ExprParserOfEval
+  {
+  public:
+    ExprParserOfEval():_leaf(0) { }
+    ExprParserOfEval(LeafExpr *leaf, const std::vector<ExprParserOfEval>& subParts, const std::vector<Function *>& funcs):_leaf(leaf),_sub_parts(subParts),_funcs(funcs) { }
+    void evaluateDoubleInternal(std::vector<double>& stck) const
+    {
+      if(_leaf)
+        stck.push_back(_leaf->getDoubleValue());
+      else
+        for(std::vector<ExprParserOfEval>::const_iterator iter=_sub_parts.begin();iter!=_sub_parts.end();iter++)
+          (*iter).evaluateDoubleInternal(stck);
+      for(std::vector<Function *>::const_iterator iter3=_funcs.begin();iter3!=_funcs.end();iter3++)
+        (*iter3)->operateStackOfDouble(stck);
+    }
+    void evaluateDoubleInternalSafe(std::vector<double>& stck) const
+    {
+      if(_leaf)
+        stck.push_back(_leaf->getDoubleValue());
+      else
+        for(std::vector<ExprParserOfEval>::const_iterator iter=_sub_parts.begin();iter!=_sub_parts.end();iter++)
+          (*iter).evaluateDoubleInternalSafe(stck);
+      for(std::vector<Function *>::const_iterator iter3=_funcs.begin();iter3!=_funcs.end();iter3++)
+        (*iter3)->operateStackOfDoubleSafe(stck);
+    }
+    void clearSortedMemory();
+    void sortMemory();
+  private:
+    LeafExpr *_leaf;
+    std::vector<ExprParserOfEval> _sub_parts;
+    std::vector<Function *> _funcs;
   };
 
   class ExprParser
   {
   public:
+#if __cplusplus >= 201103L
+    INTERPKERNEL_EXPORT ExprParser(ExprParser&& other);
+    INTERPKERNEL_EXPORT ExprParser& operator=(ExprParser&& other);
+#endif
     INTERPKERNEL_EXPORT ExprParser(const std::string& expr, ExprParser *father=0);
     INTERPKERNEL_EXPORT ExprParser(const char *expr, int lgth, ExprParser *father=0);
     INTERPKERNEL_EXPORT ~ExprParser();
@@ -90,8 +137,14 @@ namespace INTERP_KERNEL
     INTERPKERNEL_EXPORT double evaluate() const;
     INTERPKERNEL_EXPORT DecompositionInUnitBase evaluateUnit() const;
     INTERPKERNEL_EXPORT void prepareExprEvaluation(const std::vector<std::string>& vars, int nbOfCompo, int targetNbOfCompo) const;
-    INTERPKERNEL_EXPORT void evaluateExpr(int szOfOutParam, const double *inParam, double *outParam) const;
+    INTERPKERNEL_EXPORT void prepareExprEvaluationDouble(const std::vector<std::string>& vars, int nbOfCompo, int targetNbOfCompo, int refPos, const double *ptOfInputStart, const double *ptOfInputEnd) const;
+    INTERPKERNEL_EXPORT void prepareFastEvaluator() const;
     INTERPKERNEL_EXPORT void prepareExprEvaluationVec() const;
+    INTERPKERNEL_EXPORT double evaluateDouble() const;
+    INTERPKERNEL_EXPORT void evaluateDoubleInternal(std::vector<double>& stck) const { _for_eval.evaluateDoubleInternal(stck); }
+    INTERPKERNEL_EXPORT void evaluateDoubleInternalSafe(std::vector<double>& stck) const { _for_eval.evaluateDoubleInternalSafe(stck); }
+    INTERPKERNEL_EXPORT void checkForEvaluation() const;
+    INTERPKERNEL_EXPORT void evaluateExpr(int szOfOutParam, const double *inParam, double *outParam) const;
     INTERPKERNEL_EXPORT void getSetOfVars(std::set<std::string>& vars) const;
     INTERPKERNEL_EXPORT void getTrueSetOfVars(std::set<std::string>& vars) const;
     //
@@ -105,6 +158,8 @@ namespace INTERP_KERNEL
     INTERPKERNEL_EXPORT static std::string deleteWhiteSpaces(const std::string& expr);
   private:
     Value *evaluateLowLev(Value *valGen) const;
+    void reverseThis();
+    ExprParserOfEval convertMeTo() const;
   private:
     void prepareExprEvaluationVecLowLev() const;
     bool tryToInterpALeaf();
@@ -128,8 +183,9 @@ namespace INTERP_KERNEL
     LeafExpr *_leaf;
     bool _is_parsing_ok;
     std::string _expr;
-    std::list<ExprParser> _sub_expr;
-    std::list<Function *> _func_btw_sub_expr;
+    mutable ExprParserOfEval _for_eval;
+    std::vector<ExprParser> _sub_expr;
+    std::vector<Function *> _func_btw_sub_expr;
   private:
     static const int MAX_X86_FP_ST=8;
     static const char WHITE_SPACES[];